Refreshes the Google access token using the refresh token, client ID, and client secret
Retrieves recent emails from Gmail with the first 1k characters of each email body
Retrieves email content in 1k chunks using message ID and offset
Sends an email through Gmail
Headless Gmail provides a streamlined way to interact with Gmail through a Model Context Protocol server that operates completely headless in remote environments. Unlike other Gmail solutions, it requires no browser access or local file storage, making it ideal for containerized deployments. The server enables a decoupled architecture where clients can complete OAuth flows independently and pass credentials as context, creating a clean separation between credential storage and implementation. Built on the reliable google-api-python-client library, it offers focused Gmail functionality for retrieving and sending emails.
Headless Gmail is a Model Context Protocol server that provides Gmail access capabilities without requiring local credential storage or browser dependencies. This makes it perfect for containerized environments and remote deployments where traditional Gmail access methods would be challenging.
The simplest way to use Headless Gmail is through its Docker image:
{
"mcpServers": {
"gmail": {
"command": "docker",
"args": [
"run",
"-i",
"--rm",
"buryhuang/mcp-headless-gmail:latest"
]
}
}
}
Alternatively, you can use the NPM package:
{
"mcpServers": {
"gmail": {
"command": "npx",
"args": [
"@peakmojo/mcp-server-headless-gmail"
]
}
}
}
If you prefer to install from source:
Clone the repository:
git clone https://github.com/baryhuang/mcp-headless-gmail.git
cd mcp-headless-gmail
Install dependencies:
pip install -e .
Start the server:
mcp-server-headless-gmail
Before using the Gmail functionality, you'll need Google API credentials. The server is designed to keep credential management separate from the implementation, so you'll need to provide:
These credentials are passed with each request rather than being stored on the server.
When your access token expires, use the refresh_token
tool to get a new one. For subsequent Gmail operations, include the access token with each request.
The server handles token refreshing automatically when needed, making it easy to maintain continuous access to Gmail without managing authentication flows manually.
Since credentials are passed with each request and not stored on the server, this implementation provides good separation of concerns. However, ensure your MCP client securely stores these credentials and transmits them securely to the server.