article
README
🚀 Google 工作区 MCP 服务器
这是一个基于 Model Context Protocol (MCP) 的服务器,它提供了与 Gmail 和日历 API 交互的工具。借助 MCP 接口,你能够对电子邮件和日历事件进行编程管理,极大提升工作效率。
🚀 快速开始
本服务器可让你轻松通过 MCP 接口对 Gmail 邮件和日历事件进行编程管理。在使用前,请确保完成以下先决条件和设置步骤。
✨ 主要特性
Gmail 工具
list_emails:列出收件箱中的近期邮件,还具备可选过滤功能。search_emails:支持使用 Gmail 查询语法进行高级邮件搜索。send_email:可发送新邮件,并且支持 CC 和 BCC。modify_email:能修改电子邮件标签,如存档、移动到垃圾邮件、标记为已读/未读。
日历工具
list_events:列出未来范围内的日历活动,带有日期筛选功能。create_event:可创建新日历事件,支持添加与会者。update_event:用于更新现有日历事件。delete_event:可删除日历事件。
📦 安装指南
先决条件
- Node.js:确保已安装 Node.js(推荐版本 14 或更高)。
- Google Cloud Console 设置:
- 创建项目并启用 Google Workspace API 和 Calendar API。
- 配置 OAuth 2.0 凭证,授予以下作用域:
https://www.googleapis.com/auth/gmail.readonly、https://www.googleapis.com/auth/calendar
设置步骤
- 克隆代码仓库:
git clone https://github.com/your-repository.git cd your-repository - 安装依赖项:
npm install - 创建凭证文件:
- 在 Google Cloud Console 中创建
credentials.json文件,内容示例如下:
{ "type": "service_account", "project_id": "your-project-id", "private_key_id": "your-private-key-id", "client_email": "your-service-account@your-project-id.iam.gserviceaccount.com", "private_key": "your-private-key", "client_id": "your-client-id", "auth_uri": "https://accounts.google.com/o/oauth2/auth", "token_uri": "https://oauth2.googleapis.com/token", "AuthProviderLink": "https://www.googleapis.com/auth/", "Authority": "https://accounts.google.com/o/oauth2/auth" } - 在 Google Cloud Console 中创建
- 获取刷新令牌:
npm run get-refresh-token
配置 MCP 设置
- 根据以下路径配置不同 IDE 的 MCP 设置:
- VS Code:
~/.config/google/workspace-mcp/setting.json - IntelliJ IDEA:
File > Settings > Google Workspace MCP Config - PyCharm:
File > Settings > Google Workspace MCP Config
- VS Code:
- 示例配置内容如下:
{ "gmail": { "apiKey": "your-gmail-api-key", "refreshToken": "your-refresh-token" }, "calendar": { "apiKey": "your-calendar-api-key", "refreshToken": "your-refresh-token" } }
构建与运行
npm run build
npm start
💻 使用示例
基础用法
Gmail 示例
- 列出邮件:
{ "command": "list_emails", "maxResults": 10, "q": "subject:meeting" } - 发送邮件:
{ "command": "send_email", "to": "recipient@example.com", "subject": "测试邮件", "body": "这是测试邮件内容。" }
日历示例
- 创建事件:
{ "command": "create_event", "summary": "团队会议", "location": "会议室", "description": "每周同步", "start": "2024-01-24T10:00:00Z", "end": "2024-01-24T11:00:00Z", "attendees": ["colleague@example.com"] }
📚 详细文档
故障排除
身份验证问题
- 确保所有必需的 OAuth 作用域已授权。
- 验证客户 ID 和密钥是否正确。
- 检查刷新令牌的有效性。
API 错误
- 查看 Google Cloud Console 中的 API 配额和限制。
- 确保 APIs 已为你的项目启用。
- 验证请求参数是否符合要求格式。
📄 许可证
此项目遵循 MIT 许可证。
Scan to join WeChat group