JXA Mail MCP
A high-performance MCP server for Apple Mail that uses optimized JavaScript for Automation (JXA) to search and manage emails. It enables users to list accounts, fetch mailboxes, and retrieve today's, unread, or flagged messages with significantly improved speed through batch property fetching.
README
JXA Mail MCP
A fast MCP (Model Context Protocol) server for Apple Mail, using optimized JXA (JavaScript for Automation) scripts with batch property fetching for 87x faster performance.
Features
- list_accounts - List all configured email accounts
- list_mailboxes - List mailboxes for an account
- get_emails - Fetch emails from any mailbox with pagination
- get_todays_emails - Fetch all emails received today
- get_unread_emails - Fetch unread emails
- get_flagged_emails - Fetch flagged emails
- search_emails - Search emails by subject or sender
- fuzzy_search_emails - Typo-tolerant search using trigram + Levenshtein matching
Installation
With pipx (recommended)
pipx install jxa-mail-mcp
From source
Requires Python 3.13+ and uv:
git clone https://github.com/imdinu/jxa-mail-mcp
cd jxa-mail-mcp
uv sync
Usage
Add to Claude Code
After installing with pipx:
{
"mcpServers": {
"mail": {
"command": "jxa-mail-mcp"
}
}
}
Or from source:
{
"mcpServers": {
"mail": {
"command": "uv",
"args": ["run", "--directory", "/path/to/jxa-mail-mcp", "jxa-mail-mcp"]
}
}
}
Run directly
jxa-mail-mcp
Configuration
Set default account and mailbox via environment variables:
export JXA_MAIL_DEFAULT_ACCOUNT="Work"
export JXA_MAIL_DEFAULT_MAILBOX="Inbox"
Or in Claude Code config:
{
"mcpServers": {
"mail": {
"command": "jxa-mail-mcp",
"env": {
"JXA_MAIL_DEFAULT_ACCOUNT": "Work"
}
}
}
}
Test in Python
from jxa_mail_mcp.server import get_todays_emails, search_emails, fuzzy_search_emails
emails = get_todays_emails(account="iCloud", mailbox="Inbox")
results = search_emails("meeting", account="Work", limit=10)
# Fuzzy search - tolerates typos
results = fuzzy_search_emails("meetting nottes", limit=10) # finds "meeting notes"
Architecture
src/jxa_mail_mcp/
├── __init__.py # Exports mcp instance and main()
├── server.py # FastMCP server and MCP tools
├── config.py # Environment variable configuration
├── builders.py # QueryBuilder for constructing JXA scripts
├── executor.py # JXA script execution utilities
└── jxa/
├── __init__.py # Exports MAIL_CORE_JS
└── mail_core.js # Shared JXA utilities library
Design Principles
- Separation of concerns: Python handles logic/types, JavaScript handles Mail.app interaction
- Builder pattern:
QueryBuilderconstructs optimized JXA scripts programmatically - Shared JS library:
mail_core.jsprovides reusable utilities injected into all scripts - Type safety: Python type hints ensure correct usage
Performance
The Problem
Naive AppleScript/JXA iteration is extremely slow:
// SLOW: ~54 seconds for a few hundred messages
for (let msg of inbox.messages()) {
results.push({
from: msg.sender(), // IPC call to Mail.app
subject: msg.subject(), // IPC call to Mail.app
});
}
Each property access triggers a separate Apple Event IPC round-trip.
The Solution: Batch Property Fetching
JXA supports fetching a property from all elements at once:
// FAST: ~0.6 seconds (87x faster)
const msgs = inbox.messages;
const senders = msgs.sender(); // Single IPC call returns array
const subjects = msgs.subject(); // Single IPC call returns array
for (let i = 0; i < senders.length; i++) {
results.push({ from: senders[i], subject: subjects[i] });
}
Benchmark Results
| Method | Time | Speedup |
|---|---|---|
| AppleScript (per-message) | 54.1s | 1x |
| JXA (per-message) | 53.9s | 1x |
| JXA (batch fetching) | 0.62s | 87x |
Fuzzy Search Performance
Fuzzy search uses trigrams for fast candidate selection and Levenshtein distance for accurate ranking. Tested on a mailbox with ~6,000 emails:
| Search Type | Time | Overhead |
|---|---|---|
| Regular search | ~360ms | - |
| Fuzzy search | ~480ms | +33% |
The trigram pre-filtering keeps fuzzy search fast by avoiding expensive Levenshtein calculations on non-matching words.
Example: Searching for "reserch studies" (typo) correctly finds "research studies" with 0.94 similarity score.
Development
uv sync
uv run ruff check src/
uv run ruff format src/
# Test
uv run python -c "
from jxa_mail_mcp.server import list_accounts, get_todays_emails
print('Accounts:', len(list_accounts()))
print('Today:', len(get_todays_emails()))
"
License
GPL-3.0-or-later
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。