Gmail MCP Server
A custom MCP server that gives Claude full Gmail control — send directly, read, reply, search, label, and delete emails.
README
Gmail MCP Server
A custom MCP server that gives Claude full Gmail control — send directly (no drafts), read, reply, search, label, and delete — over stdio for Claude Desktop and Cowork.
Folder Structure
gmail-mcp-server/
├── src/
│ ├── server.ts ← MCP entry point, registers all tools
│ ├── auth.ts ← OAuth2 flow + token refresh
│ ├── gmail-client.ts ← Gmail API wrapper
│ ├── templates.ts ← HTML email templates
│ ├── config.ts ← Env var loader
│ ├── logger.ts ← Structured stderr logger
│ └── tools/
│ ├── send-email.ts ← send_email
│ ├── send-bulk-email.ts ← send_bulk_email
│ ├── send-template-email.ts← send_template_email + list_templates
│ ├── list-emails.ts ← list_emails, get_email, reply_email
│ └── search-emails.ts ← search_emails, list_labels, add_label, move_email, delete_email
├── .env.example
├── claude_desktop_config.example.json
├── tsconfig.json
└── package.json
Step 1 — Google Cloud Console Setup (One-time)
- Go to https://console.cloud.google.com
- Create a new project (or use existing)
- Enable the Gmail API:
- APIs & Services → Library → search "Gmail API" → Enable
- Create OAuth2 credentials:
- APIs & Services → Credentials → Create Credentials → OAuth client ID
- Application type: Desktop app
- Name:
gmail-mcp-server - Click Create → Copy the Client ID and Client Secret
- Configure OAuth consent screen:
- OAuth consent screen → External → Add your Gmail as a test user
- Add scopes:
gmail.send,gmail.readonly,gmail.modify
Step 2 — Project Setup
# 1. Install dependencies
npm install
# 2. Create your .env file
cp .env.example .env
# 3. Edit .env and fill in your credentials
# GOOGLE_CLIENT_ID=your_client_id
# GOOGLE_CLIENT_SECRET=your_client_secret
# SENDER_NAME=Your Name
Step 3 — Authenticate (One-time)
npm run auth
This will:
- Print a Google auth URL
- You open it in your browser, sign in, approve permissions
- Paste the code back into the terminal
token.jsonis saved — never needs to be repeated
Step 4 — Build
npm run build
This compiles TypeScript → dist/ folder.
Step 5 — Connect to Claude Desktop
Edit your Claude Desktop config file:
macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
Windows: %APPDATA%\Claude\claude_desktop_config.json
Add the gmail server block (replace paths with your actual absolute paths):
{
"mcpServers": {
"gmail": {
"command": "node",
"args": ["/Users/yourname/gmail-mcp-server/dist/server.js"],
"env": {
"GOOGLE_CLIENT_ID": "your_client_id",
"GOOGLE_CLIENT_SECRET": "your_client_secret",
"TOKEN_PATH": "/Users/yourname/gmail-mcp-server/token.json",
"SENDER_NAME": "Your Name",
"LOG_LEVEL": "info"
}
}
}
}
Restart Claude Desktop. The gmail tools will appear in Claude's tool list.
Step 6 — Connect to Cowork
In Cowork, add a local MCP server with:
- Command:
node /absolute/path/to/gmail-mcp-server/dist/server.js - Environment variables: same as above
Available Tools
| Tool | What it does |
|---|---|
send_email |
Send directly to one or more recipients |
send_bulk_email |
Send same email to up to 50 recipients |
send_template_email |
Send HTML email using a template |
list_templates |
See all templates and their variables |
list_emails |
List inbox / any label with optional query |
get_email |
Read full email by message ID |
reply_email |
Reply in-thread to an email |
search_emails |
Full Gmail search query support |
list_labels |
See all labels and their IDs |
add_label |
Add labels to an email |
move_email |
Move / archive / mark read |
delete_email |
Move to Trash |
Example Prompts for Claude
Send an email to john@example.com with subject "Hello" and body "Let's connect!"
Search my emails for invoices from last month
Reply to message ID <id> saying "Thanks, I'll review this today"
Send the welcome template to sarah@example.com with name="Sarah" and company="Acme"
List my unread emails in INBOX
Move email <id> to archive (remove INBOX label)
Adding New Templates
Edit src/templates.ts and add a new entry to the TEMPLATES object.
Then rebuild: npm run build
Development (no build needed)
npm run dev # runs via tsx directly
Troubleshooting
| Problem | Fix |
|---|---|
Missing required env var |
Check your .env file or the env block in Claude Desktop config |
Token expired |
Run npm run auth again |
Permission denied on Gmail API |
Make sure Gmail API is enabled in Google Cloud Console |
| Claude doesn't see tools | Restart Claude Desktop after editing config |
| Server crashes silently | Check LOG_LEVEL=debug and watch stderr output |
推荐服务器
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 模型以安全和受控的方式获取实时的网络信息。