Skip to main content
Glama
baryhuang
by baryhuang

MCP Headless Gmail Server

npm-Version Docker-Pulls Lizenz: MIT

Ein MCP-Server (Model Context Protocol), der das Abrufen und Senden von Gmails ohne lokale Anmeldeinformationen oder Token-Einrichtung ermöglicht.

Warum MCP Headless Gmail Server?

Entscheidende Vorteile

  • Headless- und Remote-Betrieb : Im Gegensatz zu anderen MCP-Gmail-Lösungen, die außerhalb von Docker ausgeführt werden müssen und lokalen Dateizugriff erfordern, kann dieser Server in Remote-Umgebungen vollständig Headless ohne Browser und ohne lokalen Dateizugriff ausgeführt werden.

  • Entkoppelte Architektur : Jeder Client kann den OAuth-Flow unabhängig abschließen und dann Anmeldeinformationen als Kontext an diesen MCP-Server übergeben, wodurch eine vollständige Trennung zwischen der Speicherung der Anmeldeinformationen und der Serverimplementierung entsteht.

Nett, aber nicht kritisch

  • Fokussierte Funktionalität : In vielen Anwendungsfällen, insbesondere bei Marketinganwendungen, wird nur Gmail-Zugriff ohne zusätzliche Google-Dienste wie Kalender benötigt, weshalb diese fokussierte Implementierung ideal ist.

  • Docker-Ready : Entwickelt mit Blick auf die Containerisierung für eine gut isolierte, umgebungsunabhängige Einrichtung mit einem Klick.

  • Zuverlässige Abhängigkeiten : Basiert auf der gut gepflegten Bibliothek „Google API Python Client“.

Related MCP server: MCP Headless Gmail Server

Merkmale

  • Erhalten Sie die neuesten E-Mails von Gmail mit den ersten 1.000 Zeichen des Textkörpers

  • Erhalten Sie den vollständigen E-Mail-Textinhalt in 1K-Blöcken mithilfe des Offset-Parameters

  • Senden Sie E-Mails über Gmail

  • Zugriffstoken separat aktualisieren

  • Automatische Handhabung von Aktualisierungstoken

Voraussetzungen

  • Python 3.10 oder höher

  • Google API-Anmeldeinformationen (Client-ID, Client-Geheimnis, Zugriffstoken und Aktualisierungstoken)

Installation

# Clone the repository
git clone https://github.com/baryhuang/mcp-headless-gmail.git
cd mcp-headless-gmail

# Install dependencies
pip install -e .

Docker

Erstellen des Docker-Images

# Build the Docker image
docker build -t mcp-headless-gmail .

Verwendung mit Claude Desktop

Sie können Claude Desktop für die Verwendung des Docker-Images konfigurieren, indem Sie Ihrer Claude-Konfiguration Folgendes hinzufügen:

Docker

{
  "mcpServers": {
    "gmail": {
      "command": "docker",
      "args": [
        "run",
        "-i",
        "--rm",
        "buryhuang/mcp-headless-gmail:latest"
      ]
    }
  }
}

npm-Version

{
  "mcpServers": {
    "gmail": {
      "command": "npx",
      "args": [
        "@peakmojo/mcp-server-headless-gmail"
      ]
    }
  }
}

Hinweis: Bei dieser Konfiguration müssen Sie Ihre Google-API-Anmeldeinformationen in den Tool-Aufrufen angeben, wie im Abschnitt „Verwenden der Tools“ beschrieben. Gmail-Anmeldeinformationen werden nicht als Umgebungsvariablen übergeben, um die Trennung zwischen Anmeldeinformationsspeicher und Serverimplementierung zu gewährleisten.

Plattformübergreifendes Publizieren

Um das Docker-Image für mehrere Plattformen zu veröffentlichen, können Sie den Befehl docker buildx verwenden. Führen Sie dazu die folgenden Schritte aus:

  1. Erstellen Sie eine neue Builder-Instanz (falls noch nicht geschehen):

    docker buildx create --use
  2. Erstellen und pushen Sie das Image für mehrere Plattformen :

    docker buildx build --platform linux/amd64,linux/arm64,linux/arm/v7 -t buryhuang/mcp-headless-gmail:latest --push .
  3. Überprüfen Sie, ob das Bild für die angegebenen Plattformen verfügbar ist :

    docker buildx imagetools inspect buryhuang/mcp-headless-gmail:latest

Verwendung

Der Server stellt Gmail-Funktionalität über MCP-Tools bereit. Die Authentifizierung wird durch ein spezielles Token-Aktualisierungstool vereinfacht.

Starten des Servers

mcp-server-headless-gmail

Verwenden der Tools

Wenn Sie einen MCP-Client wie Claude verwenden, stehen Ihnen zwei Hauptmethoden zur Authentifizierung zur Verfügung:

