Skip to main content

WeChat Draft Editor for Edge and MCP

CI Release License: MIT Platform: Windows / Edge

English | 简体中文

Edit a WeChat Official Account article from a local AI agent while keeping the draft open in Microsoft Edge. Click the extension on the article you want to work on, then ask your agent to read a section, replace a paragraph, or check how a caption wraps on a phone. The extension uses your existing editor session. Saving a draft is an explicit tool call; publication stays in the WeChat interface.

AI Agent (MCP Client) ──stdio──▶ agent.py ──Windows Named Pipe──▶ bridge.py (Native Host) ──Native Messaging──▶ Edge Extension (mp.weixin.qq.com)

Install on Windows

You need Windows, Microsoft Edge, and Python 3.10 or newer on your PATH. Install uv if you plan to connect an MCP client. The command-line client and native host use only the Python standard library.

  1. Download both ZIP files from the latest release. Extract the Edge ZIP into a permanent folder named extension and the MCP ZIP into a separate folder named mcp. If you cloned the repository instead, use its extension directory and run the following commands from the repository root.

  2. Open edge://extensions, enable Developer mode, click Load unpacked, and select the extracted folder containing manifest.json. Copy the extension ID that Edge displays.

  3. Open PowerShell in the folder containing install.ps1 and register the native host for your Windows user:

    .\install.ps1 -ExtensionId (Read-Host 'Paste the extension ID from Edge')
    
  4. Open an article in the WeChat Official Account editor at mp.weixin.qq.com. Click the extension icon on that tab. When its badge reads ON, verify the connection in the same PowerShell window:

    python bridge.py status
    python bridge.py regions
    

    The first command reports readiness and the article title. The second reads the title, author, summary and body, including which fields are writable. Check the title before making your first edit.

Install the Python package

Starting with the v0.6.0 release, the Windows MCP server and host installer can also be installed from PyPI. Load the Edge extension as described above, then run:

uv tool install wechat-draft-editor
wechat-draft-editor install-host --extension-id (Read-Host 'Paste your Edge extension ID')
codex mcp add wechat-editor -- wechat-draft-editor serve

Other stdio clients can launch wechat-draft-editor with the argument serve. If the client cannot find the command, use the full path returned by (Get-Command wechat-draft-editor).Source. After upgrading the tool, rerun install-host to update the registered copy of the native host.

Connect an AI agent

For Codex, run this from the folder containing agent.py, then start a new Codex session:

codex mcp add wechat-editor -- uv run --locked --script "$PWD\agent.py"

For another stdio MCP client, set the command to uv and pass the arguments shown below. Replace the example script path with its absolute path on your machine. Keep the extracted MCP directory intact. On first launch, uv installs the locked dependencies.

{
  "mcpServers": {
    "wechat-editor": {
      "command": "uv",
      "args": ["run", "--locked", "--script", "C:/Tools/wechat-editor/mcp/agent.py"]
    }
  }
}

Try this read-only request first:

Read the connected draft and tell me its title. Find the last photo caption and show me how it wraps on an iPhone 13 in portrait orientation.

For an edit, quote the exact passage and its replacement. Ask the agent to read the edited paragraph back before saving. Local passage replacement requires a unique match, which helps preserve surrounding images and formatting.

Tools

Task MCP tools and behavior
Inspect the draft mp_check_status reports the connected title. mp_get_regions reads structured fields and their write status. mp_get_draft also returns body HTML.
Edit text mp_set_field edits a writable title, author or summary. mp_replace_passage replaces a unique passage. mp_write_body appends plain text by default; its replace mode replaces the entire body, including images.
Adjust supported templates mp_fit_banner adjusts heading padding and spacing. mp_fit_caption groups caption text by phrase. mp_align_credits aligns the writing and layout credit separators.
Inspect the live editor mp_get_layout returns paragraph bounds and image statistics. mp_show_passage scrolls to a unique passage. mp_visual_verify returns a JPEG of the visible editor tab, including its sidebars. Keep the tab selected for capture.
Preview the article at another size mp_device_preview renders a copy of the draft in a separate Edge process. Choose iPhone 13, Pixel 7, or iPad Mini, with optional passage and landscape arguments. WeChat's mobile client can differ in font metrics and asset loading.
Save mp_save_draft clicks the editor's save-draft button. Check the saved status in WeChat to confirm persistence.

Use the CLI without an agent

The CLI accepts UTF-8 text files via --file for text operations, or structured JSON arguments via --payload. For example, to append a paragraph, read it back, and then save:

python bridge.py append --file paragraph.txt
python bridge.py read
python bridge.py save

Examples using --payload (PowerShell 7.3+ with standard native argument passing):

python bridge.py layout --payload '{"offset":40}'
python bridge.py replace_passage --payload '{"oldText":"Original phrase","newText":""}'
python bridge.py fit_caption --payload '["First phrase ","second phrase"]'
python bridge.py align_credits

Use python bridge.py --help for the full list of browser operations. Device emulation runs in the MCP server, which reuses a headless Edge process and closes each isolated browser context after its screenshot.

