iMessage RAG MCP
Provides search and retrieval over your local iMessage history, enabling AI assistants to query messages, contacts, and conversations with dense and lexical hybrid search.
Click on "Install Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@iMessage RAG MCPfind our conversation about the camping trip"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
iMessage RAG MCP
An MCP server that makes your local macOS iMessage history searchable by AI assistants.
It syncs chat.db into a local SQLite database, splits conversations into
context-aware chunks, and serves hybrid retrieval (dense + lexical, fused and
reranked) over an MCP endpoint. Everything runs locally — no message data leaves
your machine.
Features
Hybrid retrieval — FAISS dense vector search fused with TF-IDF lexical search via reciprocal rank fusion, then reranked with a cross-encoder.
Conversation-aware chunking — messages are grouped into sessions by time gap, then chunked with overlap so retrieved passages stay coherent.
Context expansion — results include surrounding messages, not just the matching chunk.
Contact name resolution — phone numbers and emails are mapped to real names from your macOS Address Book.
Incremental sync — a fingerprint of the source database avoids redundant work when nothing has changed.
Local only — reads Apple's databases read-only; all indexes stay on disk.
Related MCP server: iMessage Max
Requirements
macOS (reads
~/Library/Messages/chat.db)Python 3.10+
Full Disk Access for whichever program runs the server (Terminal, iTerm, PyCharm, etc.) — grant it in System Settings → Privacy & Security → Full Disk Access, then restart that program.
Installation
git clone git@github.com:jaredtkatz/imessage-rag-mcp.git
cd imessage-rag-mcp
python -m venv .venv
source .venv/bin/activate
python -m pip install -r requirements.txtThe first run downloads the embedding and reranker models from Hugging Face (a few hundred MB).
Usage
Build the index and start the server:
SYNC_ON_STARTUP=true ./run.shThe initial sync and index build can take several minutes depending on the size of your message history. On later runs you can omit the flag to skip syncing and start immediately against the existing index:
./run.shrun.sh is a thin wrapper around:
python -m uvicorn mcp_server:app --host 0.0.0.0 --port 8000 --reloadConnecting an MCP client
Point your MCP client at:
http://localhost:8000/mcpHTTP endpoints
Both endpoints are also usable directly over HTTP:
GET /search?query=...&limit=8— full hybrid pipeline (dense + lexical → fusion → rerank → context expansion). This is the tool exposed over MCP.GET /lexical?query=...&limit=20— TF-IDF results only, useful for debugging retrieval.
Configuration
All settings are environment variables with sensible defaults. They can be set
in the shell or in a .env file in the project root:
cp .env.example .envShell variables take precedence over .env, so you can override a file value
for a single run:
SYNC_ON_STARTUP=true ./run.sh.env is gitignored.
Variable | Default | Description |
|
| Sync messages and rebuild indexes on startup |
|
| Source iMessage database |
|
| Name used for your own outgoing messages |
|
| Sentence-transformer embedding model |
|
| Cross-encoder reranking model |
|
| Idle gap that starts a new conversation session |
|
| Target chunk size in characters |
|
| Maximum messages per chunk |
|
| Messages repeated between adjacent chunks |
|
| Candidates retrieved from FAISS |
|
| Candidates retrieved from TF-IDF |
|
| Fused candidates passed to the reranker |
|
| Rows re-examined behind the last synced row |
How it works
Ingest (
ingest.py) — reads new and recently changed rows fromchat.db, recovers text fromattributedBodywhen the plaintextcolumn is empty, resolves sender names against the Address Book, and upserts into the local canonical database.Index (
indexer.py) — groups messages per chat, splits them into sessions on time gaps, chunks each session with overlap, then writes a FAISS index and a TF-IDF matrix.Retrieve (
rag.py) — runs dense and lexical search, fuses the rankings with RRF, reranks with a cross-encoder, drops overlapping chunks, and expands each result with surrounding messages.Serve (
mcp_server.py) — exposes the pipeline as a FastAPI app mounted as an MCP server.
Project layout
config.py Environment-driven settings and file paths
db.py SQLAlchemy models for chat.db, Address Book, and local storage
ingest.py Sync from chat.db into the canonical database
indexer.py Session splitting, chunking, and index construction
rag.py Hybrid retrieval, fusion, reranking, context expansion
mcp_server.py FastAPI application and MCP mount
run.sh Development server launcher
.env.example Template for local configurationData storage
Generated artifacts live in imessage_rag_data/ (gitignored):
messages.sqlite Canonical messages and chunks
messages.faiss Dense vector index
lexical.joblib TF-IDF vectorizer and matrix
state.json Sync watermark and source fingerprintDelete the directory to force a clean rebuild.
Notes and limitations
Syncing only happens at startup, and only when
SYNC_ON_STARTUP=true. There is no background or on-demand sync yet, so restart the server to pick up new messages.Attachments, reactions, and edited-message history are not indexed — text only.
Running uvicorn with multiple workers currently causes 404s on the MCP mount, so the server runs single-worker.
The whole index is rebuilt from scratch whenever the corpus changes; there is no incremental reindexing.
This server cannot be installed
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Related MCP Connectors
Let ChatGPT, Claude & Cursor use your Mac: email, calendar, iMessage, Teams, files. Local, free.
Search your knowledge bases from any AI assistant using hybrid RAG.
Long-term memory for AI assistants. Hybrid retrieval, query expansion, auto-topics.
MCP connector for iMessage & Contacts via a local Mac agent + Vercel relay
Related MCP Servers
- AlicenseAqualityDmaintenanceEnables AI assistants to read iMessage history and send messages on macOS. Supports conversation listing, message search with keyword and semantic modes, contact lookup, and sending messages to existing conversations.1311MIT
- AlicenseNot gradedqualityBmaintenanceEnables AI assistants to read, search, and send iMessages with features like contact name resolution, session grouping, and attachment listing. It provides intent-aligned tools to efficiently navigate conversation history and manage messages through natural language queries.6MIT
- FlicenseAqualityDmaintenanceEnables reading, searching, and sending iMessages on macOS by accessing the local messages database and utilizing AppleScript. Users can list conversations, search message history, and send messages to individuals or group chats directly through the Model Context Protocol.6
- AlicenseAqualityCmaintenanceEnables full-text search of macOS iMessages including link preview metadata. Works as an MCP server for Claude Desktop to search your messages locally.1MIT
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/jaredtkatz/imessage-rag-mcp'
If you have feedback or need assistance with the MCP directory API, please join our Discord server