Gmail MCP 服务器
一个强大而灵活的 Gmail 集成服务器,基于 MCP(消息控制协议)框架构建。该服务器提供强大的接口,可与 Gmail API 交互,并提供以编程方式阅读、发送和管理电子邮件的功能。
特征
阅读来自多个 Gmail 帐户的电子邮件
发送带附件的电子邮件
使用高级查询选项搜索电子邮件
下载电子邮件附件
处理电子邮件对话和主题
实时电子邮件监控
支持多个 Gmail 帐户
Related MCP server: Systemprompt MCP Gmail Server
先决条件
在运行 Gmail MCP 服务器之前,请确保您具备以下条件:
Python 3.12 或更高版本
已启用 Gmail API 的 Google Cloud 项目
OAuth 2.0 客户端 ID 凭证
所需的 Python 包(在 pyproject.toml 中指定)
安装
通过 Smithery 安装
要通过Smithery自动为 Claude Desktop 安装 Gmail 集成服务器:
npx -y @smithery/cli install @Quantum-369/Gmail-mcp-server --client claude克隆存储库:
git clone <your-repository-url>
cd gmail-mcp-server创建并激活虚拟环境:
python -m venv venv
# On Windows
venv\Scripts\activate
# On Unix/MacOS
source venv/bin/activate安装依赖项:
pip install .设置 Google Cloud 项目
创建新项目或选择现有项目
为您的项目启用 Gmail API
创建 OAuth 2.0 凭据:
前往“API 和服务”>“凭证”
点击“创建凭证”>“OAuth 客户端 ID”
选择“桌面应用”作为应用程序类型
下载客户端配置文件
将下载的文件重命名为
client_secret.json并放置在项目根目录下
配置
在
gmail_token_creator.py中设置电子邮件标识符:
email_identifier = 'your.email@gmail.com' # Change this for each account运行令牌创建器来验证您的 Gmail 帐户:
python gmail_token_creator.py对要集成的每个 Gmail 帐户重复此过程
服务器结构
gmail_server.py:主要 MCP 服务器实现gmail_api.py:Gmail API 交互函数google_apis.pyAPI 身份验证实用程序支持文件:
read_emails.py:电子邮件阅读功能search_emails.py:电子邮件搜索功能send_emails.py:电子邮件发送功能
用法
启动服务器
python gmail_server.py可用工具
发送电子邮件:
await send_gmail(
email_identifier="your.email@gmail.com",
to="recipient@example.com",
subject="Test Subject",
body="Email body content",
attachment_paths=["path/to/attachment"]
)搜索电子邮件:
await search_email_tool(
email_identifier="your.email@gmail.com",
query="from:someone@example.com",
max_results=30,
include_conversations=True
)阅读最新电子邮件:
await read_latest_emails(
email_identifier="your.email@gmail.com",
max_results=5,
download_attachments=False
)下载附件:
await download_email_attachments(
email_identifier="your.email@gmail.com",
msg_id="message_id",
download_all_in_thread=False
)安全注意事项
安全地存储
client_secret.json并且永远不要将其提交到版本控制确保令牌文件的安全并将其添加到
.gitignore使用环境变量来获取敏感信息
定期轮换 OAuth 凭证
监控 API 使用情况并设置适当的配额
错误处理
该服务器包括全面的错误处理和日志记录:
日志写入
gmail_mcp.log文件和控制台日志记录均已启用
用于调试的详细错误消息
贡献
分叉存储库
创建功能分支
提交你的更改
推送到分支
创建拉取请求
执照
Apache许可证2.0
支持
对于问题和功能请求,请使用 GitHub 问题跟踪器。
This server cannot be installed
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.