Skip to main content
Glama
Apple Messages MCP

Apple Messages MCP

Apple Messages MCP

在 macOS 上,通过 Claude 读取和搜索你的 iMessage、SMS 和 RCS 对话。

配套项目 claude-connector-apple-mail 和 claude-connector-apple-reminders。

状态:读取和搜索已经稳定。发送功能可用,但尚未在真实发送中验证 — 脚本调用已实现且语法已验证,但 Apple 之前曾弄坏过 send,所以请把第一次真实发送当作测试。参见 发送消息。

工具

Tool

Description

get_stats

总数、未读数、按服务(iMessage/SMS/RCS)的细分、日期范围

list_chats

对话,最近活跃的在前,包含参与者和预览

get_chat_messages

单个对话中的消息,从最旧到最新,分页

search_messages

对所有历史记录进行子串搜索,可按聊天、发送者和日期范围过滤

get_message

单条消息的完整内容,包含附件和送达时间戳

get_attachment

附件字节,base64 编码

refresh_search_index

预热或重建本地搜索索引

compose_message

打开 Messages 并预填文本 — 你按下发送

send_message

发送到现有对话;立即送达

Related MCP server: iMessage MCP Server

要求

  • macOS 13 Ventura 或更高版本。RCS 需要 macOS 26 或更高版本。

  • Claude 应用需要 Full Disk Access — 读取所必需。

  • Messages 的 Automation 权限 — 发送和联系人姓名所必需。macOS 会自动提示授予此权限。

授予 Full Disk Access

  1. System Settings → Privacy & Security → Full Disk Access

  2. 启用 Claude(如果未列出,请使用 + 添加 /Applications/Claude.app)

  3. 退出并重新打开 Claude。 macOS 会在进程启动时缓存此权限,因此必须重启 — 否则扩展会持续失败。

为什么这需要 Full Disk Access 而 Apple Mail 不需要

Apple Mail 扩展完全通过脚本与 Mail.app 通信,因此不需要特殊权限。Messages 无法这样工作。

Messages 的 AppleScript 字典恰好暴露了四个类 — account、chat、participant、file transfer — 并且没有 message 类。已在 macOS 26.5.2 上验证:

$ osascript -e 'tell application "Messages" to get every text message of first chat'
syntax error: Expected "from", etc. but found identifier. (-2741)

聊天和参与者可以正常枚举;消息正文则完全没有暴露。因此唯一的读取路径是通过 ~/Library/Messages/chat.db 的 SQLite,而该路径受 TCC 保护。与 Automation 不同,Full Disk Access 无法以编程方式请求 — 用户必须手动授予。

因此,该扩展对不同的任务使用这两种权限:

用途

机制

权限

Messages、聊天、搜索、附件

chat.db 上的 SQLite

Full Disk Access

原始 handle 的联系人姓名

Messages 脚本

Automation

发送

Messages 脚本(send)

Automation

预填的撰写窗口

imessage: / sms: URL scheme

无

联系人姓名来自 Messages 的 participant 类(full name),它读取用户的 Contacts 名片。这绕开了单独受保护的 AddressBook 数据库 — 如果 Automation 被拒绝,handle 就只会显示为原始号码。

实现说明

attributedBody。 自 Ventura 起,message.text 经常为 NULL,正文位于 message.attributedBody 中,格式为 Apple typedstream — 即旧的 NSArchiver 格式,plistlib 无法读取。typedstream.py 用纯 Python 解码它,因此该扩展包不需要 PyObjC 依赖。它锚定 NSString/NSMutableString 类名,并在 + 类型标记之后读取带长度前缀的 UTF-8 负载。解码是彻底的:无法解码的正文会得到 None,而不会导致查询失败。

时间戳。 message.date 是 Apple 纪元(2001-01-01),在 macOS 13 之前为秒,之后为纳秒。两者都会被检测并处理。

搜索。 chat.db 没有附带文本索引,而且大多数正文只存在于 attributedBody 中,SQL 无法看到它们。这种组合比看起来更棘手。

最初的实现将谓词扩大为 m.text LIKE ? OR m.attributedBody IS NOT NULL,并在 Python 中重新过滤解码后的文本。由于第二个子句对几乎每一行现代数据都为真,查询的 LIMIT 在 Python 过滤器运行之前就把扫描截断为最新的几百条消息 — 因此任何更早的匹配都会悄然消失。搜索一条真实消息返回零结果,而不是变慢。在 916 MB 的历史记录上,这意味着搜索实际上只覆盖了最近几天。

