A MCP (Model Context Protocol) server that provides get, send Gmails without local credential or token setup.
Configuration
View docs{
"mcpServers": {
"abhinavbansal17-mcp-headless-gmail": {
"command": "docker",
"args": [
"run",
"-i",
"--rm",
"buryhuang/mcp-headless-gmail:latest"
]
}
}
}You can run a headless MCP Gmail server that handles getting recent emails, fetching full email bodies in chunks, sending emails, and managing token refreshes, all without local credentials stored on the server. It’s designed to operate remotely in containers or via single-command tools, keeping credential storage separate from the server logic while enabling secure Gmail access.
You integrate the MCP Gmail server with a client that supports MCP configurations. You can start the server locally or in a container, then issue MCP calls to fetch emails, read message bodies in chunks, or send emails using the Gmail API. The server handles token refreshes automatically, so you don’t have to manage access tokens for every request.
Prerequisites: Python 3.10 or higher, and Google API credentials (client ID, client secret, access token, and refresh token). You can also run the server via container tools or through an MCP-friendly runner.
Step 1: Install via container/runtime helper (Docker example) or an MCP-enabled CLI.
# Starting a Docker-based runtime for the MCP Gmail server
# This runs the image and keeps it interactive
# You can adapt the command for your environment as needed
docker run -i --rm buryhuang/mcp-headless-gmail:latestTo run from a container using a generic MCP runner, you can configure the client to execute the appropriate runtime command for the service. The following runtime commands are shown as integration options:
{
"mcpServers": {
"gmail": {
"command": "docker",
"args": [
"run",
"-i",
"--rm",
"buryhuang/mcp-headless-gmail:latest"
]
}
}
}If you prefer to run the server directly as a local process, you can use the standard start command shown in the examples.
mcp-server-headless-gmailTypical workflows include refreshing tokens, retrieving recent emails, obtaining full bodies in chunks, and sending emails. The server supports automatic token refreshing so you can keep using the Gmail API without manual re-authentication.
Gmail credentials are not passed as environment variables to maintain separation between credential storage and server implementation. You provide credentials in your tool calls when you perform operations.
Keep your Google API credentials secure and limit access to the containers or hosts running the MCP Gmail server. Rotate tokens as needed and follow best practices for secret management in your environment.
To obtain Google API credentials, set up a project in your Google Cloud Console, enable Gmail API, configure OAuth consent, and generate Desktop-type OAuth credentials. Use scopes for reading and sending Gmail messages as required.
Fetch the most recent Gmail messages, returning metadata and the first 1000 characters of each body.
Retrieve the full email body content in 1000-character chunks by specifying an offset or thread id.
Send an email via Gmail by providing recipient, subject, and body content (plain or HTML).
Refresh access tokens using the refresh token when needed, returning a new access token and expiry.
Automatic handling of token refreshes to minimize manual credential management.