gmail-mcp
gmail-mcp
Gmail-Connector für MCP-Clients. Ein Server, viele Gmail-Konten über OAuth-Refresh-Tokens. Sendet echtes MIME (Dateipfad-Anhänge, Live-Signaturen, Nachweis nach dem Versand). Liest und organisiert E-Mails, ohne Megabytes an Base64 in das Modell zu kippen.
Kein Wrapper um das von Google gehostete Gmail-MCP – der Gmail-Connector erstellt RFC822 auf dem Host und spricht direkt mit gmail.googleapis.com.
Features
Multi-Konto-OAuth – Postfächer mit
accounts_addhinzufügen; Tokens werden lokal gespeichert (Modus 0600)Senden / Antworten / Weiterleiten – serverseitig erstelltes MIME, nur Dateipfade aus dem Outbox-Ordner, 25-MB-Grenze, Idempotenzschlüssel, Nachweis bei Erfolg
Lesen / Organisieren – Suche (Threads + Paginierung), Thread/Nachricht abrufen, Labels, Archivieren/Papierkorb, Entwürfe
Anhänge – aus
~/Outboxsenden (konfigurierbar); nach~/Inboxherunterladen (konfigurierbar)Doppelter Transport – stdio für lokale Umgebungen; Streamable HTTP hinter einem Gateway für entfernte Clients
Related MCP server: Gmail MCP Server
Anforderungen
Python 3.12+ (Entwicklung nutzt 3.13 via pyenv)
Google Cloud Desktop-OAuth-Client (Client-ID + Secret)
macOS für die enthaltenen LaunchAgent-Skripte (HTTP-Dienst); Linux funktioniert für manuelle Ausführungen
Schnellstart
git clone https://github.com/iXanadu/gmcp.git
cd gmcp
# Python 3.12+ (example with pyenv)
pyenv virtualenv 3.13 gmail-mcp-3.13
pyenv local gmail-mcp-3.13
pip install -e '.[dev]'
# Config (see examples/)
cp examples/.env.example .env
cp examples/.keys.example .keys
chmod 600 .keys
# Sanity check
gmail-doctorTrage deine Google-OAuth-Zugangsdaten und ein HTTP-Bearer-Token in .keys ein, bevor du den HTTP-Transport ausführst.
Google Cloud Console (einmalig)
Du benötigst einen Desktop-OAuth-Client – keinen Dienstaccount und keine domänenweite Delegierung.
Schritt | Wo | Was |
1 | APIs & Dienste → Bibliothek | Gmail API aktivieren |
2 | OAuth-Zustimmungsbildschirm | Extern ist für den persönlichen Gebrauch in Ordnung. Füge dein Google-Konto als Testnutzer hinzu, solange sich die App im Testmodus befindet. |
3 | Anmeldedaten → Erstellen | OAuth-Client-ID → Desktop-App |
4 | Client-Einstellungen | Füge die Redirect-URI |
5 |
| Füge Client-ID und Client-Secret als |
Beim ersten accounts_add fragt Google nach der Zustimmung. Die Scopes sind im Server festgelegt: E-Mails lesen/senden/organisieren sowie die Send-as-Signatur lesen (nicht zwischengespeichert).
Kein Benutzername/Passwort, kein App-Passwort und kein eingefügtes Refresh-Token im Chat.
Postfach verbinden (accounts_add)
accounts_add öffnet einen Browser für die Google-Zustimmung. Es läuft nur auf dem stdio-Transport (gmail-mcp), nicht über HTTP.
gmail-mcp # stdio — required for accounts_add and accounts_removeRufe accounts_add von deinem MCP-Client auf. Wenn die Zustimmung abgeschlossen ist, speichert der Server die von Google zurückgegebene Gmail-Adresse; diese Adresse ist der account-Schlüssel für alle anderen Tools.
Tokens landen in ~/.config/gmail-mcp/tokens/ (Modus 0600). Kopiere dieses Verzeichnis bei Bedarf auf jeden anderen Host, auf dem derselbe Server läuft.
Headless-Server (kein lokaler Browser)
Der OAuth-Callback ist http://127.0.0.1:8767/oauth/callback. Eine Maschine ohne Display benötigt für die Google-Anmeldeseite trotzdem irgendwo einen Browser. Zwei gängige Muster:
A – SSH-Portweiterleitung (Zustimmung auf deinem Laptop)
Starte auf dem Headless-Host stdio MCP / accounts_add. Von deinem Laptop aus:
ssh -L 8767:127.0.0.1:8767 user@headless-hostÖffne die vom Server ausgegebene Autorisierungs-URL (oder löse accounts_add über deinen MCP-Client aus, während der Tunnel aktiv ist). Der Callback erreicht über den Tunnel 127.0.0.1:8767 auf dem Headless-Host.
Wait, I just typed "127.0.0.1:8767" as "127.0.0.1:8767" but in the sentence above I accidentally wrote "127.0.0.1:8767" with a typo "8767"? Let's ensure.
Original: 127.0.0.1:8767. My sentence: "Der Callback erreicht über den Tunnel 127.0.0.1:8767 auf dem Headless-Host." Need correct. In my draft I wrote "127.0.0.1:8767" but I need ensure not "8767" vs "8767". The callback port is 8767. Yes original http://127.0.0.1:8767/oauth/callback. Actually original is http://127.0.0.1:8767/oauth/callback. Port is 8767 (four digits: 8-7-6-7? Wait original: http://127.0.0.1:8767/oauth/callback. Let's check source: "Add redirect URI http://127.0.0.1:8767/oauth/callback" Yes port is 8767 (eight-seven-six-seven? No, 8767: 8 7 6 7). Wait "8767" digits: 8,7,6,7. Yes. My text "8767" is correct if I write 8767. In previous line I wrote "8767" but accidentally "8767"? I'll be careful.
Also "Headless-Host" correct. In my line above I wrote "Auf dem Headless-Host." Good.
Let's restart final from that point to avoid typos.
Continue:
ssh -L 8767:127.0.0.1:8767 user@headless-hostÖffne die vom Server ausgegebene Autorisierungs-URL (oder löse accounts_add über deinen MCP-Client aus, während der Tunnel aktiv ist). Der Callback erreicht über den Tunnel 127.0.0.1:8767 auf dem Headless-Host.
B – Zustimmung auf einem Desktop, Tokens kopieren
Führe accounts_add einmal auf einem Mac oder PC mit Browser und derselben .env / .keys aus. Kopiere nach der Zustimmung ~/.config/gmail-mcp/tokens/ auf den Produktionshost (gleiche Pfade, Modus 0600). Keine erneute Zustimmung erforderlich, es sei denn, Google widerruft das Refresh-Token.
Deployment-Layout
Typische Produktionsaufteilung:
┌─────────────────────┐ ┌──────────────────────────┐
│ Operator machine │ │ MCP server (Linux/macOS) │
│ (browser for OAuth)│ │ gmail-mcp-http │
│ accounts_add │ copy │ 127.0.0.1:8879 │
│ token files ───────┼────────►│ + .env / .keys │
└─────────────────────┘ tokens └───────────┬──────────────┘
│
Cloudflare / gateway / TLS
│
Hand / remote MCP clientSetze den Laptop des Betreibers nicht für MCP HTTP dem öffentlichen Internet aus. HTTP bindet auf dem Server an Loopback (
127.0.0.1:8879); ein Reverse-Proxy beendet TLS und leitet an diesen Port weiter.OAuth findet dort statt, wo ein Browser existiert (Betreibermaschine oder SSH-Tunnel). Die Token-JSON-Dateien werden auf den Server kopiert.
Das Gateway zeigt auf den Server-Hostnamen, den du kontrollierst (z. B.
mcp.example.com), nicht auf die OAuth-Workstation.Generiere ein langes zufälliges
GMAIL_MCP_HTTP_BEARER_TOKEN; das Gateway präsentiert es alsAuthorization: Bearer ….
Nach dem Deployment: gmail-doctor, ./scripts/start.sh (macOS LaunchAgent) oder deine eigene systemd-Unit, dann accounts_list über HTTP, um die Tokens zu bestätigen.
Konfiguration
Nicht sensible Einstellungen stehen in .env; Geheimnisse in .keys (committe niemals eine der beiden Dateien, wenn sie befüllt sind). Siehe examples/.env.example und examples/.keys.example.
Variable | Datei | Zweck |
|
| Bezeichnung für Logs/Status |
|
| Log-Level des Servers |
|
| HTTP-Bind-Adresse (Standard |
|
| HTTP-Port (Standard |
|
| Wurzelverzeichnis für Anhangspfade beim Senden |
|
| Wurzelverzeichnis für |
|
| Verzeichnis für die Speicherung von OAuth-Tokens |
|
| OAuth-Loopback-Callback |
|
| Google-OAuth-Client-ID |
|
| Google-OAuth-Client-Secret |
|
| Bearer-Token für den HTTP-Transport |
Führe gmail-doctor aus, nachdem du die Konfiguration geändert hast.
Transporte
stdio (lokal)
gmail-mcpRegistriert alle Tools, einschließlich accounts_add und accounts_remove.
Binde es in die MCP-Konfiguration von Cursor / Claude Code ein, mit der gmail-mcp-Binärdatei aus der venv und cwd auf das Repository gesetzt (damit .env / .keys geladen werden).
Streamable HTTP (Gateway)
gmail-mcp-httpBindet standardmäßig an 127.0.0.1:8879. Erfordert Authorization: Bearer <GMAIL_MCP_HTTP_BEARER_TOKEN>; Anfragen ohne gültiges Token erhalten 401.
Manuelle Zulassungsliste (nur HTTP): Lese-/Organisations-Tools plus send, reply, forward, draft_create, draft_send, accounts_list und gmail_status. Die Kontoverwaltung bleibt auf stdio.
macOS-Dienst (Benutzer-LaunchAgent)
./scripts/start.sh # install plist → ~/Library/LaunchAgents, load
./scripts/stop.sh
./scripts/restart.shPasse die Pfade in launchd/com.gmail-mcp.plist an, wenn sich dein Checkout oder pyenv-Name unterscheidet. Logs liegen unter logs/.
Führe gmail-mcp-http unter Linux mit systemd und demselben Loopback-Bind aus – siehe Deployment-Layout oben.
Tools
Tool | Hinweise |
| Versions- und Konfigurationsübersicht |
| Verbundene Adressen und Token-Status |
| OAuth-Zustimmung (nur stdio) |
| Token widerrufen und verwerfen (nur stdio) |
| Gmail-Abfrage; gibt Threads zurück |
|
|
| Schreibt unter das Download-Wurzelverzeichnis |
| Nur Pfade; lehnt |
| Gleiche Regeln für Anhänge/Nachweis wie beim Senden |
| Benutzer- und Systemlabels |
| Durch Kommas getrennte Namen oder IDs |
| Auf Thread-Ebene |
Jedes Tool außer accounts_list, accounts_add und gmail_status erfordert ein account-Argument (die Gmail-Adresse).
Senderegeln (Zusammenfassung)
Anhänge:
{ "path": "/absolute/or/under/outbox/file.pdf" }– kein Inline-Base64Live-Gmail-Signatur wird beim Senden angehängt (nicht zwischengespeichert)
Optionaler
footernach der SignaturGibt einen Nachweis zurück: Größen, hrefs,
okfalse → Tool-Fehler (z. B. abgeschnittener Anhang odergoogle.com/url-Umschreibung)
Tests
pytest tests/ -vNutzt simuliertes Gmail-HTTP; kein echtes Postfach erforderlich.
Spezifikation
Produktanforderungen: docs/specs/gmail-mcp-spec.md
Lizenz
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.7 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-