@zyx1121/apple-messages-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 +60 -0
- package/dist/helpers.d.ts +25 -0
- package/dist/helpers.js +65 -0
- package/dist/helpers.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +11 -0
- package/dist/index.js.map +1 -0
- package/dist/server.d.ts +2 -0
- package/dist/server.js +11 -0
- package/dist/server.js.map +1 -0
- package/dist/tools/messages.d.ts +2 -0
- package/dist/tools/messages.js +82 -0
- package/dist/tools/messages.js.map +1 -0
- package/package.json +38 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 zyx1121
|
|
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,60 @@
|
|
|
1
|
+
```
|
|
2
|
+
█████╗ ██████╗ ██████╗ ██╗ ███████╗ ███╗ ███╗███████╗███████╗███████╗
|
|
3
|
+
██╔══██╗██╔══██╗██╔══██╗██║ ██╔════╝ ████╗ ████║██╔════╝██╔════╝██╔════╝
|
|
4
|
+
███████║██████╔╝██████╔╝██║ █████╗ ██╔████╔██║█████╗ ███████╗███████╗
|
|
5
|
+
██╔══██║██╔═══╝ ██╔═══╝ ██║ ██╔══╝ ██║╚██╔╝██║██╔══╝ ╚════██║╚════██║
|
|
6
|
+
██║ ██║██║ ██║ ███████╗███████╗ ██║ ╚═╝ ██║███████╗███████║███████║
|
|
7
|
+
╚═╝ ╚═╝╚═╝ ╚═╝ ╚══════╝╚══════╝ ╚═╝ ╚═╝╚══════╝╚══════╝╚══════╝
|
|
8
|
+
|
|
9
|
+
█████╗ ██████╗ ███████╗███████╗
|
|
10
|
+
██╔══██╗██╔════╝ ██╔════╝██╔════╝
|
|
11
|
+
███████║██║ ███╗█████╗ ███████╗
|
|
12
|
+
██╔══██║██║ ██║██╔══╝ ╚════██║
|
|
13
|
+
██║ ██║╚██████╔╝███████╗███████║
|
|
14
|
+
╚═╝ ╚═╝ ╚═════╝ ╚══════╝╚══════╝
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
# @zyx1121/apple-messages-mcp
|
|
18
|
+
|
|
19
|
+
MCP server for Apple Messages — send and read iMessages via Claude Code.
|
|
20
|
+
|
|
21
|
+
## Install
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
claude mcp add apple-messages -- npx @zyx1121/apple-messages-mcp
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Prerequisites
|
|
28
|
+
|
|
29
|
+
- macOS with Messages.app configured
|
|
30
|
+
- Node.js >= 18
|
|
31
|
+
- First run will prompt for Automation permission (System Settings > Privacy & Security > Automation)
|
|
32
|
+
- Reading messages requires Full Disk Access (System Settings > Privacy & Security > Full Disk Access)
|
|
33
|
+
|
|
34
|
+
## Tools
|
|
35
|
+
|
|
36
|
+
| Tool | Description |
|
|
37
|
+
|------|-------------|
|
|
38
|
+
| `messages_send` | Send an iMessage to a phone number or email |
|
|
39
|
+
| `messages_list_chats` | List recent chats/conversations |
|
|
40
|
+
| `messages_read` | Read recent messages from a specific chat or contact |
|
|
41
|
+
| `messages_search` | Search messages by keyword |
|
|
42
|
+
|
|
43
|
+
## Examples
|
|
44
|
+
|
|
45
|
+
```
|
|
46
|
+
"Send 'hello' to +886912345678" → messages_send { to: "+886912345678", message: "hello" }
|
|
47
|
+
"Show my recent chats" → messages_list_chats {}
|
|
48
|
+
"Read messages from John" → messages_read { contact: "john@example.com" }
|
|
49
|
+
"Search for 'meeting'" → messages_search { query: "meeting" }
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Limitations
|
|
53
|
+
|
|
54
|
+
- macOS only (uses AppleScript via `osascript` and `sqlite3`)
|
|
55
|
+
- Sending uses AppleScript — Messages.app must be running
|
|
56
|
+
- Reading uses `~/Library/Messages/chat.db` — requires Full Disk Access
|
|
57
|
+
|
|
58
|
+
## License
|
|
59
|
+
|
|
60
|
+
[MIT](LICENSE) — read at your own risk
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export declare class AppleMessagesError extends Error {
|
|
2
|
+
constructor(message: string);
|
|
3
|
+
}
|
|
4
|
+
export declare function runAppleScript(script: string): Promise<string>;
|
|
5
|
+
export declare function escapeForAppleScript(str: string): string;
|
|
6
|
+
export declare function runSqlite(dbPath: string, query: string): Promise<string>;
|
|
7
|
+
export declare function success(data: unknown): {
|
|
8
|
+
content: {
|
|
9
|
+
type: "text";
|
|
10
|
+
text: string;
|
|
11
|
+
}[];
|
|
12
|
+
};
|
|
13
|
+
export declare function error(message: string): {
|
|
14
|
+
content: {
|
|
15
|
+
type: "text";
|
|
16
|
+
text: string;
|
|
17
|
+
}[];
|
|
18
|
+
isError: true;
|
|
19
|
+
};
|
|
20
|
+
export declare function withErrorHandling<T extends Record<string, unknown>>(fn: (args: T) => Promise<ReturnType<typeof success | typeof error>>): (args: T) => Promise<{
|
|
21
|
+
content: {
|
|
22
|
+
type: "text";
|
|
23
|
+
text: string;
|
|
24
|
+
}[];
|
|
25
|
+
}>;
|
package/dist/helpers.js
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { execFile } from "node:child_process";
|
|
2
|
+
const TIMEOUT_MS = 15_000;
|
|
3
|
+
export class AppleMessagesError extends Error {
|
|
4
|
+
constructor(message) {
|
|
5
|
+
super(message);
|
|
6
|
+
this.name = "AppleMessagesError";
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
export async function runAppleScript(script) {
|
|
10
|
+
return new Promise((resolve, reject) => {
|
|
11
|
+
execFile("osascript", ["-e", script], { timeout: TIMEOUT_MS }, (err, stdout, stderr) => {
|
|
12
|
+
if (err) {
|
|
13
|
+
const msg = stderr || err.message;
|
|
14
|
+
if (msg.includes("not running") || msg.includes("-600"))
|
|
15
|
+
return reject(new AppleMessagesError("Messages.app is not running. Please open Messages and try again."));
|
|
16
|
+
if (msg.includes("not allowed") || msg.includes("not permitted"))
|
|
17
|
+
return reject(new AppleMessagesError("Permission denied. Grant automation access in System Settings > Privacy & Security > Automation."));
|
|
18
|
+
if (msg.includes("timed out") || err.code === "ETIMEDOUT")
|
|
19
|
+
return reject(new AppleMessagesError("AppleScript execution timed out."));
|
|
20
|
+
return reject(new AppleMessagesError(msg.trim()));
|
|
21
|
+
}
|
|
22
|
+
resolve(stdout.trimEnd());
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
export function escapeForAppleScript(str) {
|
|
27
|
+
return str.replace(/\\/g, "\\\\").replace(/"/g, '\\"');
|
|
28
|
+
}
|
|
29
|
+
export async function runSqlite(dbPath, query) {
|
|
30
|
+
return new Promise((resolve, reject) => {
|
|
31
|
+
execFile("sqlite3", ["-json", dbPath, query], { timeout: TIMEOUT_MS }, (err, stdout, stderr) => {
|
|
32
|
+
if (err) {
|
|
33
|
+
const msg = stderr || err.message;
|
|
34
|
+
if (msg.includes("unable to open"))
|
|
35
|
+
return reject(new AppleMessagesError("Cannot open chat.db. Grant Full Disk Access in System Settings > Privacy & Security > Full Disk Access."));
|
|
36
|
+
return reject(new AppleMessagesError(msg.trim()));
|
|
37
|
+
}
|
|
38
|
+
resolve(stdout.trimEnd());
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
export function success(data) {
|
|
43
|
+
return {
|
|
44
|
+
content: [{ type: "text", text: JSON.stringify(data, null, 2) }],
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
export function error(message) {
|
|
48
|
+
return {
|
|
49
|
+
content: [{ type: "text", text: JSON.stringify({ error: message }) }],
|
|
50
|
+
isError: true,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
export function withErrorHandling(fn) {
|
|
54
|
+
return async (args) => {
|
|
55
|
+
try {
|
|
56
|
+
return await fn(args);
|
|
57
|
+
}
|
|
58
|
+
catch (e) {
|
|
59
|
+
if (e instanceof AppleMessagesError)
|
|
60
|
+
return error(e.message);
|
|
61
|
+
throw e;
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=helpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAE9C,MAAM,UAAU,GAAG,MAAM,CAAC;AAE1B,MAAM,OAAO,kBAAmB,SAAQ,KAAK;IAC3C,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,oB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O,KAAK,EAAE,IAAO,EAAE,EAAE;QACvB,IAAI,CAAC;YACH,OAAO,MAAM,EAAE,CAAC,IAAI,CAAC,CAAC;QACxB,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,IAAI,CAAC,YAAY,kBAAkB;gBAAE,OAAO,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;YAC7D,MAAM,CAAC,CAAC;QACV,CAAC;IACH,CAAC,CAAC;AACJ,CAAC"}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
3
|
+
import { createServer } from "./server.js";
|
|
4
|
+
if (process.platform !== "darwin") {
|
|
5
|
+
console.error("apple-messages-mcp requires macOS with Messages.app.");
|
|
6
|
+
process.exit(1);
|
|
7
|
+
}
|
|
8
|
+
const server = createServer();
|
|
9
|
+
const transport = new StdioServerTransport();
|
|
10
|
+
await server.connect(transport);
|
|
11
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3C,IAAI,OAAO,CAAC,QAAQ,KAAK,QAAQ,EAAE,CAAC;IAClC,OAAO,CAAC,KAAK,CAAC,sDAAsD,CAAC,CAAC;IACtE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC;AAED,MAAM,MAAM,GAAG,YAAY,EAAE,CAAC;AAC9B,MAAM,SAAS,GAAG,IAAI,oBAAoB,EAAE,CAAC;AAC7C,MAAM,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC"}
|
package/dist/server.d.ts
ADDED
package/dist/server.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2
|
+
import { registerMessagesTools } from "./tools/messages.js";
|
|
3
|
+
export function createServer() {
|
|
4
|
+
const server = new McpServer({
|
|
5
|
+
name: "apple-messages",
|
|
6
|
+
version: "0.1.0",
|
|
7
|
+
});
|
|
8
|
+
registerMessagesTools(server);
|
|
9
|
+
return server;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=server.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACpE,OAAO,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AAE5D,MAAM,UAAU,YAAY;IAC1B,MAAM,MAAM,GAAG,IAAI,SAAS,CAAC;QAC3B,IAAI,EAAE,gBAAgB;QACtB,OAAO,EAAE,OAAO;KACjB,CAAC,CAAC;IAEH,qBAAqB,CAAC,MAAM,CAAC,CAAC;IAE9B,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { runAppleScript, runSqlite, escapeForAppleScript, success, withErrorHandling } from "../helpers.js";
|
|
3
|
+
const DB_PATH = `${process.env.HOME}/Library/Messages/chat.db`;
|
|
4
|
+
export function registerMessagesTools(server) {
|
|
5
|
+
server.tool("messages_send", "Send an iMessage to a phone number or email", {
|
|
6
|
+
to: z.string().describe("Recipient phone number or email address"),
|
|
7
|
+
message: z.string().describe("Message text to send"),
|
|
8
|
+
}, withErrorHandling(async ({ to, message }) => {
|
|
9
|
+
const esc = escapeForAppleScript;
|
|
10
|
+
await runAppleScript(`
|
|
11
|
+
tell application "Messages"
|
|
12
|
+
send "${esc(message)}" to buddy "${esc(to)}" of service 1
|
|
13
|
+
end tell`);
|
|
14
|
+
return success({ to, sent: true });
|
|
15
|
+
}));
|
|
16
|
+
server.tool("messages_list_chats", "List recent chats/conversations from Messages", {
|
|
17
|
+
limit: z.number().optional().default(50).describe("Max number of chats to return"),
|
|
18
|
+
}, withErrorHandling(async ({ limit }) => {
|
|
19
|
+
const query = `
|
|
20
|
+
SELECT c.ROWID as chat_id, c.chat_identifier, c.display_name,
|
|
21
|
+
datetime(m.date/1000000000 + 978307200, 'unixepoch', 'localtime') as last_message_date
|
|
22
|
+
FROM chat c
|
|
23
|
+
LEFT JOIN chat_message_join cmj ON c.ROWID = cmj.chat_id
|
|
24
|
+
LEFT JOIN message m ON cmj.message_id = m.ROWID
|
|
25
|
+
GROUP BY c.ROWID
|
|
26
|
+
ORDER BY m.date DESC
|
|
27
|
+
LIMIT ${limit};`;
|
|
28
|
+
const raw = await runSqlite(DB_PATH, query);
|
|
29
|
+
const chats = raw ? JSON.parse(raw) : [];
|
|
30
|
+
return success(chats);
|
|
31
|
+
}));
|
|
32
|
+
server.tool("messages_read", "Read recent messages from a specific chat or contact", {
|
|
33
|
+
chat_id: z.string().optional().describe("Chat ROWID from messages_list_chats"),
|
|
34
|
+
contact: z.string().optional().describe("Phone number or email to find chat by"),
|
|
35
|
+
limit: z.number().optional().default(20).describe("Max number of messages to return"),
|
|
36
|
+
}, withErrorHandling(async ({ chat_id, contact, limit }) => {
|
|
37
|
+
if (!chat_id && !contact)
|
|
38
|
+
throw new Error("Provide either chat_id or contact");
|
|
39
|
+
let chatFilter;
|
|
40
|
+
if (chat_id) {
|
|
41
|
+
chatFilter = `cmj.chat_id = ${parseInt(chat_id, 10)}`;
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
const escaped = contact.replace(/'/g, "''");
|
|
45
|
+
chatFilter = `cmj.chat_id IN (SELECT ROWID FROM chat WHERE chat_identifier LIKE '%${escaped}%')`;
|
|
46
|
+
}
|
|
47
|
+
const query = `
|
|
48
|
+
SELECT m.text, m.is_from_me,
|
|
49
|
+
datetime(m.date/1000000000 + 978307200, 'unixepoch', 'localtime') as date,
|
|
50
|
+
h.id as sender
|
|
51
|
+
FROM message m
|
|
52
|
+
JOIN chat_message_join cmj ON m.ROWID = cmj.message_id
|
|
53
|
+
LEFT JOIN handle h ON m.handle_id = h.ROWID
|
|
54
|
+
WHERE ${chatFilter} AND m.text IS NOT NULL
|
|
55
|
+
ORDER BY m.date DESC
|
|
56
|
+
LIMIT ${limit};`;
|
|
57
|
+
const raw = await runSqlite(DB_PATH, query);
|
|
58
|
+
const messages = raw ? JSON.parse(raw) : [];
|
|
59
|
+
return success(messages);
|
|
60
|
+
}));
|
|
61
|
+
server.tool("messages_search", "Search messages by keyword", {
|
|
62
|
+
query: z.string().describe("Search keyword"),
|
|
63
|
+
limit: z.number().optional().default(20).describe("Max number of results to return"),
|
|
64
|
+
}, withErrorHandling(async ({ query: keyword, limit }) => {
|
|
65
|
+
const escaped = keyword.replace(/'/g, "''");
|
|
66
|
+
const sql = `
|
|
67
|
+
SELECT m.text, m.is_from_me,
|
|
68
|
+
datetime(m.date/1000000000 + 978307200, 'unixepoch', 'localtime') as date,
|
|
69
|
+
h.id as sender, c.chat_identifier
|
|
70
|
+
FROM message m
|
|
71
|
+
LEFT JOIN handle h ON m.handle_id = h.ROWID
|
|
72
|
+
JOIN chat_message_join cmj ON m.ROWID = cmj.message_id
|
|
73
|
+
JOIN chat c ON cmj.chat_id = c.ROWID
|
|
74
|
+
WHERE m.text LIKE '%${escaped}%'
|
|
75
|
+
ORDER BY m.date DESC
|
|
76
|
+
LIMIT ${limit};`;
|
|
77
|
+
const raw = await runSqlite(DB_PATH, sql);
|
|
78
|
+
const messages = raw ? JSON.parse(raw) : [];
|
|
79
|
+
return success(messages);
|
|
80
|
+
}));
|
|
81
|
+
}
|
|
82
|
+
//# sourceMappingURL=messages.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"messages.js","sourceRoot":"","sources":["../../src/tools/messages.ts"],"names":[],"mapp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,CAAC;QAC5C,OAAO,OAAO,CAAC,QAAQ,CAAC,CAAC;IAC3B,CAAC,CAAC,CACH,CAAC;IAEF,MAAM,CAAC,IAAI,CACT,iBAAiB,EACjB,4BAA4B,EAC5B;QACE,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,gBAAgB,CAAC;QAC5C,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,iCAAiC,CAAC;KACrF,EACD,iBAAiB,CAAC,KAAK,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE,EAAE;QACpD,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QAC5C,MAAM,GAAG,GAAG;;;;;;;;sBAQI,OAAO;;QAErB,KAAK,GAAG,CAAC;QACX,MAAM,GAAG,GAAG,MAAM,SAAS,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;QAC1C,MAAM,QAAQ,GAAG,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QAC5C,OAAO,OAAO,CAAC,QAAQ,CAAC,CAAC;IAC3B,CAAC,CAAC,CACH,CAAC;AACJ,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@zyx1121/apple-messages-mcp",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "MCP server for Apple Messages — send and read iMessages via Claude Code",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"bin": {
|
|
9
|
+
"apple-messages-mcp": "dist/index.js"
|
|
10
|
+
},
|
|
11
|
+
"files": [
|
|
12
|
+
"dist"
|
|
13
|
+
],
|
|
14
|
+
"scripts": {
|
|
15
|
+
"build": "tsc",
|
|
16
|
+
"prepublishOnly": "npm run build"
|
|
17
|
+
},
|
|
18
|
+
"keywords": [
|
|
19
|
+
"mcp",
|
|
20
|
+
"apple-messages",
|
|
21
|
+
"imessage",
|
|
22
|
+
"claude",
|
|
23
|
+
"macos"
|
|
24
|
+
],
|
|
25
|
+
"author": "zyx1121",
|
|
26
|
+
"license": "MIT",
|
|
27
|
+
"engines": {
|
|
28
|
+
"node": ">=18"
|
|
29
|
+
},
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"@modelcontextprotocol/sdk": "^1.12.1",
|
|
32
|
+
"zod": "^3.25.0"
|
|
33
|
+
},
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"@types/node": "^20.0.0",
|
|
36
|
+
"typescript": "^5.0.0"
|
|
37
|
+
}
|
|
38
|
+
}
|