mail-mcp

mail-mcp

Enables AI coding agents to search, read, and manage drafts across Gmail and Outlook mailboxes via MCP.

Category
访问服务器

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.ReadWrite but not Mail.Send, so sending is impossible at the token level.
  • Gmail: there is no scope that grants drafts without also granting send (gmail.compose covers both). So for Gmail, "no send" is enforced at the application layer — no send tool is exposed and drafts.send/messages.send are never called. Keep this in mind before granting the send capability.

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)

  1. Google Cloud Console → new project → enable the Gmail API.
  2. 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).
  3. 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).
  4. .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 with Error 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.com account first to confirm your setup, then try the university one.

Outlook OAuth (personal account)

  1. Azure Portal → Microsoft Entra ID → App registrations → New. Supported account types: Personal Microsoft accounts only.
  2. Authentication → Add platform Mobile and desktop applications → redirect http://localhost → mark as a public client.
  3. API permissions → Microsoft Graph → Delegated → add Mail.Read, Mail.ReadWrite, offline_access. Do not add Mail.Send.
  4. Put the Application (client) ID into the outlook block's client_id.
  5. .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 in providers/registry.py. The tool surface is unchanged.
  • Enable sending → add "send" to an account's capabilities. The send_message tool then registers automatically. For Graph, also add Mail.Send and re-run mail-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

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 模型以安全和受控的方式获取实时的网络信息。

官方
精选