mail-mcp
Allows searching, reading messages/threads, reading & downloading attachments, and creating drafts in Gmail accounts. Read-only plus drafts; never sends, deletes, or relabels mail.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@mail-mcpfind unread emails from yesterday in my gmail"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
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.
Related MCP server: Gmail MCP Server
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_mcpCodex 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 mailboxes, provider, capabilities, auth status |
| search (Gmail operators for Gmail; free-text |
| headers + body ( |
| all messages in a thread/conversation |
| attachment id/name/mime/size |
| save to disk, return path |
| 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 srcThis server cannot be deployed
Maintenance
Related MCP Connectors
Email infrastructure for AI agents — send, receive, search, and reply to email over MCP.
Email inboxes for AI agents: send, receive, reply, search, and manage threaded email over MCP.
Hosted email for AI agents: create inboxes, send, receive, and reply over MCP with scoped API keys
- MermailOAuthapp.mermail
Privacy-first email inboxes for AI agents with MCP mail tools and Composio connect/execute.
Related MCP Servers
- FlicenseNot gradedqualityDmaintenanceAn MCP server that enables AI models to read, search, and send emails via IMAP and SMTP protocols. It supports various providers like Gmail and Outlook, allowing for tasks such as retrieving unread messages, searching by sender, and managing mailbox folders.-
- AlicenseAqualityDmaintenanceEnables AI agents to search, read, send, and organize Gmail emails via MCP protocol.2262 npm2MIT
- FlicenseNot gradedqualityDmaintenanceEnables LLMs and MCP clients to read, search, and manage Microsoft Outlook emails through a standardized interface.-
- FlicenseNot gradedqualityDmaintenanceEnables AI agents to interact with Gmail through a standardized MCP server interface, allowing for natural language email management and automation.-