Google Workspace MCP Server

Google Workspace MCP Server

用于Google Workspace集成(Gmail和日历)的模型上下文协议服务器。

简介

此服务器提供与Gmail和Google日历API交互的工具,让您能通过模型上下文协议(MCP)以编程方式管理电子邮件和日历事件。

主要功能

  • Gmail: 列出、搜索、发送和修改电子邮件
  • 日历: 查看、创建、更新和删除日历事件

设置步骤

1. 准备工作

  • 安装Node.js v14+
  • Google Cloud控制台中:
    • 创建/选择项目
    • 启用Gmail和Google日历API
    • 创建OAuth凭据(Web应用类型)
    • 添加重定向URI: http://localhost:4100/code

2. 安装

git clone https://github.com/epaproditus/google-workspace-mcp-server.git
cd google-workspace-mcp-server
npm install

3. 配置

创建credentials.json:

{
    "web": {
        "client_id": "YOUR_CLIENT_ID",
        "client_secret": "YOUR_CLIENT_SECRET",
        "redirect_uris": ["http://localhost:4100/code"],
        "auth_uri": "https://accounts.google.com/o/oauth2/auth",
        "token_uri": "https://oauth2.googleapis.com/token"
    }
}

获取刷新令牌:

node get-refresh-token.js

4. 配置MCP设置

在Claude配置文件中添加:

{
  "mcpServers": {
    "google-workspace": {
      "command": "node",
      "args": ["/path/to/google-workspace-server/build/index.js"],
      "env": {
        "GOOGLE_CLIENT_ID": "your_client_id",
        "GOOGLE_CLIENT_SECRET": "your_client_secret",
        "GOOGLE_REFRESH_TOKEN": "your_refresh_token"
      }
    }
  }
}

5. 构建并运行

npm run build

使用示例

Gmail

列出邮件:

{
  "maxResults": 5,
  "query": "is:unread"
}

发送邮件:

{
  "to": "recipient@example.com",
  "subject": "Hello",
  "body": "Message content",
  "cc": "cc@example.com",
  "bcc": "bcc@example.com"
}

日历

列出事件:

{
  "maxResults": 10,
  "timeMin": "2024-01-01T00:00:00Z",
  "timeMax": "2024-12-31T23:59:59Z"
}

创建事件:

{
  "summary": "Team Meeting",
  "location": "Conference Room",
  "description": "Weekly sync-up",
  "start": "2024-01-24T10:00:00Z",
  "end": "2024-01-24T11:00:00Z",
  "attendees": ["team@example.com"]
}

故障排除

  • 认证问题: 检查OAuth范围、客户端ID/密钥和刷新令牌
  • API错误: 验证API已启用、请求参数格式正确

许可证

MIT许可证