Headless Gmail
About
Enables headless Gmail access by separating credential storage from implementation, allowing clients to complete OAuth flows independently and pass credentials as context for email operations in containerized environments.
Details
- Author
- baryhuang
- Repository
- baryhuang/mcp-headless-gmail
- GitHub stars
- 16
- Downloads
- 523
- License
- MIT License
- Categories
- Communication, Other, Automation, AI, Design, Developer Tools, File Management, API, Security
- Tags
- #web
Jump to
- 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
Setting up with Highlight
This MCP is not yet compatible with Highlight’s one-click setup. However, you can still use it with Highlight by following these steps:
- Download and install Highlight from highlightai.com/download
- Navigate to the plugins tab and select "Add Custom Plugin"
-
Configure the plugin with the settings below
Plugin Name
Headless GmailCommand (node, npx, python, etc.)npxArguments-
Argument 1
@peakmojo/mcp-server-headless-gmail
Please refer to the README for specific instructions on how to obtain API keys or other required environment variables.
-
Argument 1
- Enable "Start Automatically" if you want the plugin to start when Highlight launches
From the repository
pip install -e .
You can configure Claude Desktop to use the Docker image by adding the following to your Claude configuration:
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"
]
}
}
}
gmail_refresh_token
Refresh the access token using the refresh token and client credentials. Parameters: google_refresh_token (string), google_client_id (string), google_client_secret (string)
get_recent_emails
Retrieve recent emails with the first 1k characters of each email body. Parameters: google_access_token (string), max_results (integer), unread_only (boolean)
get_full_email_body
Retrieve the full content of an email body in chunks. Parameters: google_access_token (string), message_id (string, optional), thread_id (string, optional), offset (integer)
send_email
Send an email through Gmail. Parameters: google_access_token (string), to (string), subject (string), body (string), html_body (string, optional)
Claude Desktop / Cursor
Paste into your MCP client config file to install this server.
{
"mcpServers": {
"headless gmail": {
"env": {},
"args": [
"@peakmojo/mcp-server-headless-gmail"
],
"command": "npx"
}
}
}
Linux
{
"env": [],
"args": [
"run",
"-i",
"--rm",
"buryhuang/mcp-headless-gmail:latest"
],
"command": "docker"
}
Macos
{
"env": [],
"args": [
"@peakmojo/mcp-server-headless-gmail"
],
"command": "npx"
}
Windows
{
"env": [],
"args": [
"/c",
"npx",
"@peakmojo/mcp-server-headless-gmail"
],
"command": "cmd"
}
MCP Headless Gmail Server (NPM & Docker)
A MCP (Model Context Protocol) server that provides get, send Gmails without local credential or token setup.
- 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.
- 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.
- 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
- Python 3.10 or higher
- Google API credentials (client ID, client secret, access token, and refresh token)
# Clone the repository git clone https://github.com/baryhuang/mcp-headless-gmail.git cd mcp-headless-gmail # Install dependencies pip install -e .
# Build the Docker image docker build -t mcp-headless-gmail .
You can configure Claude Desktop to use the Docker image by adding the following to your Claude configuration:
{ "mcpServers": { "gmail": { "command": "docker", "args": [ "run", "-i", "--rm", "buryhuang/mcp-headless-gmail:latest" ] } } }
{ "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 theUsing the Toolssection. Gmail credentials are not passed as environment variables to maintain separation between credential storage and server implementation.
To publish the Docker image for multiple platforms, you can use thedocker buildxcommand. Follow these steps:
-
Create a new builder instance(if you haven't already):
Build and push the image for multiple platforms:
docker buildx build --platform linux/amd64,linux/arm64,linux/arm/v7 -t buryhuang/mcp-headless-gmail:latest --push .
Verify the image is available for the specified platforms:
docker buildx imagetools inspect buryhuang/mcp-headless-gmail:latest
The server provides Gmail functionality through MCP tools. Authentication handling is simplified with a dedicated token refresh tool.
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:
{ "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:
{ "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.
Retrieves recent emails with the first 1k characters of each email body:
{ "google_access_token": "your_access_token", "max_results": 5, "unread_only": false }
- 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)
For emails with bodies larger than 1k characters, you can retrieve the full content in chunks:
{ "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:
{ "google_access_token": "your_access_token", "thread_id": "thread_id_from_get_recent_emails", "offset": 1000 }
- 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 untilcontains_full_bodyis true.
{ "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>" }
- Start by calling thegmail_refresh_tokentool 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
This approach simplifies most API calls by not requiring client credentials for every operation, while still enabling token refresh when needed.
To obtain the required Google API credentials, follow these steps:
- Go to theGoogle Cloud Console
- Create a new project
- Enable the Gmail API
- Configure OAuth consent screen
- Create OAuth client ID credentials (select "Desktop app" as the application type)
- Save the client ID and client secret
- 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)
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.
This server requires direct access to your Google API credentials. Always keep your tokens and credentials secure and never share them with untrusted parties.
AI personal assistant for email Inbox Zero
Send emails via SMTP. Requires SMTP server credentials to be configured through environment variables.
Query live Gmail data using LLMs via CData's read-only MCP server.
Tools for common Gmail operations, such as sending emails.
Provides comprehensive integration with Gmail for reading, searching, and sending emails.
An MCP server for Gmail, allowing AI assistants to manage emails through natural language.
Search and delete emails in your Gmail account.
Enables AI assistants to manage Gmail through natural language interactions.
An MCP server for integrating Gmail with auto-authentication support.
A standardized interface for managing, sending, and retrieving emails through the Gmail API.
Sign in to leave a review
Use Google, GitHub, or an email account so ratings stay tied to real people.
No reviews posted yet.


