Skip to main content
Glama
gmail-mcp

gmail-mcp

by iXanadu

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_add hinzufü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 ~/Outbox senden (konfigurierbar); nach ~/Inbox herunterladen (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-doctor

Trage 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 http://127.0.0.1:8767/oauth/callback hinzu (muss mit GMAIL_MCP_OAUTH_REDIRECT_URI in .env übereinstimmen)

5

.keys

Füge Client-ID und Client-Secret als GMAIL_MCP_GOOGLE_CLIENT_ID / GMAIL_MCP_GOOGLE_CLIENT_SECRET ein

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_remove

Rufe 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 client
  • Setze 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 als Authorization: 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

GMAIL_MCP_ENVIRONMENT

.env

Bezeichnung für Logs/Status

GMAIL_MCP_LOG_LEVEL

.env

Log-Level des Servers

GMAIL_MCP_HTTP_HOST

.env

HTTP-Bind-Adresse (Standard 127.0.0.1)

GMAIL_MCP_HTTP_PORT

.env

HTTP-Port (Standard 8879)

GMAIL_MCP_OUTBOX_ROOT

.env

Wurzelverzeichnis für Anhangspfade beim Senden

GMAIL_MCP_DOWNLOAD_ROOT

.env

Wurzelverzeichnis für get_attachment-Schreibvorgänge

GMAIL_MCP_TOKENS_DIR

.env

Verzeichnis für die Speicherung von OAuth-Tokens

GMAIL_MCP_OAUTH_REDIRECT_URI

.env

OAuth-Loopback-Callback

GMAIL_MCP_GOOGLE_CLIENT_ID

.keys

Google-OAuth-Client-ID

GMAIL_MCP_GOOGLE_CLIENT_SECRET

.keys

Google-OAuth-Client-Secret

GMAIL_MCP_HTTP_BEARER_TOKEN

.keys

Bearer-Token für den HTTP-Transport

Führe gmail-doctor aus, nachdem du die Konfiguration geändert hast.

Transporte

stdio (lokal)

gmail-mcp

Registriert 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-http

Bindet 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.sh

Passe 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

gmail_status

Versions- und Konfigurationsübersicht

accounts_list

Verbundene Adressen und Token-Status

accounts_add

OAuth-Zustimmung (nur stdio)

accounts_remove

Token widerrufen und verwerfen (nur stdio)

search

Gmail-Abfrage; gibt Threads zurück

get_thread / get_message

format=plain oder full

get_attachment

Schreibt unter das Download-Wurzelverzeichnis

send / reply / forward

Nur Pfade; lehnt content / base64 in JSON ab

draft_create / draft_send

Gleiche Regeln für Anhänge/Nachweis wie beim Senden

labels_list / labels_create

Benutzer- und Systemlabels

label / unlabel

Durch Kommas getrennte Namen oder IDs

archive / trash / untrash

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-Base64

  • Live-Gmail-Signatur wird beim Senden angehängt (nicht zwischengespeichert)

  • Optionaler footer nach der Signatur

  • Gibt einen Nachweis zurück: Größen, hrefs, ok false → Tool-Fehler (z. B. abgeschnittener Anhang oder google.com/url-Umschreibung)

Tests

pytest tests/ -v

Nutzt simuliertes Gmail-HTTP; kein echtes Postfach erforderlich.

Spezifikation

Produktanforderungen: docs/specs/gmail-mcp-spec.md

Lizenz

Apache-2.0

Available Tools

23 tools
accounts_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

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

    B3.1/5.0

    Scored across 23 tools

    Disambiguation4/5

    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.

    Naming Consistency3/5

    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.

    Tool Count3/5

    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.

    Completeness4/5

    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

    ActivitySlowing
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      Not graded
      quality
      C
      maintenance
      Enables 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.
      2
      MIT
    • A
      license
      Not graded
      quality
      D
      maintenance
      Enables interaction with Gmail through the MCP protocol, supporting sending, reading, searching, replying, forwarding, managing drafts and labels, and saving attachments.
      7 npm
      3
      MIT
    • F
      license
      Not graded
      quality
      B
      maintenance
      Enables interacting with multiple Gmail accounts through a single MCP server, supporting search, labels, drafts, and thread management with per-account OAuth.
      1
      -