weixin-mcp
A WeChat MCP server that lets AI assistants send/receive WeChat messages and manage contacts via the official WeChat ClawBot bot API.
Send text messages to users, using full or unique short IDs, optionally linking replies with
context_token.Send images and file attachments from local paths or URLs, with optional captions.
Poll for incoming messages with a persistent cursor, optionally resetting it for debugging.
List contacts who have messaged the bot, including userId, lastSeen, lastText, contextToken, and msgCount.
Get bot config for a user, including
typing_ticketfor typing indicators.Download media (image/file/video) from received messages using
encrypt_query_paramandaes_key.Support real-time webhook push and multi-account instances via separate directories/ports (README).
Integrate with MCP clients such as Claude Desktop, Cursor, and OpenClaw.
Allows AI assistants to send and receive WeChat messages, manage contacts, and handle media files through the official WeChat ClawBot API.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@weixin-mcp send 'Hello from AI' to user wx_abc123"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
weixin-mcp
🤖 微信 MCP Server — 让 AI 助手直接收发微信消息
⚠️ 重要说明:本项目基于微信官方 ClawBot(智能体机器人)API,需要在微信中创建 ClawBot 后扫码登录。不是用个人微信账号发消息,而是通过官方机器人接口。
👉 创建 ClawBot:最新版微信 → 设置 → 插件 → 微信 ClawBot
将微信 ClawBot 能力暴露为 MCP 工具,Claude Desktop、Cursor、OpenClaw 等 AI 助手可以直接:
📨 发送消息 — 文本、图片、文件、视频
📬 接收消息 — 轮询或 Webhook 实时推送
👥 管理联系人 — 自动记录对话用户
✨ 特性
官方接口 — 基于微信 ClawBot API,合规安全
零配置 — 创建 ClawBot 后扫码即用,无需公众号/企业微信
全类型消息 — 文本 / 图片 / 文件 / 视频
实时推送 — Webhook 模式,消息秒级推送到你的服务
多账号支持 — 不同目录运行多个实例
MCP 标准 — 兼容所有 MCP 客户端
Related MCP server: wxauto MCP Server
🚀 快速开始
# 1. 扫码登录
npx weixin-mcp login
# 2. 查看状态
npx weixin-mcp status
# 3. 发消息测试
npx weixin-mcp send <userId> "Hello from CLI!"
# 4. 启动 MCP server
npx weixin-mcp🔌 Claude Desktop 集成
编辑 claude_desktop_config.json:
{
"mcpServers": {
"weixin": {
"command": "npx",
"args": ["weixin-mcp"]
}
}
}重启 Claude Desktop,即可让 Claude 帮你收发微信消息!
🛠️ CLI 命令
命令 | 说明 |
| 扫码登录微信 |
| 查看账号和 daemon 状态 |
| 发送消息(支持短 ID) |
| 拉取消息 |
| 下载媒体文件 |
| 查看联系人 |
| 启动 HTTP daemon |
| 停止/重启 daemon |
| 查看日志 |
| 管理账号 |
| 更新到最新版 |
短 ID 匹配
联系人唯一时,可用前缀代替完整 ID:
npx weixin-mcp send abc12 "hello"
# ✓ Resolved "abc12" → abc123xyz456@im.wechat发送图片/文件/视频
# 发送图片
npx weixin-mcp send abc12 --image /path/to/photo.jpg
# 发送文件
npx weixin-mcp send abc12 --file /path/to/document.pdf
# 发送视频
npx weixin-mcp send abc12 --video /path/to/video.mp4
# 带文字说明
npx weixin-mcp send abc12 --image /path/to/photo.jpg --caption "看看这张图"🔧 MCP 工具
工具 | 说明 | 参数 |
| 发送文本 |
|
| 发送图片 |
|
| 发送文件 |
|
| 拉取消息 |
|
| 联系人列表 | - |
| 获取配置 |
|
📡 Webhook 模式
实时接收消息推送:
npx weixin-mcp start --webhook http://127.0.0.1:8080/weixin-hookHTTP MCP 只监听 127.0.0.1,并校验 Host / Origin,不直接对局域网或公网开放。仅将 webhook 配置为你信任的接收端,因为推送包含消息内容与 context token。
接收端应在处理完成后返回 2xx。非 2xx、网络失败或 10 秒超时会重试当前批次,成功前不会推进 cursor。重试可能重复投递,接收端应按消息标识去重;这不是持久化消息队列。Webhook 模式下不要同时使用 CLI / stdio 轮询同一账号,HTTP weixin_poll 会拒绝调用。
收到消息时 POST 到 webhook:
{
"event": "weixin_messages",
"messages": [{
"from_user_id": "...",
"item_list": [{"type": 1, "text_item": {"text": "你好"}}],
"context_token": "..."
}],
"timestamp": "2026-03-22T19:00:00.000Z"
}🏠 数据存储
优先级:$WEIXIN_MCP_DIR > ~/.openclaw/openclaw-weixin/ > ~/.weixin-mcp/
文件 | 说明 |
| 登录凭证 |
| 联系人 |
| Daemon 状态 |
| 日志 |
设置 WEIXIN_MCP_DIR 时,保留历史布局:账号 <id>.json 和 <id>.cursor.json 直接放在指定目录中,contacts.json、daemon.json、daemon.log 也放在该目录。未设置时,账号使用上表的 accounts/ 子目录。
升级前用旧版本停止现有 daemon。旧版本在自定义目录的父目录共享 contacts.json;升级后联系人按实例隔离,需要时手动复制该文件到对应的自定义目录,不会自动合并其他账号联系人。
🔀 多实例模式
一个 bot = 一个微信账号。需要多账号时,用不同目录运行多个实例:
# 实例 A(端口 3001)
WEIXIN_MCP_DIR=~/.weixin-mcp-a npx weixin-mcp login
WEIXIN_MCP_DIR=~/.weixin-mcp-a npx weixin-mcp start --port 3001
# 实例 B(端口 3002)
WEIXIN_MCP_DIR=~/.weixin-mcp-b npx weixin-mcp login
WEIXIN_MCP_DIR=~/.weixin-mcp-b npx weixin-mcp start --port 3002Claude Desktop 使用 stdio,无需 start 或 HTTP 端口;不要同时在同一账号启动另一套收消息轮询。
Claude Desktop 配置多账号:
{
"mcpServers": {
"weixin-personal": {
"command": "npx",
"args": ["weixin-mcp"],
"env": { "WEIXIN_MCP_DIR": "/Users/you/.weixin-mcp-personal" }
},
"weixin-work": {
"command": "npx",
"args": ["weixin-mcp"],
"env": { "WEIXIN_MCP_DIR": "/Users/you/.weixin-mcp-work" }
}
}
}🔗 相关项目
OpenClaw — AI Agent 基础设施
MCP Protocol — Model Context Protocol
ClawHub — Agent Skills 市场
📄 License
MIT © bkmashiro
下载收到的媒体(CLI)
poll(包括 --watch)为图片、文件和视频显示本地媒体 ID,不打印下载凭据:
weixin-mcp poll
weixin-mcp download --media-id <poll显示的ID> -o ./received.bin完整参数和 AES key 保存在账号目录下 media-downloads/<ID>.json,目录/文件的 POSIX 权限为 0700/0600;Windows 上请使用仅自己可访问的账号目录。下载须使用与 poll 相同的 WEIXIN_MCP_DIR(或默认目录),无需重新登录。引用不会自动过期或清理;不再需要时删除对应 JSON,删除整个 media-downloads 会使所有引用失效。不要分享这些文件。CDN 上的媒体可能独立过期。
兼容旧的 download -e <完整参数> -k <32位hex密钥> -o <路径>,但参数可能进入 shell 历史和进程列表,建议使用 ID。缺失/无效凭据或仅含 URL 的媒体显示不可下载,不输出 URL。未指定 -o 时仍仅显示原有 base64 预览。
合成回归测试覆盖三种媒体、顶层 hex / media.aes_key base64 密钥、模拟 CDN 和 AES 解密;不代表已验证真实微信用户上传媒体。
Available Tools
7 toolsweixin_contactsA
List users who have messaged the bot. Returns userId, lastSeen, lastText, contextToken, msgCount. Use userId as 'to' in weixin_send.
Inputs: no named parameters.
weixin_downloadA
Download media (image/file/video) from a received message. Extract encrypt_query_param and aes_key from the message's image_item, file_item, or video_item.
Inputs: aes_key (required), encrypt_query_param (required).
weixin_get_configA
Get bot config for a user — includes typing_ticket needed for sendTyping. Call before sending typing indicators.
Inputs: user_id (required), context_token.
weixin_pollA
Poll for new WeChat messages. Uses a persistent cursor to avoid re-delivering old messages. Returns new messages since last poll.
Inputs: reset_cursor.
weixin_sendA
Send a WeChat text message to a user. Pass context_token from a received message to link the reply to the conversation thread.
Inputs: to (required), text (required), context_token.
weixin_send_fileB
Send a file attachment to a WeChat user. Source can be a local file path or URL.
Inputs: to (required), source (required), caption, context_token.
weixin_send_imageA
Send an image to a WeChat user. Source can be a local file path or URL. Optionally include a text caption.
Inputs: to (required), source (required), caption, context_token.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 7 tools
Each tool has a distinct purpose: polling, contacts, sending different content types, config retrieval, and media download. The send variants are clearly differentiated by content type (text, image, file), and no two tools overlap.
All tool names share the weixin_ prefix and use snake_case, but the pattern is not strictly verb_noun: weixin_contacts is a noun, and weixin_poll/weixin_send are bare verbs. Overall readable and predictable, with minor deviations.
7 tools is well within the ideal range for a focused WeChat bot server, covering incoming messages, contacts, outgoing messages, config, and media download without redundancy.
Core send/receive workflows are covered, including text/image/file sending and media download. A minor gap exists: the config tool mentions a typing_ticket for sendTyping, but no send_typing tool is present.
Related MCP Connectors
Messaging tools for AI agents: send messages, manage chats, groups and channels.
WhatsApp for Claude, ChatGPT or any AI agent: search, reply and send. Personal or Business API.
Read, summarize and send your own WhatsApp messages from AI assistants (OAuth 2.1).
Let AI assistants post to your Telegram chats, groups and channels. Not affiliated with Telegram.
Related MCP Servers
- FlicenseNot gradedqualityDmaintenanceEnables AI assistants to send WeChat messages through automation, supporting both immediate and scheduled message delivery to contacts and groups using the Model Context Protocol standard.37-
- AlicenseBqualityDmaintenanceProvides WeChat automation capabilities for AI development tools via the Model Context Protocol. It enables users to send messages, manage contacts, and handle file transfers through AI assistants like Claude and Cursor.2735MIT
- FlicenseNot gradedqualityCmaintenanceEnables AI applications to send and read WeChat messages on Windows PCs through QR code authentication. Provides message polling, text sending, and session persistence for AI-powered chat interactions.43 npm1-
- FlicenseAqualityDmaintenanceEnables AI agents to control WeChat through MCP protocol, including sending messages, managing contacts, and searching messages.10-