Connection and upgrades

  • Switch articles: click the extension on the new editor tab. Clicking it again on the connected tab disconnects it. Reconnect after refreshing the page.
  • ERR badge: hover over the icon for the reason. For host-registration errors, rerun the installer with the ID currently shown in Edge. If multiple editor regions match, place the caret in the article body and reconnect.
  • Base Python path: the installer records the base Python executable when run inside a standard virtual environment. Keep that base installation available.
  • Key rotation: to replace a potentially exposed key, disconnect the extension, run .\install.ps1 -ExtensionId <extension-id> -RotateKey (or wechat-draft-editor install-host --extension-id <extension-id> --rotate-key for PyPI installs), then reconnect. Regular reinstalls preserve the key.
  • Upgrade: extract the new files into their existing folders, reload the extension in Edge, rerun the host installer, and restart the MCP session. Keeping the unpacked extension at the same path helps preserve its ID. See CHANGELOG.md for version-specific upgrade notes (such as the v0.5 protocol change).

How it works

The MCP server (agent.py) and CLI send requests through an authenticated Windows named pipe. Edge launches bridge.py as a Native Messaging host and restricts access to the extension ID registered by the installer. The host registration, scripts, and generated authentication key live under the current Windows user in %LOCALAPPDATA%\WxDraftAgent.

The extension binds requests to the selected tab and document. extension/editor.js, extension/editor-support.js, and extension/templates.js locate article fields and apply supported edits. wechat_draft_editor/device_preview.py handles alternative viewport rendering.

Security, privacy, and disclaimer

  • Local-only bridge: All communication between Edge, the native host, and the MCP server stays on your local machine over an authenticated Windows named pipe. The installer restricts NTFS permissions on %LOCALAPPDATA%\WxDraftAgent and its key file to the installing Windows user.
  • Isolated device preview: wechat_draft_editor/device_preview.py sanitizes draft HTML into a sandboxed page with a strict Content Security Policy (default-src 'none') and allows only HTTPS image requests to mmbiz.qpic.cn and mmbiz.qlogo.cn with redirects blocked.
  • Data shared with your AI agent: This project collects no telemetry and contacts no author-hosted servers. However, any draft text, HTML, or screenshots requested through MCP tools are sent to the MCP client and AI model provider you configure.
  • Timeout safety: After a write timeout, read the current draft before retrying because the editor may already have applied the change.
  • Non-affiliation: This is an independent open-source project and is not affiliated with, endorsed by, or supported by Tencent or WeChat. Changes to the WeChat Official Account editor DOM may require extension updates.

Development and contributing

Issues and pull requests are welcome. From a source checkout on Windows, install the locked runtime and development dependencies and run the validation suite:

$env:UV_DEFAULT_INDEX = 'https://pypi.org/simple'
uv lock --check --script agent.py
python tests/check_locks.py
uv sync --locked
uv run --locked ruff check .
uv run --locked ruff format --check .
node --test tests/worker.test.cjs
uv run --locked python -m unittest discover -s tests -v

The browser tests require Microsoft Edge. For the worker tests, use Node 22 or later. If the default uv cache is inaccessible, set UV_CACHE_DIR to a writable user directory. Windows CI also runs ./tests/installer.ps1 under both Windows PowerShell and PowerShell 7 against a temporary profile and registry subtree. Keep the PEP 723 runtime requirements in agent.py and the dependencies in pyproject.toml in sync when updating agent.py.lock and uv.lock.

Commit messages

Use Conventional Commits with an imperative subject, for example fix(bridge): discard expired replies or test(editor): cover caption wrapping. Use chore(release): prepare vX.Y.Z for release preparation. Describe incompatible protocol changes in the commit body and the release notes.

Publishing a release

Publish a GitHub Release with a tag matching both the Python project and the extension version, for example v0.6.0. The release workflow runs Windows CI, builds the wheel and source distribution, uploads them to PyPI, and attaches both ZIP downloads and their checksums to the release. The upload step reads UV_PUBLISH_TOKEN from the GitHub Actions environment named pypi.

License

Released under the MIT License.

Metadata

Release files for wechat-draft-editor 0.6.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for wechat-draft-editor 0.6.0
File Size Uploaded Provenance Actions
wechat_draft_editor-0.6.0.tar.gz 14.2 kB Without provenance Details for wechat_draft_editor-0.6.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for wechat-draft-editor 0.6.0
File Interpreter ABI Platform Actions
wechat_draft_editor-0.6.0-py3-none-any.whl Python 3 none any Details for wechat_draft_editor-0.6.0-py3-none-any.whl

Total release size: 30.9 kB

Release files / wechat_draft_editor-0.6.0.tar.gz

Download URL wechat_draft_editor-0.6.0.tar.gz
Size 14.2 kB
Tags Source
SHA-256 checksum
How to use checksums
f32cec1789699e280617d79da25b8db84897183c802bd6bb37f30f2a9b85f6e1
BLAKE2b-256 checksum
How to use checksums
a3de1ae186ec005af8109b2768a6e5b429f1013844a1af26275aab5eb3de0508
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.21 {"installer":{"name":"uv","version":"0.12.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / wechat_draft_editor-0.6.0-py3-none-any.whl

Download URL wechat_draft_editor-0.6.0-py3-none-any.whl
Size 16.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
aedec1555f082f0cb83784d854d662dc954cdef946299b79bf54ee31ccd04954
BLAKE2b-256 checksum
How to use checksums
dd490294a031af4f120ef54f411adfb51c189a38ee8282125c85195102b41c83
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.21 {"installer":{"name":"uv","version":"0.12.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for wechat-draft-editor 0.6.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.6.0 This release

2 release files No provenance

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