Skip to main content
Glama
wechat-mcp-publisher

wechat-mcp-publisher

by weinh

wechat-mcp-publisher

WeChat Official Account draft publishing local MCP tool. It turns "written HTML → Official Account draft box" into a single LLM tool call: image upload, inline image replacement in the article body with WeChat URLs, cover material, and draft creation are all automated.

Based on the official mcp SDK (2.x MCPServer), stdio transport, single account, uv-managed dependencies.

Tools (5)

工具

用途

create_news_draft

Article draft: accepts HTML (or a .html file path) + cover image; embedded <img> tags are automatically uploaded and replaced with WeChat URLs

create_newspic_draft

Image message draft: plain-text description + 1~20 images (in order)

list_drafts

Paginated draft box query

get_draft

Draft details (including body)

delete_draft

Delete draft (does not delete materials along with it)

The access_token is obtained internally, cached, and self-heals on expiration (stable_token + automatic refresh and retry once on 40001/42001); it is not exposed as a tool. Errors are uniformly converted into Chinese messages with handling suggestions (e.g., 40164 prompts adding the IP allowlist, 48001 prompts a verified account), and they contain no credentials.

Related MCP server: WeChat Official Account MCP Server

Installation

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

Get credentials: mp.weixin.qq.com → Settings & Development → Basic Configuration. On the same page, add this machine's public IP to the IP allowlist, otherwise token retrieval returns 40164.

Once published to PyPI, you can also run it directly without cloning (in a directory containing .env):

uvx wechat-mcp-publisher
# 或 pip install wechat-mcp-publisher && wechat-mcp-publisher

In this case, the MCP client configuration can be simplified to "command": "uvx", "args": ["wechat-mcp-publisher"].

Connecting to MCP clients

Claude Code (recommended, one command):

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

Project-level configuration (this repository already includes .mcp.json, which takes effect when Claude Code is opened in this repository's directory; on first use, confirm trust in /mcp): no manual addition is required.

Claude Desktop / other clients: merge the snippet from examples/mcp-client-config.example.json into the corresponding configuration file.

Usage examples

Say to the LLM:

Help me publish /path/article.html as an Official Account article draft, using /path/cover.jpg as the cover.

Or for an image message:

Send these three images /a.jpg /b.jpg /c.jpg as an image message draft, with the caption: weekend shots.

A real API pipeline demo is available at examples/simple_usage.py (token → upload → create draft; also serves as a live smoke test).

Testing

uv run pytest

All endpoints are mocked via responses, so they can be run successfully without a real account.

Scope and known limitations

  • No markdown→HTML conversion: the article body input is HTML; use your existing md→html tool for conversion

  • No publishing (freepublish): currently only goes as far as drafts; publishing is left for extension after account verification

  • Personal unverified subscription accounts: the material/draft APIs return 48001; live verification requires a verified account (development and testing are unaffected)

  • HTML WeChat compatibility: the WeChat editor only accepts a subset of HTML with inline styles; layout adaptation is handled by the upstream conversion tool; this tool neither validates nor fixes it

  • Material buildup: deleting a draft does not delete the permanent material images it occupies; with long-term use, clean them up occasionally in the Official Account backend

  • Single account: credentials come from .env; no multi-account switching is provided

Available Tools

5 tools
create_news_draftA

创建图文草稿(news),成功返回 {"media_id": ..., "title": ..., "cover_url": ...}。

参数:
  title: 文章标题(必填)
  content: 正文。支持两种形态——HTML 字符串,或本地 .html 文件路径
           (若该路径存在则自动读取文件,否则按 HTML 内容处理)
  cover: 封面图片(必填):本地文件路径或 http(s) URL,自动上传为封面素材
  author: 作者名(可选)
  digest: 摘要(可选,留空时微信自动截取正文)
  content_source_url: 原文链接(可选)

正文 HTML 中的 <img> 会自动上传到微信并替换 src 为微信托管的 URL;
已指向微信域名(mmbiz.qpic.cn / mp.weixin.qq.com)的图片保持不变。

Inputs: cover (required), title (required), content (required), author, +2 more. Returns: object

create_newspic_draftA

创建图片消息草稿(newspic),成功返回 {"media_id": ..., "title": ..., "image_count": ...}。

参数:
  title: 消息标题(必填)
  images: 1~20 张图片,按传入顺序展示;每项为本地文件路径或 http(s) URL
  content: 图片下方的纯文字说明(可选,注意不是 HTML)

与图文消息不同:图片消息的 content 是纯文本,图片本体在 images 中,
全部经永久素材接口上传后按序组装。

Inputs: title (required), images (required), content. Returns: object

delete_draftA

删除指定草稿,成功返回 {"media_id": ..., "deleted": true}。

注意:删除草稿不会连带删除其占用的永久素材图片(微信行为)。
参数:
  media_id: 草稿 ID

Inputs: media_id (required). Returns: object

get_draftA

查询草稿详情(含 news_item 全部字段:标题、正文 HTML、封面等)。

参数:
  media_id: 草稿 ID(由 create_news_draft / create_newspic_draft 返回,或从 list_drafts 获取)

Inputs: media_id (required). Returns: object

list_draftsA

分页查询草稿箱列表,返回 {"total": 总数, "offset": 当前偏移, "items": [{media_id, title, update_time}]}。

参数:
  offset: 起始位置(默认 0)
  count: 每页数量(默认 20,最大 20)

Inputs: count, offset. Returns: object

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    A4.3/5.0

    Scored across 5 tools

    Disambiguation5/5

    The two create tools are clearly separated by draft type (newspic vs news) with distinct parameter semantics, while list, get, and delete have unambiguous scopes. No two tools appear to overlap in purpose.

    Naming Consistency4/5

    Most tools follow a verb_noun snake_case pattern such as list_drafts, get_draft, and delete_draft. The create tools also align with verb+type+draft, though 'newspic' vs 'news' is a slightly non-parallel naming choice.

    Tool Count5/5

    Five tools is well-scoped for a draft-management server: two creation variants plus standard list, get, and delete operations. Each tool earns its place without unnecessary overlap or bloat.

    Completeness3/5

    The set covers create, read/list, and delete for drafts, but lacks an update_draft operation, forcing agents to delete and recreate to modify content. Additionally, despite the 'publisher' name, there is no publish/send tool, leaving a notable gap in the apparent domain.

    Maintenance

    ActivityInactive
    ResponsivenessOutdated data

    Related MCP Connectors

    Related MCP Servers