gmail-mcp
Gmail second account MCP server
从 Claude.ai 和 Claude Code 读写一个 Gmail 邮箱。Claude.ai 自带的 Gmail 连接器只处理单个账户,因此这个项目用于第二个账户:每个邮箱运行一个实例,每个连接器只访问分配给它的地址。
每个实例一个邮箱
实例服务哪个账户由 GMAIL_CREDENTIALS_DIR 决定,该进程无法访问任何其他内容。这种隔离正是关键,而非限制:当服务器只持有一组凭据时,草稿不可能落入错误的邮箱。
Related MCP server: Gmail MCP Local Server
工具
读取
工具 | 返回内容 |
| 此实例服务的邮箱及其计数 |
| 使用 Gmail 自身的查询语法搜索 |
| 单条消息及其正文 |
| 整个会话,按时间从旧到新 |
| 消息附件的文件名、类型和大小 |
| 所有标签及其 ID |
| 邮箱中待处理的草稿 |
写入
工具 | 作用 |
| 撰写草稿,可选择作为回复加入会话 |
| 替换草稿内容 |
| 丢弃草稿 |
| 在消息上添加或移除标签 |
| 将消息移出收件箱 |
| 标记为已读或未读 |
| 移入回收站及恢复 |
| 管理标签 |
| 发送现有草稿 |
| 一步完成撰写并发送 |
这两个发送工具被标记为破坏性操作,并在其描述中明确说明:它们会触达他人,且无法撤销。安全的做法是先使用 gmail_create_draft 创建草稿,阅读确认后,再在有人批准文本后使用 gmail_send_draft 发送。
搜索
gmail_search 使用与 Gmail 搜索框相同的运算符:
is:unread from:client.com
subject:invoice has:attachment newer_than:7d
label:important -in:trash它返回每封邮件的标头和摘要,而不是正文,因此宽泛搜索的返回量仍然很小。后续可配合 gmail_get_message 或 gmail_get_thread 使用。
整体结构
Claude.ai / Claude Code
| HTTPS
Cloudflare Tunnel, or any proxy that gives you HTTPS
|
nginx 127.0.0.1:8461
|
auth-server.js :8462 handles the login and the tokens
|
gmail-mcp :8460 the server itself, local only
|
gmail.googleapis.comMCP 本身没有登录机制,并且只监听本机,因此所有到达它的请求都已经通过了登录。
设置
你需要一个已启用 Gmail API 的 Google Cloud OAuth 客户端,以及该邮箱的刷新令牌。凭据目录包含两个文件:
credentials.json {"refresh_token": "..."}
gcp-oauth.keys.json the downloaded OAuth clientgmail.modify 是要授予的权限范围。它涵盖读取、标记、起草和发送;如果你希望凭据本身无法发送,可降级为 gmail.readonly 加 gmail.compose。
git clone https://github.com/rollecode/gmail-second-account-mcp.git
cd gmail-second-account-mcp
uv venv && uv pip install -e .
npm install --omit=dev
CONFIG_DIR=~/.config/gmail-mcp node set-password.js 'your-password-here'
openssl rand -hex 32 > ~/.config/gmail-mcp/token
chmod 600 ~/.config/gmail-mcp/token在 systemd/*.service 和 nginx/gmail-mcp.conf 中填写 YOUR_USER、主机名和凭据目录,然后:
sudo cp systemd/*.service /etc/systemd/system/
sudo systemctl daemon-reload
sudo systemctl enable --now gmail-mcp gmail-mcp-auth
sudo cp nginx/gmail-mcp.conf /etc/nginx/sites-enabled/gmail-mcp
sudo nginx -t && sudo systemctl reload nginx将隧道或 HTTPS 代理指向 127.0.0.1:8461。OAuth 需要 HTTPS。
从外部检查:发现端点返回元数据,且不带令牌访问 /mcp 必须返回 401。
curl https://your-host/.well-known/oauth-authorization-server
curl -o /dev/null -w '%{http_code}\n' -X POST https://your-host/mcp连接
Claude.ai:设置、连接器、添加自定义连接器,https://your-host/mcp,客户端 ID 和密钥留空。
Claude Code:
claude mcp add --transport http gmail https://your-host/mcp \
--header "Authorization: Bearer $(cat ~/.config/gmail-mcp/token)" --scope user本地通过 stdio 运行,完全不需要服务器:
GMAIL_CREDENTIALS_DIR=/path/to/creds claude mcp add gmail -- /path/to/.venv/bin/gmail-mcp配置
变量 | 用途 |
| 存放 |
| 邮箱名称,显示在服务器的说明中 |
| 公共地址,用于展示图标 |
| 登录服务器的公共源 |
| 登录服务器端口,默认为 8462 |
| MCP 服务器 URL,默认为 |
| 密码、令牌和 OAuth 数据库的存放位置 |
访问令牌过期时会在内存中刷新;只有刷新令牌会从磁盘读取。
致谢
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Related MCP Servers
- AlicenseNot gradedqualityFmaintenanceEnables reading, sending, searching, and managing Gmail through Claude using the official Google Gmail API.1653MIT
- FlicenseNot gradedqualityDmaintenanceProvides Claude with Gmail capabilities including sending emails, managing drafts, and searching messages.
- AlicenseNot gradedqualityDmaintenanceEnables Claude to read, search, send, and manage Gmail messages and threads through natural language.205MIT
- AlicenseNot gradedqualityDmaintenanceEnables Gmail integration with Claude Code for reading, sending, searching emails, and managing labels through natural language.205MIT
Related MCP Connectors
Manage Gmail end-to-end: search, read, send, draft, label, and organize threads. Automate workflow…
Manage Gmail messages, threads, labels, drafts, and settings from your workflows. Send and organiz…
Read, search, send, organize, draft and schedule email across your inboxes from any MCP client.
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
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/rollecode/gmail-second-account-mcp'
If you have feedback or need assistance with the MCP directory API, please join our Discord server