@mgcrea/mcp-apple-messages 1.3.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 +138 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +29 -0
- package/dist/cli.js.map +1 -0
- package/dist/index.d.ts +806 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2 -0
- package/dist/server-DH4U3LBX.js +2137 -0
- package/dist/server-DH4U3LBX.js.map +1 -0
- package/package.json +70 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Olivier Louvignes <olivier@mgcrea.io>
|
|
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,138 @@
|
|
|
1
|
+
# @mgcrea/mcp-apple-messages
|
|
2
|
+
|
|
3
|
+
Model Context Protocol server for **Apple Messages** — iMessage, SMS and RCS — on macOS.
|
|
4
|
+
|
|
5
|
+
> **Unofficial.** Not affiliated with Apple. It reads the message store already on your Mac.
|
|
6
|
+
|
|
7
|
+
## The surface with no second lane
|
|
8
|
+
|
|
9
|
+
Every other server in this family has two ways in and picks the faster one. This one has exactly
|
|
10
|
+
one, and that is measured rather than assumed: **every read through Messages' scripting dictionary
|
|
11
|
+
fails.** It answers `Application isn't running` even while `NSRunningApplication` reports it running,
|
|
12
|
+
because it lives as a windowless background process that declines to wake for a script.
|
|
13
|
+
|
|
14
|
+
So **Full Disk Access is mandatory, not an upgrade.** Without it this server does nothing at all —
|
|
15
|
+
there is no degraded mode to fall back to.
|
|
16
|
+
|
|
17
|
+
Apple Events is still here, for exactly one verb. `send` is the only command in the dictionary that
|
|
18
|
+
works, which makes this the one surface where Apple Events is a **write lane and nothing else** —
|
|
19
|
+
and therefore the one where the write gate is also a permission boundary. With
|
|
20
|
+
`APPLE_MESSAGES_ALLOW_WRITES` off, no Apple Event is ever sent and no Automation grant is ever
|
|
21
|
+
requested. There is no read to leak through the gate, because there is no read.
|
|
22
|
+
|
|
23
|
+
## One message in thirty-two is invisible to SQL
|
|
24
|
+
|
|
25
|
+
`chat.db` keeps message text in two places, and the one you would reach for is the _incomplete_ one.
|
|
26
|
+
Measured on a real 97,416-message store:
|
|
27
|
+
|
|
28
|
+
| | |
|
|
29
|
+
| ----------------------------- | ---------------- |
|
|
30
|
+
| Messages | 97,416 |
|
|
31
|
+
| With a plain `text` column | 94,043 |
|
|
32
|
+
| With an `attributedBody` blob | 97,094 |
|
|
33
|
+
| **Blob only — no text** | **3,051 (3.1%)** |
|
|
34
|
+
|
|
35
|
+
The blob is an `NSArchiver` _typedstream_, and no amount of SQL reaches inside one. A server that
|
|
36
|
+
selects `text` returns nothing for one message in thirty-two, silently and with no error to notice.
|
|
37
|
+
|
|
38
|
+
**And that ratio is a historical average.** Measured through this server against a live store: 2016
|
|
39
|
+
through 2025 are ~99% plain `text`, and then it stops — **from March 2026 every message is blob-only.**
|
|
40
|
+
Apple appears to have dropped the column between late February and late March. So the decoder is not
|
|
41
|
+
handling an edge case; it is the only way to read anything recent, and a server without one would
|
|
42
|
+
report that the conversation stopped in February.
|
|
43
|
+
|
|
44
|
+
This package decodes it. The decoder was written against ground truth — `NSArchiver` still ships on
|
|
45
|
+
macOS 26 and is what wrote those blobs, so archiving a known string produces a fixture nobody has to
|
|
46
|
+
guess at — and then validated against the whole store using `text` as an oracle on 94,043 labelled
|
|
47
|
+
rows:
|
|
48
|
+
|
|
49
|
+
**100.000% agreement. 97,094 of 97,094 blobs decoded, none failed.** ~2 ms per thousand.
|
|
50
|
+
|
|
51
|
+
`decodeAttributedBody()` is exported from the package root.
|
|
52
|
+
|
|
53
|
+
## Names come from Contacts
|
|
54
|
+
|
|
55
|
+
`chat.db` records a correspondent as `+15551234567` and nothing else, so this server depends on
|
|
56
|
+
[`@mgcrea/mcp-apple-contacts`](../contacts) to turn that into a name. Every correspondent carries
|
|
57
|
+
both, plus a `resolution` status.
|
|
58
|
+
|
|
59
|
+
**`unknown` is normal, not an error.** Measured against a real address book: 97.6% of the last year's
|
|
60
|
+
messages resolve, but only ~84% of the twenty-five busiest correspondents — so roughly one in six of
|
|
61
|
+
the people you talk to most has no contact card. Code that treats an unresolved handle as a failure
|
|
62
|
+
will be wrong several times on any real inbox.
|
|
63
|
+
|
|
64
|
+
If the Contacts permission has not been granted, resolution is skipped and handles come back raw.
|
|
65
|
+
That is a capability downgrade reported through `diagnostics`, never a throw.
|
|
66
|
+
|
|
67
|
+
## Tools
|
|
68
|
+
|
|
69
|
+
Read: `diagnostics`, `list_chats`, `list_messages`, `search_messages`, `get_message`.
|
|
70
|
+
|
|
71
|
+
Write: `send_message`, and that is the whole dictionary. `sdef` lists three commands — `send`,
|
|
72
|
+
`login` and `logout` — and the other two would sign the user out of iMessage on every device they
|
|
73
|
+
own. There is no edit, delete, mark-as-read or reaction verb to expose, so **everything this server
|
|
74
|
+
can show you, it cannot change.**
|
|
75
|
+
|
|
76
|
+
`send`'s direct parameter is typed `file` OR `text`; only the text form ships. A tool that hands an
|
|
77
|
+
arbitrary local path to a remote person is an exfiltration primitive whose blast radius, unlike the
|
|
78
|
+
text form's, is not bounded by what the model can say.
|
|
79
|
+
|
|
80
|
+
### Sending, and how it reports what it sent
|
|
81
|
+
|
|
82
|
+
Prefer a `chatRef` from `list_chats` over a raw handle. Messages refuses to enumerate participants
|
|
83
|
+
for a script, so an existing conversation is the only target that can be addressed reliably — but
|
|
84
|
+
`chat` carries an id, and the store holds a guid for every conversation. **The read lane picks the
|
|
85
|
+
target and the write lane addresses it by id**, which is the only arrangement where neither lane has
|
|
86
|
+
to do the thing it cannot.
|
|
87
|
+
|
|
88
|
+
Apple Events then hands back nothing at all — no identifier for what it sent. So the client takes a
|
|
89
|
+
timestamp before the send and polls `chat.db` for the outgoing row:
|
|
90
|
+
|
|
91
|
+
| `reconciliation` | meaning |
|
|
92
|
+
| ---------------- | ---------------------------------------------------------- |
|
|
93
|
+
| `matched` | the row was found; the result carries a real message ref |
|
|
94
|
+
| `pending` | Messages accepted the send and has not written the row yet |
|
|
95
|
+
| `unavailable` | there was no existing chat to look in |
|
|
96
|
+
|
|
97
|
+
**`pending` is not a failure. Do not retry it** — the message was sent, and a retry sends it twice.
|
|
98
|
+
|
|
99
|
+
**No send has yet been executed against a live Messages.** The lane is written from the dictionary
|
|
100
|
+
and from the store, and its tests run against a fake `osascript` on purpose. `docs/messages.md`
|
|
101
|
+
records exactly what that leaves open; the safe way to measure it is a message to your own handle.
|
|
102
|
+
|
|
103
|
+
## Configuration
|
|
104
|
+
|
|
105
|
+
| Variable | Default | |
|
|
106
|
+
| ----------------------------------- | ------- | --------------------------------------- |
|
|
107
|
+
| `APPLE_MESSAGES_RESOLVE_CONTACTS` | on | Look names up in Contacts. |
|
|
108
|
+
| `APPLE_MESSAGES_INDEX_MODE` | `auto` | `auto` \| `ro` \| `immutable` \| `off`. |
|
|
109
|
+
| `APPLE_MESSAGES_STORE` | auto | Explicit store path. |
|
|
110
|
+
| `APPLE_MESSAGES_DEFAULT_RANGE_DAYS` | `30` | Window when only a start is given. |
|
|
111
|
+
| `APPLE_MESSAGES_MAX_RESULTS` | `50` | Default page size. |
|
|
112
|
+
| `APPLE_MESSAGES_ALLOW_WRITES` | off | Register `send_message` at all. |
|
|
113
|
+
| `APPLE_MESSAGES_SEND_RECONCILE_MS` | `5000` | How long to wait for the sent row. |
|
|
114
|
+
|
|
115
|
+
## Notes that will bite you
|
|
116
|
+
|
|
117
|
+
- **Dates do not fit in a JavaScript number.** Every date column is nanoseconds since 2001 —
|
|
118
|
+
eighteen digits, past `Number.MAX_SAFE_INTEGER` — and `node:sqlite` _throws_ rather than
|
|
119
|
+
truncating. Swallowed by a `try`/`catch` that throw looks exactly like "this column is empty", and
|
|
120
|
+
it is how a probe once reported "no dates present" for all seven columns across 97,414 messages.
|
|
121
|
+
Every query here divides in SQL so the integer never reaches JavaScript.
|
|
122
|
+
- **Tapbacks are rows in the message table.** 2,788 of them on the measured store, and a reader that
|
|
123
|
+
does not filter them renders `Liked "see you at 8"` as if somebody typed it. They are excluded
|
|
124
|
+
from conversations by default and reported on the message they target.
|
|
125
|
+
- **Search covers the blob-only messages.** A `LIKE` pass over the column (16 ms across 97,416 rows)
|
|
126
|
+
plus a decode pass over the 3,051 rows SQL cannot see (~6 ms). Completeness turned out to be
|
|
127
|
+
nearly free; a search that silently omitted 3% would not have been.
|
|
128
|
+
- **Refs are GUIDs, not rowids.** SQLite reuses a deleted row's id, and Messages deletes constantly,
|
|
129
|
+
so a rowid handed out in one turn can resolve to a different message two turns later — plausible,
|
|
130
|
+
wrong, and silent.
|
|
131
|
+
- **A send cannot be taken back, and nothing here pretends otherwise.** There is no unsend, no draft
|
|
132
|
+
and no preview in the dictionary; `send` delivers. The tool is gated on `ALLOW_WRITES`, requires
|
|
133
|
+
`confirm: true`, and its description says all of this, because the model calling it is the last
|
|
134
|
+
thing between a wording and a recipient.
|
|
135
|
+
|
|
136
|
+
## Licence
|
|
137
|
+
|
|
138
|
+
[MIT](LICENSE).
|
package/dist/cli.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {}
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { A as MESSAGES_SURFACE, V as BUILD_INFO, a as loadConfig, r as createServer } from "./server-DH4U3LBX.js";
|
|
3
|
+
import { runStdioServer } from "@mgcrea/mcp-apple-core";
|
|
4
|
+
//#region src/cli.ts
|
|
5
|
+
const LOG_PREFIX = "apple-messages-mcp";
|
|
6
|
+
runStdioServer({
|
|
7
|
+
build: BUILD_INFO,
|
|
8
|
+
surface: MESSAGES_SURFACE,
|
|
9
|
+
logPrefix: LOG_PREFIX,
|
|
10
|
+
start: async (logger) => {
|
|
11
|
+
const config = loadConfig();
|
|
12
|
+
const { server, client } = createServer({
|
|
13
|
+
config,
|
|
14
|
+
logger
|
|
15
|
+
});
|
|
16
|
+
const status = client.status();
|
|
17
|
+
return {
|
|
18
|
+
server,
|
|
19
|
+
banner: `read-only, store=${status.store.opened ? "open" : "UNREADABLE"}, messages=${status.counts?.messages ?? 0}, chats=${status.counts?.chats ?? 0}, names=${status.contacts.available ? "contacts" : "raw handles"}, index=${config.indexMode}`
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
}).catch((err) => {
|
|
23
|
+
console.error(`[${LOG_PREFIX}] fatal:`, err);
|
|
24
|
+
process.exit(1);
|
|
25
|
+
});
|
|
26
|
+
//#endregion
|
|
27
|
+
export {};
|
|
28
|
+
|
|
29
|
+
//# sourceMappingURL=cli.js.map
|
package/dist/cli.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.js","names":[],"sources":["../src/cli.ts"],"sourcesContent":["#!/usr/bin/env node\nimport { runStdioServer } from \"@mgcrea/mcp-apple-core\";\n\nimport { BUILD_INFO } from \"./build-info.js\";\nimport { MESSAGES_SURFACE } from \"./client/errors.js\";\nimport { loadConfig } from \"./config.js\";\nimport { createServer } from \"./server.js\";\n\nconst LOG_PREFIX = \"apple-messages-mcp\";\n\nrunStdioServer({\n build: BUILD_INFO,\n surface: MESSAGES_SURFACE,\n logPrefix: LOG_PREFIX,\n start: async (logger) => {\n const config = loadConfig();\n const { server, client } = createServer({ config, logger });\n const status = client.status();\n return {\n server,\n // No writes= line: this surface has no mutating tool, and printing a flag\n // that gates nothing would imply one exists.\n banner:\n `read-only, ` +\n `store=${status.store.opened ? \"open\" : \"UNREADABLE\"}, ` +\n `messages=${status.counts?.messages ?? 0}, ` +\n `chats=${status.counts?.chats ?? 0}, ` +\n `names=${status.contacts.available ? \"contacts\" : \"raw handles\"}, ` +\n `index=${config.indexMode}`,\n };\n },\n}).catch((err: unknown) => {\n console.error(`[${LOG_PREFIX}] fatal:`, err);\n process.exit(1);\n});\n"],"mappings":";;;;AAQA,MAAM,aAAa;AAEnB,eAAe;CACb,OAAO;CACP,SAAS;CACT,WAAW;CACX,OAAO,OAAO,WAAW;EACvB,MAAM,SAAS,WAAW;EAC1B,MAAM,EAAE,QAAQ,WAAW,aAAa;GAAE;GAAQ;EAAO,CAAC;EAC1D,MAAM,SAAS,OAAO,OAAO;EAC7B,OAAO;GACL;GAGA,QACE,oBACS,OAAO,MAAM,SAAS,SAAS,aAAa,aACzC,OAAO,QAAQ,YAAY,EAAE,UAChC,OAAO,QAAQ,SAAS,EAAE,UAC1B,OAAO,SAAS,YAAY,aAAa,cAAc,UACvD,OAAO;EACpB;CACF;AACF,CAAC,CAAC,CAAC,OAAO,QAAiB;CACzB,QAAQ,MAAM,IAAI,WAAW,WAAW,GAAG;CAC3C,QAAQ,KAAK,CAAC;AAChB,CAAC"}
|