Gmail MCP Server
Enables AI assistants to read unread Gmail messages and create properly threaded draft replies through the Gmail API, allowing natural language email management while keeping drafts for manual review before sending.
README
Gmail MCP Server
An MCP (Model Context Protocol) server that lets an AI assistant:
- Read your unread Gmail messages via the Gmail API
- Create properly threaded draft replies in Gmail
Built for the Anthropic programme foundation project as an end-to-end example.
Features
get_unread_emails(maxResults: int = 10)
Fetches unread emails from your inbox and returns a JSON structure:
{
"emails": [
{
"id": "string",
"threadId": "string",
"from": "string",
"subject": "string",
"snippet": "string",
"internalDate": "string"
}
]
}
Fields:
id– Gmail message IDthreadId– Gmail thread ID (used when replying)from– sendersubject– email subjectsnippet– short preview of the messageinternalDate– message timestamp (ms since epoch, as string)
create_draft_reply(threadId: str, replyBody: str)
Creates a draft reply in the specified Gmail thread.
Returns a JSON structure:
{
"draftId": "string | null",
"threadId": "string",
"to": "string",
"subject": "string"
}
- Correctly threads the reply using
In-Reply-ToandReferencesheaders. - Leaves the draft in your Gmail Drafts folder for manual review / sending.
OAuth tokens are stored locally in token.json and refreshed automatically.
Architecture / Tech Stack
- Language: Python 3
- MCP server:
mcpPython SDK (FastMCP) - Gmail API client:
google-api-python-client,google-auth-oauthlib - Client: Claude Desktop using MCP over stdio
Prerequisites
- Python 3.10+ installed
- Claude Desktop installed
- A Google account with access to Gmail
- A Google Cloud project with the Gmail API enabled
Setup
-
Clone the repository and create a virtual environment
git clone <your-repo-url> gmail-mcp-server cd gmail-mcp-server python3 -m venv .venv source .venv/bin/activate # Windows: .venv\Scripts\Activate.ps1 pip install -r requirements.txt -
Create a Google Cloud project & enable Gmail API
- Go to the Google Cloud Console.
- Create (or select) a project.
- Enable Gmail API for that project.
- Configure the OAuth consent screen (External / Testing is fine for personal use).
-
Create OAuth credentials
- In APIs & Services → Credentials, create an OAuth client ID.
- Application type: Desktop app.
- Download the JSON file and save it in the project root as:
credentials.json -
First-time Gmail authentication (optional sanity check)
The project includes a small script to verify Gmail is configured correctly:
source .venv/bin/activate python debug_gmail.pyThis will:
- Open a browser window asking you to sign in and approve Gmail scopes.
- Save a local
token.jsonfile for future runs. - Print the IDs of your unread messages.
-
Ignore local secrets and environment-specific files
Make sure your
.gitignore(in this repo) includes at least:.venv/ __pycache__/ credentials.json token.json *.logThese files must never be committed to GitHub.
Claude Desktop Configuration
Claude Desktop uses claude_desktop_config.json to know how to launch MCP servers.
On macOS this file is usually at:
~/Library/Application Support/Claude/claude_desktop_config.json
Add (or merge) the following configuration:
{
"mcpServers": {
"gmail-mcp-server": {
"command": "/Users/<you>/Code/gmail-mcp-server/.venv/bin/python",
"args": [
"/Users/<you>/Code/gmail-mcp-server/server.py"
],
"env": {
"GMAIL_CREDENTIALS_PATH": "/Users/<you>/Code/gmail-mcp-server/credentials.json"
}
}
}
}
Replace /Users/<you>/Code/gmail-mcp-server with the actual path to this project on your machine.
After editing the file, quit and restart Claude Desktop so it picks up the new MCP server.
Usage in Claude
Once Claude Desktop is restarted, open a new chat and try:
List and summarise unread emails
“Use the
gmail-mcp-servertools to callget_unread_emailswithmaxResults5, then summarise the emails.”
Claude will:
- Call the
get_unread_emailstool. - Receive the JSON list of unread emails.
- Summarise them in natural language.
Inspect raw JSON (for debugging / demo)
“Call
get_unread_emailswithmaxResults3 and show me the raw JSON output.”
Create a draft reply
- First fetch unread emails and inspect the JSON to find a
threadId. - Then:
“Use the
gmail-mcp-servertools to callcreate_draft_replywith thisthreadId:<PASTE_THREAD_ID>and a reply body that politely confirms I received their email and proposes a call next week. Tell me whatdraftIdwas created.”
- Open Gmail → Drafts to see the newly created reply in the correct thread.
Screenshots (for project submission)
Suggested screenshots to include in your submission / repo:
- Claude calling
get_unread_emailsand showing the JSON result. - Claude summarising the unread emails.
- Claude calling
create_draft_replyand reporting the createddraftId. - Gmail UI showing the draft reply in the correct thread.
Place them in a screenshots/ folder and reference them in your application as needed.
Security Notes
- This server is intended for local, personal use as a learning/demo project.
credentials.jsonandtoken.jsonare sensitive and must remain local.- Scopes are limited to:
gmail.readonly– reading messagesgmail.compose– creating drafts
- The server does not send credentials or email content to any third-party service other than Gmail and the local Claude Desktop client.
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.