This MCP server for Gmail allows Claude Desktop users to access and search their Gmail inbox through a secure OAuth2 connection. It provides a bridge between Claude and the Gmail API, enabling email browsing capabilities directly within Claude.
credentials.json
# Create a conda environment
conda create -n mcp-gmail python=3.12
conda activate mcp-gmail
# Install the package
cd gmail-mcp-server
pip install -e .
Add the following to your claude_desktop_config.json
:
{
"mcpServers": {
"gmail": {
"command": "/path/to/conda/envs/mcp-gmail/bin/python",
"args": ["-m", "gmail_mcp_server.server"],
"env": {
"PYTHONPATH": "/path/to/gmail-mcp-server/src",
"GMAIL_CREDENTIALS_FILE": "/path/to/credentials.json",
"GMAIL_TOKEN_FILE": "/path/to/token.json"
}
}
}
}
Note: Replace /path/to/
with your actual file paths. The token file will be created automatically during first authentication.
When you first try to access Gmail through Claude, you'll be prompted to authorize the application in your browser. After authorization, your credentials will be saved to the token file for future use.
gmail://inbox/recent
- Returns your 10 most recent emailsThe server provides a search_emails
tool with the following parameters:
query
(required): Gmail search query using Gmail's standard search syntaxmax_results
(optional): Maximum number of results to return (default: 10)Example search query in Claude:
Could you show me any emails from sanrio in the last two days?
The server requires two environment variables:
GMAIL_CREDENTIALS_FILE
: Path to your Google OAuth credentials fileGMAIL_TOKEN_FILE
: Path where the authentication token will be savedFor testing purposes, you can run the server directly:
GMAIL_CREDENTIALS_FILE="/path/to/credentials.json" \
GMAIL_TOKEN_FILE="/path/to/token.json" \
python -m gmail_mcp_server.server
The Gmail MCP server implements these security features:
To add this MCP server to Claude Code, run this command in your terminal:
claude mcp add-json "gmail" '{"command":"/path/to/conda/envs/mcp-gmail/bin/python","args":["-m","gmail_mcp_server.server"],"env":{"PYTHONPATH":"/path/to/gmail-mcp-server/src","GMAIL_CREDENTIALS_FILE":"/path/to/credentials.json","GMAIL_TOKEN_FILE":"/path/to/token.json"}}'
See the official Claude Code MCP documentation for more details.
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 > Tools & Integrations and click "New MCP Server".
When you click that button the ~/.cursor/mcp.json
file will be opened and you can add your server like this:
{
"mcpServers": {
"gmail": {
"command": "/path/to/conda/envs/mcp-gmail/bin/python",
"args": [
"-m",
"gmail_mcp_server.server"
],
"env": {
"PYTHONPATH": "/path/to/gmail-mcp-server/src",
"GMAIL_CREDENTIALS_FILE": "/path/to/credentials.json",
"GMAIL_TOKEN_FILE": "/path/to/token.json"
}
}
}
}
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 explicitly ask the agent to use the tool by mentioning the tool name and describing what the function does.
To add this MCP server to Claude Desktop:
1. Find your configuration file:
~/Library/Application Support/Claude/claude_desktop_config.json
%APPDATA%\Claude\claude_desktop_config.json
~/.config/Claude/claude_desktop_config.json
2. Add this to your configuration file:
{
"mcpServers": {
"gmail": {
"command": "/path/to/conda/envs/mcp-gmail/bin/python",
"args": [
"-m",
"gmail_mcp_server.server"
],
"env": {
"PYTHONPATH": "/path/to/gmail-mcp-server/src",
"GMAIL_CREDENTIALS_FILE": "/path/to/credentials.json",
"GMAIL_TOKEN_FILE": "/path/to/token.json"
}
}
}
}
3. Restart Claude Desktop for the changes to take effect