wechat_oa_mcp
Provides tools for managing WeChat Official Account content, including creating and publishing drafts, deleting drafts and permanent materials, and obtaining access tokens.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@wechat_oa_mcpCreate a draft for an article titled 'New Product Launch' with the content provided."
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
微信公众号 MCP 服务器
这是一个基于 FastMCP 框架的微信公众号MCP服务器,提供了一系列实用的微信公众号 API 接口封装,包括草稿创建、发布、删除等功能。
项目简介
本项目使用 Python 和 FastMCP 框架,通过 Model Control Protocol (MCP) 规范提供微信公众号管理 API,可以轻松集成到各种 AI 系统和自动化工作流程中,帮助用户便捷地管理微信公众号内容。
Related MCP server: wemp-operator-mcp
项目背景与架构变更
这个功能原本服务端程序是部署在 Coze、ModelScope 等平台上。但是由于这些平台提供的服务端 IP 经常是不固定的,因此没办法加入到微信公众号的白名单中。
后来的解决方法就是将代码一拆为二:
服务端功能:移到个人云服务器上,IP 是固定的,解决了白名单问题。
MCP 代码:则可以托管到任何地方。
如果需要在本地部署以保证数据安全,下面的代码仓库实现调用微信公众号 API 的功能也在一起,可以完全本地部署,项目地址是:https://github.com/kakaxi3019/wechat_oa_api_mcp
微信公众平台
微信公众平台官方网址:https://mp.weixin.qq.com
您需要先在微信公众平台注册并创建公众号,获取开发者ID(AppID)和密钥(AppSecret)才能使用本工具。
安装方法
使用 pip 安装
pip install wechat_oa_mcp项目结构
./
├── README.md # 项目文档
├── examples/ # 使用示例
│ └── simple_usage.py # 简单使用示例
├── setup.py # 安装配置
├── pyproject.toml # Python项目配置
└── wechat_oa_mcp/ # 包主目录
├── __init__.py # 包初始化文件
├── __main__.py # 模块直接执行入口
├── cli.py # 命令行工具入口
└── server.py # 主要功能代码依赖项
Python 3.10+
fastmcp
requests
功能列表
本服务器提供以下功能:
获取微信 Access Token: 获取接口调用凭证
创建微信公众号草稿: 创建图文消息草稿
发布微信公众号草稿: 将草稿发布到公众号
删除微信公众号草稿: 删除未发布的草稿
删除永久素材: 删除公众号中的永久素材
API 接口说明
1. 获取 Access Token
WeChat_get_access_token输入参数:
AppID: String·第三方用户唯一凭证(公众号-设置与开发-开发接口管理中获取)
AppSecret: String·第三方用户唯一凭证密钥(公众号-设置与开发-开发接口管理中获取)输出:
{
"success": true,
"error": null,
"access_token": "获取到的access_token",
"expires_in": 7200
}2. 创建草稿
WeChat_create_draft输入参数:
access_token: String·你的access_token,调用接口凭证,可通过WeChat_get_access_token获取
image_url: String·封面图片URL
title: String·文章标题
content: String·图文消息的具体内容,支持HTML标签,必须少于2万字符,小于1M
author: String·(可选)作者名称
digest: String·(可选)图文消息的摘要,仅有单图文消息才有摘要,多图文此处为空。如果本字段为没有填写,则默认抓取正文前54个字。
content_source_url: String·(可选)图文消息的原文地址,即点击"阅读原文"后的URL
need_open_comment: Integer·(可选)Uint32 是否打开评论,0不打开(默认),1打开输出:
{
"success": true,
"error": null,
"draft_media_id": "草稿的media_id",
"image_media_id": "封面图片的media_id"
}3. 发布草稿
WeChat_publish_draft输入参数:
access_token: String·调用接口凭证,可通过WeChat_get_access_token获取
draft_media_id: String·在之前调用WeChat_create_draft之后返回的draft_media_id输出:
{
"success": true,
"error": null,
"errmsg": "ok",
"publish_id": "发布任务id"
}4. 删除草稿
WeChat_del_draft输入参数:
access_token: String·调用接口凭证,可通过WeChat_get_access_token获取
media_id: String·草稿对应凭证,也就是WeChat_create_draft返回的draft_media_id输出:
{
"success": true,
"error": null,
"errcode": 0,
"errmsg": "ok"
}5. 删除永久素材
WeChat_del_material输入参数:
access_token: String·调用接口凭证,可通过WeChat_get_access_token获取
media_id: String·永久素材对应凭证,也就是WeChat_create_draft返回的image_media_id输出:
{
"success": true,
"error": null,
"errcode": 0,
"errmsg": "ok"
}使用方法
1. 安装服务器
# 通过pip安装
pip install wechat_oa_mcp2. 调用MCP Server的几种方式
2.1 通过代码调用
您可以通过以下方式在Python代码中直接调用微信MCP API(只需完成安装步骤即可使用):
from wechat_oa_mcp import (
WeChat_get_access_token,
WeChat_create_draft,
WeChat_publish_draft,
WeChat_del_draft,
WeChat_del_material
)
# 获取access_token
token_result = WeChat_get_access_token({
"AppID": "您的微信AppID",
"AppSecret": "您的微信AppSecret"
})
if token_result["success"]:
access_token = token_result["access_token"]
# 创建草稿
draft_result = WeChat_create_draft({
"access_token": access_token,
"image_url": "https://example.com/image.jpg",
"title": "测试文章标题",
"content": "<p>这是文章内容</p>",
"author": "作者名称"
})
if draft_result["success"]:
draft_id = draft_result["draft_media_id"]
image_id = draft_result["image_media_id"]
# 发布草稿
publish_result = WeChat_publish_draft({
"access_token": access_token,
"draft_media_id": draft_id
})
if publish_result["success"]:
print(f"发布成功!发布ID: {publish_result['publish_id']}")
# 删除草稿示例
# 注意:通常在发布后才会删除草稿,这里仅为演示API用法
del_draft_result = WeChat_del_draft({
"access_token": access_token,
"media_id": draft_id
})
if del_draft_result["success"]:
print(f"删除草稿成功:{del_draft_result['errmsg']}")
# 删除素材示例
# 注意:通常在不需要图片素材时才会删除,这里仅为演示API用法
del_material_result = WeChat_del_material({
"access_token": access_token,
"media_id": image_id
})
if del_material_result["success"]:
print(f"删除素材成功:{del_material_result['errmsg']}")2.2 通过MCP Inspector进行调试
只需完成安装步骤后,即可使用以下命令进行交互测试:
npx @modelcontextprotocol/inspector python -m wechat_oa_mcp之后访问 http://localhost:6274 可进行交互测试
2.3 通过json添加mcp server
注意:此方式需要先启动MCP服务器
首先通过命令行启动服务:
# 直接启动(默认端口8000)
wechat-oa-mcp
# 或者
python -m wechat_oa_mcp
# 指定端口启动
wechat-oa-mcp --port 8123
# 或者
python -m wechat_oa_mcp --port 8123然后将微信MCP服务器添加到其他MCP兼容应用(如Cursor)的配置中:
{
"mcpServers": {
"wechat_oa_mcp": {
"type": "sse",
"url": "http://localhost:8000/sse"
}
}
}配置参数说明:
type: 通信协议类型,支持"sse"(Server-Sent Events)url: 服务器地址,默认端口为8000。如果之前指定了port,则以指定端口号为准wechat_oa_mcp: 服务器名称,可自定义
技术架构
本项目基于 FastMCP 框架,通过 MCP 协议提供微信公众号相关服务。服务器采用模块化设计,每个功能都封装为独立的 MCP 工具,可以单独调用。
服务器内部通过 HTTP 请求与微信公众号 API 通信,处理认证、参数校验等细节,让使用者可以专注于业务逻辑而不用关心底层实现。
使用限制
为了分散服务器压力,每个IP每分钟内最多能调用同一接口五次。
IP白名单配置
根据微信公众号开发接口管理规定,通过开发者ID及密码调用获取access_token接口时,需要设置访问来源IP为白名单。请将以下IP添加至微信公众号-设置与开发-开发接口管理-IP白名单:
106.15.125.133致谢
感谢 FastMCP 项目提供的框架支持
免责声明:此 MCP 服务器仅限研究用途,禁止用于商业目的。
Available Tools
5 toolsWeChat_create_draftA
创建微信公众号草稿
Metadata:
input: access_token, image_url, title, content, author, digest, content_source_url, need_open_comment
output: success, error, draft_media_id, image_media_id
参数说明:
access_token: 接口凭证
image_url: 封面图片URL
title: 文章标题
content: 图文消息内容,支持HTML,<2万字符,<1M
author: (可选)作者名称
digest: (可选)摘要,默认取正文前54字
content_source_url: (可选)原文URL
need_open_comment: (可选)0关闭评论(默认),1开启
| Name | Required | Description | Default |
|---|---|---|---|
| args | Yes |
Output Schema
| Name | Required | Description |
|---|---|---|
| result | Yes |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
With no annotations provided, the description carries the full burden. It discloses input/output fields, content constraints (<2万字符, <1M), default behavior for digest, and the access_token requirement. However, it does not describe side effects like whether existing drafts are affected or specific error behavior beyond listing 'success, error' outputs.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
The description is well-structured with a purpose statement, metadata overview, and parameter explanations. It is front-loaded with the core action. Some redundancy exists (metadata list repeats parameter names), but the overall length is appropriate and every line adds value.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
The description covers all parameters and output fields, which is good for a complex tool. However, it fails to explain how the eight logical parameters relate to the single 'args' string in the schema, leaving a critical invocation ambiguity. It also omits usage guidance. These gaps affect completeness.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
The schema is minimal with only an 'args' string and 0% description coverage, so the description is the sole documentation for parameters. It explains all 8 parameters, including optional flags, constraints, and defaults, fully compensating for the schema's lack of detail.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
The description explicitly states '创建微信公众号草稿' (Create WeChat Official Account draft), which is a specific verb+resource action. It clearly distinguishes from sibling tools like WeChat_del_draft, WeChat_publish_draft, and WeChat_del_material by focusing on creation. The detailed parameter list further clarifies the scope.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
The description provides no guidance on when to use this tool versus alternatives. It does not mention exclusions, prerequisites, or recommended use cases. While the tool name and sibling names imply its role, the description itself lacks explicit usage direction.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
WeChat_del_draftA
删除微信公众号草稿
Metadata:
input: access_token, media_id
output: success, error, errcode, errmsg
参数说明:
access_token: 接口凭证
media_id: 草稿ID,即WeChat_create_draft返回的draft_media_id
| Name | Required | Description | Default |
|---|---|---|---|
| args | Yes |
Output Schema
| Name | Required | Description |
|---|---|---|
| result | Yes |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
The description discloses the basic destructive action (delete) and lists input/output fields. It adds useful context that media_id refers to the draft_media_id from create_draft. However, with no annotations provided, it does not explicitly warn about irreversibility, authorization requirements beyond access_token, or potential side effects, leaving some burden unmet.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
The description is compact and well-structured: a one-sentence purpose, followed by metadata and parameter descriptions. Every piece of information earns its place, and the most important point (what it does) is front-loaded.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
For a simple deletion tool, the description covers the essential action, input parameters, and output fields. The output schema exists, so return values are already documented. The main gap is explicit usage guidance relative to siblings, but overall it is sufficiently complete for an agent to understand what the tool does and how to call it.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
The input schema is essentially a single 'args' string with no sub-properties, so schema coverage is 0%. The description compensates by listing access_token and media_id and explaining their meanings, including the fact that media_id is the draft_media_id from WeChat_create_draft. This adds significant meaning beyond the schema, though it stops short of specifying the exact JSON format inside args.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
The description clearly states the action: '删除微信公众号草稿' (Delete WeChat Official Account draft). This is a specific verb+resource combination that directly distinguishes it from sibling tools like create, publish, or get_access_token.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
The description implies usage context by noting that media_id is the draft_media_id returned by WeChat_create_draft, indicating a typical create-then-delete workflow. However, it does not explicitly state when to use this tool over alternatives or provide exclusions, so guidance is implied rather than explicit.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
WeChat_del_materialB
删除微信公众号永久素材
Metadata:
input: access_token, media_id
output: success, error, errcode, errmsg
参数说明:
access_token: 接口凭证
media_id: 素材ID,即WeChat_create_draft返回的image_media_id
| Name | Required | Description | Default |
|---|---|---|---|
| args | Yes |
Output Schema
| Name | Required | Description |
|---|---|---|
| result | Yes |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
No annotations are provided, and the description only lists inputs/outputs. It does not disclose that deletion is irrevocable, does not mention required permissions or side effects, and does not explain error conditions beyond the output field names. The output fields (success, error, errcode, errmsg) provide minimal signal but not substantive behavior.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
The description is brief and organized with clear sections (description, metadata, parameter notes). It front-loads the purpose. The metadata section repeats output fields that might already exist in an output schema, but it remains compact.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
The tool has a dangerously simplistic schema (args string) that conflicts with the documented access_token/media_id inputs. The description does not clarify how to pass the parameters, nor does it warn about the irreversible nature of deletion. It also lacks guidance on obtaining access_token. These gaps make it incomplete for an agent to invoke reliably.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
The description defines access_token as '接口凭证' (API credential) and media_id as the ID returned by WeChat_create_draft, providing meaning beyond the schema, which only has a generic 'args' string. However, it does not explain how these parameters map to the schema's 'args' field, leaving ambiguity in invocation.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
The description opens with '删除微信公众号永久素材' (Delete WeChat Official Account permanent material), which clearly states the action and resource. This distinguishes it from siblings like WeChat_del_draft (delete draft) and WeChat_create_draft.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
The parameter description for media_id states it is the image_media_id returned by WeChat_create_draft, implying a workflow connection. However, there is no explicit statement of when to use this tool versus alternatives like WeChat_del_draft, nor any exclusions.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
WeChat_get_access_tokenB
获取微信公众号Access Token
Metadata:
input: AppID, AppSecret
output: success, error, access_token, expires_in
参数说明:
AppID: 公众号唯一凭证
AppSecret: 公众号凭证密钥
expires_in: 凭证有效时间(秒),默认7200
| Name | Required | Description | Default |
|---|---|---|---|
| args | Yes |
Output Schema
| Name | Required | Description |
|---|---|---|
| result | Yes |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
With no annotations, the description carries the transparency burden. It discloses output fields (success, error, access_token, expires_in) and the default expires_in value (7200 seconds), but does not mention authentication requirements, side effects, or error handling. This is adequate but shallow.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
The description is compact and includes a structured metadata block. It avoids redundancy, though the parameter explanation could be better aligned with the actual schema.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
While the output schema is declared, the description only lists output fields without detailing the actual argument format. The mismatch between the described inputs and the schema parameter makes the tool difficult to use correctly, leaving critical gaps.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
The input schema defines a single string parameter 'args', but the description separately lists AppID, AppSecret, and expires_in as if they are independent inputs. This mismatch is misleading, and the description does not explain how these values should be passed within 'args'. Schema coverage is 0%, so the description fails to provide necessary parameter meaning.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
The description states '获取微信公众号Access Token' (Get WeChat Official Account Access Token), which clearly identifies the verb (获取/get) and resource (Access Token). It is distinct from sibling tools that handle drafts and materials.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
The description provides no guidance on when to use this tool versus alternatives. While siblings are clearly different operations, there is no explicit context, prerequisites, or scenarios for using this token retrieval tool.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
WeChat_publish_draftA
发布微信公众号草稿
Metadata:
input: access_token, draft_media_id
output: success, error, errmsg, publish_id
参数说明:
access_token: 接口凭证
draft_media_id: 草稿ID,即WeChat_create_draft返回的draft_media_id
publish_id: 发布任务ID
| Name | Required | Description | Default |
|---|---|---|---|
| args | Yes |
Output Schema
| Name | Required | Description |
|---|---|---|
| result | Yes |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
No annotations are provided, so the description carries the full burden. It lists input and output fields, including publish_id as a task ID which hints at asynchronous publishing, but it does not disclose side effects, reversibility, or error conditions. Some behavioral context is present but not comprehensive.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
The description is relatively short, front-loaded with the main purpose, and uses a structured Metadata list. There is slight redundancy between the metadata section and the parameter explanation, but it remains clear and easy to scan.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
For a simple wrapper-style tool, the description covers necessary inputs and outputs, including the publish task ID. It could be improved by explicitly stating that publishing creates a task and may be asynchronous, but overall it provides sufficient context given the tool's simplicity.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
The schema only has a generic 'args' string with 0% description coverage. The description fully compensates by enumerating access_token and draft_media_id with explanations and explicitly linking draft_media_id to the output of WeChat_create_draft, adding meaningful parameter semantics beyond the schema.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
The description opens with '发布微信公众号草稿' which clearly states the action (publish) and resource (WeChat Official Account draft). It is distinct from sibling tools like create/del draft, making the purpose unambiguous.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
The parameter section mentions that draft_media_id comes from WeChat_create_draft, implying a workflow but not explicitly stating when to use this tool versus alternatives. It lacks explicit when-to-use or when-not-to-use guidance, though the context is somewhat implied.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
5 tool updates
v0.1.0- First observed
WeChat_create_draft - First observed
WeChat_del_draft - First observed
WeChat_del_material - First observed
WeChat_get_access_token - First observed
WeChat_publish_draft
TDQS
Scored across 5 tools
Each tool targets a distinct action: creating, deleting drafts, deleting materials, fetching tokens, and publishing. The only potential overlap between del_draft and del_material is resolved by clear parameter descriptions referencing the specific media IDs returned from create_draft.
All tools follow a consistent WeChat_verb_noun pattern with snake_case. The only minor deviation is the use of 'del' as an abbreviation instead of the full 'delete', but it's applied consistently across both delete operations.
Five tools is well-scoped for a focused WeChat draft management workflow. Each tool serves a necessary step in creating, publishing, and cleaning up articles, with no redundant or missing obvious tools for the intended scope.
The set covers create, publish, and delete for drafts, plus token retrieval and material deletion. However, it lacks get/list/update draft operations, which are essential for managing existing drafts, forcing agents to rely on previously stored IDs.
Maintenance
Related MCP Connectors
Create, schedule, and publish social posts, manage accounts, and read analytics as MCP tools.
Social media MCP: publish, schedule & analyze posts on TikTok, Instagram, YouTube, LinkedIn & X
Manage SocialBu posts, scheduling, publishing, automations, and analytics from MCP clients.
Schedule, publish, and analyze social posts across 11 platforms from any MCP client.
Related MCP Servers
- FlicenseNot gradedqualityDmaintenanceEnables management of WeChat Official Accounts by supporting draft creation, image uploads, and content publishing via the MCP protocol. It provides tools for interacting with the WeChat API, including secure token caching and draft list management.-
- AlicenseNot gradedqualityDmaintenanceEnables to operate a WeChat Official Account via MCP tools, including searching and executing API workflows and uploading files.MIT
- FlicenseAqualityFmaintenanceEnables AI agents to publish articles to WeChat Official Account (微信公众号). Supports image upload, draft creation, and publishing via standardized MCP protocol.51-
- AlicenseCqualityBmaintenanceEnables WeChat Official Account content publishing via MCP tools, covering image upload, draft management, and async publication with a dual-gate safety model.531MIT