Gmail MCP Server
A comprehensive MCP server providing 24 tools for full Gmail management, including email operations, label organization, and batch filtering. It features multi-account support and secure OAuth authentication for interacting with mailboxes via natural language.
README
Gmail MCP Server
A comprehensive Model Context Protocol (MCP) server for Gmail, providing 24 tools for full email management including sending, receiving, labels, filters, attachments, and batch operations.
Features
- 24 Gmail Tools: Full email operations, label management, filters, batch operations, and attachments
- Multi-Account Support: Manage multiple Gmail accounts with
--accountflag - OAuth Authentication: Secure authentication with automatic token refresh
- Attachment Support: Download and send attachments
- Batch Operations: Efficiently modify or delete up to 1000 emails at once
- Filter Templates: Pre-built filter templates for common use cases
- MCP Resources: Access messages, threads, and labels via URI
Prerequisites
- Node.js 18+
- A Google Cloud Project with Gmail API enabled
- OAuth 2.0 credentials (Desktop app type)
Setup
1. Create Google Cloud OAuth Credentials
- Go to Google Cloud Console
- Create a new project or select an existing one
- Enable the Gmail API:
- Navigate to "APIs & Services" > "Library"
- Search for "Gmail API"
- Click "Enable"
- Create OAuth credentials:
- Go to "APIs & Services" > "Credentials"
- Click "Create Credentials" > "OAuth Client ID"
- If prompted, configure the OAuth consent screen:
- Choose "External" user type (or "Internal" for Workspace)
- Fill in required fields (app name, user support email, developer email)
- Add scopes:
gmail.modifyandgmail.settings.basic - Add your email as a test user
- Select "Desktop app" as the application type
- Name it (e.g., "Gmail MCP")
- Click "Create"
- Download the JSON credentials file
2. Install and Configure
# Clone or download the project
cd gmail-mcp
# Install dependencies
npm install
# Build the project
npm run build
# Create config directory and save credentials
mkdir -p ~/.gmail-mcp
cp /path/to/downloaded/credentials.json ~/.gmail-mcp/credentials.json
# Authenticate (for a single account)
node dist/index.js auth
# Or authenticate with a named account (for multi-account support)
node dist/index.js auth --account work
node dist/index.js auth --account personal
The auth command will:
- Open your browser to Google's OAuth consent page
- Ask you to authorize the application
- Save the tokens to
~/.gmail-mcp/tokens/<account>.json
To list authenticated accounts:
node dist/index.js list
3. Add to Claude Code
For a single account:
claude mcp add gmail -- node /path/to/gmail-mcp/dist/index.js
For multiple accounts, add each with its own name:
claude mcp add gmail-work -- node /path/to/gmail-mcp/dist/index.js --account work
claude mcp add gmail-personal -- node /path/to/gmail-mcp/dist/index.js --account personal
Or add manually to your Claude Code MCP settings:
{
"mcpServers": {
"gmail-work": {
"command": "node",
"args": ["/path/to/gmail-mcp/dist/index.js", "--account", "work"]
},
"gmail-personal": {
"command": "node",
"args": ["/path/to/gmail-mcp/dist/index.js", "--account", "personal"]
}
}
}
Available Tools
Email Operations (7 tools)
| Tool | Description |
|---|---|
search_emails |
Search with Gmail query syntax, pagination |
read_email |
Full message with headers, body, attachment info |
send_email |
Send with to/cc/bcc, attachments, threading |
draft_email |
Create draft without sending |
delete_email |
Trash or permanent delete |
modify_email |
Add/remove labels from message |
get_thread |
Get full conversation thread |
Label Management (6 tools)
| Tool | Description |
|---|---|
list_labels |
All labels (system + user) |
create_label |
Create with color, visibility |
update_label |
Rename, change settings |
delete_label |
Remove custom label |
get_or_create_label |
Idempotent label creation |
get_label |
Get single label details |
Filter Management (5 tools)
| Tool | Description |
|---|---|
list_filters |
All Gmail filters |
get_filter |
Single filter details |
create_filter |
Custom criteria + actions |
delete_filter |
Remove filter |
create_filter_from_template |
Preset templates |
Batch Operations (2 tools)
| Tool | Description |
|---|---|
batch_modify_emails |
Bulk add/remove labels (50 at a time) |
batch_delete_emails |
Bulk delete with fallback |
Attachments (2 tools)
| Tool | Description |
|---|---|
download_attachment |
Save to local filesystem |
list_attachments |
Get attachment metadata for message |
Utilities (2 tools)
| Tool | Description |
|---|---|
get_profile |
User email address, history ID |
get_quota |
Storage usage info |
Resources
| Resource | URI Pattern |
|---|---|
| Message | gmail://messages/{messageId} |
| Thread | gmail://threads/{threadId} |
| Label | gmail://labels/{labelId} |
Usage Examples
Search for unread emails
Search my Gmail for unread emails from the last week
Read a specific email
Read the email with ID 18abc123def
Send an email
Send an email to john@example.com with subject "Hello" and body "Hi John, how are you?"
Create a filter
Create a Gmail filter that labels all emails from newsletter@example.com with "Newsletters"
Batch operations
Move all emails matching "is:unread older_than:30d" to trash
OAuth Scopes
The server uses these scopes:
gmail.modify- Read, compose, send, and modify emails and labelsgmail.settings.basic- Manage mail filters
File Structure
gmail-mcp/
├── src/
│ ├── index.ts # CLI entry point
│ ├── server.ts # MCP server setup
│ ├── gmail/
│ │ ├── auth.ts # OAuth flow
│ │ ├── client.ts # Gmail API wrapper
│ │ ├── mime.ts # MIME parsing/encoding
│ │ └── types.ts # Type definitions
│ ├── tools/
│ │ ├── index.ts # Tool registration
│ │ ├── emails.ts # Email operations
│ │ ├── labels.ts # Label management
│ │ ├── filters.ts # Filter management
│ │ ├── batch.ts # Batch operations
│ │ └── attachments.ts # Attachment handling
│ ├── resources/
│ │ └── index.ts # MCP resources
│ └── schemas/
│ └── index.ts # Zod schemas
├── package.json
├── tsconfig.json
└── README.md
Security
- Credentials stored in
~/.gmail-mcp/with restricted permissions (0600) - Per-account tokens stored in
~/.gmail-mcp/tokens/ - Tokens automatically refresh when expired
- OAuth callback only on localhost
- No external telemetry or data collection
Troubleshooting
"Not authenticated" error
Run node dist/index.js auth --account <name> to authenticate.
"Permission denied" error
Ensure your OAuth credentials have the correct scopes and the Gmail API is enabled.
Token refresh fails
Delete ~/.gmail-mcp/tokens/<account>.json and run auth again.
Port 3000 in use
The OAuth callback requires port 3000. Close any applications using this port.
License
MIT
推荐服务器
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 模型以安全和受控的方式获取实时的网络信息。