- Swift 99.6%
- Makefile 0.4%
Refs #5. Operator requested merge after the red integration report; default-consumer resolution, docs, tests and release acceptance remain outstanding on #5. |
||
|---|---|---|
| Sources | ||
| Tests | ||
| .gitignore | ||
| CHANGELOG.md | ||
| LICENSE | ||
| Makefile | ||
| Package.swift | ||
| README.md | ||
apple-messages-blade-mcp
Stallari-internal Swift library blade for read-only access to Apple Messages
via the on-disk ~/Library/Messages/chat.db SQLite database. The SQLite
family member of the local-corpus class — a sibling of
apple-mail-blade-mcp,
whose skeleton it mirrors with the .emlx parser swapped for a typedstream
decoder.
Defined by ADR-0053 Phase C (issue #294) and governed by ADR-0087.
There is no official Apple read API for Messages; chat.db is the only path,
reframed as a consent-gated local read of the user's own data — unsupported,
not forbidden (a Developer-ID binary removes the App-Review gate). The prior
Python implementation lives, deprecated, at
apple-messages-blade-mcp-deprecated.
Backend & interface
| Read backend | SQLite chat.db, opened readonly |
| Message text | Decoded from the message.attributedBody typedstream BLOB when the plain text column is NULL (the modern-macOS default) |
| Attachment bytes | On disk under ~/Library/Messages/Attachments/, path-confined + 25MB cap |
| TCC gate | Full Disk Access — chat.db sits under a protected path |
Products
The package ships two library products and no binary.
| Product | Holds | Depends on |
|---|---|---|
MessagesCore |
The read-only store, the schema, the models, the typedstream decoder, the config and the errors. It also holds the mirror reads (see the CHANGELOG). | SQLite only. It links no MCP package. |
AppleMessagesBlade |
The nine MCP tools and the attachment byte reader. It re-exports MessagesCore. |
MessagesCore and the MCP SDK. |
MessagesCore exists so that a read-only consumer can read the history
without the MCP code. What MessagesCore promises to every consumer:
- It opens
chat.dbwithreadonly: true, and every statement is aSELECT. - It never reads the edit-history blob or the text of a deleted message part.
- It holds no attachment byte reader. The mirror reads give the type and the size of an attachment, never a file name, a path or bytes.
What it does not promise: it applies no deny list, no redaction and no consent
check. A consumer that serves these reads to another process owns those rules,
its own access control and its own exposure. The section "No external
exposure" below binds the AppleMessagesBlade tools only.
Use MessagesCore without Stallari
MessagesCore needs no Stallari app, no StallariKit and no daemon. A Swift
package that depends on it reads chat.db directly. The Feeder of
dev/messages-mind-mcp is such a consumer.
AppleMessagesBlade is different. Its tools run only inside StallariKit (see
"No external exposure"), and this package ships no MCP server that runs on its
own.
Requirements
-
macOS 14 or later, and a Swift 6.1 toolchain or later.
-
FileVault on.
chat.dbis a plain SQLite file. Nothing in this package encrypts it, and SQLCipher does not apply to it. FileVault on the Mac's volume is its only protection at rest. Run this check before you grant Full Disk Access, and stop if it fails:fdesetup status # must print "FileVault is On."If the output also says that encryption or decryption is in progress, wait until it ends and run the check again.
-
The macOS user who owns the history.
MessagesBladeConfigaccepts~/Library/Messages/chat.dbunder the home folder of the running process only. It also accepts/tmp/and/private/tmp/for fixture tests. To read the history of a test account, log in as that account, then build and run the consumer there. One account cannot read the history of another. -
Network access at the first resolve. This repository clones without credentials. SwiftPM also fetches
SQLite.swiftandSQLCipher.swiftfrom GitHub.SQLCipher.swiftdownloads a prebuiltSQLCipher.xcframework, and SwiftPM checks it against the checksum in that package's manifest.
Add the dependency
Depend on the MessagesCore product only. AppleMessagesBlade links the MCP
SDK, and a reader does not need it. Use 0.2.1 or later: a fresh resolve of
0.2.0 picks SQLite.swift 0.17.0 and does not compile (issue #6). A program
that holds Full Disk Access should pin an exact version, so that each new
version gets a review before it runs.
// swift-tools-version: 6.1
import PackageDescription
let package = Package(
name: "messages-probe",
platforms: [.macOS(.v14)],
dependencies: [
.package(
url: "https://git.groupthink.asia/dev/apple-messages-blade-mcp.git",
exact: "0.2.1")
],
targets: [
.executableTarget(
name: "messages-probe",
dependencies: [
.product(name: "MessagesCore", package: "apple-messages-blade-mcp")
]
)
]
)
Read the history
This program opens the store of the user who runs it. It prints counts only: no names, no handles and no message text.
import MessagesCore
do {
// The chat.db of the macOS user who runs this process.
let store = try MessagesStore(config: MessagesBladeConfig())
let chats = try await store.listChats(limit: 5)
// Print counts only: no names, handles or message text.
print("chats read: \(chats.count)")
for chat in chats {
print(chat.id, chat.serviceName ?? "-", chat.messageCount ?? 0)
}
} catch MessagesBladeError.permissionDenied {
print("No Full Disk Access for this process.")
} catch {
print("read failed: \(error)")
}
Build it with swift build, then run the binary from .build/debug/.
Without Full Disk Access it prints No Full Disk Access for this process.
Full Disk Access
macOS guards chat.db with Full Disk Access. Without the grant,
MessagesStore throws MessagesBladeError.permissionDenied.
- macOS ties the grant to the code signature of the program. A command-line program that you start from Terminal uses the grant of Terminal.
- For a program that you ship, grant access to that signed program only. On an account that holds real messages, never grant it to Terminal, a shell or an interpreter.
- On a synthetic test account, you can grant Terminal access on that account, run the test and then remove the grant.
MessagesBladeError.pointerToFullDiskAccessnames no product. It tells the user to enable "the app that reads Messages". A consumer can show its own instruction with its own name. TheAppleMessagesBladetools useAppleMessagesBlade.fullDiskAccessRecovery, which names Stallari.
What a consumer links
The manifest turns on the SQLCipher trait of SQLite.swift for every
consumer (see the comment in Package.swift). A consumer therefore links
SQLCipher.framework, a prebuilt dynamic framework, and loads it at run time.
A signed release of the consumer must carry and sign that framework.
MessagesCore calls no SQLCipher API. Issue #5 tracks a trait that lets a
consumer build on the system SQLite.
Check a Mac before you write code
Log in as the account, clone this repository and run the live smoke tests:
MESSAGES_BLADE_LIVE_SMOKE=1 swift test --filter SmokeTests
The process that runs the tests needs Full Disk Access (see above). The smoke
tests read through the AppleMessagesBlade tools in process; they need no
Stallari install either.
Tools (v0.1.0 — read-only, 9)
apple_messages_list_chatsapple_messages_list_handlesapple_messages_list_messagesapple_messages_read_messageapple_messages_read_threadapple_messages_read_attachmentapple_messages_search_messagesapple_messages_headapple_messages_extract_entities
The typedstream decoder
Modern macOS stores message text in message.attributedBody as a legacy
NSArchiver typedstream of an NSMutableAttributedString, leaving text NULL.
TypedStreamDecoder extracts the plain string with two strategies:
- Structural — validate the
streamtypedheader, anchor on the backingNSStringclass declaration, then read the following C-string value by its declared length using the typedstream length-prefix rules. Reading the exact declared byte count and UTF-8-decoding it is correct across emoji, embedded newlines, mentions, and text containing marker-like bytes — the failure modes of pure byte-scanning. - Heuristic — the ported fallback from the deprecated Python blade (length- prefixed run scan, then longest-printable-run), used only when the structural parse yields nothing.
Bounded by design: oversized blobs are rejected unscanned; scan windows and candidate counts are fixed — no unbounded recursion.
Read-only, permanently
This release registers no write tool under any flag (ADR-0053 decision 3 +
its 2026-07-01 amendment). A Messages send leg has an unbounded chat-send blast
radius and is a reserved-dormant signed compose add-on — never part of this
baseline. Enforced by testNoWriteToolIsRegistered.
Known limitations (v0.1.0)
- Search misses attributedBody-only messages.
search_messagesis aLIKEovermessage.text; messages whose text lives only inattributedBody(text column NULL) are not matched. A device-local FTS5 index (deferred) closes this. - No Contacts resolution.
list_handlesreturns raw phone/email/iCloud identifiers; handle→display-name via AddressBook is a deferred follow-up.
No external exposure
This section binds the AppleMessagesBlade product. Its tools are consumed
only via StallariKit's internal tool registry (in-process Dispatcher
path through AppleMessagesBladeWiring). Never advertised on the daemon's
public :9847/mcp HTTP MCP surface, and never crosses the fleet mesh. Guarded by
testMessagesNotAdvertisedExternally on the harness side. See
directives/local-corpus-blades.md (DD-240 invariant #8).
Build & test
make build # swift build
make test # offline unit tests (no live chat.db access needed)
MESSAGES_BLADE_LIVE_SMOKE=1 swift test # include the live smoke (needs Full Disk Access)
Distribution: an SPM dependency. StallariKit consumes AppleMessagesBlade; a
read-only consumer can depend on MessagesCore alone. No notarised pkg, no
standalone binary, no online CI signing.