imessage-mcp-server 1.0.0 → 2.0.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/README.md CHANGED
@@ -1,7 +1,9 @@
1
1
  # imessage-mcp-server
2
2
 
3
- > **MCP server for reading and sending iMessages on macOS**
4
- > Expose your iMessage history and send capabilities via the [Model Context Protocol](https://modelcontextprotocol.io).
3
+ > **MCP server + AI bridge for iMessage on macOS**
4
+ > Expose your iMessage history and send capabilities via the [Model Context Protocol](https://modelcontextprotocol.io), or turn your Mac into a 24/7 AI assistant that auto-replies to your iMessages.
5
+
6
+ [中文 README](README.zh.md)
5
7
 
6
8
  ⚠️ **macOS only** — requires the Messages app and its SQLite database (`~/Library/Messages/chat.db`).
7
9
 
@@ -9,15 +11,26 @@
9
11
 
10
12
  ## Features
11
13
 
12
- This MCP server provides **4 tools** for interacting with iMessage:
14
+ ### MCP Server mode
15
+ Four standard MCP tools for reading and sending iMessages:
13
16
 
14
17
  | Tool | Description |
15
18
  |------|-------------|
16
19
  | `send_imessage` | Send an iMessage to a recipient's email or phone number |
17
20
  | `list_conversations` | List recent conversations with latest message preview and unread count |
18
- | `read_conversation` | Read paginated messages from a specific conversation (by chat_id or handle) |
21
+ | `read_conversation` | Read paginated messages from a specific conversation |
19
22
  | `get_new_messages` | Poll for new incoming messages since a timestamp |
20
23
 
24
+ ### Bridge mode
25
+ Run an autonomous AI agent in the background:
26
+
27
+ - Polls for new iMessages from your configured `masterHandle`
28
+ - Sends them to Claude, OpenAI, DeepSeek, Kimi, or any OpenAI-compatible model
29
+ - Connects any MCP Servers as tools (filesystem, shell, git, etc.)
30
+ - Auto-replies with results
31
+ - Remembers conversation context
32
+ - Supports macOS LaunchAgent for auto-start on login
33
+
21
34
  ---
22
35
 
23
36
  ## Prerequisites
@@ -38,31 +51,31 @@ xcode-select --install
38
51
 
39
52
  ## Quick Start
40
53
 
41
- ### Option 1: npx (recommended)
54
+ ### MCP Server mode
42
55
 
43
- No installation needed — just add to your MCP configuration:
56
+ Add to your MCP configuration:
44
57
 
45
- **Claude Desktop** (`~/Library/Application Support/Claude/claude_desktop_config.json`):
58
+ **Claude Code** (`.claude/settings.json`):
46
59
 
47
60
  ```json
48
61
  {
49
62
  "mcpServers": {
50
63
  "imessage": {
51
64
  "command": "npx",
52
- "args": ["-y", "imessage-mcp-server"]
65
+ "args": ["-y", "imessage-mcp-server", "--server"]
53
66
  }
54
67
  }
55
68
  }
56
69
  ```
57
70
 
58
- **Claude Code** (`.claude/settings.json` in your project):
71
+ **Claude Desktop** (`~/Library/Application Support/Claude/claude_desktop_config.json`):
59
72
 
60
73
  ```json
61
74
  {
62
75
  "mcpServers": {
63
76
  "imessage": {
64
77
  "command": "npx",
65
- "args": ["-y", "imessage-mcp-server"]
78
+ "args": ["-y", "imessage-mcp-server", "--server"]
66
79
  }
67
80
  }
68
81
  }
@@ -75,7 +88,7 @@ No installation needed — just add to your MCP configuration:
75
88
  "mcpServers": {
76
89
  "imessage": {
77
90
  "command": "npx",
78
- "args": ["-y", "imessage-mcp-server"]
91
+ "args": ["-y", "imessage-mcp-server", "--server"]
79
92
  }
80
93
  }
81
94
  }
@@ -88,138 +101,205 @@ No installation needed — just add to your MCP configuration:
88
101
  "servers": {
89
102
  "imessage": {
90
103
  "command": "npx",
91
- "args": ["-y", "imessage-mcp-server"]
104
+ "args": ["-y", "imessage-mcp-server", "--server"]
92
105
  }
93
106
  }
94
107
  }
95
108
  ```
96
109
 
97
- ### Option 2: Global install
98
-
99
- ```bash
100
- npm install -g imessage-mcp-server
101
- ```
110
+ ### Bridge mode
102
111
 
103
- Then reference the binary directly in your MCP config:
112
+ Create a `bridge-config.json`:
104
113
 
105
114
  ```json
106
115
  {
116
+ "masterHandle": "your-email@icloud.com",
117
+ "provider": "anthropic",
118
+ "apiKey": "${ANTHROPIC_API_KEY}",
119
+ "model": "claude-3-5-sonnet-20241022",
107
120
  "mcpServers": {
108
- "imessage": {
109
- "command": "imessage-mcp",
110
- "args": []
121
+ "filesystem": {
122
+ "command": "npx",
123
+ "args": ["-y", "@modelcontextprotocol/server-filesystem", "/Users/YOU"]
111
124
  }
112
125
  }
113
126
  }
114
127
  ```
115
128
 
116
- ### Option 3: Clone from source
129
+ Run in foreground for testing:
117
130
 
118
131
  ```bash
119
- git clone https://github.com/tinyxia/imessage-mcp.git
120
- cd imessage-mcp
121
- npm install
132
+ npx imessage-mcp-server --bridge --config ./bridge-config.json --foreground
122
133
  ```
123
134
 
124
- Then reference the local path:
135
+ Install as a macOS LaunchAgent (auto-start on login):
136
+
137
+ ```bash
138
+ npx imessage-mcp-server --bridge --install-service --config ./bridge-config.json
139
+ npx imessage-mcp-server --bridge --status
140
+ npx imessage-mcp-server --bridge --uninstall
141
+ ```
142
+
143
+ > **Note:** When running as a LaunchAgent, the bridge does **not** inherit environment variables from your shell. If your `apiKey` uses `${ANTHROPIC_API_KEY}` env substitution, the service won't be able to resolve it. Put the API key directly in the config file instead.
144
+
145
+ ---
146
+
147
+ ## CLI Reference
148
+
149
+ ```bash
150
+ # Show help / version
151
+ npx imessage-mcp-server --help
152
+ npx imessage-mcp-server --version
153
+
154
+ # MCP Server mode
155
+ npx imessage-mcp-server --server
156
+
157
+ # Bridge mode
158
+ npx imessage-mcp-server --bridge --config ./bridge-config.json
159
+ npx imessage-mcp-server --bridge --foreground
160
+ npx imessage-mcp-server --bridge --test-config
161
+ npx imessage-mcp-server --bridge --install-service --config ./bridge-config.json
162
+ npx imessage-mcp-server --bridge --status
163
+ npx imessage-mcp-server --bridge --uninstall
164
+ ```
165
+
166
+ ---
167
+
168
+ ## Bridge Configuration
169
+
170
+ ### Full schema
125
171
 
126
172
  ```json
127
173
  {
174
+ "masterHandle": "your-email@icloud.com",
175
+ "provider": "anthropic",
176
+ "apiKey": "${ANTHROPIC_API_KEY}",
177
+ "baseUrl": null,
178
+ "model": "claude-3-5-sonnet-20241022",
179
+ "maxTokens": 4096,
180
+ "pollIntervalMs": 3000,
181
+ "maxHistoryPerConversation": 20,
182
+ "maxToolIterations": 10,
183
+ "sendProcessingIndicator": true,
184
+ "systemPrompt": "Optional custom system prompt",
185
+ "projectDir": "/Users/YOU/project",
128
186
  "mcpServers": {
129
- "imessage": {
130
- "command": "node",
131
- "args": ["/path/to/imessage-mcp/index.js"]
187
+ "filesystem": {
188
+ "command": "npx",
189
+ "args": ["-y", "@modelcontextprotocol/server-filesystem", "/Users/YOU"]
190
+ },
191
+ "shell": {
192
+ "command": "npx",
193
+ "args": ["-y", "mcp-shell-server"]
132
194
  }
195
+ },
196
+ "safety": {
197
+ "requireConfirmation": false,
198
+ "allowedTools": null,
199
+ "blockedTools": [],
200
+ "blockedCommands": ["rm -rf /", "sudo"],
201
+ "readOnly": false
133
202
  }
134
203
  }
135
204
  ```
136
205
 
206
+ ### Supported providers
207
+
208
+ | Provider | `provider` value | Notes |
209
+ |----------|------------------|-------|
210
+ | Anthropic / Claude | `anthropic` or `claude` | Native thinking blocks |
211
+ | OpenAI | `openai` | Official API |
212
+ | DeepSeek | `deepseek` | OpenAI-compatible endpoint |
213
+ | Kimi | `kimi` | OpenAI-compatible endpoint |
214
+ | Any OpenAI-compatible | `openai` | Set `baseUrl` |
215
+
216
+ ### Environment variables
217
+
218
+ | Variable | Description |
219
+ |----------|-------------|
220
+ | `IMESSAGE_DB_PATH` | Override the path to `chat.db` |
221
+ | `IMESSAGE_MASTER_HANDLE` | Your iMessage handle for bridge mode |
222
+ | `IMESSAGE_PROVIDER` | Default LLM provider |
223
+ | `ANTHROPIC_API_KEY` / `OPENAI_API_KEY` | API keys |
224
+ | `ANTHROPIC_BASE_URL` / `OPENAI_BASE_URL` | Custom API endpoints |
225
+
226
+ Config files support `${VAR_NAME}` syntax for env substitution.
227
+
137
228
  ---
138
229
 
139
- ## Tool Reference
230
+ ## MCP Tools (Server mode)
140
231
 
141
232
  ### `send_imessage`
142
233
 
143
234
  Send an iMessage to a recipient.
144
235
 
145
- **Parameters:**
146
-
147
- | Param | Type | Required | Description |
148
- |-------|------|----------|-------------|
149
- | `recipient` | string | ✅ | Email address or phone number of the recipient |
150
- | `text` | string | ✅ | Message text to send |
151
-
152
- **Example:**
153
236
  ```json
154
237
  { "recipient": "example@icloud.com", "text": "Hello from MCP!" }
155
238
  ```
156
239
 
157
240
  ### `list_conversations`
158
241
 
159
- List recent conversations with the latest message preview and unread count.
160
-
161
- **Parameters:**
242
+ List recent iMessage conversations.
162
243
 
163
- | Param | Type | Required | Default | Description |
164
- |-------|------|----------|---------|-------------|
165
- | `limit` | number | ❌ | 20 | Max conversations to return (max 100) |
244
+ | Param | Type | Default | Description |
245
+ |-------|------|---------|-------------|
246
+ | `limit` | number | 20 | Max conversations (max 100) |
166
247
 
167
248
  ### `read_conversation`
168
249
 
169
250
  Read messages from a specific conversation.
170
251
 
171
- **Parameters:**
172
-
173
- | Param | Type | Required | Default | Description |
174
- |-------|------|----------|---------|-------------|
175
- | `handle` | string | | | Filter by handle (email or phone number) |
176
- | `chat_id` | number | ❌ | — | Filter by chat ROWID |
177
- | `limit` | number | | 30 | Max messages to return (max 200) |
178
- | `before_id` | number | | | Paginate: return messages before this ROWID |
179
- | `include_read` | boolean | ❌ | true | Include already-read messages |
180
- | `unread_only` | boolean | ❌ | false | Only return unread messages |
252
+ | Param | Type | Default | Description |
253
+ |-------|------|---------|-------------|
254
+ | `handle` | string | | Filter by email/phone |
255
+ | `chat_id` | number | — | Filter by chat ROWID |
256
+ | `limit` | number | 30 | Max messages (max 200) |
257
+ | `before_id` | number | — | Paginate before ROWID |
258
+ | `include_read` | boolean | true | Include read messages |
259
+ | `unread_only` | boolean | false | Only unread |
181
260
 
182
261
  ### `get_new_messages`
183
262
 
184
263
  Poll for recently received messages.
185
264
 
186
- **Parameters:**
187
-
188
- | Param | Type | Required | Default | Description |
189
- |-------|------|----------|---------|-------------|
190
- | `since` | string | | last 10 | ISO timestamp to fetch messages from (e.g. `2026-06-28T10:00:00.000Z`) |
191
- | `mark_read` | boolean | ❌ | false | Mark unread messages as read in chat.db |
192
- | `max_results` | number | ❌ | 10 | Max messages to return (max 100) |
265
+ | Param | Type | Default | Description |
266
+ |-------|------|---------|-------------|
267
+ | `since` | string | | ISO timestamp |
268
+ | `max_results` | number | 10 | Max messages (max 100) |
269
+ | `unread_only` | boolean | false | Only unread |
193
270
 
194
271
  ---
195
272
 
196
- ## Environment Variables
273
+ ## Bridge Tools
274
+
275
+ In bridge mode, the AI can use any tools exposed by the configured MCP servers, plus two built-in local tools:
197
276
 
198
- | Variable | Default | Description |
199
- |----------|---------|-------------|
200
- | `IMESSAGE_DB_PATH` | `~/Library/Messages/chat.db` | Override the path to the iMessage chat database |
277
+ - `send_imessage` send a message to any recipient
278
+ - `send_long_reply` — split a long response into multiple iMessages
201
279
 
202
280
  ---
203
281
 
204
- ## Troubleshooting
282
+ ## Security Notes
205
283
 
206
- | Problem | Solution |
207
- |---------|----------|
208
- | **iMessage database not found** | Make sure you are signed into iMessage in the Messages app. If your database is in a non-standard location, set `IMESSAGE_DB_PATH`. |
209
- | 🔒 **Permission denied / database unreadable** | Grant **Full Disk Access** to your terminal/IDE in _System Settings → Privacy & Security → Full Disk Access_. Restart your terminal after granting. |
210
- | 🔐 **"Database is locked"** | Quit the Messages app completely or wait for sync to finish. |
211
- | 💻 **osascript failed** | Make sure Messages.app is running and signed into your Apple ID. |
212
- | ⚠️ **better-sqlite3 compilation errors** | Install Xcode CLI Tools: `xcode-select --install` and try again. |
213
- | 🐢 **First `npx` run is slow** | npx downloads and compiles native modules on first run. Subsequent runs are cached. |
284
+ - The iMessage database is opened in **read-only mode** for all read operations.
285
+ - Bridge mode only processes messages from the configured `masterHandle`; all other senders are ignored.
286
+ - Use `safety.readOnly: true` to prevent write tools.
287
+ - Use `safety.allowedTools` to whitelist allowed tools.
288
+ - Use `safety.blockedCommands` to blacklist dangerous shell patterns.
289
+ - All chat data stays on your Mac; only API calls to your chosen LLM provider leave the machine.
214
290
 
215
291
  ---
216
292
 
217
- ## Security Notes
293
+ ## Troubleshooting
218
294
 
219
- - The iMessage database is opened in **read-only mode** (`chat.db` is never modified by read operations)
220
- - The `mark_read` option in `get_new_messages` is the only operation that writes to the database
221
- - Sending messages is done through **AppleScript** (`osascript`) which respects macOS privacy controls
222
- - Your chat data **never leaves your machine** all processing is local
295
+ | Problem | Solution |
296
+ |---------|----------|
297
+ | iMessage database not found | Sign into Messages app or set `IMESSAGE_DB_PATH`. |
298
+ | 🔒 Permission denied | Grant **Full Disk Access** to your terminal/IDE. |
299
+ | 🔐 "Database is locked" | Quit Messages app or wait for sync. |
300
+ | 💻 osascript failed | Make sure Messages.app is running and signed in. |
301
+ | ⚠️ better-sqlite3 compile errors | Run `xcode-select --install`. |
302
+ | 🐢 First `npx` run is slow | Native modules compile on first run; later runs are cached. |
223
303
 
224
304
  ---
225
305
 
package/README.zh.md ADDED
@@ -0,0 +1,310 @@
1
+ # imessage-mcp-server
2
+
3
+ > **macOS 上的 iMessage MCP Server + AI Bridge**
4
+ > 通过 [Model Context Protocol](https://modelcontextprotocol.io) 暴露你的 iMessage 读写能力,或者把你的 Mac 变成 24 小时在线的 iMessage AI 助手。
5
+
6
+ [English README](README.md)
7
+
8
+ ⚠️ **仅限 macOS** — 需要系统「信息」应用及其 SQLite 数据库(`~/Library/Messages/chat.db`)。
9
+
10
+ ---
11
+
12
+ ## 功能特性
13
+
14
+ ### MCP Server 模式
15
+
16
+ 提供 4 个标准 MCP 工具,用于读取和发送 iMessage:
17
+
18
+ | 工具 | 说明 |
19
+ | ------ | ------ |
20
+ | `send_imessage` | 向指定邮箱或手机号发送 iMessage |
21
+ | `list_conversations` | 列出最近会话,含最新消息摘要和未读数 |
22
+ | `read_conversation` | 读取某个会话的分页消息 |
23
+ | `get_new_messages` | 按时间戳轮询新收到的消息 |
24
+
25
+ ### Bridge 模式
26
+
27
+ 在后台运行一个自主 AI Agent:
28
+
29
+ - 轮询你指定的 `masterHandle` 发来的新 iMessage
30
+ - 调用 Claude、OpenAI、DeepSeek、Kimi 或任意 OpenAI 兼容模型
31
+ - 连接任意 MCP Server 作为工具(文件系统、Shell、Git 等)
32
+ - 自动把结果通过 iMessage 回复给你
33
+ - 记住多轮对话上下文
34
+ - 支持 macOS LaunchAgent 开机自启
35
+
36
+ ---
37
+
38
+ ## 环境要求
39
+
40
+ - **macOS**(建议 Ventura 或更新版本)
41
+ - **Node.js >= 18**
42
+ - 已在「信息」App 中**登录 iMessage**
43
+ - 给终端 / IDE 授予**完全磁盘访问权限**
44
+ - 系统设置 → 隐私与安全性 → 完全磁盘访问权限
45
+ - 添加你的终端应用(Terminal、iTerm2、VS Code 等)
46
+ - **Xcode 命令行工具**(用于编译原生模块 `better-sqlite3`)
47
+
48
+ ```bash
49
+ xcode-select --install
50
+ ```
51
+
52
+ ---
53
+
54
+ ## 快速开始
55
+
56
+ ### MCP Server 模式
57
+
58
+ 把以下内容加到 MCP 客户端配置中:
59
+
60
+ **Claude Code**(`.claude/settings.json`):
61
+
62
+ ```json
63
+ {
64
+ "mcpServers": {
65
+ "imessage": {
66
+ "command": "npx",
67
+ "args": ["-y", "imessage-mcp-server", "--server"]
68
+ }
69
+ }
70
+ }
71
+ ```
72
+
73
+ **Claude Desktop**(`~/Library/Application Support/Claude/claude_desktop_config.json`):
74
+
75
+ ```json
76
+ {
77
+ "mcpServers": {
78
+ "imessage": {
79
+ "command": "npx",
80
+ "args": ["-y", "imessage-mcp-server", "--server"]
81
+ }
82
+ }
83
+ }
84
+ ```
85
+
86
+ **Cursor**(`.cursor/mcp.json`):
87
+
88
+ ```json
89
+ {
90
+ "mcpServers": {
91
+ "imessage": {
92
+ "command": "npx",
93
+ "args": ["-y", "imessage-mcp-server", "--server"]
94
+ }
95
+ }
96
+ }
97
+ ```
98
+
99
+ **VS Code + GitHub Copilot**(`.vscode/mcp.json`):
100
+
101
+ ```json
102
+ {
103
+ "servers": {
104
+ "imessage": {
105
+ "command": "npx",
106
+ "args": ["-y", "imessage-mcp-server", "--server"]
107
+ }
108
+ }
109
+ }
110
+ ```
111
+
112
+ ### Bridge 模式
113
+
114
+ 创建 `bridge-config.json`:
115
+
116
+ ```json
117
+ {
118
+ "masterHandle": "你的邮箱@icloud.com",
119
+ "provider": "anthropic",
120
+ "apiKey": "${ANTHROPIC_API_KEY}",
121
+ "model": "claude-3-5-sonnet-20241022",
122
+ "mcpServers": {
123
+ "filesystem": {
124
+ "command": "npx",
125
+ "args": ["-y", "@modelcontextprotocol/server-filesystem", "/Users/你的用户名"]
126
+ }
127
+ }
128
+ }
129
+ ```
130
+
131
+ 前台测试运行:
132
+
133
+ ```bash
134
+ npx imessage-mcp-server --bridge --config ./bridge-config.json --foreground
135
+ ```
136
+
137
+ 安装为 macOS LaunchAgent(开机自启):
138
+
139
+ ```bash
140
+ npx imessage-mcp-server --bridge --install-service --config ./bridge-config.json
141
+ npx imessage-mcp-server --bridge --status
142
+ npx imessage-mcp-server --bridge --uninstall
143
+ ```
144
+
145
+ > **注意**:LaunchAgent 不会继承 shell 的环境变量。如果 `apiKey` 使用 `${ANTHROPIC_API_KEY}` 这种环境变量引用,服务启动时会读不到。建议直接把 API Key 写入配置文件。
146
+
147
+ ---
148
+
149
+ ## CLI 参考
150
+
151
+ ```bash
152
+ # 查看帮助 / 版本
153
+ npx imessage-mcp-server --help
154
+ npx imessage-mcp-server --version
155
+
156
+ # MCP Server 模式
157
+ npx imessage-mcp-server --server
158
+
159
+ # Bridge 模式
160
+ npx imessage-mcp-server --bridge --config ./bridge-config.json
161
+ npx imessage-mcp-server --bridge --foreground
162
+ npx imessage-mcp-server --bridge --test-config
163
+ npx imessage-mcp-server --bridge --install-service --config ./bridge-config.json
164
+ npx imessage-mcp-server --bridge --status
165
+ npx imessage-mcp-server --bridge --uninstall
166
+ ```
167
+
168
+ ---
169
+
170
+ ## Bridge 配置说明
171
+
172
+ ### 完整配置示例
173
+
174
+ ```json
175
+ {
176
+ "masterHandle": "你的邮箱@icloud.com",
177
+ "provider": "anthropic",
178
+ "apiKey": "${ANTHROPIC_API_KEY}",
179
+ "baseUrl": null,
180
+ "model": "claude-3-5-sonnet-20241022",
181
+ "maxTokens": 4096,
182
+ "pollIntervalMs": 3000,
183
+ "maxHistoryPerConversation": 20,
184
+ "maxToolIterations": 10,
185
+ "sendProcessingIndicator": true,
186
+ "systemPrompt": "可选的自定义系统提示词",
187
+ "projectDir": "/Users/你的用户名/project",
188
+ "mcpServers": {
189
+ "filesystem": {
190
+ "command": "npx",
191
+ "args": ["-y", "@modelcontextprotocol/server-filesystem", "/Users/你的用户名"]
192
+ },
193
+ "shell": {
194
+ "command": "npx",
195
+ "args": ["-y", "mcp-shell-server"]
196
+ }
197
+ },
198
+ "safety": {
199
+ "requireConfirmation": false,
200
+ "allowedTools": null,
201
+ "blockedTools": [],
202
+ "blockedCommands": ["rm -rf /", "sudo"],
203
+ "readOnly": false
204
+ }
205
+ }
206
+ ```
207
+
208
+ ### 支持的模型后端
209
+
210
+ | 后端 | `provider` 值 | 说明 |
211
+ | ------ | -------------- | ------ |
212
+ | Anthropic / Claude | `anthropic` 或 `claude` | 原生支持 thinking blocks |
213
+ | OpenAI | `openai` | 官方 API |
214
+ | DeepSeek | `deepseek` | OpenAI 兼容接口 |
215
+ | Kimi | `kimi` | OpenAI 兼容接口 |
216
+ | 任意 OpenAI 兼容模型 | `openai` | 设置 `baseUrl` 即可 |
217
+
218
+ ### 环境变量
219
+
220
+ | 变量 | 说明 |
221
+ | ------ | ------ |
222
+ | `IMESSAGE_DB_PATH` | 自定义 `chat.db` 路径 |
223
+ | `IMESSAGE_MASTER_HANDLE` | Bridge 模式的主用户 iMessage 账号 |
224
+ | `IMESSAGE_PROVIDER` | 默认 LLM 后端 |
225
+ | `ANTHROPIC_API_KEY` / `OPENAI_API_KEY` | API 密钥 |
226
+ | `ANTHROPIC_BASE_URL` / `OPENAI_BASE_URL` | 自定义 API 端点 |
227
+
228
+ 配置文件支持 `${VAR_NAME}` 语法引用环境变量。
229
+
230
+ ---
231
+
232
+ ## MCP 工具(Server 模式)
233
+
234
+ ### `send_imessage`
235
+
236
+ 发送一条 iMessage。
237
+
238
+ ```json
239
+ { "recipient": "example@icloud.com", "text": "Hello from MCP!" }
240
+ ```
241
+
242
+ ### `list_conversations`
243
+
244
+ 列出最近会话。
245
+
246
+ | 参数 | 类型 | 默认值 | 说明 |
247
+ |------|------|--------|------|
248
+ | `limit` | number | 20 | 最大返回会话数(最大 100) |
249
+
250
+ ### `read_conversation`
251
+
252
+ 读取某个会话的消息。
253
+
254
+ | 参数 | 类型 | 默认值 | 说明 |
255
+ | ------ | ------ | -------- | ------ |
256
+ | `handle` | string | — | 按邮箱/手机号过滤 |
257
+ | `chat_id` | number | — | 按 chat ROWID 过滤 |
258
+ | `limit` | number | 30 | 最大返回消息数(最大 200) |
259
+ | `before_id` | number | — | 分页:返回该 ROWID 之前的消息 |
260
+ | `include_read` | boolean | true | 包含已读消息 |
261
+ | `unread_only` | boolean | false | 仅返回未读消息 |
262
+
263
+ ### `get_new_messages`
264
+
265
+ 轮询最近收到的消息。
266
+
267
+ | 参数 | 类型 | 默认值 | 说明 |
268
+ | ------ | ------ | -------- | ------ |
269
+ | `since` | string | — | ISO 时间戳 |
270
+ | `max_results` | number | 10 | 最大返回消息数(最大 100) |
271
+ | `unread_only` | boolean | false | 仅返回未读消息 |
272
+
273
+ ---
274
+
275
+ ## Bridge 工具
276
+
277
+ Bridge 模式下,AI 可以使用所有已配置 MCP Server 提供的工具,外加两个内置本地工具:
278
+
279
+ - `send_imessage` — 向任意收件人发送消息
280
+ - `send_long_reply` — 把长回复拆成多条 iMessage 发送
281
+
282
+ ---
283
+
284
+ ## 安全说明
285
+
286
+ - 所有读取操作都以**只读模式**打开 `chat.db`,不会修改数据库。
287
+ - Bridge 模式只处理 `masterHandle` 发来的消息,其他人完全忽略。
288
+ - 使用 `safety.readOnly: true` 可禁用写入类工具。
289
+ - 使用 `safety.allowedTools` 可白名单限制可调用的工具。
290
+ - 使用 `safety.blockedCommands` 可黑名单拦截危险命令。
291
+ - 所有聊天数据留在你的 Mac 上;只有调用 LLM 后端的请求会离开本机。
292
+
293
+ ---
294
+
295
+ ## 常见问题
296
+
297
+ | 问题 | 解决方法 |
298
+ | ------ | --------- |
299
+ | ❌ 找不到 iMessage 数据库 | 确认已在「信息」App 登录;或通过 `IMESSAGE_DB_PATH` 指定路径。 |
300
+ | 🔒 读取数据库权限不足 | 给终端/IDE 开启「完全磁盘访问权限」。 |
301
+ | 🔐 提示 "Database is locked" | 完全退出「信息」App,或等待同步完成。 |
302
+ | 💻 osascript 执行失败 | 确认「信息」App 已运行并登录 Apple ID。 |
303
+ | ⚠️ better-sqlite3 编译失败 | 运行 `xcode-select --install` 后重试。 |
304
+ | 🐢 首次 `npx` 运行很慢 | 首次会下载并编译原生模块,后续会缓存。 |
305
+
306
+ ---
307
+
308
+ ## 许可证
309
+
310
+ MIT © 2026 tinyxia
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env node
2
+ import { main } from "../src/cli.js";
3
+
4
+ await main();