解决办法是只解码一次,而不是每次查询都解码。index.py 将解码后并经过 casefold 处理的正文镜像到 ~/Library/Caches/apple-messages-mcp/search-index.db,搜索时再与该库进行 join — 因此匹配、过滤、排序和 LIMIT 都作用于 SQL 中的完整历史记录。该镜像具有以下特性:

  • 增量式。 新消息通过 message.ROWID 水位线来发现。编辑和撤回会复用已有的 ROWID,因此每次刷新还会查看最近的 2000 行 — 但只查看那些设置了 date_edited 或两个正文列现在都为 NULL 的行,因为每次搜索都重新解码 2000 个 blob 是实实在在的工作,而且几乎总是毫无所获。如果 Messages 出于某种原因没有标记某次编辑,或者编辑早于该窗口,则需要 refresh_search_index(rebuild=True)。改进 attributedBody 解码器也需要重建;提升 SCHEMA_VERSION 会强制重建。

  • 仅 casefold,仅此而已。 显示文本仍然来自 chat.db,因此该镜像纯粹是一个匹配判断器。存储 str.casefold() 可将其体积减半,并让不区分大小写的匹配对非 ASCII 字符也正确 — SQLite 的 LIKE 只对 ASCII 进行大小写折叠。

  • 可丢弃。 它位于 ~/Library/Caches,如果被删除会重建。这里没有任何操作会写入 chat.db。

这里没有使用 FTS5,尽管早先的计划如此:FTS5 匹配整个词元,因此 MATCH 'dentist' 永远找不到 "mydentist",这比 search_messages 所记录的子串语义更窄。对紧凑的 casefold 文本进行子串扫描已经很快,所以 FTS5 只会让索引体积翻倍,却提供我们无法使用的语义。如果将来某个查询确实变慢,再添加它也是一个可控的改动。

只读且不锁定。 连接以 mode=ro 打开,没有任何语句会修改数据库。如果 SQLite 无法以只读方式打开正在使用的 WAL,它会回退到私有快照副本,这样正在运行的 Messages.app 永远不会被打扰。

Tapbacks、编辑、回复。 反应从 associated_message_type 解码(2000–2007,3000 范围表示移除),线程回复从 thread_originator_guid 解码,编辑从 date_edited 解码。

发送消息

Messages 没有草稿对象,因此不存在与 Mail 扩展“草稿优先”设计完全对应的方案。所以写入路径分为两个层级,而且它们有意地并不等价。

compose_message — 安全的默认选项。 通过 imessage: / sms: URL scheme 打开 Messages,并预填收件人和正文,然后停下。由人来阅读并按下发送,因此不会有任何内容仅凭 Claude 的指示就离开机器。这也是启动新对话的唯一方式。完全不需要任何权限。

send_message — 立即送达。 使用脚本接口的 send,且无法撤回。它接受 chat_id 而不是电话号码,这并非限制,而正是关键所在:字典接受 participant 或 chat,而通过 GUID 指定现有聊天可以让 Messages 选择传输方式(iMessage / SMS / RCS),而不是由调用方猜测,从而避免在对方使用 iMessage 时悄悄发送 SMS。它还要求 confirm=True,纯粹是为了防止被随意触发。

哪些已得到验证,哪些没有

已在 macOS 26.5.2 上确认 — 字典暴露了

send : direct-parameter (file | text), to: (participant | chat)

service type 枚举为 SMS、iMessage、RCS,chat 具有可用于寻址的 GUID id 属性,并且生成的 AppleScript 可以编译。

未确认:真实发送是否真的能送达。 Apple 之前曾弄坏过 AppleScript send,而且它出现在字典中从来都不能证明它有效。测试套件中没有任何内容会实际发送消息,因此第一次真实发送就是实验。如果失败,使用“Send Message”操作的 shortcuts run 是接下来值得尝试的备选方案。

消息文本以 osascript 参数(on run argv)的形式到达 AppleScript,而不是被插值到脚本源码中,因此包含双引号的正文是惰性的,不会造成语法错误或注入。

发送附件尚未接通,不过 file 直接参数意味着它触手可及。

开发

python3 tests/test_db.py       # SQL, decoder, and search-index tests
python3 tests/test_send.py     # compose URLs, send guards, argv safety
python3 tools/probe_schema.py  # verify the real chat.db (needs Full Disk Access)
./build.sh                     # test, validate manifest, pack the .mcpb

tests/test_db.py 使用真实 schema 构建一次性数据库,因此无需 Full Disk Access 或真实消息历史即可验证 SQL。其中一个测试把匹配项埋在 3000 条较新消息之下,这正是针对上述截断搜索 bug 的回归测试。

tests/test_send.py 从不发送任何内容,也不会打开窗口:它覆盖 URL 构建器、保护子句以及确切的 osascript argv — 因此它在任何地方都是安全的,相应地也无法告诉你 Apple 的 send 是否有效。

两个测试套件都不会触碰真实的搜索索引;它们都会注入一个临时索引。

许可证

MIT

Available Tools

9 tools
compose_messageA

Open Messages with a recipient and text prefilled, WITHOUT sending.

This is the safe way to write a message: it puts the text in front of the user in Messages and stops, so they read it and press send themselves. Prefer it over send_message, and use it whenever the conversation does not exist yet — send_message can only reply to an existing one.

Args: handle: Recipient phone number or email, e.g. "+15551234567". body: Text to prefill. May be empty to just open the conversation. service: "imessage" or "sms" — which transport Messages preselects.

Inputs: handle (required), body, service. Returns: A compose window was opened; nothing was sent.

get_attachmentA

Retrieve an attachment's bytes, base64-encoded.

Args: attachment_id: Attachment id from get_message.

