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).
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.
E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.