iMessage RAG MCP
iMessage RAG MCP
一个 MCP 服务器,让 AI 助手可以搜索你本地 macOS 的 iMessage 历史记录。
它将 chat.db 同步到本地 SQLite 数据库,将对话拆分为上下文感知的块,并通过 MCP 端点提供混合检索(稠密 + 词法,融合并重排序)。一切都在本地运行——没有消息数据离开你的机器。
特性
混合检索 — FAISS 稠密向量搜索与 TF-IDF 词法搜索通过倒数排名融合(RRF)融合,然后使用交叉编码器重排序。
对话感知分块 — 消息按时间间隔分组为会话,然后带重叠进行分块,使检索到的段落保持连贯。
上下文扩展 — 结果包含周围的消息,而不仅仅是匹配的块。
联系人姓名解析 — 电话号码和电子邮件从你的 macOS 通讯录映射到真实姓名。
增量同步 — 源数据库的指纹可避免在无变化时进行冗余工作。
仅本地 — 只读方式读取 Apple 的数据库;所有索引都保留在磁盘上。
Related MCP server: iMessage Max
要求
macOS(读取
~/Library/Messages/chat.db)Python 3.10+
运行服务器的程序(终端、iTerm、PyCharm 等)需要完全磁盘访问权限——在系统设置 → 隐私与安全性 → 完全磁盘访问权限中授予,然后重新启动该程序。
安装
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.txt首次运行会从 Hugging Face 下载嵌入和重排序模型(几百 MB)。
用法
构建索引并启动服务器:
SYNC_ON_STARTUP=true ./run.sh初始同步和索引构建可能需要几分钟,具体取决于消息历史的大小。在后续运行中,你可以省略该标志以跳过同步并立即针对现有索引启动:
./run.shrun.sh 是以下命令的薄包装:
python -m uvicorn mcp_server:app --host 0.0.0.0 --port 8000 --reload连接 MCP 客户端
将你的 MCP 客户端指向:
http://localhost:8000/mcpHTTP 端点
两个端点也可以直接通过 HTTP 使用:
GET /search?query=...&limit=8— 完整混合管道(稠密 + 词法 → 融合 → 重排序 → 上下文扩展)。这是通过 MCP 暴露的工具。GET /lexical?query=...&limit=20— 仅 TF-IDF 结果,用于调试检索。
配置
所有设置都是具有合理默认值的环境变量。它们可以在 shell 中或项目根目录的 .env 文件中设置:
cp .env.example .envShell 变量优先于 .env,因此你可以为单次运行覆盖文件值:
SYNC_ON_STARTUP=true ./run.sh.env 已被 gitignore。
变量 | 默认值 | 描述 |
|
| 启动时同步消息并重建索引 |
|
| 源 iMessage 数据库 |
|
| 用于你自己发出的消息的名称 |
|
| 句子变换器嵌入模型 |
|
| 交叉编码器重排序模型 |
|
| 开始新对话会话的空闲间隔 |
|
| 目标块大小(字符数) |
|
| 每个块的最大消息数 |
|
| 相邻块之间重复的消息数 |
|
| 从 FAISS 检索的候选数 |
|
| 从 TF-IDF 检索的候选数 |
|
| 传递给重排序器的融合候选数 |
|
| 在最后同步行之后重新检查的行数 |
工作原理
摄取(
ingest.py)— 从chat.db读取新增和最近更改的行,当纯text列为空时从attributedBody恢复文本,根据通讯录解析发送者姓名,并 upsert 到本地规范数据库。索引(
indexer.py)— 按聊天分组消息,按时间间隔拆分为会话,带重叠对每个会话进行分块,然后写入 FAISS 索引和 TF-IDF 矩阵。检索(
rag.py)— 运行稠密和词法搜索,使用 RRF 融合排名,使用交叉编码器重排序,丢弃重叠块,并用周围消息扩展每个结果。服务(
mcp_server.py)— 将管道作为 FastAPI 应用挂载为 MCP 服务器。
项目布局
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 configuration数据存储
生成的工件位于 imessage_rag_data/(已 gitignore):
messages.sqlite Canonical messages and chunks
messages.faiss Dense vector index
lexical.joblib TF-IDF vectorizer and matrix
state.json Sync watermark and source fingerprint删除该目录以强制干净重建。
注意事项和限制
同步仅在启动时进行,且仅当
SYNC_ON_STARTUP=true时。目前没有后台或按需同步,因此重启服务器以获取新消息。附件、反应和编辑消息历史不会被索引——仅文本。
使用多个 worker 运行 uvicorn 目前会导致 MCP 挂载出现 404,因此服务器以单 worker 运行。
每当语料库发生变化时,整个索引都会从头重建;没有增量重新索引。
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