logo
Free, unlimited AI code reviews that run on commit
git-lrc git-lrc GitHub Install Now We'd appreciate a star git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt

mcp-remote-gmail-interface

Facilitates secure interaction with the Gmail API from isolated execution environments. Enables sending and retrieval of electronic mail messages without requiring persistent, local storage of authentication credentials, strictly separating secrets management.

Author

mcp-remote-gmail-interface logo

baryhuang

MIT License

Quick Info

GitHub GitHub Stars 53
NPM Weekly Downloads 0
Tools 1
Last Updated 2026-02-19

Tags

gmailmcpemailsheadless gmailgmail headlessgmail functionality

Remote Gmail Orchestration Service (MCP Implementation)

NPM Package Version Docker Pull Count License: MIT

An independent Model Context Protocol (MCP) server endpoint dedicated to manipulating Gmail data (fetch and dispatch) entirely divorced from local credential persistence or interactive setup procedures.

Headless Gmail Server MCP server

Rationale for this Isolated Gmail Handler

Key Architectural Benefits

  • Containerized Autonomy: In contrast to other solutions demanding local filesystem access or interactive sessions, this server thrives in fully automated, remote, containerized deployments (e.g., Docker) without needing a graphical interface or local token files.
  • Strict Credential Decoupling: The authentication mechanism allows any external client process to complete the OAuth handshake independently, subsequently injecting the necessary tokens as contextual data into the MCP server. This enforces a hard boundary between credential vaulting and the core service logic.

Secondary Advantages

  • Functional Singularity: Ideal for specific workflows (like targeted marketing automation) where only email operations are required, avoiding unnecessary dependencies on broader Google Workspace APIs (e.g., Calendar).
  • Container-First Design: Engineered for seamless integration into CI/CD pipelines via Docker, ensuring predictable, isolated operation across any supported host system.
  • Robust Foundation: Leverages the mature and actively maintained google-api-python-client library.

Core Capabilities

  • Retrieve latest correspondence, summarizing the initial 1024 characters of the message body.
  • Sequential retrieval of extensive email bodies using an offset parameter, delivered in 1024-character segments.
  • Dispatch outgoing electronic mail messages via Gmail.
  • Independent utility for refreshing expired access tokens.
  • Automated management of the token refresh lifecycle.

System Requirements

  • Python environment, version 3.10 or newer.
  • Valid Google API credentials (Client Identifier, Client Secret, active Access Token, and Refresh Token).

Deployment Instructions

bash

Obtain source code

git clone https://github.com/baryhuang/mcp-headless-gmail.git cd mcp-headless-gmail

Install required packages

pip install -e .

Containerization Deployment

Image Creation

bash

Build the Docker distribution image

docker build -t mcp-headless-gmail .

Integration with Desktop Clients (e.g., Claude)

Configuration snippet for invoking the service via Docker:

docker

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

Configuration snippet for invoking the service via NPM execution:

npm version

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

Important Note: In both setups, operational Google API keys must be supplied within the tool invocation payload, adhering to the principle of separating credential storage from the execution runtime (refer to the Tool Invocation Protocol section).

Multi-Architecture Image Publishing

To ensure broad compatibility, utilize docker buildx for generating multi-platform images:

  1. Initialize Builder (if necessary): bash docker buildx create --use

  2. Build and Push Across Architectures: bash docker buildx build --platform linux/amd64,linux/arm64,linux/arm/v7 -t buryhuang/mcp-headless-gmail:latest --push .

  3. Validate Published Manifests: bash docker buildx imagetools inspect buryhuang/mcp-headless-gmail:latest

Operational Usage Guide

The server exposes its capabilities through defined MCP tool signatures. Token renewal is managed via a specialized utility call.

Server Initialization

bash mcp-server-headless-gmail

Tool Invocation Protocol

When interacting via an MCP client, authentication is managed dynamically. The primary mechanism for credential updates is the dedicated token refresh utility.

Token Lifecycle Management (Initial Setup or Expiration Handling)

If both access and refresh tokens are known:

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

If only the access token is stale, refresh using these parameters:

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

Successful execution yields a fresh access token and its validity period, suitable for immediate subsequent API requests.

Fetching Recent Messages

Fetches a list of recent messages, including the first 1024 characters of the body content:

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

Output Structure Details: - Essential metadata (identifier, thread identifier, sender/recipient details, subject line, timestamp, etc.). - The initial 1000 characters of the body payload. - body_size_bytes: Total byte count of the entire message body. - contains_full_body: Boolean indicating if the returned segment is complete.

Segmented Retrieval of Full Message Body

For messages exceeding the initial 1024-character preview, utilize chunked retrieval:

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

Alternatively, targeting content by conversational thread:

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

