Content
# mcp-wechat-server
MCP (Model Context Protocol) based WeChat robot server, enabling any AI Agent to send and receive WeChat messages.

## Features
- **6 MCP Tools**: Login, message polling, text sending, typing status
- **Scan Code Login**: Generate terminal text QR code, PNG image, and URL link
- **Long Polling**: Block and wait for new messages, up to 7 days
- **Typing Status**: Automatically display "对方正在输入..." when Agent processes messages
- **State Persistence**: Restart without losing login credentials and message cursor
- **Independent Operation**: No need for OpenClaw framework, ready to use out of the box
## Quick Start
### Claude Desktop
Add to `claude_desktop_config.json`:
```json
{
"mcpServers": {
"wechat": {
"command": "bunx",
"args": ["mcp-wechat-server"]
}
}
}
```
### OpenCode
Add to `opencode.json`:
```json
{
"mcp": {
"wechat": {
"type": "local",
"command": ["bunx", "mcp-wechat-server"],
"enabled": true
}
}
}
```
### Cursor / Other MCP Clients
```json
{
"command": "bunx",
"args": ["mcp-wechat-server"]
}
```
> `bunx` will automatically download and run from npm, no manual installation required.
## Environment Requirements
- [Bun](https://bun.sh/) >= 1.0.0
## Usage
### 1. Scan Code Login
AI Agent calls `login_qrcode` to generate QR code, which can be scanned via:
- Run `cat ~/.mcp-wechat-server/qrcode.txt` in terminal to view QR code
- Open image file `~/.mcp-wechat-server/qrcode.png`
- Copy link to WeChat to open
> **Tip**: If mobile scan code page keeps loading, switch to **mobile data network** (turn off WiFi).
<img src="assets/opencode_screenshot1.png" alt="OpenCode Login QR Code" width="600">
### 2. Confirm Login
Agent calls `check_qrcode_status` to confirm login status.
### 3. Start Chatting
After successful login, Agent will automatically execute the following process:
1. Call `get_messages` to poll new messages
2. Call `send_typing` to display "typing..."
3. Process and call `send_text_message` to reply
4. Call `send_typing` to cancel typing status
<img src="assets/wechat_screenshot1.jpg" alt="WeChat Sending and Receiving Messages" width="400">
<img src="assets/opencode_screenshot2.png" alt="OpenCode Agent Interaction" width="600">
<img src="assets/wechat_screenshot2.jpg" alt="WeChat Receiving Reply" width="400">
## Tool List
| Tool | Description |
|------|-------------|
| `login_qrcode` | Generate WeChat login QR code |
| `check_qrcode_status` | Check if QR code has been scanned and confirmed |
| `logout` | Logout and clear credentials |
| `get_messages` | Pull new messages (`wait=true` to block and wait until message received) |
| `send_text_message` | Send text message |
| `send_typing` | Send or cancel "typing..." status |
## Data Storage
All data stored in `~/.mcp-wechat-server/` directory:
| File | Description |
|------|-------------|
| `account.json` | Bot Token and user ID (permissions 600) |
| `state.json` | Message cursor and context Token |
| `qrcode.png` | Generated QR code image |
| `qrcode.txt` | Generated terminal QR code text |
## Local Development
```bash
git clone https://github.com/Howardzhangdqs/mcp-wechat-server.git
cd mcp-wechat-server
bun install
bun run dev
```
## License
MIT