Aktualisieren von Token (Erster Schritt oder wenn Token ablaufen)

Wenn Sie sowohl Zugriffs- als auch Aktualisierungstoken haben:

{
  "google_access_token": "your_access_token",
  "google_refresh_token": "your_refresh_token",
  "google_client_id": "your_client_id",
  "google_client_secret": "your_client_secret"
}

Wenn Ihr Zugriffstoken abgelaufen ist, können Sie die Aktualisierung nur mit dem Aktualisierungstoken durchführen:

{
  "google_refresh_token": "your_refresh_token",
  "google_client_id": "your_client_id",
  "google_client_secret": "your_client_secret"
}

Dadurch werden ein neues Zugriffstoken und dessen Ablaufzeit zurückgegeben, die Sie für nachfolgende Aufrufe verwenden können.

Aktuelle E-Mails abrufen

Ruft aktuelle E-Mails mit den ersten 1.000 Zeichen jedes E-Mail-Texts ab:

{
  "google_access_token": "your_access_token",
  "max_results": 5,
  "unread_only": false
}

Die Antwort umfasst:

  • E-Mail-Metadaten (ID, Thread-ID, Von, An, Betreff, Datum usw.)

  • Die ersten 1000 Zeichen des E-Mail-Textes

  • body_size_bytes : Gesamtgröße des E-Mail-Textes in Bytes

  • contains_full_body : Boolescher Wert, der angibt, ob der gesamte Textkörper enthalten (true) oder abgeschnitten (false) ist.

Vollständigen E-Mail-Textinhalt abrufen

Bei E-Mails mit einem Textkörper von mehr als 1.000 Zeichen können Sie den gesamten Inhalt in Blöcken abrufen:

{
  "google_access_token": "your_access_token",
  "message_id": "message_id_from_get_recent_emails",
  "offset": 0
}

Sie können E-Mail-Inhalte auch nach Thread-ID abrufen:

{
  "google_access_token": "your_access_token",
  "thread_id": "thread_id_from_get_recent_emails",
  "offset": 1000
}

Die Antwort umfasst:

  • Ein 1k-Block des E-Mail-Textes, beginnend ab dem angegebenen Offset

  • body_size_bytes : Gesamtgröße des E-Mail-Textes

  • chunk_size : Größe des zurückgegebenen Blocks

  • contains_full_body : Boolescher Wert, der angibt, ob der Block den Rest des Hauptteils enthält

Um den gesamten E-Mail-Text einer langen Nachricht abzurufen, führen Sie sequenzielle Aufrufe durch und erhöhen Sie den Offset jedes Mal um 1000, bis contains_full_body wahr ist.

Senden einer E-Mail

{
  "google_access_token": "your_access_token",
  "to": "recipient@example.com",
  "subject": "Hello from MCP Gmail",
  "body": "This is a test email sent via MCP Gmail server",
  "html_body": "<p>This is a <strong>test email</strong> sent via MCP Gmail server</p>"
}

Token-Aktualisierungs-Workflow

  1. Beginnen Sie mit dem Aufruf des Tools gmail_refresh_token mit einem der folgenden Befehle:

    • Ihre vollständigen Anmeldeinformationen (Zugriffstoken, Aktualisierungstoken, Client-ID und Client-Geheimnis) oder

    • Nur Ihr Aktualisierungstoken, Ihre Client-ID und Ihr Client-Geheimnis, wenn das Zugriffstoken abgelaufen ist

  2. Verwenden Sie das zurückgegebene neue Zugriffstoken für nachfolgende API-Aufrufe.

  3. Wenn Sie eine Antwort erhalten, die auf den Ablauf des Tokens hinweist, rufen Sie das Tool gmail_refresh_token erneut auf, um ein neues Token zu erhalten.

Dieser Ansatz vereinfacht die meisten API-Aufrufe, da nicht für jeden Vorgang Client-Anmeldeinformationen erforderlich sind, die Token-Aktualisierung bei Bedarf jedoch weiterhin möglich ist.

Abrufen der Google-API-Anmeldeinformationen

Um die erforderlichen Google-API-Anmeldeinformationen zu erhalten, führen Sie die folgenden Schritte aus:

  1. Gehen Sie zur Google Cloud Console

  2. Erstellen eines neuen Projekts

  3. Aktivieren Sie die Gmail-API

  4. OAuth-Zustimmungsbildschirm konfigurieren

  5. OAuth-Client-ID-Anmeldeinformationen erstellen (als Anwendungstyp „Desktop-App“ auswählen)

  6. Speichern Sie die Client-ID und das Client-Geheimnis

  7. Verwenden Sie OAuth 2.0, um Zugriffs- und Aktualisierungstoken mit den folgenden Bereichen zu erhalten:

    • https://www.googleapis.com/auth/gmail.readonly (zum Lesen von E-Mails)

    • https://www.googleapis.com/auth/gmail.send (zum Senden von E-Mails)

