gmail-mcp
Enables interacting with multiple Gmail accounts through a single MCP server, supporting search, labels, drafts, and thread management with per-account OAuth.
README
gmail-mcp — multi-account Gmail MCP server
A Gmail MCP server that supports multiple
Google accounts at once. Every tool takes an optional account (email);
omit it to use the default. search_all_threads fans out across all connected
accounts in one call.
The architecture in one line: OAuth is one-token-per-account, so this server keeps a token store keyed by email and routes each call to the right token, instead of holding a single global token.
Layout
gmail-mcp/
├── gmail_mcp/
│ ├── store.py # SQLite token store, keyed by email; refresh tokens encrypted (Fernet)
│ ├── auth.py # OAuth consent flow (add_account) + resolve(account) -> live creds
│ ├── gmail.py # Gmail API helpers; service_for(account) is the one routing point
│ ├── server.py # FastMCP server; all tools
│ └── __main__.py # `python -m gmail_mcp`
├── credentials/ # client_secret.json (you add) + accounts.db + fernet.key (runtime). All gitignored.
└── requirements.txt
One-time setup
1. Google Cloud OAuth client
- console.cloud.google.com → create/select a project.
- APIs & Services → Enable APIs → enable Gmail API.
- OAuth consent screen → External → add yourself as a Test user (test mode is fine; you don't need verification for personal use).
- Credentials → Create Credentials → OAuth client ID → Desktop app.
- Download the JSON, save it as
credentials/client_secret.json.
The Desktop app client type matters — it enables the loopback redirect that
add_account uses (run_local_server), so no redirect URI config is needed.
2. Python env (pyenv-win + venv, per PYTHON_SETUP.md)
cd C:\Users\ronildo\Developer\gmail-mcp
pyenv local 3.13.13
python -m venv .venv
.venv\Scripts\python.exe -m pip install -r requirements.txt
Connecting accounts
add_account is itself an MCP tool — but the first connect opens a browser for
consent, so it's easiest to run it once from the shell before wiring the server
into a client:
.venv\Scripts\python.exe -c "from gmail_mcp import auth; print(auth.add_account())"
A browser opens → pick the Google account → approve. The server reads the account's email from its Gmail profile and stores the tokens. Repeat for each account. The first account connected becomes the default.
If the wrong browser profile opens
add_account opens your default browser, which may be the wrong Chrome
profile (e.g. a work profile not signed into the account you want, or one whose
account isn't a test user → 403 access_denied). Use the URL-based helper
instead — it prints the consent URL rather than opening a browser, so you can
paste it into the exact profile signed into the right account:
$env:PYTHONUNBUFFERED='1'; .venv\Scripts\python.exe -u connect_account.py
It prints AUTHURL <url>. Open that URL in the correct browser/profile, approve,
and the loopback redirect completes the flow (prints CONNECTED <email>).
Testing-mode gotcha: the consent shows "Google hasn't verified this app" (Advanced → Continue) and the Gmail permission must actually be granted — if only the sign-in/email scope comes back, the connect fails with a scope error. If a partial grant gets cached, revoke the app at myaccount.google.com permissions and reconnect.
Wiring into an MCP client
stdio server. Add to your MCP client config (e.g. Claude Code's mcp settings):
{
"mcpServers": {
"gmail-multi": {
"command": "C:\\Users\\ronildo\\Developer\\gmail-mcp\\.venv\\Scripts\\python.exe",
"args": ["-m", "gmail_mcp"],
"cwd": "C:\\Users\\ronildo\\Developer\\gmail-mcp"
}
}
}
Tools
| Tool | Purpose |
|---|---|
add_account |
OAuth-connect a new Google account (opens browser) |
list_accounts |
List connected accounts + which is default |
set_default_account |
Choose the account used when account is omitted |
remove_account |
Disconnect an account, delete its tokens |
search_threads |
Search one account (Gmail query syntax) |
get_thread |
Full thread: messages, headers, decoded bodies |
search_all_threads |
Cross-account search across every connected account |
list_labels / create_label |
Label management |
label_thread / unlabel_thread |
Add/remove labels on a thread |
create_draft / list_drafts |
Draft management |
Every Gmail tool accepts account="you@example.com". Omit it to hit the default.
Scopes
gmail.modify (read + labels + threads + drafts) plus openid + userinfo.email
for account identity — see auth.SCOPES. Sending is intentionally not
granted; add gmail.send and a send tool if you need it. Changing scopes
requires re-running add_account for each account.
Security notes
- Refresh tokens (long-lived) are encrypted at rest with Fernet; the key
lives in
credentials/fernet.key(gitignored). Access tokens are short-lived and stored plaintext. client_secret.json,accounts.db, andfernet.keyare all gitignored — never commit them.- Back up
fernet.keyif you back upaccounts.db: without the key the stored refresh tokens are unrecoverable (you'd just re-runadd_account).
推荐服务器
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 模型以安全和受控的方式获取实时的网络信息。