gmail-mcp
Gmail connector for MCP clients: manage multiple Gmail accounts via OAuth and read, send, and organize mail without large base64 payloads.
Connect and manage Gmail accounts: list connected addresses, start OAuth consent over HTTP, and (stdio only) add/remove accounts.
List verified send-as identities for an account.
Send, reply, forward, and draft real MIME messages with file-path attachments, live signatures, idempotency keys, and post-send proof.
Search threads, list message headers/snippets, and fetch threads/messages at metadata, plain, or full formats.
Download attachments to a configured download root.
Manage labels: list, create, add/remove labels on threads.
Organize threads: archive, trash, untrash.
Check server status and configuration.
Provides integration with Gmail, allowing agents to send, reply to, forward, draft, search, read, and organize emails, manage labels and attachments, and support multiple Gmail accounts via OAuth.
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., "@gmail-mcp Search my inbox for unread emails from my boss"
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.
pigeon-mcp
Gmail connector for MCP clients. One server, many Gmail accounts via OAuth refresh tokens. Sends real MIME (file-path attachments, live signatures, post-send proof). Reads and organises mail without dumping megabytes of base64 into the model.
Not a wrapper around Google's hosted Gmail MCP — this builds RFC822 on the host and talks to gmail.googleapis.com directly.
Scope today: Gmail only. The Google Cloud project may also have Calendar and Drive APIs enabled for later work — this server does not call them yet. Do not request Calendar/Drive OAuth scopes until those tools ship.
Features
Multi-account OAuth — add mailboxes with
accounts_add; tokens stored asgmail-token-*.json(mode 0640)Many identities on one mailbox —
identities_listreads Gmail's verified send-as list;from_identityon send/reply/forward/draft setsFrom,Reply-Toand the alias's own signature, validated in the handler. Seedocs/mailroom.mdRouting headers — every read exposes
originalTo(X-Gm-Original-To),deliveredTo,replyTo,authResults;messages_listsweeps headers without bodiesSend / reply / forward — server-built MIME, outbox file paths only, 25 MB cap, idempotency keys, proof on success
Read / organise — search (threads + pagination), get thread/message, labels, archive/trash, drafts
Attachments — send from configured outbox root (default
~/Outbox); stage viaPOST /outbox/stage(bearer); download to configured download root (default~/Inbox); remote seats fetch pulls via a single-usedownload_url; the HTTP server deletes both after 24 hDual transport — stdio for local harnesses; Streamable HTTP behind a gateway for remote clients
Related MCP server: Gmail MCP Server
Requirements
Python 3.12+ (development uses 3.13 via pyenv)
A Google Cloud Web application OAuth client with redirect
https://<your-host>/oauth/callbackA Linux or macOS host you control, behind TLS (nginx / Caddy / Cloudflare)
Quick start
git clone https://github.com/iXanadu/pigeon-mcp.git
cd pigeon-mcp
# Python 3.12+ (example with pyenv)
pyenv virtualenv 3.13 pigeon-mcp-3.13
pyenv local pigeon-mcp-3.13
pip install -e '.[dev]'
# Config (see examples/)
cp examples/config.example .env
cp examples/secrets.example .keys
chmod 600 .keys
# Sanity check
pigeon-doctorFill in .keys with the Web client id/secret and a long random PIGEON_MCP_HTTP_BEARER_TOKEN (this becomes tenant grokbot — the seat that may connect mailboxes). Set PIGEON_MCP_OAUTH_PUBLIC_REDIRECT_URI in .env to your public callback.
Google Cloud Console (one-time)
Step | Where | What |
1 | APIs & Services → Library | Enable Gmail API |
2 | OAuth consent screen | External → Publish app (In production). Do not stay in Testing (7-day refresh expiry). See the doc for Workspace Internal. |
3 | Credentials → Create | OAuth client ID → Web application |
4 | Web client | Redirect |
5 |
| Web client id/secret → |
Full guide (scopes, the unverified-app warning, Workspace vs personal Gmail, the 7-day Testing trap, token protection, legal URLs): docs/google-oauth-setup.md. Privacy / Terms URLs for the consent screen: docs/legal/.
Scopes are fixed in the server: gmail.modify + gmail.send + gmail.settings.basic — read/send/organise mail; modify also reads the send-as list (identities, live signature, not cached); settings.basic exists only so filters_create / filters_delete work. No username/password, app password, or pasted refresh token in chat.
First run — tenants, not one shared key
After HTTP is up (see Deployment layout):
GrokBot (or one operator agent) gets the env bearer and the MCP URL. It calls
accounts_auth_start; you open the Google link on your computer and Allow. The Gmail refresh token stays on the server (gmail-token-*.json, mode 0640). Emptyaccounts_liston a fresh host is success.You register a passkey: proxy
/~/like/mcp, runpigeon-admin bootstrap, open the one-time URL, then sign in athttps://<your-host>/~/.Mint one tenant per coding harness on that page. Copy the
pgn_…once. Grant only the mailboxes that seat may see. Leave “can connect mailboxes” off unless the seat should add Gmail accounts.Wire Cursor / Claude / Codex / Grok like Share: secret in
~/.config/pigeon-mcp/identities/<name>(0600), harness config only hasPIGEON_IDENTITY. Installscripts/pigeon-mcp-proxyas~/.local/bin/pigeon-mcp.
Do not paste pgn_… into mcp.json. Do not reuse GrokBot’s vault token for a coding session.
Full walk-through (who may connect a mailbox, audit, files on disk): docs/tenants.md.
If you run pigeon purely on your own machine over stdio and never expose HTTP, you can add a Google Desktop OAuth client (redirect http://127.0.0.1:8767/oauth/callback) to .keys as PIGEON_MCP_GOOGLE_CLIENT_ID / _SECRET and use accounts_add, which opens a local browser. accounts_add / accounts_remove exist only on the stdio transport. Most deployments do not need this.
Deployment layout
┌──────────────────────┐ ┌──────────────────────────────┐
│ Any browser │ │ Your server (Linux/macOS) │
│ (human clicks Allow)│──────► │ TLS proxy ─► pigeon-mcp-http │
│ │ /oauth │ 127.0.0.1:8879 + .env/.keys │
└──────────────────────┘callback└──────────────┬───────────────┘
│ /mcp /outbox/stage
agent seat (bearer)pigeon-mcp-httpbinds loopback (127.0.0.1:8879); the proxy terminates TLS and forwards/mcp,/outbox/stage,/inbox/fetch/,/oauth/callback,/healthz,/~/.Each HTTP bearer is a tenant. The env token
PIGEON_MCP_HTTP_BEARER_TOKENis seeded as tenantgrokbotand may start Google consent. Other tenants are minted on the owner dashboard (/~/, passkey login) and only see mailboxes you grant./oauth/callbackis public by necessity (a browser redirect carries no bearer); it is protected by single-usestate+ PKCE and only a tenant that may connect mailboxes can start a flow.If you put an access gate (e.g. Cloudflare Access) in front of the host, exempt
/oauth/callbackor consent dies after the user clicks Allow.In-repo deploy kit for the reference host:
deploy/DEPLOYING.md.
After deploy: pigeon-doctor, start the service, pigeon-admin bootstrap, then connect mailboxes from the grokbot seat. See docs/tenants.md.
Configuration
Non-sensitive settings live in .env; secrets in .keys (never commit either when populated). Templates: examples/config.example and examples/secrets.example.
Variable | File | Purpose |
|
| Label for logs/status |
|
| Server log level |
|
| HTTP bind address (default |
|
| HTTP port (default |
|
| Send/stage attachment paths (pick per machine; |
|
|
|
|
| HTTP server deletes outbox + download files older than this, hourly (default |
|
| OAuth token storage directory |
|
| Optional SQLite path (default: next to tokens dir, |
|
| Public HTTPS callback — must match the Web client exactly |
|
| Google Web OAuth client id |
|
| Google Web OAuth client secret |
|
| GrokBot / legacy tenant bearer (hashed into SQLite as |
|
| Optional, stdio only: loopback callback for a Desktop client |
|
| Optional, stdio only: Desktop client for local |
Run pigeon-doctor after changing config.
Transports
stdio (local process on the pigeon host)
pigeon-mcpSame tools as HTTP plus accounts_add / accounts_remove (local Desktop-client consent). This is the server binary in the venv — use it when you are sitting on the pigeon machine. Remote Cursor / Claude / Codex / Grok should use scripts/pigeon-mcp-proxy and a tenant identity file, not this process.
Streamable HTTP (gateway)
pigeon-mcp-httpBinds 127.0.0.1:8879 by default. Requires a tenant bearer (Authorization: Bearer …); requests without a valid token get 401. There is no OAuth authorization server for MCP clients, and /.well-known/oauth-* 404s are intentional.
Owner dashboard: pigeon-admin bootstrap → one-time setup URL → passkey → https://<host>/~/ to mint and grant. Nginx must proxy /~/. Step-by-step: docs/tenants.md.
HTTP allow-list: read/organise tools plus send, reply, forward, draft_create, draft_send, identities_list, messages_list, accounts_list, accounts_auth_start, and gmail_status. accounts_add / accounts_remove stay on stdio.
Stage attachments (no scp required):
curl -sS -X POST "https://pigeon.c52.com/outbox/stage?filename=deed.pdf" \
-H "Authorization: Bearer $PIGEON_MCP_HTTP_BEARER_TOKEN" \
--data-binary @deed.pdf
# → {"path":".../deed.pdf","filename":"deed.pdf","size":N,...}Then call send / reply / forward with attachments_json using that path. Proxy must expose /outbox/stage (same bearer as /mcp). Cap: 25 MB.
Fetch inbound attachments: over HTTP, get_attachment returns a download_url (/inbox/fetch/<ticket>). GET it with the same bearer; it is single-use, expires in 15 minutes, and only the seat that pulled the file can redeem it. Proxy must expose /inbox/fetch/.
macOS service (user LaunchAgent)
./scripts/start.sh # install plist → ~/Library/LaunchAgents, load
./scripts/stop.sh
./scripts/restart.shEdit launchd/com.pigeon-mcp.plist paths if your checkout or pyenv name differs. Logs go to logs/.
On Linux, run pigeon-mcp-http under systemd with the same loopback bind — see Deployment layout above.
Tools
Tool | Notes |
| Version and config summary |
| Connected addresses and token health |
| Start Google consent over HTTP; returns |
| Local Desktop-client consent (stdio only, optional) |
| Revoke and drop token (stdio only) |
| Verified send-as identities for an account — the only values |
| Gmail query; returns threads |
| Gmail query; returns messages with headers + snippet, no bodies (routing sweeps) |
|
|
| Writes under download root; over HTTP, into the seat's own folder plus a single-use |
| Paths only; rejects |
| Carries the original body and attachments server-side; |
| Same attach/proof rules as send; |
| User + system labels |
| Gmail filters (server-side routing: |
| Comma-separated names or ids |
| Thread-level |
Every tool except accounts_list, accounts_add, and gmail_status requires an account argument (the Gmail address).
Send rules (summary)
send/reply/forward/draft_sendrequire a uniqueidempotency_key; a replay with the same key returns the first result and sends nothingStage remote files first:
POST /outbox/stage(bearer) → use returnedpathAttachments:
{ "path": "/absolute/or/under/outbox/file.pdf" }— no inline base64from_identity(optional): a verified send-as address on the account — setsFromwith display name andReply-To; rejected in the handler if not inidentities_listLive Gmail signature of the sending identity appended at send time (not cached)
Optional
footerafter signatureReturns proof: sizes, hrefs,
okfalse → tool error (e.g. chopped attachment orgoogle.com/urlrewrite)
Tests
pytest tests/ -vUses mocked Gmail HTTP; no live mailbox required.
Mailroom: one mailbox, many agents
Give each agent its own address on one mailbox (Workspace catch-all + send-as, or consumer plus-addressing), route inbound on originalTo → deliveredTo → to, trust only recipients in identities_list, send with from_identity. Full pattern, setup steps, DKIM/alias tiers, label scheme and the do-not-attempt list: docs/mailroom.md.
Docs
Doc | For whom | What |
New operator | Passkey admin, one bearer per harness, identity files, who may connect a mailbox | |
The agent seat (GrokBot, OpenClaw, Hermes, …) | Connect card, OAuth gotchas, send-with-file, rules of the road, do-not-attempt, escalation — paste into the seat's context | |
Operator + agent | One mailbox, many identities: setup, dispatch, trust tiers, labels, DKIM | |
Operator | Consent screen, scopes, Testing trap, unverified-app warning | |
Operator with no server yet | The $5 VPS on-ramp: ten minutes by hand, four prompts for the rest | |
Operator | How the reference host ships: pull, install, restart, verify, auto-rollback | |
Operator | Privacy / Terms for the consent screen | |
Contributors | Acceptance criteria |
Same content lives on the reference site (pigeon.c52.com) as pages; the repo is the source of truth.
Spec
Product requirements: docs/specs/gmail-mcp-spec.md
License
Apache-2.0
Available Tools
23 toolsaccounts_addA
Connect a Gmail account via local loopback OAuth (stdio only).
Inputs: no named parameters. Returns: result
accounts_auth_startA
Start Google OAuth for a mailbox over HTTP. Returns auth_url for a human to open; consent completes via the public /oauth/callback and the account appears in accounts_list.
Inputs: no named parameters. Returns: result
accounts_listA
List connected Gmail addresses and whether each refresh token still works.
Inputs: no named parameters. Returns: result
accounts_removeA
Remove a connected Gmail account and revoke its token at Google.
Inputs: account (required). Returns: result
archiveB
Remove INBOX from a thread.
Inputs: account (required), thread_id (required). Returns: result
draft_createC
Create a draft with the same MIME rules as send (from_identity as in send).
Inputs: to (required), account (required), subject (required), cc, +6 more. Returns: result
draft_sendB
Send a draft with post-send proof.
Inputs: account (required), draft_id (required), idempotency_key (required). Returns: result
forwardC
Forward a message on-thread. Same attachment and proof rules as send.
Inputs: to (required), account (required), message_id (required), idempotency_key (required), +6 more. Returns: result
get_attachmentA
Write an attachment under download_root. output_path may be a bare filename (lands in download_root) or an absolute path under it. Returns path and size.
Inputs: account (required), message_id (required), output_path (required), attachment_id (required). Returns: result
get_messageA
Get one message. format=metadata is headers+snippet only (cheap); plain adds the text body; full adds HTML and attachment metadata.
Inputs: account (required), message_id (required), format. Returns: result
get_threadB
Get messages on a thread. format=metadata is headers+snippet only (cheap); plain adds the text body; full adds HTML and attachment metadata.
Inputs: account (required), thread_id (required), format. Returns: result
gmail_statusA
Report server version and configuration (no Gmail API calls).
Inputs: no named parameters. Returns: result
identities_listA
Verified send-as identities for an account. Only these may be used as from_identity.
Inputs: account (required). Returns: result
labelA
Add labels to a thread (comma-separated names or ids).
Inputs: labels (required), account (required), thread_id (required). Returns: result
labels_createC
Create a user label.
Inputs: name (required), account (required). Returns: result
labels_listA
List system and user labels for an account.
Inputs: account (required). Returns: result
messages_listA
List messages (not threads) with headers only — no bodies. Use for routing sweeps: originalTo is the real recipient behind a catch-all; authResults carries dkim/dmarc. Fetch bodies afterwards with get_message only where needed.
Inputs: query (required), account (required), page_token, max_results. Returns: result
replyC
Reply on a thread. Same attachment and proof rules as send.
Inputs: account (required), message_id (required), idempotency_key (required), body, +5 more. Returns: result
searchC
Search Gmail threads using Gmail query syntax.
Inputs: query (required), account (required), page_token, max_results. Returns: result
sendB
Send new mail. Attachments are outbox file paths only. Returns proof payload.
from_identity: optional verified send-as address (see identities_list). Sets From with its display name and Reply-To. Empty = the account address itself.
Inputs: to (required), account (required), subject (required), idempotency_key (required), +6 more. Returns: result
trashC
Move a thread to trash.
Inputs: account (required), thread_id (required). Returns: result
unlabelA
Remove labels from a thread (comma-separated names or ids).
Inputs: labels (required), account (required), thread_id (required). Returns: result
untrashB
Restore a thread from trash.
Inputs: account (required), thread_id (required). Returns: result
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 23 tools
Most tools target clearly distinct actions or resources, such as send vs reply vs forward or get_thread vs get_message. A few boundaries are close, notably accounts_add vs accounts_auth_start and get_message vs get_thread, but the descriptions are sufficient to avoid serious misselection.
The naming style is mixed: some tools use resource_action (accounts_list, labels_create), some use action_resource (get_attachment, get_thread), and some are bare verbs (send, reply, archive, label). Within subfamilies the naming is consistent, but across the whole set there is no single predictable pattern.
23 tools is on the heavy side and falls into the borderline range for a single server. However, the count is justified by the breadth of Gmail functionality covered: accounts, labels, threads, messages, drafts, sending, and attachments.
The tool surface covers core Gmail workflows well: search, read, send, reply, forward, draft, label, archive, trash, and attachment retrieval. Minor gaps exist, such as no explicit mark-read/unread or message mutation beyond labels and trash, but agents can work around these.
Maintenance
Related MCP Connectors
Hosted email MCP for your own Gmail, Outlook.com, Microsoft 365, iCloud or IMAP inbox: read, search, draft, reply in thread, forward and file mail. It moves or flags up to 500 messages in one call, and a send leaves exactly one copy in Sent. A calendar is a separate connection, and connecting one adds diary and scheduling tools.
Email infrastructure for AI agents — send, receive, search, and reply to email over MCP.
A MCP server for Gmail that lets you search, read, and draft emails and replies.
Gmail for agents: create inboxes, read and reply to mail, send email, manage domains. OAuth sign-in.
Related MCP Servers
- AlicenseNot gradedqualityCmaintenanceEnables interaction with Gmail through MCP-compatible clients to list, read, search, and send emails. It supports advanced features such as managing labels, handling threaded replies, and utilizing Gmail's native search syntax.2MIT
- AlicenseAqualityDmaintenanceProvides access to Gmail functionalities including listing unread emails, searching via query syntax, and managing messages through archiving or marking as read. It enables MCP clients to securely interact with and organize email data using the Gmail API.5MIT
- AlicenseNot gradedqualityDmaintenanceEnables interaction with Gmail through the MCP protocol, supporting sending, reading, searching, replying, forwarding, managing drafts and labels, and saving attachments.6 npm3MIT
- FlicenseNot gradedqualityBmaintenanceEnables interacting with multiple Gmail accounts through a single MCP server, supporting search, labels, drafts, and thread management with per-account OAuth.1-