gmail-multi-mcp-server
gmail-multi-mcp-server
一个将 Claude 连接到多个 Gmail 账户的 MCP 服务器,暴露与内置 Gmail 连接器相同的工具接口。每个工具都接受一个额外的 account 参数,用于指定要操作的邮箱——这是与单邮箱连接器唯一的结构性差异。
"Check my work inbox for anything from the lender, and draft the reply from my personal account."为什么存在
内置的 Gmail 连接器只授权一个邮箱。如果你使用多个独立账户——工作、个人、公司别名——就必须不断切换。此服务器保存你授权的所有 Gmail 账户的凭据,并将每次调用路由到你指定的那个账户。
Related MCP server: multiGmailMCP
要求
Node.js 20 或更高版本
一个启用了 Gmail API 的 Google Cloud 项目,以及一个类型为 桌面应用 的 OAuth 客户端
1. 获取 Google OAuth 客户端
打开 Google Cloud Console 并选择或创建一个项目。
在 API 和服务 → 库 中启用 Gmail API。
前往 API 和服务 → OAuth 同意屏幕 进行配置。当应用处于 测试 状态时,在 测试用户 下添加你计划连接的每个 Gmail 地址。
前往 API 和服务 → 凭据 → 创建凭据 → OAuth 客户端 ID,应用类型选择 桌面应用。下载 JSON 文件。
桌面应用客户端允许在任何端口上进行环回重定向,add-account 流程使用的正是这一点。
2. 安装并构建
git clone <this repo>
cd Gmail-MCP
npm install
npm run build3. 让服务器使用你的 OAuth 客户端
选择其中一种方式:
# Option A — save the downloaded JSON where the server looks by default
mkdir -p ~/.gmail-mcp && cp ~/Downloads/client_secret_*.json ~/.gmail-mcp/credentials.json
# Option B — point at it explicitly
export GMAIL_MCP_CREDENTIALS=/path/to/client_secret.json
# Option C — pass the values directly
export GMAIL_MCP_CLIENT_ID=...apps.googleusercontent.com
export GMAIL_MCP_CLIENT_SECRET=...4. 授权每个邮箱
每个 Gmail 账户运行一次:
node dist/index.js add-account --alias work
node dist/index.js add-account --alias personal
node dist/index.js list-accounts每次运行都会打印一个 Google 同意 URL,在本地环回端口上等待重定向,并存储生成的刷新令牌。在无头机器上,添加 --manual 参数并粘贴重定向后的 URL。
服务器运行期间添加的账户会被自动识别——无需重启。
5. 连接到 Claude
Claude Code
claude mcp add gmail-multi -- node /absolute/path/to/Gmail-MCP/dist/index.jsClaude Desktop — 添加到 claude_desktop_config.json:
{
"mcpServers": {
"gmail-multi": {
"command": "node",
"args": ["/absolute/path/to/Gmail-MCP/dist/index.js"],
"env": {
"GMAIL_MCP_CREDENTIALS": "/absolute/path/to/client_secret.json"
}
}
}
}选择账户
除 list_accounts 之外,每个工具都接受 account。匹配顺序为:
完整的电子邮件地址 —
mikael@example.com在
add-account时设置的别名 —work@前面的本地部分 —mikael任何无歧义的前缀
当只配置了一个邮箱时,或设置了 GMAIL_MCP_DEFAULT_ACCOUNT 时,account 是可选的。否则它是必填的,错误信息会列出可用的账户。
ID 是按邮箱隔离的。 来自一个账户的消息、会话、草稿或标签 ID 在另一个账户中没有意义。出现 “not found” 错误通常意味着传入了错误的 account。
工具
共 35 个工具——即连接器的完整工具集,外加两个用于多账户的工具。
类别 | 工具 |
账户 |
|
会话 |
|
邮件 |
|
发送 |
|
草稿 |
|
标签 |
|
工具名称特意与 Gmail 连接器保持一致,因此提示词和使用习惯都可以沿用。MCP 客户端按服务器对工具进行命名空间隔离,因此两者可以同时启用而不会冲突。
与内置连接器的差异
以下内容都是新增功能——连接器的行为在这里不会有任何变化。
每个工具上都有
account,外加list_accounts和get_profile。每个工具都支持
response_format(markdown|json)。默认值为markdown,保持简洁;无论如何,完整的结构化负载都会作为structuredContent返回。delete_draft和get_message_attachment,连接器有引用但未暴露。reply接受quoteOriginal(默认false),用于将原邮件作为引用块附加。forward接受includeAttachments(默认true);将其设为false可跳过大型附件。get_message_attachment接受savePath,用于将文件写入磁盘,而不是内联 base64。响应限制为 25,000 个字符,会先压缩分页列表,并明确说明丢弃了什么以及如何获取其余部分。
值得了解的行为
search_threads返回每个会话最早邮件的预览(约 5 封),与连接器类似。在回答任何关于最近或未读邮件的问题之前,请先调用get_thread。除非查询中提到草稿,否则
search_threads会排除草稿。请使用list_drafts。标签通过 ID 来引用,而不是显示名称。请先调用
list_labels。DRAFT和SENT是只读的;添加TRASH/SPAM会路由到apply_sensitive_*工具,因此破坏性操作总是被明确命名。update_draft会合并字段,但附件是替换而不是合并——响应会报告丢弃了多少个附件。reply会设置In-Reply-To和References,以便客户端能正确地将邮件归入会话,并且绝不会将回复地址指向已授权的邮箱本身。
安全性
刷新令牌保存在
~/.gmail-mcp/accounts.json中,在0700目录内以0600权限原子写入。任何能读取该文件的人都拥有对邮箱的完全访问权限。OAuth 流程会校验
state参数,并且只监听127.0.0.1。remove-account会删除本地令牌。要完全撤销,还需在 myaccount.google.com/permissions 中移除该应用。授予的权限范围允许读取、发送和删除邮件。
send_message、reply和forward会立即发送——工具描述会指示模型在用户未明确要求发送邮件时优先使用create_draft。
开发
npm run build # compile TypeScript to dist/
npm test # build, then unit tests + stdio smoke test
npm run test:unit # MIME, reply addressing, parsing, truncation — no network
npm run test:smoke # boots the server, checks all 35 tools register
npm run inspect # open the MCP Inspector against the serversrc/
index.ts CLI entry point and server bootstrap
constants.ts scopes, limits, paths
types.ts normalized message/thread/draft shapes
auth/ token store, OAuth flow, account registry
schemas/common.ts shared Zod fields (account, formats, pagination, colors)
services/ Gmail parsing, MIME building, formatting, errors
tools/ tool registration by domain故障排除
症状 | 修复方法 |
尚未授权任何 Gmail 账户 | 运行 |
Google 未返回刷新令牌 | 在 myaccount.google.com/permissions 撤销该应用,然后重新运行 |
账户 'x' 存在歧义 | 使用完整的电子邮件地址 |
每次调用都返回 403 | Google Cloud 项目未启用 Gmail API,或该地址不在测试用户列表中 |
有效 ID 出现 not-found 错误 | 该 ID 属于另一个邮箱——请检查 |
许可证
MIT
This server cannot be installed
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 Connectors
Connect any mailbox to Claude, ChatGPT & AI: read, send, reply, schedule & search emails.
Manage Gmail end-to-end: search, read, send, draft, label, and organize threads. Automate workflow…
Give AI agents secure access to your email via private aliases with dedicated mailbox storage.
Email infrastructure for AI agents — send, receive, search, and reply to email over MCP.
Related MCP Servers
- AlicenseBqualityBmaintenanceEnables AI assistants to manage multiple Gmail accounts simultaneously with built-in OAuth authentication, supporting email reading, sending, drafts, labels, and account management.60482MIT
- FlicenseAqualityBmaintenanceConnects AI assistants to multiple Gmail accounts simultaneously, enabling search, read, draft, send, and reply operations with per-account permission controls.54
- AlicenseNot gradedqualityCmaintenanceEnables searching and summarizing emails across multiple Gmail accounts simultaneously through Claude.1MIT
- AlicenseBqualityCmaintenanceEnables multi-account Gmail and Google Calendar access through MCP, allowing operations across multiple Google accounts with a single tool call.11MIT
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/Seventhdd/Gmail-MCP'
If you have feedback or need assistance with the MCP directory API, please join our Discord server