WeChat MCP server for reading and replying to messages via macOS Accessibility APIs
Project description
WeChat MCP Server
This project provides an MCP server that automates WeChat on macOS using the Accessibility API and screen capture. It exposes tools that LLMs can call to:
- Fetch recent messages for a specific chat (contact or group)
- Generate and send a reply to a chat based on recent history
Environment setup (using uv)
This project uses uv for dependency and environment management.
-
Install
uv(if not already installed):curl -LsSf https://astral.sh/uv/install.sh | sh
-
From the project root, create/sync the environment:
cd WeChat-MCP uv sync
This will create a virtual environment (if needed) and install dependencies defined in
pyproject.toml.
Add the MCP server to configuration
Claude Code
claude mcp add --transport stdio wechat-mcp -- uv --directory $(pwd) run wechat-mcp
The MCP server entrypoint is wechat_mcp.mcp_server:main, exposed as the wechat-mcp console script.
Typical invocation:
uv run wechat-mcp --transport stdio
Supported transports:
stdio(default)streamable-http(with--port, default3001)sse(with--port, default3001)
Example:
uv run wechat-mcp --transport streamable-http --port 3001
Tools exposed to MCP clients
The server is implemented in src/wechat_mcp/mcp_server.py and defines two @mcp.tool() functions:
-
fetch_messages_by_chat(chat_name: str, last_n: int = 50) -> list[dict]Opens the chat forchat_name(first via the left session list, then via the global search box if needed). When using global search it prefers an exact name match in the "Contacts" section, then in the "Group Chats" section, and explicitly ignores matches under "Chat History", "Official Accounts", or "More". If no exact match is found, it does not fall back to the top search result; instead it returns a structured error plus up to 15 candidate names from each of "Contacts" and "Group Chats" so the LLM can choose a more specific target. Once a chat is successfully opened, it uses scrolling plus screenshots to collect the true lastlast_nmessages, even if they span multiple screens of history. Each message is a JSON object:{ "sender": "ME" | "OTHER" | "UNKNOWN", "text": "message text" }
-
reply_to_messages_by_chat(chat_name: str, reply_message: str | null = null) -> dictEnsures the chat forchat_nameis open (skipping an extra click when the current chat already matches), and (optionally) sends the providedreply_messageusing the Accessibility-basedsend_messagehelper. This tool is intended to be driven by the LLM that is already using this MCP: first callfetch_messages_by_chat, then compose a reply, then call this tool with that reply. Returns:{ "chat_name": "The chat (contact or group)", "reply_message": "The message that was sent (or null)", "sent": true }
If an error occurs, the tools return an object containing an "error" field describing the issue.
Internally, fetch_messages_by_chat scrolls the WeChat message list using the system’s standard macOS scroll semantics (no third‑party scroll reversal tools enabled) and continues scrolling until it has assembled the true last last_n messages or reached the beginning of the chat history, rather than stopping after a fixed number of scroll steps.
Logging
The project has a comprehensive logging setup:
- Logs are written to a rotating file under the
logs/directory (by defaultlogs/wechat_mcp.log) - Logs are also sent to the terminal (stdout)
You can customize the log directory via:
WECHAT_MCP_LOG_DIR– directory path where.logfiles should be stored (defaults tologsunder the current working directory)
macOS and Accessibility requirements
Because this project interacts with WeChat via the macOS Accessibility API:
- WeChat must be running (
com.tencent.xinWeChat) - The Python process (or the terminal app running it) must have Accessibility permissions enabled in System Settings → Privacy & Security → Accessibility
The helper scripts and MCP tools rely on:
- Accessibility tree inspection to find chat lists, search fields, and message lists
- Screen capture to classify message senders (
MEvsOTHERvsUNKNOWN) - Synthetic keyboard events to search, focus inputs, and send messages
TODO
- Detect and switch to contact by clicking
- Scroll to get full/more history messages
- Prefer exact match in Contacts/Group Chats search results
- Support WeChat with Chinese language
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file wechat_mcp_server-0.1.0.tar.gz.
File metadata
- Download URL: wechat_mcp_server-0.1.0.tar.gz
- Upload date:
- Size: 12.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
23755d7015c1889c324e044decbc587b66358bae3e7638947bc9a0d05c77fccf
|
|
| MD5 |
35b2719bac3757e9c7e9dc866edefc41
|
|
| BLAKE2b-256 |
c7c63225d698769baa1854840473b411662fb2aac3013338c12163dcbeb62883
|
Provenance
The following attestation bundles were made for wechat_mcp_server-0.1.0.tar.gz:
Publisher:
publish.yml on BiboyQG/WeChat-MCP
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
wechat_mcp_server-0.1.0.tar.gz -
Subject digest:
23755d7015c1889c324e044decbc587b66358bae3e7638947bc9a0d05c77fccf - Sigstore transparency entry: 748080300
- Sigstore integration time:
-
Permalink:
BiboyQG/WeChat-MCP@66ffa86a07a7ebbd2c670bee8d10c0bcd0db8cd4 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/BiboyQG
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@66ffa86a07a7ebbd2c670bee8d10c0bcd0db8cd4 -
Trigger Event:
release
-
Statement type:
File details
Details for the file wechat_mcp_server-0.1.0-py3-none-any.whl.
File metadata
- Download URL: wechat_mcp_server-0.1.0-py3-none-any.whl
- Upload date:
- Size: 3.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
38391ee7d9a8cf48383408943e0d404feece4b3d329467e42bdd33b6da0a9a69
|
|
| MD5 |
4346e58978f0d7ecbf9de569ee51dfdf
|
|
| BLAKE2b-256 |
2546f7c30052acb9e7080e079e83614a29ad61fcebd8b8cefcacfcd69d6001f6
|
Provenance
The following attestation bundles were made for wechat_mcp_server-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on BiboyQG/WeChat-MCP
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
wechat_mcp_server-0.1.0-py3-none-any.whl -
Subject digest:
38391ee7d9a8cf48383408943e0d404feece4b3d329467e42bdd33b6da0a9a69 - Sigstore transparency entry: 748080308
- Sigstore integration time:
-
Permalink:
BiboyQG/WeChat-MCP@66ffa86a07a7ebbd2c670bee8d10c0bcd0db8cd4 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/BiboyQG
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@66ffa86a07a7ebbd2c670bee8d10c0bcd0db8cd4 -
Trigger Event:
release
-
Statement type: