使用说明
Gmail MCP服务器
一个全面的Gmail MCP(模型上下文协议)服务器,为Goose等AI助手提供Gmail集成。该服务器允许通过Gmail API阅读、搜索和发送电子邮件。
🚀 特性
- 📧 发送电子邮件:通过Gmail API直接发送电子邮件
- 📋 列出电子邮件:从收件箱中检索最近的电子邮件
- 📖 阅读电子邮件:阅读特定电子邮件的完整内容
- 🔍 搜索电子邮件:使用Gmail查询语法搜索电子邮件
- 🖥️ CLI接口:用于终端使用的命令行工具
- 🤖 MCP集成:通过模型上下文协议与AI助手协作
🛠️ 设置
先决条件
- Python 3.12+
- 来自谷歌云控制台的Gmail API凭据
- 具有Gmail访问权限的Google帐户
安装
-
克隆存储库:
git clone https://github.com/Rajganesh-75/gmail-mcp-server.git cd gmail-mcp-server -
设置虚拟环境:
python -m venv .venv source .venv/bin/activate # On Windows: .venv\Scripts\activate -
安装依赖项:
pip install -r requirements.txt -
设置Gmail API凭据:
- 首选 谷歌云控制台
- 创建新项目或选择现有项目
- 启用Gmail API
- 创建OAuth 2.0凭据
- 下载
credentials.json并将其放置在项目根目录中
-
首次身份验证:
python test_server.py这将打开一个用于OAuth身份验证的浏览器,并创建
token.json.
🖥️ 命令行用法
发送电子邮件
python gmail_cli.py send "recipient@example.com" "Subject" "Message body"
列出最近的电子邮件
python gmail_cli.py list 10
阅读特定电子邮件
python gmail_cli.py read "message_id_here"
搜索电子邮件
python gmail_cli.py search "from:github.com" 5
python gmail_cli.py search "subject:important"
获得帮助
python gmail_cli.py
🤖 MCP集成(鹅/AI助手)
启动MCP服务器
python run_server.py
添加到Goose配置
将此添加到您的 ~/.config/goose/config.yaml:
extensions:
gmail_custom:
enabled: true
type: stdio
name: Gmail Custom
cmd: python
args:
- /path/to/gmail-mcp-server/run_server.py
envs: {}
env_keys: []
timeout: 300
description: Custom Gmail MCP server with full read/write access
bundled: false
available_tools: []
可用的MCP工具
list_emails(count)-列出最近的电子邮件read_email(message_id)-阅读完整的电子邮件内容send_email(to, subject, body)-发送电子邮件search_emails(query, count)-搜索电子邮件
📁 项目结构
gmail-mcp-server/
├── server.py # Main MCP server with Gmail functions
├── gmail_cli.py # Command-line interface
├── run_server.py # MCP server runner
├── test_server.py # Test script for functionality
├── send_email_cli.py # Simple email sender CLI
├── credentials.json # Google OAuth credentials (not in repo)
├── token.json # Authentication token (not in repo)
├── pyproject.toml # Project dependencies
├── requirements.txt # Pip requirements
└── README.md # This file
🔒 安全说明
credentials.json和token.json包含敏感信息- 这些文件通过以下方式从git中排除
.gitignore - 从不将身份验证文件提交到公共存储库
- 将环境变量用于生产部署
🧪 测试
运行测试套件以验证一切正常:
python test_server.py
这将测试:
- Gmail API身份验证
- MCP服务器功能
- 电子邮件列表功能
📋 需求
google-api-python-client>=2.181.0google-auth-httplib2>=0.2.0google-auth-oauthlib>=1.2.2mcp[cli]>=1.13.1
🤝 贡献
- 分叉存储库
- 创建要素分支
- 进行更改
- 如果适用,添加测试
- 提交拉取请求
📄 许可证
此项目根据MIT许可证获得许可-有关详细信息,请参阅许可证文件。
🙏 致谢
- 使用Google Gmail API构建
- 实现模型上下文协议(MCP)
- 与Goose AI助手兼容
- 受人工智能工作流程中无缝电子邮件集成需求的启发
📞 支持
对于问题和疑问:
- 在GitHub上创建问题
- 查看下面的故障排除部分
🔧 故障排除
身份验证问题
- 确保
credentials.json已正确配置 - 检查Gmail API是否已在谷歌云控制台中启用
- 验证OAuth范围是否包括Gmail访问
MCP连接问题
- 确保服务器正在运行(
python run_server.py) - 检查Goose配置文件语法
- 验证配置中的文件路径
权限错误
- 在Google云控制台中检查Gmail API配额
- 确保OAuth同意屏幕配置正确
- 验证帐户是否具有必要的Gmail权限