iMessage MCP Server

iMessage MCP Server

Enables Claude to send and read iMessages on macOS, with smart contact lookup, message history retrieval, and cross-conversation search using natural language commands.

Category
访问服务器

README

iMessage Gateway CLI

macOS Python License Claude Code

The fastest iMessage integration for Claude Code. Direct CLI architecture delivers 19x faster performance than MCP-based alternatives.

Features

  • Send Messages: Send iMessages using natural language
  • Read Messages: Retrieve message history with contacts or phone numbers
  • Smart Contact Lookup: Fuzzy matching for contact names
  • Semantic Search (RAG): AI-powered search across iMessages, SuperWhisper, Notes
  • Follow-up Detection: Find conversations needing response
  • Group Chats: List and read group conversations
  • Analytics: Conversation patterns and statistics

Performance

Operation Gateway CLI MCP-based Speedup
List contacts 40ms ~763ms 19x
Find messages 43ms ~763ms 18x
Unread messages 44ms ~763ms 17x
Groups 61ms ~763ms 12x
Semantic search 150ms ~900ms 6x

Requirements

  • macOS (required - iMessage is macOS only)
  • Python 3.9+
  • Full Disk Access permission (for reading message history)

Quick Start

1. Clone and Install

git clone https://github.com/yourusername/imessage-gateway.git
cd imessage-gateway
pip install -r requirements.txt

2. Set Up Contacts

# Sync from macOS Contacts (recommended)
python3 scripts/sync_contacts.py

# Or manual setup
cp config/contacts.example.json config/contacts.json
# Edit config/contacts.json with your contacts

3. Grant Permissions

  1. Full Disk Access (for reading messages):

    • System Settings → Privacy & Security → Full Disk Access
    • Add Terminal.app or your Python interpreter
  2. Automation (for sending messages):

    • Will be requested automatically on first send

4. Test It Out

# List your contacts
python3 gateway/imessage_client.py contacts --json

# Check unread messages
python3 gateway/imessage_client.py unread --json

# Get recent messages
python3 gateway/imessage_client.py recent --limit 20 --json

# Send a message
python3 gateway/imessage_client.py send "John" "Hey, are you free for coffee?"

Command Reference (27 Commands)

Messaging (3)

# Send to contact
python3 gateway/imessage_client.py send "John" "Hello!"

# Send to phone number directly
python3 gateway/imessage_client.py send-by-phone "+14155551234" "Hi there!"

# Add a new contact
python3 gateway/imessage_client.py add-contact "Jane Doe" "+14155559876"

Reading (12)

# Messages with a contact
python3 gateway/imessage_client.py messages "John" --limit 20 --json

# Find messages (keyword search)
python3 gateway/imessage_client.py find "John" --query "meeting" --json

# Recent across all contacts
python3 gateway/imessage_client.py recent --limit 50 --json

# Unread messages
python3 gateway/imessage_client.py unread --json

# Recent phone handles
python3 gateway/imessage_client.py handles --days 30 --json

# Messages from unknown senders
python3 gateway/imessage_client.py unknown --days 7 --json

# Attachments
python3 gateway/imessage_client.py attachments "John" --json

# Voice messages
python3 gateway/imessage_client.py voice --json

# Links shared
python3 gateway/imessage_client.py links --days 30 --json

# Message thread
python3 gateway/imessage_client.py thread "<message-guid>" --json

# Scheduled messages
python3 gateway/imessage_client.py scheduled --json

# Conversation summary
python3 gateway/imessage_client.py summary "John" --days 7 --json

Groups (2)

# List group chats
python3 gateway/imessage_client.py groups --json

# Messages from a group
python3 gateway/imessage_client.py group-messages --group-id "chat123456" --json

Analytics (3)

# Conversation analytics
python3 gateway/imessage_client.py analytics "John" --days 30 --json

# Follow-ups needed
python3 gateway/imessage_client.py followup --days 7 --json

# Reactions
python3 gateway/imessage_client.py reactions "John" --json

Contacts (1)

# List all contacts
python3 gateway/imessage_client.py contacts --json

Semantic Search / RAG (6)

# Index iMessages for semantic search
python3 gateway/imessage_client.py index --source=imessage --days 30

# Index SuperWhisper transcriptions
python3 gateway/imessage_client.py index --source=superwhisper

# Index Notes
python3 gateway/imessage_client.py index --source=notes

# Index all local sources
python3 gateway/imessage_client.py index --source=local

# Semantic search
python3 gateway/imessage_client.py search "dinner plans with Sarah" --json

# AI-formatted context
python3 gateway/imessage_client.py ask "What restaurant did Sarah recommend?"

# Knowledge base stats
python3 gateway/imessage_client.py stats --json

# List available/indexed sources
python3 gateway/imessage_client.py sources --json

# Clear indexed data
python3 gateway/imessage_client.py clear --source=imessage --force

Architecture

Messages.db (SQLite) ←─ ~/Library/Messages/chat.db
        ↓
MessagesInterface ────→ SQLite queries (read)
        │                AppleScript → Messages.app (send)
        ↓
ContactsManager ──────→ config/contacts.json (fuzzy matching)
        ↓
Gateway CLI ──────────→ gateway/imessage_client.py
        ↓
Claude Code ──────────→ Bash tool calls

Why Gateway CLI?

The Gateway CLI architecture bypasses MCP framework overhead entirely:

  • Direct execution: Python script runs immediately, no JSON-RPC initialization
  • No session startup: MCP servers have ~700-800ms cold start per session
  • Smaller footprint: No MCP SDK dependency, simpler codebase
  • Same reliability: Uses identical MessagesInterface code for all operations

Claude Code Integration

Using the Skill

The imessage-gateway skill provides natural language access:

/imessage-gateway unread
/imessage-gateway send John "Running late!"
/imessage-gateway search "meeting next week"

Bash Pre-approval

Ensure your settings include:

Bash(python3:*::*)

Configuration

Contact Format

Contacts are stored in config/contacts.json:

{
  "contacts": [
    {
      "name": "John Doe",
      "phone": "14155551234",
      "relationship_type": "friend",
      "notes": "Optional notes"
    }
  ]
}

Phone numbers can be in any format - they're normalized automatically.

Troubleshooting

"Contact not found"

  • Run python3 scripts/sync_contacts.py to sync contacts
  • Check config/contacts.json exists and has contacts
  • Try partial names (e.g., "John" instead of "John Doe")

"Permission denied" reading messages

  • Grant Full Disk Access to Terminal/Python
  • Restart Terminal after granting permission
  • Verify: ls ~/Library/Messages/chat.db

Messages show "[message content not available]"

  • Some older messages use a different format
  • Attachment-only messages don't have text content
  • This is normal for some message types

Development

# Run tests
pytest tests/ -v

# Run performance benchmarks
python3 -m Texting.benchmarks.run_benchmarks

# Sync contacts
python3 scripts/sync_contacts.py

Privacy & Security

  • All data stays local on your Mac
  • No cloud services for core functionality
  • Contacts file is gitignored by default
  • Message history accessed read-only
  • Optional OpenAI API for semantic search embeddings

MCP Server (Archived)

The MCP server has been archived in mcp_server_archive/. See mcp_server_archive/ARCHIVED.md for restoration instructions if needed.

License

MIT License - see LICENSE for details.


Built for use with Claude Code

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选