Content
# Tool List
This is a WeChat Official Account MCP server based on the FastMCP framework, providing a series of practical WeChat Official Account API interface encapsulations, including draft creation, publishing, deletion, and other functions.
## Project Introduction
This project uses Python and the FastMCP framework to provide WeChat Official Account management APIs through the Model Control Protocol (MCP) specification, which can be easily integrated into various AI systems and automated workflows, helping users manage WeChat Official Account content conveniently.
## Project Background and Architecture Changes
Originally, the server program was deployed on platforms like Coze and ModelScope. However, since these platforms provided server IPs that were often non-fixed, they couldn't be added to the whitelist of WeChat Official Accounts.
The solution was to split the code into two parts:
1. **Server functionality**: Moved to a personal cloud server with a fixed IP, solving the whitelist problem.
2. **MCP code**: Can be hosted anywhere.
If you need to deploy locally to ensure data security, the code repository that implements the WeChat Official Account API call function is also included, and you can deploy it completely locally. The project address is: [https://github.com/kakaxi3019/wechat_oa_api_mcp](https://github.com/kakaxi3019/wechat_oa_api_mcp)
## WeChat Official Platform
The official website of WeChat Official Platform: [https://mp.weixin.qq.com](https://mp.weixin.qq.com)
You need to register and create an Official Account on the WeChat Official Platform, obtain the developer ID (AppID) and key (AppSecret) to use this tool.
## Installation Method
### Install using pip
```bash
pip install wechat_oa_mcp
```
## Project Structure
```
./
├── README.md # Project documentation
├── examples/ # Usage examples
│ └── simple_usage.py # Simple usage example
├── setup.py # Installation configuration
├── pyproject.toml # Python project configuration
└── wechat_oa_mcp/ # Package main directory
├── __init__.py # Package initialization file
├── __main__.py # Module direct execution entry
├── cli.py # Command-line tool entry
└── server.py # Main functional code
```
## Dependencies
- Python 3.10+
- fastmcp
- requests
## Function List
This server provides the following functions:
- **Get WeChat Access Token**: Get interface call credentials
- **Create WeChat Official Account Draft**: Create a graphic message draft
- **Publish WeChat Official Account Draft**: Publish the draft to the Official Account
- **Delete WeChat Official Account Draft**: Delete unpublished drafts
- **Delete Permanent Material**: Delete permanent materials in the Official Account
## API Interface Description
### 1. Get Access Token
```python
WeChat_get_access_token
```
**Input parameters:**
```json
AppID: String·Third-party user unique credential (obtained in WeChat Official Platform - Settings and Development - Development Interface Management)
AppSecret: String·Third-party user unique credential key (obtained in WeChat Official Platform - Settings and Development - Development Interface Management)
```
**Output:**
```json
{
"success": true,
"error": null,
"access_token": "Obtained access_token",
"expires_in": 7200
}
```
### 2. Create Draft
```python
WeChat_create_draft
```
**Input parameters:**
```json
access_token: String·Your access_token, call interface credentials, can be obtained through WeChat_get_access_token
image_url: String·Cover picture URL
title: String·Article title
content: String·Specific content of the graphic message, support HTML tags, must be less than 20,000 characters, less than 1M
author: String·(Optional) Author name
digest: String·(Optional) Summary of the graphic message, only single graphic messages have summaries, multiple graphic messages are empty here. If this field is not filled, the first 54 characters of the main text will be captured by default.
content_source_url: String·(Optional) Original address of the graphic message, that is, the URL after clicking "Read Original"
need_open_comment: Integer·(Optional) Uint32 Whether to open comments, 0 not open (default), 1 open
```
**Output:**
```json
{
"success": true,
"error": null,
"draft_media_id": "Media ID of the draft",
"image_media_id": "Media ID of the cover picture"
}
```
### 3. Publish Draft
```python
WeChat_publish_draft
```
**Input parameters:**
```json
access_token: String·Call interface credentials, can be obtained through WeChat_get_access_token
draft_media_id: String·draft_media_id returned after calling WeChat_create_draft
```
**Output:**
```json
{
"success": true,
"error": null,
"errmsg": "ok",
"publish_id": "Publish task ID"
}
```
### 4. Delete Draft
```python
WeChat_del_draft
```
**Input parameters:**
```json
access_token: String·Call interface credentials, can be obtained through WeChat_get_access_token
media_id: String·Draft corresponding credential, that is, draft_media_id returned by WeChat_create_draft
```
**Output:**
```json
{
"success": true,
"error": null,
"errcode": 0,
"errmsg": "ok"
}
```
### 5. Delete Permanent Material
```python
WeChat_del_material
```
**Input parameters:**
```json
access_token: String·Call interface credentials, can be obtained through WeChat_get_access_token
media_id: String·Permanent material corresponding credential, that is, image_media_id returned by WeChat_create_draft
```
**Output:**
```json
{
"success": true,
"error": null,
"errcode": 0,
"errmsg": "ok"
}
```
## Usage Method
### 1. Install Server
```bash
# Install through pip
pip install wechat_oa_mcp
```
### 2. Call MCP Server in Several Ways
#### 2.1 Call through Code
You can directly call the WeChat MCP API in Python code (just complete the installation steps):
```python
from wechat_oa_mcp import (
WeChat_get_access_token,
WeChat_create_draft,
WeChat_publish_draft,
WeChat_del_draft,
WeChat_del_material
)
# Get access_token
token_result = WeChat_get_access_token({
"AppID": "Your WeChat AppID",
"AppSecret": "Your WeChat AppSecret"
})
if token_result["success"]:
access_token = token_result["access_token"]
# Create draft
draft_result = WeChat_create_draft({
"access_token": access_token,
"image_url": "https://example.com/image.jpg",
"title": "Test article title",
"content": "<p>This is the article content</p>",
"author": "Author name"
})
if draft_result["success"]:
draft_id = draft_result["draft_media_id"]
image_id = draft_result["image_media_id"]
# Publish draft
publish_result = WeChat_publish_draft({
"access_token": access_token,
"draft_media_id": draft_id
})
if publish_result["success"]:
print(f"Published successfully! Publish ID: {publish_result['publish_id']}")
# Delete draft example
# Note: Usually, drafts are deleted after publishing, here only for demonstration API usage
del_draft_result = WeChat_del_draft({
"access_token": access_token,
"media_id": draft_id
})
if del_draft_result["success"]:
print(f"Draft deleted successfully: {del_draft_result['errmsg']}")
# Delete material example
# Note: Usually, materials are deleted when not needed, here only for demonstration API usage
del_material_result = WeChat_del_material({
"access_token": access_token,
"media_id": image_id
})
if del_material_result["success"]:
print(f"Material deleted successfully: {del_material_result['errmsg']}")
```
#### 2.2 Debug through MCP Inspector
After completing the installation steps, you can use the following command for interactive testing:
```bash
npx @modelcontextprotocol/inspector python -m wechat_oa_mcp
```
Then visit http://localhost:6274 for interactive testing
#### 2.3 Add MCP Server through JSON
**Note: This method requires the MCP server to be started first**
1. Start the service through the command line:
```bash
# Start directly (default port 8000)
wechat-oa-mcp
# or
python -m wechat_oa_mcp
# Start with specified port
wechat-oa-mcp --port 8123
# or
python -m wechat_oa_mcp --port 8123
```
2. Add the WeChat MCP server to the configuration of other MCP compatible applications (such as Cursor):
```json
{
"mcpServers": {
"wechat_oa_mcp": {
"type": "sse",
"url": "http://localhost:8000/sse"
}
}
}
```
**Configuration parameter description:**
- `type`: Communication protocol type, supports "sse" (Server-Sent Events)
- `url`: Server address, default port is 8000. If a port is specified before, the specified port number shall prevail
- `wechat_oa_mcp`: Server name, can be customized
## Technical Architecture
This project is based on the FastMCP framework and provides WeChat Official Account related services through the MCP protocol. The server adopts a modular design, and each function is encapsulated as an independent MCP tool, which can be called separately.
The server communicates with the WeChat Official Account API internally through HTTP requests, processing authentication, parameter verification, and other details, allowing users to focus on business logic without worrying about the underlying implementation.
## Usage Restrictions
To disperse server pressure, each IP can call the same interface at most five times within a minute.
## IP Whitelist Configuration
According to the WeChat Official Account development interface management regulations, when calling the access_token interface through developer ID and password, you need to set the access source IP as a whitelist. Please add the following IP to the whitelist:
```
106.15.125.133
```
## Acknowledgments
- Thanks for the framework support provided by the FastMCP project
**Disclaimer: This MCP server is for research purposes only and is prohibited for commercial use.**
Connection Info
You Might Also Like
cc-switch
All-in-One Assistant for Claude Code, Codex & Gemini CLI across platforms.
awesome-mcp-servers
A collection of MCP servers.
git
A Model Context Protocol server for Git automation and interaction.
oh-my-opencode
Background agents · Curated agents like oracle, librarians, frontend...
TrendRadar
TrendRadar: Your hotspot assistant for real news in just 30 seconds.
Appwrite
Build like a team of hundreds