MCP谷歌多账户服务器
Beta通知: 此软件包使用等待Google验证审查的OAuth凭据。在此期间,只能通过邀请访问——您必须在Google Cloud Console中添加为测试用户才能完成OAuth。或者,您可以 携带您自己的OAuth凭据。一旦谷歌批准,此通知将被删除。
MCP(模型上下文协议)服务器,用于从Claude Code、Claude Desktop或任何兼容MCP的客户端访问多个Google帐户。支持Gmail、谷歌云端硬盘和谷歌日历。
自然地和克劳德谈谈:
"Check my email"
"Find messages from my boss this week"
"Write a reply thanking them for the update"
"Send it"没有特别的命令需要记住——克劳德知道你想要什么。
快速开始
无需安装Google Cloud,只需安装并连接您的Google帐户:
克劳德代码CLI:
claude mcp add proGoogleMCP -- npx -y @procedure-tech/mcp-google克劳德桌面版 --添加到您的 claude_desktop_config.json:
{
"mcpServers": {
"proGoogleMCP": {
"command": "npx",
"args": ["-y", "@procedure-tech/mcp-google"]
}
}
}然后使用 google_add_account 连接您的Google帐户的工具。就是这样!
特性
- 零配置:开箱即用——无需设置谷歌云项目
- 自然语言:只需描述你想要什么——“查找我未读的电子邮件”、“起草回复”
- 多账户支持:连接工作、个人和其他帐户-在所有帐户中搜索
- 完全访问Gmail:搜索、阅读、撰写、发送和组织电子邮件
- Google 云端硬盘:搜索、预览、下载到磁盘、从磁盘上传和共享文件
- 谷歌日历:查看、创建、更新和管理事件
- 附件:下载并发送文件附件
- 收件箱管理:标签、存档、回收站、已读/未读状态
- 过滤器和假期:创建电子邮件过滤器并配置假期回复者
- 人工智能生产力:主题摘要、智能回复建议、行动项提取
- 安全第一:所有发送都需要确认-克劳德在发送前会向您展示草稿
- 注重隐私:本地存储在计算机上的所有凭据
安装
来自npm
npx -y @procedure-tech/mcp-google本地开发
git clone https://github.com/bkbaheti/google-multi-account-mcp.git
cd google-multi-account-mcp
pnpm install
pnpm build先决条件
- Node.js 20+ -所需运行时间
- 克劳德代码或克劳德桌面 -MCP客户端连接到此服务器
就是这样!OAuth凭据是内置的。请参阅 高级:携带自己的OAuth凭据 如果你想使用自己的GCP项目。
配置
配置克劳德代码(CLI)
# Add to current project only (default)
claude mcp add proGoogleMCP -- npx -y @procedure-tech/mcp-google
# Add globally (available in all projects)
claude mcp add -s user proGoogleMCP -- npx -y @procedure-tech/mcp-google
# With passphrase for token encryption
claude mcp add -s user proGoogleMCP -e MCP_GOOGLE_PASSPHRASE=optional-passphrase -- npx -y @procedure-tech/mcp-google要验证或删除:
claude mcp list # List configured servers
claude mcp remove proGoogleMCP # Remove this server配置Claude桌面
添加 ~/Library/Application Support/Claude/claude_desktop_config.json (macOS)或 %APPDATA%\Claude\claude_desktop_config.json (Windows):
{
"mcpServers": {
"proGoogleMCP": {
"command": "npx",
"args": ["-y", "@procedure-tech/mcp-google"]
}
}
}高级:携带自己的OAuth凭据
如果你更喜欢使用自己的GCP项目,你可以覆盖内置的默认值:
- 环境变量:设置
GOOGLE_CLIENT_ID和GOOGLE_CLIENT_SECRET - 配置文件:添加
oauth.clientId和oauth.clientSecret到~/.config/mcp-google/config.json
优先级:环境变量>配置文件>内置默认值。
Click for full GCP setup instructions
第一步:创建谷歌云项目
- 首选 谷歌云控制台
- 创建新项目(或选择现有项目)
步骤2:启用API
- 首选 API和服务 > 图书馆
- 启用所需的API: Gmail API, Google Drive API, 谷歌日历API
步骤3:配置OAuth同意屏幕
- 首选 API和服务 > OAuth 同意屏幕
- 选择 外部 用户类型(除非你有谷歌工作区)
- 填写必填字段(应用程序名称、支持电子邮件、开发人员联系方式)
- 添加您需要的范围(例如Gmail、云端硬盘、日历)
- 将您的Google电子邮件添加为测试用户
步骤4:创建OAuth 2.0客户端ID
- 首选 API和服务 > 凭证
- 点击 创建凭证 > OAuth客户端ID
- 选择 桌面应用程序 作为应用程序类型
- 复制 客户端ID 和 客户端密钥
步骤5:添加重定向URI
- 在...之下 授权重定向URI,添加:
http://localhost:8089/callback
步骤6:配置
通过环境变量设置:
export GOOGLE_CLIENT_ID="your-client-id.apps.googleusercontent.com"
export GOOGLE_CLIENT_SECRET="your-client-secret"或添加到 ~/.config/mcp-google/config.json:
{
"version": 1,
"oauth": {
"clientId": "your-client-id.apps.googleusercontent.com",
"clientSecret": "your-client-secret"
}
}用法
入门指南
- 启动Claude Code(如果已经运行,则重新启动以获取配置更改)
- 验证服务器是否已连接并检查版本:
"What version of the Google MCP server is running?"Claude将显示版本、git提交和构建日期。
- 添加Google帐户:
"Add my Gmail account"克劳德将:
- 询问您需要哪些权限(只读、撰写、完整等) - 显示要在浏览器中打开的授权URL - 在浏览器中完成OAuth后,Claude将确认帐户已添加
- 开始使用您的电子邮件:
"Find my unread emails"
"Search for emails from john@example.com"
"Draft a reply to the last email"注: 这些示例是自然语言——Claude理解您的意图并自动使用适当的MCP工具。您不需要知道工具名称。
对话示例
以下是一些使用此MCP服务器与Claude交互的真实示例:
阅读和搜索电子邮件
You: "Check my email for anything from Amazon in the last week"
Claude: [Searches and returns matching emails with subjects, dates, and snippets]
You: "Show me the full email about my order"
Claude: [Fetches the complete message with body content]
You: "What attachments are in that email?"
Claude: [Lists any attachments with filenames and sizes]撰写和发送
You: "Write an email to sarah@example.com thanking her for the meeting"
Claude: I'll draft that email for you.
[Creates draft]
Here's the draft:
To: sarah@example.com
Subject: Thank you for the meeting
...
Would you like me to send it, or make any changes?
You: "Looks good, send it"
Claude: [Sends the email with confirmation]管理收件箱
You: "Archive all emails from newsletters@example.com"
Claude: [Archives matching messages]
You: "Create a label called 'Urgent' with a red color"
Claude: [Creates the label]
You: "Mark the last 5 unread emails as read"
Claude: [Updates the messages]多帐户工作流
You: "Add my work Gmail account"
Claude: Which permissions would you like?
- readonly: Read and search only
- compose: Also send emails (recommended)
- full: Also manage labels, archive, trash
...
You: "Compose, please"
Claude: [Opens OAuth flow for work account]
You: "Label my work account as 'work' and my personal as 'personal'"
Claude: [Sets labels on both accounts]
You: "Search for 'project update' across all my accounts"
Claude: [Searches both accounts and shows combined results]人工智能驱动的生产力
You: "Summarize this email thread"
Claude: [Analyzes the thread and provides]:
- Main topic: Q3 budget review
- Participants: Finance team (5 people)
- Key decisions: Budget approved with 10% increase
- Action items: Submit receipts by Friday
You: "What action items do I have from my unread emails?"
Claude: [Scans unread messages and extracts tasks with deadlines]
You: "Suggest a reply to the last email"
Claude: Based on the context, here are 3 options:
1. Brief: "Thanks, I'll review and get back to you."
2. Detailed: [longer response addressing all points]
...
Which would you like me to draft?设置自动化
You: "Create a filter to auto-archive emails from noreply@example.com"
Claude: I'll create that filter. This will automatically archive
all future emails from that sender. Confirm?
You: "Yes"
Claude: [Creates the filter]
You: "Set up my vacation responder - I'm out Dec 20-27"
Claude: What message would you like to send?
You: "Just say I'm on holiday and will respond when I return"
Claude: [Configures vacation responder with dates]范围层次
添加帐户时,Claude会询问您需要哪些权限:
| 级别 | 你能做什么 | 最好的 |
|---|---|---|
mail_readonly | 阅读和搜索电子邮件 | 检查电子邮件,研究 |
mail_compose | +创建草稿并发送 | 日常电子邮件使用(推荐) |
mail_full | +标签、存档、垃圾箱 | 收件箱组织 |
mail_settings | +过滤器,假期回复者 | 电子邮件自动化 |
drive_readonly | 浏览和下载文件 | 阅读文档 |
drive_full | +上传、共享、组织 | 文件管理 |
calendar_readonly | 查看活动和日历 | 检查日程 |
calendar_full | +创建、更新、删除事件 | 日程管理 |
all | 以上一切 | 完全控制 |
它是如何工作的:
readonly→compose→full相互建立settings是单独的(仅用于过滤器/假期)- 您可以将它们组合在一起:“我想要收件箱管理和过滤器”→
full+settings
示例:
You: "Add my Gmail account"
Claude: Which permissions would you like?
[Shows options]
You: "I just want to read emails"
Claude: [Adds with readonly scope]
You: "Actually, I need to send emails too"
Claude: You'll need to remove and re-add with compose permissions.
Want me to do that?可用工具
你不需要记住工具名称,只需描述你想要什么。以下是可用的内容:
账户管理
| 说吧。.. | 发生了什么 |
|---|---|
| “显示我的Google帐户” | 列出所有已连接的帐户 |
| “添加我的Gmail帐户” | 启动OAuth流以添加帐户 |
| “删除我的工作帐户” | 断开帐户连接并吊销令牌 |
| “将此帐户标记为‘个人’” | 标记帐户以便于参考 |
阅读电子邮件(只读范围)
| 说吧。.. | 发生了什么 |
|---|---|
| “查找来自的电子邮件john@example.com“ | 使用Gmail查询语法进行搜索 |
| “显示本周未读的电子邮件” | 返回匹配的邮件 |
| “获取有关项目的完整电子邮件” | 获取完整的邮件内容 |
| “显示整个对话” | 获取包含所有消息的线程 |
| “此电子邮件中有哪些附件?” | 列出具有名称和大小的文件 |
| “下载PDF附件” | 检索文件数据 |
Gmail搜索提示: 使用Gmail的搜索语法进行强大的查询:
from:someone@example.com-来自特定发件人subject:meeting-主题包含单词is:unread-仅限未读邮件has:attachment-带有附件的邮件newer_than:7d-过去7天label:important-具有特定标签
撰写电子邮件(撰写范围)
| 说吧。.. | 发生了什么 |
|---|---|
| “发送电子邮件至sarah@example.com“ | 创建草稿以供审阅 |
| “起草对最后一封电子邮件的回复” | 使用适当的线程创建回复 |
| “将report.pdf附加到此草稿” | 向草稿添加附件 |
| “更新草稿-更改主题” | 修改现有草稿 |
| “发送前显示我的草稿” | 预览草稿 |
| “删除该草稿” | 删除草稿 |
| “发送电子邮件” | 确认后发送 |
安全特性: 所有电子邮件都要经过草稿优先工作流程。克劳德总是会给你看草稿,并在发送前要求确认。
收件箱管理(全范围)
| 说吧。.. | 发生了什么 |
|---|---|
| “显示我的标签” | 列出所有Gmail标签 |
| “创建蓝色的“项目”标签” | 创建带颜色的标签 |
| “将‘旧’标签重命名为‘存档’” | 更新标签属性 |
| “删除'Temp'标签” | 删除标签(保留消息) |
| “将“重要”标签添加到此电子邮件” | 将标签应用于邮件 |
| “将这50封电子邮件标记为‘完成’” | 批量标记操作 |
| “将此标记为已读” | 更改读取状态 |
| “存档此电子邮件” | 从收件箱中删除 |
| “删除此电子邮件” | 移至垃圾箱 |
| “从垃圾箱还原” | 恢复已删除的邮件 |
过滤器和假期(设置范围)
| 说吧。.. | 发生了什么 |
|---|---|
| “显示我的电子邮件过滤器” | 列出自动规则 |
| “为新闻稿创建筛选器” | 设置自动处理 |
| “删除以下筛选器old@example.com“ | 删除自动化规则 |
| “检查我的假期设置” | 显示自动回复配置 |
| “打开假期回复” | 启用自动回复 |
| “我回来了-禁用假期回复” | 关闭自动回复 |
AI生产力提示
这些提示指导克劳德完成复杂的工作流程:
| 说吧。.. | 发生了什么 |
|---|---|
| “帮我写一封电子邮件” | 带预览和确认的指导性起草 |
| “帮我回复此线程” | 正确的线程,色调匹配 |
| “查看我的待处理草稿” | 显示草稿,提供发送/编辑/删除 |
| “总结此电子邮件线索” | 提取关键点、决策和行动项 |
| “建议回复此电子邮件” | 提供简短/标准/详细选项 |
| “我有哪些行动项目?” | 扫描电子邮件以查找任务和截止日期 |
| “帮我整理收件箱” | 为未分类的电子邮件建议标签 |
技术参考
Click to see exact tool names (for advanced users)
账户管理:
google_version,google_list_accounts,google_add_account,google_check_pending_auth,google_remove_account,google_set_account_labels
Gmail阅读:
gmail_search_messages,gmail_get_message,gmail_get_messages_batch,gmail_get_thread,gmail_list_attachments,gmail_get_attachment
Gmail撰写:
gmail_create_draft,gmail_create_draft_with_attachment,gmail_update_draft,gmail_get_draft,gmail_delete_draft,gmail_send_draft,gmail_reply_in_thread
收件箱管理:
gmail_list_labels,gmail_create_label,gmail_update_label,gmail_delete_label,gmail_modify_labels,gmail_batch_modify_labels,gmail_mark_read_unread,gmail_archive,gmail_trash,gmail_untrash
设置:
gmail_list_filters,gmail_create_filter,gmail_delete_filter,gmail_get_vacation,gmail_set_vacation
谷歌云端硬盘:
drive_search_files,drive_list_files,drive_get_file,drive_get_file_content,drive_get_full_file_content,drive_download_file,drive_upload_file,drive_create_folder,drive_move_file,drive_copy_file,drive_rename_file,drive_trash_file,drive_share_file,drive_update_permissions
谷歌日历:
calendar_list_calendars,calendar_list_events,calendar_get_event,calendar_search_events,calendar_freebusy,calendar_create_event,calendar_update_event,calendar_delete_event,calendar_rsvp,calendar_move_event
MCP提示:
compose-email,reply-to-email,review-drafts,summarize-thread,smart-reply,extract-action-items,categorize-emails
MCP资源:
accounts://list-列出已连接的帐户cache://stats-缓存统计信息
环境变量
| 变量 | 描述 |
|---|---|
MCP_GOOGLE_CONFIG_PATH | 覆盖默认配置文件位置 |
MCP_GOOGLE_PASSPHRASE | 加密令牌存储的密码短语(密钥链不可用时回退) |
MCP_GOOGLE_LOG_LEVEL | 日志级别: debug, info, warn, error |
故障排除
“未收到刷新令牌”
如果您之前已授权该应用程序,则可能会出现这种情况。要修复:
- 首选 Google帐户权限
- 查找并删除您的MCP应用程序
- 再次说“添加我的Gmail帐户”
OAuth URL未显示
添加帐户时,OAuth授权URL应显示在:
- 克劳德代码:查找带有URL的警告级别日志消息
- 克劳德桌面版:检查MCP服务器日志
- 终端错误:URL也会写入stderr,并带有可见的横幅
如果你看不到URL:
- 检查MCP客户端的日志输出或通知区域
- URL也会记录到stderr中-如果手动运行,请检查终端输出
- 如果未完成,OAuth流将在5分钟后超时
端口8089已在使用中
OAuth回调服务器使用端口8089。如果正在使用:
- 等待上一个OAuth流完成
- 终止使用该端口的任何进程:
lsof -ti:8089 | xargs kill
钥匙链访问问题(Linux/headless)
如果操作系统钥匙链不可用,请设置 MCP_GOOGLE_PASSPHRASE:
{
"env": {
"MCP_GOOGLE_PASSPHRASE": "your-secure-passphrase"
}
}令牌将使用此密码使用AES-256-GCM进行加密。
“范围不足”错误
您正在尝试执行需要比帐户更多权限的操作。
You: "Archive this email"
Claude: This account only has readonly permissions. You need 'full' scope
to archive emails. Would you like me to remove and re-add the
account with higher permissions?修复: 说“删除我的帐户并以完全权限重新添加”
MCP服务器未连接
- 验证设置中的路径是否正确且绝对
- 确保你已经跑过了
pnpm build编译TypeScript - 检查一下
dist/cli.js存在 - 尝试手动运行:
node /path/to/dist/cli.js
常见问题
Q: 我可以使用多个Google帐户吗? 对!只需说“添加另一个Gmail帐户”,然后重复OAuth流程。您可以将它们标记为(“将我的工作帐户标记为'工作'”),并在所有这些帐户中搜索。
Q: 克劳德会不问就发邮件吗? 否。所有发送都需要明确确认。克劳德总是先给你看草稿,然后问“你想让我寄这个吗?”
Q: 如果我不小心删除了一封电子邮件,会发生什么? 电子邮件首先会被丢弃,并在那里停留30天。说“显示我的垃圾箱”或“从垃圾箱还原该电子邮件”以恢复它。
Q: 克劳德可以在我不使用的时候阅读我的电子邮件吗? 不可以。MCP服务器仅在Claude Code/Desk处于活动状态时运行,并且仅在您要求时访问电子邮件。
发展
# Install dependencies
pnpm install
# Build TypeScript
pnpm build
# Watch mode for development
pnpm dev
# Run tests
pnpm test
# Lint and format
pnpm lint:fix
pnpm format安全说明
- 零配置OAuth:附带内置OAuth凭据(桌面应用程序类型,与gcloud CLI模式相同)。如果愿意,您可以用自己的凭据覆盖。
- 本地存储:所有令牌都存储在本地计算机上
- 首选钥匙扣:在可用时使用操作系统密钥链,回退到加密文件
- 初稿:所有发送都需要先创建草稿,然后明确确认
- 帐户隔离:每个帐户的令牌、缓存和速率限制都是隔离的
许可证
麻省理工学院
