wechatbot-mcp

wechatbot-mcp

MCP server that lets agents read and reply to WeChat messages, send text/media/files, and manage login via the official WeChat iLink Bot SDK.

Category
访问服务器

README

wechatbot-mcp

OpenCode / MCP server wrapping @wechatbot/wechatbot — the official WeChat iLink Bot SDK (Tencent partner program, not a hook / reverse-engineered client).

Lets any Agent (OpenCode, Claude Code, Cursor, etc.) read and reply to WeChat messages over MCP stdio.

Quick start

npm install
npm run build
node dist/index.js                  # stdio MCP server

Register with OpenCode in ~/.config/opencode/opencode.json:

{
  "mcp": {
    "wechatbot": {
      "type": "local",
      "command": ["node", "<absolute-path>/wechatbot-mcp/dist/index.js"],
      "enabled": true
    }
  }
}

Then ask your Agent to call wechat_login once. A QR code PNG is auto-opened on screen; scan with WeChat. Credentials are persisted to ~/.wechatbot/credentials/ for ~14 days — subsequent restarts re-auth silently without a QR.

Tools

Tool Description
wechat_login Login. Silent re-auth from disk if creds exist; otherwise renders a QR PNG.
wechat_logout Stop polling. clearCredentials:true wipes on-disk creds.
wechat_status Connection state, account, queue depth, known-user count.
wechat_send_text Send a text message. SDK auto-splits on natural paragraphs.
wechat_send_image Send a local image file (optional caption).
wechat_send_file Send any local file — auto-routes by extension (.png → image, .mp4 → video, else file).
wechat_send_url Send media from a remote URL. SDK downloads and uploads to WeChat CDN.
wechat_send_typing / wechat_stop_typing Show / cancel "对方正在输入中…".
wechat_pending_messages Drain received messages (images/files auto-downloaded to ~/.wechatbot/pending-media/).
wechat_known_users List user IDs we have a context_token for (i.e. who can be replied to).

Protocol note (anti-spam)

WeChat iLink requires the recipient to message you first before you can reply. wechat_send_* tools return a clear error listing known users when the target isn't in that set. Always wechat_pending_messages first to learn user IDs from inbound messages.

Storage layout

~/.wechatbot/
├── credentials/     # iLink tokens (auto-managed, ~14-day TTL)
├── mcp/             # rendered QR PNGs (qr-*.png) + ASCII fallback (qr-latest.txt)
└── pending-media/   # media auto-downloaded from received messages

Architecture

   ┌────────────────┐
   │  WeChat user   │
   └────────┬───────┘
            │ iLink Bot protocol (Tencent)
   ┌────────▼───────┐
   │ @wechatbot/    │  ← npm SDK (long-poll, login, send, media)
   │   wechatbot    │
   └────────┬───────┘
            │ IncomingMessage + SendContent
   ┌────────▼───────┐
   │  BotManager    │  ← this repo: lifecycle, queue, snapshot
   └────────┬───────┘
            │ tools/call JSON-RPC
   ┌────────▼───────┐
   │  MCP server    │  ← stdio transport, 11 tools
   │  (this repo)   │
   └────────┬───────┘
            │ stdin/stdout
   ┌────────▼───────┐
   │ OpenCode / LLM │
   └────────────────┘

Tested with

  • Node.js ≥ 22 (tested on 24.11)
  • @wechatbot/wechatbot ^2.2.0
  • @modelcontextprotocol/sdk ^1.0
  • Windows 10/11 (PowerShell + cmd)

24/7 background auto-reply (optional)

A standalone daemon (scripts/wechat-daemon.mjs) runs the MCP server in a child process and auto-replies to incoming messages. Useful when OpenCode is closed or you're AFK.

# Default: none mode — log only, NO auto-reply (recommended unless you
# explicitly want a bot running 24/7)
node scripts/wechat-daemon.mjs

# LLM mode: shell out to any command, message JSON via stdin, reply = stdout
node scripts/wechat-daemon.mjs --reply-mode=llm --llm-cmd "opencode run --message"

# echo mode: just echo back the user's text (testing only — NOT recommended)
node scripts/wechat-daemon.mjs --reply-mode=echo

# Whitelist specific userIds (others get silently logged but no reply)
node scripts/wechat-daemon.mjs --reply-mode=llm --llm-cmd "..." \
    --allowed-users="o9cq804w_6mDSHAhyIQnPntiKI4c@im.wechat"

# Customize the AI-label prefix (default: "[ai助手]")
node scripts/wechat-daemon.mjs --reply-mode=llm --llm-cmd "..." --reply-prefix="[bot]"

# Tune cadence and log path
node scripts/wechat-daemon.mjs --poll-interval=1000 --log-file=/path/to/daemon.log

Every non-empty reply is auto-prefixed with [ai助手] (configurable via --reply-prefix) so recipients can tell the message came from an AI, not from the user themselves. This applies to all reply modes that produce output (echo, llm).

Logs go to both stderr (visible in your terminal) and ~/.wechatbot/daemon.log (persistent). Use Task Scheduler / nohup / pm2 / Windows Service to keep it running across reboots.

Concurrency note: only ONE listener per WeChat account. If you also run the OpenCode skill below, pick one — both will race on wechat_pending_messages (the queue is consumed atomically on each drain).

OpenCode skill (optional)

A user-global skill wechat-monitor makes OpenCode itself run the polling loop within an interactive session. The agent sees each incoming message and replies through the same MCP tools, with full LLM reasoning.

Install location: ~/.claude/skills/wechat-monitor/SKILL.md (auto-discovered by OpenCode alongside the bundled wps-* / mmx-cli skills).

Trigger: type /skill wechat-monitor or say "monitor wechat" / "wechat 监控".

The skill's SKILL.md documents the loop, concurrency rules, and reply strategies — agent reads it on invocation.

License

MIT

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选