wechatmp-mcp
An MCP server that drives the WeChat Official Account back office from
an MCP client: build an image message or a rich-text article from a
title, a cover image, the body text and local inline images, then keep it as a
draft or publish it straight from the editor — with a human in the loop
for every irreversible step.
English | Simplified Chinese
- No MCP SDK — a hand-written JSON-RPC 2.0 layer, standard library only at the
protocol level.
- Two transports:
stdio (default) and Streamable HTTP.
- Tool text is bilingual. MCP exposes exactly one
description per tool and
registries ingest that same string, so each description holds an English block
followed by a Chinese block; argument descriptions use the shorter
english / Chinese form. The same applies to the server instructions and to
server.json, so a marketplace listing shows both languages.
server.json fits in 100 characters. The registry schema caps that
description at 100 characters, so the listing line is one terse bilingual
sentence (90 characters) and the detail lives in the tool descriptions and the
server instructions, not in the registry entry.
- The first line is a registry marker.
mcp-name: io.github.xiaobinger/wechatmp-mcp
inside an HTML comment is how the MCP registry proves this PyPI package belongs
to that server name. It never renders, but removing it makes
mcp-publisher publish fail with an ownership error, and it only exists on PyPI
once a release is uploaded — so a published version that predates the marker can
never be fixed in place, only superseded.
- The login session lives inside a persistent Playwright profile. The server never
reads, exports or logs a cookie, a storage entry or a usable token.
mp_status ──► mp_account_login (scan) ──► mp_publish_material ──► mp_list_drafts
kind=tietu│article │
│ ├─► mp_publish_draft ─┐
action=draft ─┤ │ (confirm) │
action=publish ┤ └─► mp_delete_draft │
│ (confirm) ▼
admin scans a QR ──► ~2 min ──► mp_list_published
(the proof)
A note on the console's language: every label, hint and error on
mp.weixin.qq.com is Chinese. The exact literals are kept as module constants
in src/wxmp/tietu.py, src/wxmp/article.py and src/wxmp/drafts.py, so there
is one place to update them when the console changes. This document describes
them in English.
Status: what is actually verified
This project was carved out of a hand-run session on a live account (an unverified
personal subscription account) and then re-verified on the same machine. Honesty
about coverage matters more than a feature list.
| Area |
State |
| Browser launch (system Edge, persistent profile), console login detection, QR screenshot, redirect → token extraction, token masking in every reply |
verified on a live account |
mp_create_tietu end to end: upload, cover hint, title, description, save draft, draft id |
verified — one image attached through the uploader input, the cover hint appeared, title and description typed, draft id returned |
mp_publish_material with kind=tietu, action=draft |
verified on draft 100000219 — the unified entry point builds the same image message and reports the new draft id |
mp_publish_material with kind=article, action=draft |
verified on draft 100000232 — title, two body paragraphs, one inline picture, 作者 and 摘要 written, 封面 set through the image library, draft id returned; reopening the draft showed the title, both paragraphs, the inline picture and a real mmbiz.qpic.cn cover |
| Cover of a 图文 (the console has no local cover upload) |
verified through 从图片库选择: the picker's 上传文件 input takes the local file, the new entry arrives already ticked, 下一步 → 编辑封面 (2.35:1 / 1:1) → 确认, and the saved draft renders the cover as a 235x100 CSS background image |
| Inline pictures inside a 图文 body |
verified — the toolbar 图片 → 本地上传 file input inserts the picture at the caret (.ProseMirror img went 0 → 2, the editor adds a wrapper node, so the count is a floor) |
Draft box listing, cards keyed by data-appid |
verified; the console normalises the image-message tab filter to the article value (0) whenever that tab is empty, and both the requested and the landed value are reported |
| Opening an existing draft in its composer |
verified — it is the URL the console itself redirects to after saving a draft |
mp_delete_draft end to end |
verified on draft 100000205 — the card's icon row is hover-only and textless, so each icon is hovered until its tooltip reads "delete" (index 0; index 2 is "edit"); the confirmation is a popover, not a modal, and the id was gone from the list afterwards |
mp_publish_draft with action=publish |
verified once, end to end, on draft 100000210 → msgid 1000000021: the publish dialog was submitted, the admin scanned a QR page, the console then reported "this draft is being published, do not repeat the operation", finished in the background about two minutes after the scan, closed the editor tab itself, the draft disappeared from the draft box and publish records grew from 20 to 21 entries |
Publish records (mp_list_published) |
verified — the payload is an escaped JSON string whose entries are {publish_type, publish_info} wrappers; counters read total 21 / publish 1 / masssend 20 and the newest entry reproduces msgid 1000000021, sent_status 3/3/0, msg_status 2, and its public URL |
action=schedule |
mechanics verified, submission NOT verified — the switch, the time picker (today, HH:MM) and the footer submit were all driven and the console's own pre-flight checks ran, but no publish-record entry appeared afterwards. verified is therefore false and the reply says so |
| Account quotas as reported by the console |
observed: one mass-send left (daily 1/1), is_admin true, is_force_not_masssend 0, time_send_oper_left 20, face_check_resp.need_check false, user_publish_mode 1 |
Rich-text article composition (kind=article) |
draft path verified (see above). The article publish was never submitted: it needs the admin scan and produces public content, so action=publish for a 图文 is implemented but unproven |
| Group-send preview, asset library management |
not implemented |
Bilingual tool text (English + Chinese in one description, arguments as english / Chinese) |
enforced by the test suite — a tool or argument that loses either language fails selftest |
Correction (important). An earlier revision of this file claimed that
publishing needed no QR scan, because the automation only ever saw the "being
published" text. The account owner confirmed they scanned a QR page on that
run. Publishing is gated by an admin scan; the server screenshots that page,
waits for the human, and only trusts a new publish-record entry as proof.
Anything in the "not verified" rows may need selector work on your account. The
error payload always carries the page URL (token masked), a screenshot path and
what was clicked, so a failure is diagnosable instead of silent.
Requirements
- Python 3.10+
- A WeChat Official Account you can log into with the WeChat app
- A browser: Microsoft Edge (default) or Chrome.
playwright install is not
required when you use an installed browser via WXMP_BROWSER_CHANNEL.
Install
git clone https://github.com/xiaobinger/wechatmp-mcp
cd wechatmp-mcp
python -m venv .venv
.\.venv\Scripts\python.exe -m pip install -e .
The distribution name is wechatmp-publish-mcp (the PyPI name) while the code,
the console scripts and the MCP server name stay wxmp / wechatmp-mcp. Two
console scripts point at the same entry point — wxmp and
wechatmp-publish-mcp — so uvx wechatmp-publish-mcp starts the server once the
package is on PyPI, and server.json can name that same identifier.
First run: log in once
The login is manual by design — nobody should be typing a console password into a
tool, and the QR flow is what the console itself offers.
- Call
mp_status. It opens https://mp.weixin.qq.com/ in the controlled browser
and reports logged_in: false plus the login markers it saw.
- Call
mp_account_login with timeout_s (default 180). It writes a PNG of the
QR code into out/ and waits.
- Scan the QR that is visible in the browser window (the PNG is a fallback
for unattended setups; set
WXMP_DEVICE_SCALE=2 if you need a
higher-resolution PNG).
- The call returns as soon as the console redirects with a session token.
- The session is stored in
WXMP_PROFILE_DIR and reused by later calls until the
console expires it. If it expires, the call says so and the QR appears again.
The profile directory contains live login cookies. It is git-ignored; keep it that
way and treat the whole directory as a secret.
Its location is resolved from the package, never from the process working
directory: an MCP client may start the server anywhere, and a cwd-relative profile
would silently create a second, empty profile whose console answer is "not logged
in" even though the real one still holds the session. Point WXMP_PROFILE_DIR at
the same directory in every client to keep one shared login.
Tools