Labsco
baryhuang logo

MCP Headless Gmail Server

β˜… 55

from baryhuang

A headless server to get and send emails via the Gmail API, requiring Google API credentials at runtime.

πŸ”₯πŸ”₯πŸ”₯βœ“ VerifiedFreeAdvanced setup

MCP Headless Gmail Server (NPM & Docker)

npm version Docker Pulls License: MIT

A MCP (Model Context Protocol) server that provides get, send Gmails without local credential or token setup.

<a href="https://glama.ai/mcp/servers/@baryhuang/mcp-headless-gmail"> <img width="380" height="200" src="https://glama.ai/mcp/servers/@baryhuang/mcp-headless-gmail/badge" alt="Headless Gmail Server MCP server" /> </a>

Why MCP Headless Gmail Server?

Critical Advantages

  • Headless & Remote Operation: Unlike other MCP Gmail solutions that require running outside of docker and local file access, this server can run completely headless in remote environments with no browser no local file access.
  • Decoupled Architecture: Any client can complete the OAuth flow independently, then pass credentials as context to this MCP server, creating a complete separation between credential storage and server implementation.

Nice but not critical

  • Focused Functionality: In many use cases, especially for marketing applications, only Gmail access is needed without additional Google services like Calendar, making this focused implementation ideal.
  • Docker-Ready: Designed with containerization in mind for a well-isolated, environment-independent, one-click setup.
  • Reliable Dependencies: Built on the well-maintained google-api-python-client library.

Features

  • Get most recent emails from Gmail with the first 1k characters of the body
  • Get full email body content in 1k chunks using offset parameter
  • Send emails through Gmail
  • Refresh access tokens separately
  • Automatic refresh token handling

Docker

Building the Docker Image

Copy & paste β€” that's it
# Build the Docker image
docker build -t mcp-headless-gmail .

Cross-Platform Publishing

To publish the Docker image for multiple platforms, you can use the docker buildx command. Follow these steps:

  1. Create a new builder instance (if you haven't already):

    Copy & paste β€” that's it
    docker buildx create --use
  2. Build and push the image for multiple platforms:

    Copy & paste β€” that's it
    docker buildx build --platform linux/amd64,linux/arm64,linux/arm/v7 -t buryhuang/mcp-headless-gmail:latest --push .
  3. Verify the image is available for the specified platforms:

    Copy & paste β€” that's it
    docker buildx imagetools inspect buryhuang/mcp-headless-gmail:latest

Obtaining Google API Credentials

To obtain the required Google API credentials, follow these steps:

  1. Go to the Google Cloud Console
  2. Create a new project
  3. Enable the Gmail API
  4. Configure OAuth consent screen
  5. Create OAuth client ID credentials (select "Desktop app" as the application type)
  6. Save the client ID and client secret
  7. Use OAuth 2.0 to obtain access and refresh tokens with the following scopes:
    • https://www.googleapis.com/auth/gmail.readonly (for reading emails)
    • https://www.googleapis.com/auth/gmail.send (for sending emails)

Token Refreshing

This server implements automatic token refreshing. When your access token expires, the Google API client will use the refresh token, client ID, and client secret to obtain a new access token without requiring user intervention.

Security Note

This server requires direct access to your Google API credentials. Always keep your tokens and credentials secure and never share them with untrusted parties.

License

See the LICENSE file for details.