Google Workspace MCP Server

Google Workspace MCP Server

镜像

概述

这是一个 MCP (模型上下文协议) 服务器,提供 Gmail 和 Google Calendar API 集成功能。

主要功能

Gmail 工具:

  • 列出/搜索邮件
  • 发送新邮件
  • 修改邮件标签

日历工具:

  • 列出/创建/更新/删除日历事件

快速设置

1. 先决条件

  • Node.js 14+
  • Google Cloud 项目与已启用的 Gmail 和 Calendar API
  • OAuth 2.0 客户端 ID 和密钥

2. 安装

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

3. 配置 OAuth

创建 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"
    }
}

4. 获取刷新令牌

node get-refresh-token.js

5. 配置 MCP 设置

将以下配置添加到 Claude 的 MCP 设置文件中:

{
  "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"
      }
    }
  }
}

6. 构建服务器

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"
}

Calendar

列出事件:

{
  "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": ["colleague@example.com"]
}

常见问题

如遇身份验证问题,请检查:

  • OAuth 权限范围是否正确
  • 客户端 ID 和密钥是否有效
  • 刷新令牌是否正常工作