Skip to main content

wechat-mcp-publisher

微信公众号草稿发布本地 MCP 工具。把「写好的 HTML → 公众号草稿箱」变成一次 LLM 工具调用:图片上传、正文内嵌图换微信 URL、封面素材、建草稿全部自动完成。

基于官方 mcp SDK(2.x MCPServer),stdio 传输,单账号,uv 管理依赖。

工具面(5 个)

工具 用途
create_news_draft 图文草稿:吃 HTML(或 .html 文件路径)+ 封面图;内嵌 <img> 自动上传换微信 URL
create_newspic_draft 图片消息草稿:纯文本说明 + 1~20 张图(按序)
list_drafts 分页查草稿箱
get_draft 草稿详情(含正文)
delete_draft 删除草稿(不连带删素材)

access_token 由内部获取、缓存、失效自愈(stable_token + 40001/42001 自动刷新重试一次),不暴露为工具。错误统一转为带处置提示的中文信息(如 40164 提示加 IP 白名单、48001 提示需认证账号),且不含凭据。

安装

uv sync
cp .env.example .env   # 填入 WECHAT_APP_ID / WECHAT_APP_SECRET

凭据获取:mp.weixin.qq.com → 设置与开发 → 基本配置。同一页面需把本机公网 IP 加入 IP 白名单,否则 token 获取报 40164

接入 MCP 客户端

Claude Code(推荐,一条命令):

claude mcp add wechat-mcp-publisher -- uv run --directory /你的路径/wechat-mcp-publisher python -m wechat_mcp_publisher

项目级配置(本仓库已内置 .mcp.json,Claude Code 在本仓库目录打开即生效,首次需在 /mcp 中确认信任):无需手动添加。

Claude Desktop / 其他客户端:把 examples/mcp-client-config.example.json 中的片段合入对应配置文件。

使用示例

对 LLM 说:

帮我把 /path/article.html 发成公众号图文草稿,封面用 /path/cover.jpg

或图片消息:

把这三张图 /a.jpg /b.jpg /c.jpg 发成图片消息草稿,说明文字:周末出片

真实 API 链路演示见 examples/simple_usage.py(token → 上传 → 建草稿,兼作真机冒烟)。

测试

uv run pytest

全部接口经 responses mock,不需要真实账号即可跑通。

范围与已知限制

  • 不做 markdown→HTML 转换:正文入口是 HTML,转换请用你已有的 md→html 工具完成
  • 不做发布freepublish):当前只到草稿;发布留给账号认证后扩展
  • 个人未认证订阅号:素材/草稿接口会返回 48001,真机验证需已认证账号(开发与测试不受影响)
  • HTML 微信兼容性:微信编辑器只认内联样式的 HTML 子集,排版适配由上游转换工具负责,本工具不校验不修复
  • 素材堆积:删除草稿不会删除其占用的永久素材图片,长期使用需偶尔在公众号后台清理
  • 单账号:凭据来自 .env,不提供多账号切换

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

wechat_mcp_publisher-0.1.0.tar.gz (13.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

wechat_mcp_publisher-0.1.0-py3-none-any.whl (20.7 kB view details)

Uploaded Python 3

File details

Details for the file wechat_mcp_publisher-0.1.0.tar.gz.

File metadata

  • Download URL: wechat_mcp_publisher-0.1.0.tar.gz
  • Upload date:
  • Size: 13.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.26 {"installer":{"name":"uv","version":"0.9.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for wechat_mcp_publisher-0.1.0.tar.gz
Algorithm Hash digest
SHA256 1728388fbdc2af24b8413637e972c894b1de8c075eca373db4b00a1079886ff1
MD5 7e45675b2f96e10b98781e5a8d941b9a
BLAKE2b-256 d6fa2bf887ed15dd5fa9503a5d840cacadd69380ea16c440cb54854653dbc6b8

See more details on using hashes here.

File details

Details for the file wechat_mcp_publisher-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: wechat_mcp_publisher-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 20.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.26 {"installer":{"name":"uv","version":"0.9.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for wechat_mcp_publisher-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a153c7255874dc29ce80b8d88385ba5b104ca717b14d42c13ba14412b0c88778
MD5 14ea0e10e525810712f76ee2c880f90d
BLAKE2b-256 0086a6809d2a4a07cfc46ae90bedc6a7f2a7b460dcda948111c09df3fb5c1c8b

See more details on using hashes here.

Release history Release notifications | RSS feed

0.2.1

2 files

0.2.0

2 files

This release

0.1.0 This release

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page