The MCP Headless Gmail Server enables Gmail operations (reading and sending emails) in remote environments without requiring local credential setup or browser access. It operates as a Model Context Protocol server that can run headless in containerized environments.
Install the server globally using NPM:
npm install -g @peakmojo/mcp-server-headless-gmail
Or run it directly with npx:
npx @peakmojo/mcp-server-headless-gmail
Pull and run the Docker image:
docker pull buryhuang/mcp-headless-gmail
docker run -i --rm buryhuang/mcp-headless-gmail:latest
Add this to your Claude configuration:
{
"mcpServers": {
"gmail": {
"command": "docker",
"args": [
"run",
"-i",
"--rm",
"buryhuang/mcp-headless-gmail:latest"
]
}
}
}
For the NPM version:
{
"mcpServers": {
"gmail": {
"command": "npx",
"args": [
"@peakmojo/mcp-server-headless-gmail"
]
}
}
}
When your access token expires or for initial setup, use the token refresh tool:
{
"google_refresh_token": "your_refresh_token",
"google_client_id": "your_client_id",
"google_client_secret": "your_client_secret"
}
Or with an existing access token:
{
"google_access_token": "your_access_token",
"google_refresh_token": "your_refresh_token",
"google_client_id": "your_client_id",
"google_client_secret": "your_client_secret"
}
Get the most recent emails (first 1k characters of each body):
{
"google_access_token": "your_access_token",
"max_results": 5,
"unread_only": false
}
For emails with bodies larger than 1k characters, retrieve content in chunks:
{
"google_access_token": "your_access_token",
"message_id": "message_id_from_get_recent_emails",
"offset": 0
}
Or by thread ID:
{
"google_access_token": "your_access_token",
"thread_id": "thread_id_from_get_recent_emails",
"offset": 1000
}
For long emails, make sequential calls increasing the offset by 1000 each time until contains_full_body
is true.
Send an email through Gmail:
{
"google_access_token": "your_access_token",
"to": "[email protected]",
"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>"
}
To use this server, you'll need to obtain Google API credentials:
https://www.googleapis.com/auth/gmail.readonly
(for reading emails)https://www.googleapis.com/auth/gmail.send
(for sending emails)This server requires direct access to your Google API credentials. Always keep your tokens and credentials secure and never share them with untrusted parties.
There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json
file so that it is available in all of your projects.
If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json
file.
To add a global MCP server go to Cursor Settings > MCP and click "Add new global MCP server".
When you click that button the ~/.cursor/mcp.json
file will be opened and you can add your server like this:
{
"mcpServers": {
"cursor-rules-mcp": {
"command": "npx",
"args": [
"-y",
"cursor-rules-mcp"
]
}
}
}
To add an MCP server to a project you can create a new .cursor/mcp.json
file or add it to the existing one. This will look exactly the same as the global MCP server example above.
Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.
The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.
You can also explictly ask the agent to use the tool by mentioning the tool name and describing what the function does.