Token-Aktualisierung

Dieser Server implementiert eine automatische Token-Aktualisierung. Wenn Ihr Zugriffstoken abläuft, verwendet der Google API-Client das Aktualisierungstoken, die Client-ID und das Client-Geheimnis, um ohne Benutzereingriff ein neues Zugriffstoken zu erhalten.

Sicherheitshinweis

Dieser Server benötigt direkten Zugriff auf Ihre Google API-Anmeldeinformationen. Bewahren Sie Ihre Token und Anmeldeinformationen stets sicher auf und geben Sie sie niemals an nicht vertrauenswürdige Dritte weiter.

Lizenz

Weitere Einzelheiten finden Sie in der Datei LICENSE.

Available Tools

4 tools
gmail_get_email_body_chunkB

Get a 1k character chunk of an email body starting from the specified offset

ParametersJSON Schema
NameRequiredDescriptionDefault
google_access_tokenYesGoogle OAuth2 access token
message_idNoID of the message to retrieve
thread_idNoID of the thread to retrieve (will get the first message if multiple exist)
offsetNoOffset in characters to start from (default: 0)

TDQS

B3.1/5.0
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden for behavioral disclosure. It mentions the 1k character chunking behavior, which is valuable, but doesn't address authentication needs (though implied by google_access_token parameter), error handling, rate limits, or what happens with invalid offsets/message_ids. For a tool with no annotation coverage, this leaves significant gaps.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that immediately conveys the core functionality without any wasted words. It's appropriately sized and front-loaded with the essential information.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's moderate complexity (4 parameters, no output schema, no annotations), the description is minimally adequate. It explains the chunking behavior but lacks details about authentication requirements, error conditions, and how this tool relates to siblings. Without annotations or output schema, more behavioral context would be helpful for safe usage.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so parameters are well-documented in the schema. The description adds context about the 'offset' parameter (default: 0) and clarifies that thread_id retrieves the first message if multiple exist, providing some value beyond the schema. However, it doesn't explain parameter interactions or provide additional semantic context.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('Get'), resource ('email body chunk'), and key constraint ('1k character chunk starting from specified offset'), making the purpose immediately understandable. However, it doesn't explicitly differentiate from sibling tools like gmail_get_recent_emails, which retrieves multiple emails rather than a specific body chunk.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No guidance is provided about when to use this tool versus alternatives. The description doesn't mention prerequisites (like needing a message_id or thread_id), nor does it explain when this tool is appropriate compared to gmail_get_recent_emails for retrieving email content.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

gmail_get_recent_emailsC

Get the most recent emails from Gmail (returns metadata, snippets, and first 1k chars of body)

ParametersJSON Schema
NameRequiredDescriptionDefault
google_access_tokenYesGoogle OAuth2 access token
max_resultsNoMaximum number of emails to return (default: 10)
unread_onlyNoWhether to return only unread emails (default: False)

TDQS

C2.9/5.0
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden for behavioral disclosure. It mentions what data is returned (metadata, snippets, first 1k chars of body) which is helpful, but doesn't cover important behavioral aspects like authentication requirements (beyond the parameter), rate limits, pagination behavior, error conditions, or whether this is a read-only operation. For a tool with no annotations, this leaves significant gaps.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that communicates the core functionality and return format. It's appropriately sized for a straightforward retrieval tool, though it could potentially benefit from slightly more detail given the lack of annotations and output schema.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the complexity of email retrieval (3 parameters, no annotations, no output schema), the description is insufficiently complete. It doesn't explain the return format in detail, doesn't mention authentication requirements beyond the parameter, and doesn't cover important behavioral aspects. For a tool with no annotations or output schema, the description should provide more context about what to expect from the operation.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema already fully documents all three parameters. The description doesn't add any parameter-specific information beyond what's in the schema. The baseline of 3 is appropriate when the schema does all the parameter documentation work.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: 'Get the most recent emails from Gmail' specifies the verb (get) and resource (emails). It distinguishes from sibling 'gmail_get_email_body_chunk' by indicating it returns metadata, snippets, and partial body content, but doesn't explicitly differentiate from other siblings like 'gmail_send_email' or 'gmail_refresh_token' beyond the obvious functional difference.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No explicit guidance on when to use this tool versus alternatives is provided. The description doesn't mention when to use this versus 'gmail_get_email_body_chunk' for full body retrieval, or when to use 'gmail_refresh_token' for token management. Usage context is implied by the tool name but not explicitly stated.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

gmail_refresh_tokenB

Refresh the access token using the refresh token and client credentials

ParametersJSON Schema
NameRequiredDescriptionDefault
google_access_tokenNoGoogle OAuth2 access token (optional if expired)
google_refresh_tokenYesGoogle OAuth2 refresh token
google_client_idYesGoogle OAuth2 client ID for token refresh
google_client_secretYesGoogle OAuth2 client secret for token refresh

