iMessage RAG MCP
iMessage RAG MCP
ローカルのmacOS iMessage履歴をAIアシスタントから検索可能にするMCPサーバーです。
chat.dbをローカルのSQLiteデータベースに同期し、会話をコンテキストを考慮したチャンクに分割し、MCPエンドポイント経由でハイブリッド検索(密ベクトル+語彙ベース、融合・再ランク付け)を提供します。すべてローカルで実行され、メッセージデータがマシンの外に出ることはありません。
特徴
ハイブリッド検索 — FAISSの密ベクトル検索とTF-IDFの語彙ベース検索を相互ランク融合で融合し、クロスエンコーダーで再ランク付けします。
会話を考慮したチャンク分割 — メッセージを時間間隔でセッションにグループ化し、重複を持たせてチャンク化することで、取得したパッセージの一貫性を保ちます。
コンテキスト拡張 — 結果には一致したチャンクだけでなく、周囲のメッセージも含まれます。
連絡先名の解決 — 電話番号とメールアドレスを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 --reloadMCPクライアントの接続
MCPクライアントを次の場所に向けます:
http://localhost:8000/mcpHTTPエンドポイント
両方のエンドポイントはHTTP経由でも直接利用できます:
GET /search?query=...&limit=8— 完全なハイブリッドパイプライン(密ベクトル+語彙ベース → 融合 → 再ランク → コンテキスト拡張)。これはMCP経由で公開されるツールです。GET /lexical?query=...&limit=20— TF-IDFの結果のみ。検索のデバッグに便利です。
設定
すべての設定は環境変数で、適切なデフォルト値を持ちます。シェルまたはプロジェクトルートの.envファイルで設定できます:
cp .env.example .envシェル変数は.envより優先されるため、単一の実行でファイルの値を上書きできます:
SYNC_ON_STARTUP=true ./run.sh.envはgitignoreされています。
変数 | デフォルト | 説明 |
|
| 起動時にメッセージを同期しインデックスを再構築する |
|
| ソースのiMessageデータベース |
|
| 自分の送信メッセージに使用する名前 |
|
| 文変換の埋め込みモデル |
|
| クロスエンコーダーの再ランクモデル |
|
| 新しい会話セッションを開始するアイドル間隔 |
|
| チャンクの目標サイズ(文字数) |
|
| チャンクあたりの最大メッセージ数 |
|
| 隣接するチャンク間で繰り返されるメッセージ数 |
|
| FAISSから取得する候補数 |
|
| TF-IDFから取得する候補数 |
|
| 再ランク付けに渡される融合候補数 |
|
| 最後に同期した行の後ろで再検査する行数 |
仕組み
取り込み(
ingest.py)—chat.dbから新規および最近変更された行を読み取り、text列が空の場合にattributedBodyからテキストを復元し、送信者名をアドレス帳に対して解決し、ローカルの正規データベースにアップサートします。インデックス(
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の場合のみ行われます。バックグラウンドやオンデマンドの同期はまだないため、新しいメッセージを取得するにはサーバーを再起動してください。添付ファイル、リアクション、編集済みメッセージの履歴はインデックスされません。テキストのみです。
uvicornを複数ワーカーで実行すると、現在MCPマウントで404が発生するため、サーバーはシングルワーカーで実行されます。
コーパスが変更されるたびにインデックス全体がゼロから再構築されます。増分再インデックスはありません。
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