Inputs: attachment_id (required). Returns: size, filename, mime_type, data_base64

get_chat_messagesA

Read messages from one conversation, returned oldest-first.

In Claude the result renders as an inline card, so don't repeat its contents in your reply — a one-line summary or the answer to the user's question is enough.

Args: chat_id: Conversation id from list_chats. limit: Maximum messages to return (default 50). before_id: Return messages older than this message id, to page back through history.

Inputs: chat_id (required), limit, before_id. Returns: result

get_messageA

Read one message in full, including attachments and delivery times.

In Claude the result renders as an inline card, so don't repeat its contents in your reply — a one-line summary or the answer to the user's question is enough.

Args: message_id: Message id from search_messages or get_chat_messages.

Inputs: message_id (required). Returns: id, date, guid, text, +15 more

get_statsA

Overview of the Messages database: message and chat totals, unread count, attachment count, a per-service breakdown (iMessage / SMS / RCS), and the date range covered.

Inputs: no named parameters. Returns: by_service, attachments, group_chats, total_chats, +5 more

list_chatsA

List conversations, most recently active first.

In Claude the result renders as an inline card, so don't repeat its contents in your reply — a one-line summary or the answer to the user's question is enough.

Args: limit: Maximum conversations to return (default 30). offset: Conversations to skip, for paging through the list.

Inputs: limit, offset. Returns: result

refresh_search_indexA

Update the local search index, and report on it.

search_messages keeps this current on its own, so calling this is optional. It is useful for warming the index deliberately — the first build on a large history decodes every message and takes a while — and for forcing a full rebuild.

Args: rebuild: Discard the index and decode every message again. Needed only to pick up edits to messages older than the recent-edit window.

Inputs: rebuild. Returns: State of the local search mirror (see index.py).

search_messagesA

Search message bodies across every conversation, over all history.

Backed by a local index of decoded message bodies, which is brought up to date automatically. The first search on a large history has to build that index and may take a while; later searches are fast.

In Claude the result renders as an inline card, so don't repeat its contents in your reply — a one-line summary or the answer to the user's question is enough.

Args: query: Text to look for (case-insensitive substring match). Leave it out to search on the filters alone — chat_id plus a date range with no search term reads one conversation newest-first. limit: Maximum messages to return (default 30). chat_id: Restrict to one conversation from list_chats. from_me: True for only messages you sent, False for only received. after: Only messages at or after this time. before: Only messages at or before this time.

Inputs: after, limit, query, before, +2 more. Returns: query, total, messages, truncated

send_messageA

Send a message to an existing conversation. This delivers immediately.

IRREVERSIBLE — the message goes out as soon as this runs, and scripting cannot unsend it. Confirm the exact recipient and wording with the user before calling, and pass confirm=True to acknowledge that. If they have not clearly asked for it to be sent, use compose_message instead and let them press send.

Messages picks the transport (iMessage, SMS, or RCS) for the conversation itself, which is why this addresses a chat rather than a raw handle. To start a new conversation, use compose_message.

Args: chat_id: Conversation id from list_chats. body: Text to send. confirm: Must be True. A guard against sending by accident.

Inputs: body (required), chat_id (required), confirm. Returns: A message was actually delivered.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    A4.1/5.0

    Scored across 9 tools

    Disambiguation4/5

    Each tool has a clear primary purpose: listing chats, reading messages, single-message lookup, attachments, stats, compose, send, and index refresh are all distinct. The only mild overlap is between get_chat_messages and search_messages when search is given a chat_id with no query term, but the descriptions explicitly clarify this boundary.

    Naming Consistency5/5

    All tools use snake_case with a verb_noun shape (list_chats, get_message, send_message, compose_message, search_messages, refresh_search_index). No mixed conventions or vague standalone verbs.

    Tool Count5/5

    Nine tools is well-scoped for a Messages client: a compact read/search surface plus the two write paths (compose/send) and one maintenance operation. Nothing feels redundant or missing by count.

    Completeness4/5

    Core lifecycle is covered: discover chats, read messages, search, fetch attachments, send and draft messages, plus stats and index maintenance. Minor gaps remain (e.g. group-chat creation or participant management, reactions, marking read), but agents can work around them.

    Maintenance

    ActivitySlowing
    ResponsivenessOutdated data

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      Not graded
      quality
      D
      maintenance
      Enables Claude to send and read iMessages on macOS, with smart contact lookup, message history retrieval, and cross-conversation search using natural language commands.
      6
      MIT
    • A
      license
      Not graded
      quality
      D
      maintenance
      Enables Claude to read and search through iMessage, SMS, and RCS conversations, including mixed-protocol group chats with Android users. It decodes binary message data from the macOS Messages database to provide a comprehensive view of message history.
      MIT
    • A
      license
      Not graded
      quality
      D
      maintenance
      Enables Claude to send and read iMessages on macOS, with human approval required for sending and no auto-replies.
      2
      Apache 2.0
    • A
      license
      A
      quality
      D
      maintenance
      Connects Claude Desktop to iMessage on macOS, enabling reading conversations, searching messages, sending texts, and managing attachments.
      7
      8 npm
      MIT