mail-mcp
Enables AI coding agents to search, read, and manage drafts across Gmail and Outlook mailboxes via MCP.
README
mail-mcp
A local MCP server that lets AI coding agents (Claude Code and OpenAI Codex CLI) access your mailboxes: search, read messages/threads, read & download attachments, and create drafts — across multiple Gmail and personal Outlook accounts, routed by nickname.
Current capability: read-only + drafts. It never sends, deletes, or relabels mail. Sending/organizing are declared in the provider contract but gated off; enabling them later is a config change, not a rewrite (see Extending).
How safety is enforced
- Outlook (Graph): we request
Mail.Read+Mail.ReadWritebut notMail.Send, so sending is impossible at the token level. - Gmail: there is no scope that grants drafts without also granting send
(
gmail.composecovers both). So for Gmail, "no send" is enforced at the application layer — no send tool is exposed anddrafts.send/messages.sendare never called. Keep this in mind before granting thesendcapability.
Install
Requires Python ≥ 3.11.
uv venv --python 3.12 .venv
uv pip install --python .venv/bin/python -e ".[dev]"
Configure
.venv/bin/mail-mcp init # creates ~/.config/mail-mcp/{config.toml,secrets,tokens,downloads}
Edit ~/.config/mail-mcp/config.toml (see config.example.toml). Each mailbox is one
[accounts.<nickname>] block. Everything lives under $MAIL_MCP_HOME (default
~/.config/mail-mcp); set MAIL_MCP_HOME to relocate it.
Gmail OAuth (per Google account)
- Google Cloud Console → new project → enable the Gmail API.
- OAuth consent screen → User type External → add each Gmail address as a Test user (or publish to Production to avoid the 7-day refresh-token expiry in Testing mode).
- Credentials → Create OAuth client ID → Desktop app → download the JSON →
save as
~/.config/mail-mcp/secrets/gmail_client_secret.json(the same client can serve multiple Gmail accounts). .venv/bin/mail-mcp auth gmail-personal
University / Workspace accounts (e.g.
@g.ecc.u-tokyo.ac.jp): the admin may restrict third-party API access. If login fails withError 400: admin_policy_enforced, your self-made client is blocked at the org level — Testing mode does not bypass this; only the Workspace admin can allowlist the client ID. Test a personal@gmail.comaccount first to confirm your setup, then try the university one.
Outlook OAuth (personal account)
- Azure Portal → Microsoft Entra ID → App registrations → New. Supported account types: Personal Microsoft accounts only.
- Authentication → Add platform Mobile and desktop applications → redirect
http://localhost→ mark as a public client. - API permissions → Microsoft Graph → Delegated → add
Mail.Read,Mail.ReadWrite,offline_access. Do not addMail.Send. - Put the Application (client) ID into the
outlookblock'sclient_id. .venv/bin/mail-mcp auth outlook
Check status any time: .venv/bin/mail-mcp accounts
Register with your AI client
Both launch the server over stdio. Use an absolute interpreter path and set
MAIL_MCP_HOME explicitly so token discovery never depends on cwd or env forwarding.
Claude Code (user scope — available in every project):
claude mcp add --scope user mail \
--env MAIL_MCP_HOME=/Users/<you>/.config/mail-mcp \
-- /path/to/mail_mcp/.venv/bin/python -m mail_mcp
Codex CLI — add to ~/.codex/config.toml (Codex does not forward parent env by
default, hence env_vars):
[mcp_servers.mail]
command = "/path/to/mail_mcp/.venv/bin/python"
args = ["-m", "mail_mcp"]
env_vars = ["HOME", "PATH"]
[mcp_servers.mail.env]
MAIL_MCP_HOME = "/Users/<you>/.config/mail-mcp"
Verify: claude mcp list (shows mail ✓ Connected) / Codex /mcp.
Tools
| Tool | Purpose |
|---|---|
list_accounts |
list mailboxes, provider, capabilities, auth status |
search_messages(account, query, limit=20) |
search (Gmail operators for Gmail; free-text $search for Outlook) |
read_message(account, message_id, format="text") |
headers + body (text/html/full) + attachment list |
read_thread(account, thread_id, format="text") |
all messages in a thread/conversation |
list_attachments(account, message_id) |
attachment id/name/mime/size |
download_attachment(account, message_id, attachment_id, dest_dir=None, include_base64=False) |
save to disk, return path |
create_draft(account, to, subject, body, cc, bcc, reply_to_message_id, body_is_html, attachments) |
create an unsent draft |
Extending
- A new mailbox of an existing type → add an
[accounts.<nick>]block +mail-mcp auth <nick>. No code. - A new mailbox type (e.g. IMAP) → implement
MailProvider(src/mail_mcp/providers/base.py) and register it inproviders/registry.py. The tool surface is unchanged. - Enable sending → add
"send"to an account'scapabilities. Thesend_messagetool then registers automatically. For Graph, also addMail.Sendand re-runmail-mcp auth; Gmail needs no scope change. (Re-read the Gmail safety note first.)
Development
.venv/bin/pytest # unit tests (no network)
.venv/bin/ruff check .
.venv/bin/mypy src
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
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 模型以安全和受控的方式获取实时的网络信息。