TDQS

B3.2/5.0
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden but only states what the tool does at a high level. It doesn't disclose behavioral traits like whether this invalidates previous tokens, rate limits, error conditions, or what the refreshed token enables. For a security-sensitive operation with zero annotation coverage, this is inadequate.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that directly states the tool's purpose with zero waste. It's appropriately sized and front-loaded, with every word contributing to understanding the core functionality.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a security-critical token refresh operation with no annotations and no output schema, the description is insufficient. It doesn't explain what happens after refresh (e.g., token lifetime, scope preservation), error handling, or integration with sibling tools. Given the complexity and lack of structured data, more context is needed.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema already documents all 4 parameters thoroughly. The description adds no parameter-specific semantics beyond what's in the schema (e.g., it doesn't explain relationships between parameters or provide usage examples). Baseline 3 is appropriate when schema does the heavy lifting.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the verb ('Refresh') and resource ('access token'), specifying it uses refresh token and client credentials. It distinguishes from sibling tools (email-related operations) by focusing on authentication token management, though it doesn't explicitly name alternatives for token refresh.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies usage when access tokens expire (via 'optional if expired' in schema), but doesn't explicitly state when to use this tool versus alternatives like initial authentication or other token management methods. No guidance on prerequisites or exclusions is provided.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

gmail_send_emailC

Send an email via Gmail

ParametersJSON Schema
NameRequiredDescriptionDefault
google_access_tokenYesGoogle OAuth2 access token
toYesRecipient email address
subjectYesEmail subject
bodyYesEmail body content (plain text)
html_bodyNoEmail body content in HTML format (optional)

TDQS

C2.9/5.0
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It states the action ('send an email') but lacks critical details: it doesn't mention authentication requirements (implied by the 'google_access_token' parameter but not explicitly stated), potential rate limits, error handling, or what happens upon success (e.g., whether it returns a confirmation). This leaves significant gaps for a mutation tool.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence with zero wasted words—'Send an email via Gmail' is front-loaded and directly conveys the core action. It's appropriately sized for the tool's complexity, making it easy to parse quickly.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's complexity (a mutation tool with 5 parameters, no annotations, and no output schema), the description is incomplete. It fails to address key contextual aspects like authentication needs, behavioral traits (e.g., what 'send' entails operationally), or output expectations, leaving the agent with insufficient information for reliable use.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The schema description coverage is 100%, with all parameters well-documented in the schema (e.g., 'to' as recipient email, 'body' as plain text content). The description adds no additional meaning beyond the schema, such as explaining parameter interactions (e.g., 'body' vs. 'html_body') or constraints. This meets the baseline for high schema coverage.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description 'Send an email via Gmail' clearly states the verb ('send') and resource ('email via Gmail'), making the purpose immediately understandable. However, it doesn't differentiate from sibling tools like 'gmail_get_recent_emails' or 'gmail_refresh_token' beyond the obvious action distinction, which keeps it from a perfect score.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention prerequisites (e.g., needing authentication via 'google_access_token'), nor does it clarify scenarios where other tools like 'gmail_get_recent_emails' might be more appropriate, leaving usage context entirely implicit.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

  1. 4 tool updates
    • First observedgmail_get_email_body_chunk
    • First observedgmail_get_recent_emails
    • First observedgmail_refresh_token
    • First observedgmail_send_email

TDQS

B3.4/5.0

Scored across 4 tools

Disambiguation5/5

Each tool has a clearly distinct purpose: retrieving email body chunks, listing recent emails, refreshing tokens, and sending emails. There is no overlap in functionality that would cause confusion or misselection.

Naming Consistency5/5

All tools follow a consistent 'gmail_verb_noun' pattern with snake_case, making them predictable and easy to understand. The naming convention is uniform across all four tools.

Tool Count4/5

With 4 tools, the count is reasonable for a Gmail server, though it feels slightly thin for covering all common email operations. It includes core functions but could benefit from additional tools like searching or managing drafts.

Completeness3/5

The tools cover basic email operations (read, list, send) and authentication, but there are notable gaps such as searching emails, managing labels, or handling attachments. This could limit agents in performing more complex email tasks.

Maintenance

ActivityInactive
ResponsivenessNo issues

Related MCP Connectors

Related MCP Servers

  • A
    license
    Not graded
    quality
    Not graded
    maintenance
    A Model Context Protocol server that enables applications to interact with Gmail through a clean API, supporting email searching, sending, reading, and label management.
    MIT
  • A
    license
    Not graded
    quality
    D
    maintenance
    A Model Context Protocol server that exposes the Gmail API for integration with LLMs, enabling email management tasks such as reading, labeling, and searching emails.
    7
    MIT

Appeared in Searches