@paean-ai/wechat-mcp 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +164 -0
- package/dist/cli.js +1341 -0
- package/dist/daemon/server.js +565 -0
- package/dist/index.d.ts +195 -0
- package/dist/index.js +443 -0
- package/package.json +66 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Paean AI
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
# @paean-ai/wechat-mcp
|
|
2
|
+
|
|
3
|
+
WeChat MCP middleware — shared WeChat connection for multiple AI agents with @mention routing.
|
|
4
|
+
|
|
5
|
+
## Problem
|
|
6
|
+
|
|
7
|
+
WeChat's official iLink protocol only allows **one bot per WeChat account**. If you use multiple AI agents (Claude Code, OpenClaw, Paean CLI, etc.), you're forced to choose which one gets WeChat access.
|
|
8
|
+
|
|
9
|
+
**wechat-mcp** solves this by providing a shared middleware layer: one WeChat connection, many agents.
|
|
10
|
+
|
|
11
|
+
## How It Works
|
|
12
|
+
|
|
13
|
+
```
|
|
14
|
+
WeChat iLink API
|
|
15
|
+
│
|
|
16
|
+
┌────────┴────────┐
|
|
17
|
+
│ wechat-mcp │
|
|
18
|
+
│ daemon │
|
|
19
|
+
│ (background) │
|
|
20
|
+
└───┬────┬────┬───┘
|
|
21
|
+
│ │ │ HTTP IPC (localhost)
|
|
22
|
+
┌──────┘ │ └──────┐
|
|
23
|
+
▼ ▼ ▼
|
|
24
|
+
MCP Server MCP Server MCP Server
|
|
25
|
+
(claude) (openclaw) (paean)
|
|
26
|
+
▲ ▲ ▲
|
|
27
|
+
│ │ │ stdio MCP
|
|
28
|
+
Claude Code OpenClaw Paean CLI
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
1. A **background daemon** manages the single WeChat connection (QR login, message polling, token cache)
|
|
32
|
+
2. Each agent connects via its own **MCP stdio server** (thin client)
|
|
33
|
+
3. Incoming messages are **routed by @mention**: `@claude hello` goes to Claude, `@openclaw run task` goes to OpenClaw
|
|
34
|
+
4. Any agent can **send messages** through the shared connection
|
|
35
|
+
|
|
36
|
+
## Quick Start
|
|
37
|
+
|
|
38
|
+
### 1. Install
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
npm install -g @paean-ai/wechat-mcp
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### 2. Authenticate
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
wechat-mcp setup
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Scan the QR code with WeChat. Credentials are saved to `~/.wechat-mcp/`.
|
|
51
|
+
|
|
52
|
+
### 3. Add to Any Agent
|
|
53
|
+
|
|
54
|
+
Add this to your agent's MCP configuration:
|
|
55
|
+
|
|
56
|
+
**Claude Code** (`~/.claude.json` or project `.mcp.json`):
|
|
57
|
+
|
|
58
|
+
```json
|
|
59
|
+
{
|
|
60
|
+
"mcpServers": {
|
|
61
|
+
"wechat": {
|
|
62
|
+
"command": "npx",
|
|
63
|
+
"args": ["@paean-ai/wechat-mcp", "serve", "--agent", "claude"]
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
**OpenClaw / Other Agents:**
|
|
70
|
+
|
|
71
|
+
```json
|
|
72
|
+
{
|
|
73
|
+
"mcpServers": {
|
|
74
|
+
"wechat": {
|
|
75
|
+
"command": "npx",
|
|
76
|
+
"args": ["@paean-ai/wechat-mcp", "serve", "--agent", "openclaw"]
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
Each agent uses a different `--agent` name. That's it — the daemon auto-starts when any agent connects.
|
|
83
|
+
|
|
84
|
+
## Message Routing
|
|
85
|
+
|
|
86
|
+
| WeChat Message | Routed To | Agent Receives |
|
|
87
|
+
|---|---|---|
|
|
88
|
+
| `@claude hello` | agent "claude" | `hello` |
|
|
89
|
+
| `@openclaw run task` | agent "openclaw" | `run task` |
|
|
90
|
+
| `hello` (no @) | default agent (first registered) | `hello` |
|
|
91
|
+
| `@unknown hi` | default agent | `@unknown hi` |
|
|
92
|
+
|
|
93
|
+
## CLI Commands
|
|
94
|
+
|
|
95
|
+
```bash
|
|
96
|
+
wechat-mcp setup # QR login
|
|
97
|
+
wechat-mcp serve --agent X # Start MCP server (used in agent config)
|
|
98
|
+
wechat-mcp daemon # Start daemon in foreground
|
|
99
|
+
wechat-mcp stop # Stop daemon
|
|
100
|
+
wechat-mcp status # Show status
|
|
101
|
+
wechat-mcp contacts # List known contacts
|
|
102
|
+
wechat-mcp send --to X --text Y # One-shot send
|
|
103
|
+
wechat-mcp logout # Remove credentials & stop daemon
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
## MCP Tools
|
|
107
|
+
|
|
108
|
+
When connected as an MCP server, agents can use these tools:
|
|
109
|
+
|
|
110
|
+
| Tool | Description |
|
|
111
|
+
|---|---|
|
|
112
|
+
| `wechat_send` | Send a text message to a WeChat user |
|
|
113
|
+
| `wechat_get_contacts` | List known WeChat contacts |
|
|
114
|
+
| `wechat_get_status` | Get connection status and registered agents |
|
|
115
|
+
|
|
116
|
+
## Proactive Messaging
|
|
117
|
+
|
|
118
|
+
Agents can send messages proactively (e.g., from cron jobs or scheduled tasks) using the shared WeChat connection:
|
|
119
|
+
|
|
120
|
+
```bash
|
|
121
|
+
# CLI
|
|
122
|
+
wechat-mcp send --to "friend@im.wechat" --text "Task completed!"
|
|
123
|
+
|
|
124
|
+
# Or via MCP tool: agents call wechat_send at any time
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
## Architecture
|
|
128
|
+
|
|
129
|
+
- **Daemon** (`~/.wechat-mcp/daemon.json`): Auto-started background process that owns the WeChat connection. Listens on `127.0.0.1` only.
|
|
130
|
+
- **MCP Server**: Thin stdio process spawned per-agent. Connects to daemon over local HTTP.
|
|
131
|
+
- **Credentials**: Stored in `~/.wechat-mcp/credentials.json` with `0600` permissions.
|
|
132
|
+
|
|
133
|
+
## Programmatic API
|
|
134
|
+
|
|
135
|
+
```typescript
|
|
136
|
+
import {
|
|
137
|
+
ensureDaemon,
|
|
138
|
+
DaemonClient,
|
|
139
|
+
loadCredentials,
|
|
140
|
+
parseMention,
|
|
141
|
+
} from "@paean-ai/wechat-mcp";
|
|
142
|
+
|
|
143
|
+
// Connect to daemon
|
|
144
|
+
const daemon = await ensureDaemon();
|
|
145
|
+
const client = new DaemonClient(daemon.port);
|
|
146
|
+
|
|
147
|
+
// Register and poll
|
|
148
|
+
await client.registerAgent("my-bot");
|
|
149
|
+
const messages = await client.pollMessages("my-bot");
|
|
150
|
+
|
|
151
|
+
// Send
|
|
152
|
+
await client.send("user@wxid", "Hello from my bot!", "my-bot");
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
## Security
|
|
156
|
+
|
|
157
|
+
- Credentials stored with `0600` file permissions
|
|
158
|
+
- Daemon listens only on `127.0.0.1` (no network exposure)
|
|
159
|
+
- No secrets in environment variables or logs
|
|
160
|
+
- Token stored locally, never transmitted to third parties
|
|
161
|
+
|
|
162
|
+
## License
|
|
163
|
+
|
|
164
|
+
MIT
|