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.
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。