Integrations
Enables complete email management through Gmail, including sending emails with attachments, reading and searching emails, managing labels and organization, handling drafts, and performing batch operations on multiple emails.
Integrates with Google Cloud for authentication and API access, allowing the MCP server to securely connect to Gmail services through OAuth 2.0 credentials.
Gmail MCP 服务器
强大的模型上下文协议 (MCP) 服务器,使 Claude AI 能够直接与 Gmail 交互。
📖 目录
📋 概述
Gmail MCP 服务器是一个全面的实现,它使像 Claude 这样的 AI 助手能够通过自然语言直接与 Gmail 交互。它提供了一套丰富的电子邮件管理工具,实现了对话式 AI 与收件箱的无缝集成。
💡 主要特点
- 完整的电子邮件管理
- 发送带有附件的纯文本和 HTML 电子邮件
- 通过对复杂消息结构进行适当的解析来阅读电子邮件
- 使用 Gmail 强大的查询语法搜索您的收件箱
- 创建和更新电子邮件草稿
- 管理标签、已读/未读状态和垃圾箱
- 对多封电子邮件执行批量操作
- 高级集成
- 具有 async/await 模式的现代 Python 代码库
- 全面的错误处理和恢复
- 详细进度报告
- 安全 OAuth 身份验证流程
- 多种传输模式(STDIO 和 SSE)
- 支持不同的部署场景
🚀 快速入门
先决条件
- Python 3.8 或更高版本
- 启用了 Gmail API 的 Google Cloud 项目
- Gmail API 的 OAuth 2.0 凭据
安装
- 克隆存储库Copy
- 设置虚拟环境Copy
- 安装依赖项Copy
- 设置 Google Cloud 和 OAuth 凭据访问Google Cloud Console来执行以下操作:
- 创建新项目
- 启用 Gmail API
- 设置 OAuth 同意屏幕
- 创建 OAuth 客户端 ID 凭证(桌面应用程序)
- 在项目根目录中将凭证下载为
credentials.json
首次运行和身份验证
运行服务器一次以进行身份验证:
这将打开一个浏览器窗口,要求您使用 Google 帐户进行身份验证。身份验证完成后,将创建并保存一个token.json
文件以供将来使用。
配置 Claude 桌面
- 编辑您的 Claude Desktop 配置文件:
- macOS:
~/Library/Application Support/Claude/claude_desktop_config.json
- Windows:
%APPDATA%\Claude\claude_desktop_config.json
- macOS:
- 将 Gmail MCP 服务器添加到配置中:Copy
- 保存文件并重新启动Claude Desktop
**注意:**将"/absolute/path/to/gmail-mcp-server/gmail_server.py"
替换为克隆存储库中gmail_server.py
文件的实际绝对路径。
🧰 可用工具
Gmail MCP 服务器向 Claude 公开了以下工具:
电子邮件发送
send_email
- 发送包含文本/HTML 内容的基本电子邮件send_email_with_attachment
- 发送带有文件附件的电子邮件send_email_with_multiple_attachments
- 发送带有多个附件的电子邮件
电子邮件阅读
read_email
- 根据 ID 读取特定电子邮件的内容get_unread_emails
- 获取未读电子邮件列表get_important_emails
- 获取标记为重要的电子邮件get_emails_with_attachments
- 获取带有附件的电子邮件get_recent_emails
- 获取过去 X 天的电子邮件
电子邮件搜索和组织
search_emails
- 使用 Gmail 的查询语法搜索电子邮件get_email_labels
- 列出所有 Gmail 标签/文件夹create_email_label
- 创建新标签delete_email_label
- 删除现有标签label_email
- 将标签应用于电子邮件remove_email_label
- 从电子邮件中删除标签
电子邮件状态管理
mark_as_read
- 将电子邮件标记为已读mark_as_unread
- 将电子邮件标记为未读delete_email
- 将电子邮件移至垃圾箱
草稿管理
create_email_draft
- 创建新的电子邮件草稿update_email_draft
- 更新现有草稿list_email_drafts
- 列出可用的草稿send_draft
- 发送现有草稿
批量操作
batch_apply_label
- 将标签应用于多封电子邮件batch_delete_emails
- 将多封电子邮件移至垃圾箱
帐户信息
get_email_profile
- 获取 Gmail 个人资料信息summarize_recent_emails
最近的电子邮件 - 创建最近电子邮件的摘要
💬 使用示例
以下是针对 Claude 的一些示例提示:
🔧 高级配置
环境变量
服务器支持多种环境变量进行定制:
多变的 | 描述 |
---|---|
GMAIL_TOKEN_PATH | 存储 OAuth 令牌的自定义路径 |
GMAIL_CREDENTIALS_PATH | OAuth 凭证的自定义路径 |
GOOGLE_CLIENT_ID | OAuth 客户端 ID(凭证文件的替代) |
GOOGLE_CLIENT_SECRET | OAuth 客户端密钥(凭证文件的替代) |
MCP_PORT | SSE 传输端口(默认值:3000) |
DEBUG | 启用调试模式( true 或false ) |
SSE 服务器模式
服务器可以在 SSE(服务器发送事件)模式下运行,以实现基于 HTTP 的集成:
这将在指定端口(默认值:3000)上启动服务器,使其可以通过 HTTP 访问。
📚 文档
- MCP 规范- 了解模型上下文协议
- Gmail API 文档- Gmail API 功能参考
- Google Cloud OAuth - 身份验证流程详情
🔒 安全注意事项
- 服务器使用 OAuth 2.0 进行安全的 Gmail API 身份验证
- 所有操作都在您的机器上本地运行 - 电子邮件绝不会通过第三方服务器
- 身份验证令牌存储在本地,可随时撤销
- 服务器仅需要本地文件访问权限才能读取附件
- 克劳德在发送或删除电子邮件之前总是要求确认
🤝 贡献
欢迎贡献代码!欢迎提交 Pull 请求。
- 分叉存储库
- 创建你的功能分支(
git checkout -b feature/amazing-feature
) - 提交您的更改(
git commit -m 'Add some amazing feature'
) - 推送到分支(
git push origin feature/amazing-feature
) - 打开拉取请求
📝 许可证
该项目根据 MIT 许可证获得许可 - 有关详细信息,请参阅LICENSE文件。
🙏 致谢
- Google 的 Gmail API
- 克劳德的人类学和模型上下文协议
- Python Gmail API 客户端库的贡献者
Related MCP Servers
- -securityFlicense-qualityA Model Context Protocol server that enables AI assistants to interact with Gmail services, supporting email operations, draft management, and calendar functionality through Google API integration.Last updated -TypeScript
- -securityAlicense-qualityA Model Context Protocol server that provides a seamless email management interface through Claude, allowing users to search, read, and send emails directly through natural language conversations.Last updated -40PythonMIT License
- -securityAlicense-qualityA Model Context Protocol server that enables AI assistants like Claude to interact with Gmail through natural language, providing comprehensive email management capabilities including sending, reading, organizing, searching, and managing drafts and labels.Last updated -PythonGPL 3.0
- -securityFlicense-qualityA Model Context Protocol server that enables AI assistants to access and manage email through IMAP, supporting browsing, searching, reading, and organizing emails while learning user preferences over time.Last updated -2Python