WeChat Desktop MCP

WeChat Desktop MCP

A production-oriented MCP server that exposes task-level WeChat Desktop automation to AI clients, enabling status checks, message fetching/reply, contact addition, and Moment publishing on macOS via accessibility automation.

Category
访问服务器

README

WeChat Desktop MCP

A production-oriented MCP server that exposes task-level WeChat Desktop automation to AI clients. The MCP layer runs on Bun and TypeScript with the stable Model Context Protocol TypeScript SDK v2. A small native Swift bridge owns all macOS Accessibility and input-event work.

This project automates the visible WeChat for macOS application. It does not use, intercept, or reverse-engineer the WeChat network protocol.

Capabilities

MCP tool Behavior Side effect
wechat_status Reports platform, permissions, bridge, installation, process, and sign-in readiness None
fetch_messages_by_chat Resolves an exact contact/group chat and returns up to 200 newest text messages Navigates and scrolls the UI
reply_to_messages_by_chat Opens an exact chat and optionally sends a text reply Can send a message
add_contact_by_wechat_id Submits a friend request with remark/privacy options Can modify the account/contact graph
publish_moment_without_media Prepares or publishes a text-only Moment Can publish account content

The four tool names from the original Python project are preserved for client compatibility. wechat_status is new and provides a safe readiness probe.

Why this design

  • One dependency-injected MCP server factory is shared by stdio, HTTP, and tests.
  • Full Zod v4 input/output schemas produce model documentation, runtime validation, and validated structured results.
  • All GUI operations pass through one cancellable FIFO mutex. Concurrent MCP calls cannot race the single WeChat UI state machine.
  • Recoverable desktop failures become actionable MCP tool errors with stable codes.
  • Exact contact/group matching fails closed and returns candidates instead of clicking a similar result.
  • The native bridge is a compiled process with a minimal JSON protocol. MCP handlers do not contain shell, Accessibility, or mouse logic.
  • Operational logs are structured JSON on stderr. stdout remains exclusively available to the stdio transport.
  • A deterministic fake driver supports complete development and MCP contract testing without a WeChat account.

The primary-source design research is in docs/research/mcp-typescript-sdk-v2-best-practices.md.

Requirements

  • macOS 14 or newer on Apple Silicon or Intel
  • Bun 1.2.20 or newer
  • Xcode Command Line Tools (xcode-select --install)
  • WeChat for macOS for native operation
  • Accessibility permission for the terminal or MCP host application

Screen Recording permission is reported by the status tool but is not currently required; sender classification uses Accessibility geometry rather than screenshots.

Setup

bun install
bun run build:native
bun run check

The native bridge is built at .build/wechat-bridge. No WeChat login is required to build, type-check, or run the automated test suite.

Before live use:

  1. Start WeChat and sign in.
  2. Open System Settings → Privacy & Security → Accessibility.
  3. Grant access to the application that starts this MCP server (for example Terminal, Codex, or the relevant desktop host).
  4. Restart that host and call wechat_status.

Run over stdio

stdio is the default and recommended transport for a local desktop MCP:

bun run start

Example MCP host configuration:

{
  "mcpServers": {
    "wechat-desktop": {
      "command": "bun",
      "args": ["/Users/YOU/Code/wechat-desktop-mcp/src/index.ts"],
      "env": {
        "WECHAT_MCP_LOG_LEVEL": "info"
      }
    }
  }
}

All runtime diagnostics go to stderr. Do not redirect application logs to stdout when using stdio.

Run as HTTP ingress

The Bun Web Standard transport serves modern Streamable HTTP and compatible older clients through the SDK v2 handler:

bun run start -- --transport http
# http://127.0.0.1:3210/mcp

It binds to loopback by default and validates Host and Origin headers. Binding to another interface is rejected unless WECHAT_MCP_AUTH_TOKEN contains a token of at least 16 characters:

WECHAT_MCP_AUTH_TOKEN='replace-with-a-long-random-secret' \
  bun run start -- --transport http --host 0.0.0.0

For use outside one trusted machine, place the endpoint behind TLS and an authenticated reverse proxy. The bearer token is a deployment guard, not a complete multi-user authorization system. Because this server controls a personal desktop session, do not expose it directly to the public internet.

Configuration is documented in .env.example. CLI flags override their equivalent environment values.

Development without WeChat

Use the deterministic driver only for development and protocol tests:

bun run start -- --driver fake

The fake exposes one chat named Test Chat. It never accesses the native WeChat app.

Verification

bun run check       # type-check, lint/format verification, all tests
bun run build       # compile Swift bridge and bundle the Bun entry point

The tests cover pure application behavior, exact-match failures, FIFO serialization, cancellation, every tool through a real SDK client, schema rejection, and a spawned stdio process.

Optional interactive inspection:

bunx @modelcontextprotocol/inspector bun ./src/index.ts --driver fake

Operational constraints

  • The native tools require an interactive, unlocked macOS user session.
  • WeChat UI changes can invalidate Accessibility identifiers. Failures return a stage and stable error category rather than attempting an unsafe fallback click.
  • English and common Simplified Chinese labels are supported in the current selector profile.
  • Reading is limited to Accessibility-exposed text. Rich media, reactions, quoted-message structure, and sender identity inside group chats are not fully represented.
  • Sender is classified as ME, OTHER, or UNKNOWN from message geometry. Clients must handle UNKNOWN.
  • Mutations are not automatically retried. A timeout after a click or Return key can leave the remote result indeterminate.
  • Logs intentionally omit contact names and message bodies.

See docs/architecture.md for module boundaries and docs/migration-from-python.md for the migration inventory.

License and attribution

MIT. This implementation preserves the behavior and acknowledges the original MIT-licensed BiboyQG/WeChat-MCP project while replacing its Python/PyObjC architecture.

推荐服务器

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 模型以安全和受控的方式获取实时的网络信息。

官方
精选