MCP Headless Gmail Server logo

MCP Headless Gmail Server

Community
baryhuang

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

Publisherbaryhuang
Repositorymcp-headless-gmail
LanguagePython
Forks
29
Stars
54
Available tools
4
Transport typestdio
Categories
LicenseMIT
Links
  • Connect tools to AI workflows

    MCP Headless Gmail Server exposes MCP capabilities that can be used by compatible AI clients and agents.

  • 4 available tools

    Browse the callable actions below, including names and descriptions when provided by the server.

  • Ready-to-copy setup

    Use the installation snippets to configure this server in your preferred MCP client.

  • Open source signals

    54 stars and 29 forks from the linked repository.

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.

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

Prerequisites

  • Python 3.10 or higher
  • Google API credentials (client ID, client secret, access token, and refresh token)

Installation

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

# Install dependencies
pip install -e .

Docker

Building the Docker Image

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

Usage with Claude Desktop

You can configure Claude Desktop to use the Docker image by adding the following to your Claude configuration:

docker

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

npm version

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

Note: With this configuration, you'll need to provide your Google API credentials in the tool calls as shown in the Using the Tools section. Gmail credentials are not passed as environment variables to maintain separation between credential storage and server implementation.

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):

    bash
    docker buildx create --use
  2. Build and push the image for multiple platforms:

    bash
    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:

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

Usage

The server provides Gmail functionality through MCP tools. Authentication handling is simplified with a dedicated token refresh tool.

Starting the Server

bash
mcp-server-headless-gmail

Using the Tools

When using an MCP client like Claude, you have two main ways to handle authentication:

Refreshing Tokens (First Step or When Tokens Expire)

If you have both access and refresh tokens:

json
{
  "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 your access token has expired, you can refresh with just the refresh token:

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

This will return a new access token and its expiration time, which you can use for subsequent calls.

Getting Recent Emails

Retrieves recent emails with the first 1k characters of each email body:

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

Response includes:

  • Email metadata (id, threadId, from, to, subject, date, etc.)
  • First 1000 characters of the email body
  • body_size_bytes: Total size of the email body in bytes
  • contains_full_body: Boolean indicating if the entire body is included (true) or truncated (false)

Getting Full Email Body Content

For emails with bodies larger than 1k characters, you can retrieve the full content in chunks:

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

You can also get email content by thread ID:

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

The response includes:

  • A 1k chunk of the email body starting from the specified offset
  • body_size_bytes: Total size of the email body
  • chunk_size: Size of the returned chunk
  • contains_full_body: Boolean indicating if the chunk contains the remainder of the body

To retrieve the entire email body of a long message, make sequential calls increasing the offset by 1000 each time until contains_full_body is true.

Sending an Email

json
{
  "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 Refresh Workflow

  1. Start by calling the gmail_refresh_token tool with either:
    • Your full credentials (access token, refresh token, client ID, and client secret), or
    • Just your refresh token, client ID, and client secret if the access token has expired
  2. Use the returned new access token for subsequent API calls.
  3. If you get a response indicating token expiration, call the gmail_refresh_token tool again to get a new token.

This approach simplifies most API calls by not requiring client credentials for every operation, while still enabling token refresh when needed.

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.

Installation

TypingMind
Prerequisites:

Node.js 18+

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

Use MCP Headless Gmail Server MCP with multiple AI models

TypingMind connects MCP tools at the workspace level, so once MCP Headless Gmail Server is connected, you can use it with different AI models in TypingMind instead of setting it up separately for each model. This MCP runs locally through the TypingMind MCP connector on your device.

Setup guide to use the local connector

Use this when the MCP server needs access to local files, apps, or private resources on your computer.

1

Open the MCP settings

In TypingMind, go to Settings, Advanced Settings, then Model Context Protocol and choose Setup Connector.

  1. Open TypingMind in your browser.
  2. Click the Settings icon.
  3. Go to Advanced Settings.
  4. Open the Model Context Protocol section.
  5. Click Setup Connector and choose This Device.
TypingMind MCP connector setup screen with This Device selected
2

Run the connector command

Choose This Device, copy the command from TypingMind, and run it in Terminal. Keep the process running while you use MCP.

  1. Copy the setup command shown by TypingMind.
  2. Open Terminal on macOS or Windows Terminal on Windows.
  3. Paste and run the command.
  4. Approve the package install if Terminal asks you to proceed.
  5. Keep the Terminal window running while using MCP tools.
3

Add MCP Headless Gmail Server as a server

When the connector status is Ready, click Edit Servers and paste the MCP server configuration.

  1. Wait until the connector status shows Ready.
  2. Click Edit Servers.
  3. Paste the MCP Headless Gmail Server MCP server configuration.
  4. Save the server list.
  5. Refresh if you want to confirm the connector is still ready.
TypingMind MCP settings showing active server and Edit Servers button
{
  "mcpServers": {
    "baryhuang-mcp-headless-gmail": {
      "command": "npx",
      "args": [
        "-y",
        "@peakmojo/mcp-server-headless-gmail"
      ]
    }
  }
}
4

Use it across models

Save the server list, open Plugins, enable the MCP Headless Gmail Server MCP tools, then select any supported AI model in TypingMind and use the tools in chat or assign them to an AI agent.

  1. Open the Plugins page in TypingMind.
  2. Enable the MCP Headless Gmail Server MCP tools.
  3. Start a chat and choose the AI model you want to use.
  4. Use the MCP tools in chat or assign them to an AI agent.
  5. Switch to another AI model whenever needed without reconnecting MCP.
TypingMind chat using enabled MCP tools with a selected AI model
Can you use MCP Headless Gmail Server to help me with this task?
MCP Headless Gmail Server
Sure. I read it.
Here is what I found using MCP Headless Gmail Server.

Frequently asked questions

What is the MCP Headless Gmail Server MCP server used for?

MCP Headless Gmail Server is an MCP server that lets compatible AI clients connect to external tools and context. In TypingMind, you can add this MCP server once and make its tools available in your AI workspace.

Can I use MCP Headless Gmail Server MCP with multiple AI models in TypingMind?

Yes. TypingMind connects MCP tools at the workspace level, so you can use MCP Headless Gmail Server with different AI models such as Claude, ChatGPT, Gemini, or other models you have configured in TypingMind without setting up the MCP server separately for each model.

Why use MCP Headless Gmail Server MCP with TypingMind?

TypingMind is one of the best frontends for LLM chat because it brings multiple AI models, prompts, plugins, AI agents, API keys, and MCP tools into one workspace. With MCP Headless Gmail Server connected, you can use its MCP tools across your preferred models while keeping your chat workflow organized in TypingMind.

How do I connect MCP Headless Gmail Server MCP to TypingMind?

MCP Headless Gmail Server runs through the TypingMind local MCP connector. This is best when the MCP server needs access to local files, desktop apps, command-line tools, or private resources on your computer.

What tools does MCP Headless Gmail Server MCP provide in TypingMind?

MCP Headless Gmail Server exposes 4 MCP tools that can be enabled from the TypingMind Plugins page and used in chat or assigned to AI agents.

Do I need to share my API keys with TypingMind to use MCP Headless Gmail Server MCP?

No. TypingMind is local-first and lets you keep your model providers, API keys, prompts, and MCP configuration under your control. If MCP Headless Gmail Server requires authentication, add the required headers, OAuth settings, or local configuration for that MCP server when you create the connection.

Related MCP Servers

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