Gmail MCP Server
Provides tools for reading unread emails and creating correctly threaded draft replies using the Gmail API.
Click on "Install Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@Gmail MCP Servershow my unread emails"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
# Gmail MCP Server
A Windows-first Python MCP server for Gmail that reads unread emails and creates correctly threaded draft replies using the Gmail API, OAuth 2.0 Desktop credentials, and local stdio transport.
Overview
This project implements a local Model Context Protocol server for Gmail with Python 3.11 and the official MCP Python SDK using FastMCP.
It exposes two focused tools:
get_unread_emailscreate_draft_reply
The server is designed for local Windows development and Claude Desktop-compatible MCP configuration. It is verified locally through Gmail OAuth, direct Python smoke testing, manual stdio server startup, and Claude Desktop configuration pickup through main.log.
What this project demonstrates
MCP server implementation with Python and FastMCP
Gmail API integration with OAuth 2.0 Desktop App credentials
correctly threaded Gmail draft reply creation
Windows-first local developer workflow
Claude Desktop local MCP configuration on Windows
practical verification of a local MCP server independent of hosted execution constraints
The key implementation detail is Gmail threading correctness. Draft replies are created using the original Gmail threadId, RFC Message-ID, In-Reply-To, References, and matching subject so that the resulting draft remains attached to the correct conversation.
Tech stack
Python 3.11
MCP Python SDK with FastMCP
Gmail API
Google OAuth 2.0 Desktop App credentials
local stdio MCP transport
Claude Desktop-compatible Windows configuration
MCP tools
get_unread_emails(limit: int = 10)
Reads unread Gmail messages from the authenticated mailbox and returns structured message data including:
message_idthread_idsendersubjectsnippetbody_textinternal_date
create_draft_reply(reply_body: str, original_message_id: str | None = None, thread_id: str | None = None)
Creates a correctly threaded Gmail draft reply.
Accepted inputs:
original_message_idthread_id
Returned metadata includes:
statusdraft_iddraft_message_idthread_idreply_tosubjectsource_message_idin_reply_toreferences
Architecture
Runtime flow
The local MCP server exposes Gmail operations as MCP tools.
OAuth credentials are loaded from local token storage or refreshed when needed.
Gmail API calls are executed on behalf of the authenticated user.
The server runs over stdio for local MCP compatibility.
Claude Desktop can be configured to launch the server locally on Windows.
Thread-safe draft creation
To create correctly threaded Gmail draft replies, the implementation uses:
Gmail
threadIdoriginal RFC
Message-IDIn-Reply-ToReferencesmatching subject
This avoids creating detached drafts that appear as new conversations instead of replies.
Project structure
gmail-mcp-server/
├── .env
├── .env.example
├── .gitignore
├── authenticate.py
├── LICENSE
├── README.md
├── requirements.txt
├── run_server.py
├── smoke_test.py
├── pyproject.toml
├── gmail_mcp_server/
│ ├── __init__.py
│ ├── auth.py
│ ├── config.py
│ ├── gmail_client.py
│ └── server.py
├── secrets/
│ ├── credentials.json
│ └── token.json
└── docs/
└── screenshots/Local setup
Prerequisites
Windows
Python 3.11
Git
Visual Studio Code
a Gmail account
a Google Cloud project with Gmail API enabled
OAuth 2.0 Desktop App credentials
Claude Desktop for local MCP configuration
Create and activate the virtual environment
Set-Location D:\Projects\gmail-mcp-server
py -3.11 -m venv .venv
.\.venv\Scripts\Activate.ps1If PowerShell blocks activation:
Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass
.\.venv\Scripts\Activate.ps1Install dependencies
Set-Location D:\Projects\gmail-mcp-server
.\.venv\Scripts\Activate.ps1
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install -e .Create the runtime environment file
Set-Location D:\Projects\gmail-mcp-server
Copy-Item .env.example .env -ForceEnvironment variables
GOOGLE_CLIENT_SECRET_PATH=D:\Projects\gmail-mcp-server\secrets\credentials.json
GOOGLE_TOKEN_PATH=D:\Projects\gmail-mcp-server\secrets\token.json
GMAIL_USER_ID=me
DEFAULT_UNREAD_LIMIT=10
LOG_LEVEL=INFOGmail API configuration
Create a Google Cloud project
Enable the Gmail API
Configure the OAuth consent screen
Add these scopes:
https://www.googleapis.com/auth/gmail.readonlyhttps://www.googleapis.com/auth/gmail.compose
Create an OAuth client with application type
Desktop appSave the downloaded client JSON as:
D:\Projects\gmail-mcp-server\secrets\credentials.jsonAuthentication
Run:
Set-Location D:\Projects\gmail-mcp-server
.\.venv\Scripts\Activate.ps1
python .\authenticate.pyThis opens a browser-based Gmail OAuth flow and saves the token at:
D:\Projects\gmail-mcp-server\secrets\token.jsonDo not press Ctrl + C during normal browser authentication. Press Ctrl + C only if the process is clearly stuck and no browser window appears.
Verification
Verify OAuth token creation
Test-Path D:\Projects\gmail-mcp-server\secrets\token.jsonExpected result:
TrueVerify Gmail read access
Set-Location D:\Projects\gmail-mcp-server
.\.venv\Scripts\Activate.ps1
python .\smoke_test.pyExpected result:
valid JSON output
unread message count
structured email objects
no exception
Verify MCP server startup
Set-Location D:\Projects\gmail-mcp-server
.\.venv\Scripts\Activate.ps1
python .\run_server.pyExpected result:
startup log appears
no immediate traceback
the process blocks normally as a stdio server
After confirming startup, press:
Ctrl + Cto stop the server.
Claude Desktop integration
On Windows, Claude Desktop MCP configuration is stored at:
$env:APPDATA\Claude\claude_desktop_config.jsonExample server entry:
{
"mcpServers": {
"gmail-mcp-server": {
"command": "D:\\Projects\\gmail-mcp-server\\.venv\\Scripts\\python.exe",
"args": [
"D:\\Projects\\gmail-mcp-server\\run_server.py"
],
"env": {
"PYTHONUNBUFFERED": "1"
}
}
}
}If your existing Claude config already contains a preferences block, keep it.
Verify Claude Desktop config pickup
Get-Content "$env:APPDATA\Claude\logs\main.log" -Tail 120
Select-String -Path "$env:APPDATA\Claude\logs\main.log" -Pattern "gmail-mcp-server","Launching MCP Server"Expected evidence includes:
MCP Server connection requested for: gmail-mcp-serverLaunching MCP Server: gmail-mcp-server
Example Claude prompts
These are representative prompts for local MCP usage once the server is configured:
Read my 5 unread emails and summarize the sender, subject, and key message.Create a draft reply to the unread email from John saying: Thanks for the update. I will review this today and respond with next steps.Reply to the latest message in this thread with: Thanks — this looks good to me. Please go ahead.Verification note
This repository accurately documents:
local Gmail OAuth success
Python smoke test success
manual stdio server startup success
Claude Desktop configuration presence
Claude
main.loglaunch-attempt evidence
If Claude Desktop cannot execute MCP tools in-chat on a Free plan, that is a client-plan limitation rather than a server implementation failure. For that reason, this README documents Claude Desktop compatibility and local verification without overstating in-chat execution results that were not directly captured.
Screenshots
Project structure

Dependency installation

Gmail API enabled

OAuth Desktop app client

Claude Desktop MCP config

MCP server startup

Smoke test success

Claude log launch attempt

OAuth token creation

GitHub repository page

GitHub rendered README

Security notes
Never commit
.envNever commit
secrets/credentials.jsonNever commit
secrets/token.jsonNever publish token contents or credential contents in screenshots
Redact mailbox-sensitive data before publishing screenshots
Stretch goal direction
A natural extension is adding external or local reply context to improve draft quality, for example:
a local style guide
reusable reply templates
a lightweight knowledge folder for organization-specific context
This keeps the Gmail integration focused while making generated draft content more useful and more tailored.
License
This project is licensed under the MIT License.
See the LICENSE file for full details.
This server cannot be installed
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Latest Blog Posts
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/cherryaugusta/gmail-mcp-server'
If you have feedback or need assistance with the MCP directory API, please join our Discord server