Response Attributes: - A 1024-character segment of the body content beginning at the specified offset. - body_size_bytes: Total size. - chunk_size: Length of the segment returned in this specific call. - contains_full_body: True if this chunk completes the message.

To reconstruct a lengthy message, repeatedly invoke this tool, incrementing the offset by 1000 until contains_full_body evaluates to true.

Dispatching Mail

{ "google_access_token": "your_access_token", "to": "recipient@destination.org", "subject": "Status Update via MCP Gateway", "body": "The process has successfully completed.", "html_body": "

The process has successfully completed.

" }

Token Refresh Protocol Summary

  1. Initiate the process by invoking the gmail_refresh_token utility using either the complete set of credentials (access, refresh, client ID/secret) or, if the access token is known to be expired, just the refresh token, ID, and secret.
  2. Apply the newly minted access token to all subsequent Gmail API interactions.
  3. If any operational call returns an explicit token expiry notice, re-execute the refresh utility.

This strategy minimizes the data footprint required for standard operations while maintaining a robust recovery path for token validity.

Acquiring Google API Authorization Assets

Follow this sequence within the Google Cloud ecosystem:

  1. Navigate to the Google Cloud Console.
  2. Provision a new project.
  3. Activate the Gmail Application Programming Interface.
  4. Configure the OAuth Consent Screen.
  5. Generate OAuth Client ID credentials, selecting "Desktop Application" as the client type.
  6. Securely record the generated Client ID and Secret.
  7. Perform an OAuth 2.0 flow to obtain both the initial Access Token and the persistent Refresh Token, ensuring these scopes are requested:
  8. https://www.googleapis.com/auth/gmail.readonly
  9. https://www.googleapis.com/auth/gmail.send

Automated Token Renewal Mechanism

This server incorporates native logic for token lifecycle management. Upon detecting an expired access token, the system automatically employs the stored refresh token, client ID, and client secret to procure a new access token without requiring manual user interaction.

Security Advisory

This component necessitates direct exposure to your primary Google API authentication artifacts. Absolute security protocols must be maintained for all stored tokens and secrets; dissemination to unverified entities is strictly prohibited.

Licensing

Refer to the LICENSE file for usage rights.

WIKIPEDIA: Business management tools comprise the complete assortment of systems, functional applications, oversight mechanisms, computational frameworks, and formalized methodologies employed by commercial entities to navigate evolving market dynamics, secure a favorable competitive position, and systematically enhance operational efficiency.

== Conceptual Framework == Business management solutions can be categorized based on the organizational function they serve—for instance, tools dedicated to strategic forecasting, workflow governance, record keeping, personnel administration, analytical decision support, or performance monitoring. A functional categorization often encompasses these primary areas:

  • Data entry and integrity verification utilities applicable across all departments.
  • Systems focused on monitoring and optimizing operational workflows.
  • Platforms designed for data aggregation and executive insight generation. Modern management technology has undergone radical transformation in the past decade due to rapid technological advancement, making the selection of optimal business tooling complex for any given enterprise scenario. This complexity stems from the perpetual drive to reduce operational expenditure while maximizing revenue, coupled with the necessity of deeply understanding client requirements and efficiently delivering offerings that satisfy those demands. In this environment, leadership must adopt a strategic posture regarding business management utilities rather than passively adopting the newest trending solution. Over-reliance on off-the-shelf tools without bespoke organizational alignment frequently results in systemic instability. Therefore, business management platforms require deliberate selection followed by tailored integration into the firm's specific operational context.

== Prevalent Methodologies (2013 Benchmark) == In 2013, a significant analysis by Bain & Company illuminated global patterns in the adoption of management practices. These practices reflect regional economic needs and prevailing market conditions:

The leading ten methodologies identified included:

Strategic planning Customer relationship management Employee engagement surveys Benchmarking Balanced scorecard Core competency Outsourcing Change management programs Supply chain management Mission statement and vision statement Market segmentation Total quality management

== Enterprise Software Landscape == Software, defined as programmed instruction sets utilized by business professionals to execute diverse corporate functions, is often termed business software or enterprise application. These applications are instrumental in augmenting productivity, quantifying performance metrics, and ensuring precision across various organizational endeavors. Evolution spanned from rudimentary Management Information Systems (MIS) to comprehensive Enterprise Resource Planning (ERP) suites. Subsequently, Customer Relationship Management (CRM) components were integrated, culminating in the contemporary shift toward cloud-based business management solutions. While a clear correlation exists between IT investment and organizational outcome, two factors critically amplify value creation: the efficacy of the implementation process and the precision in selecting and customizing the appropriate tools.

== Focus on Small and Medium Enterprises (SMEs) == Tools specifically tailored for SMEs are crucial as they offer pathways to conserve organizational resources...

See Also

`