Google日历MCP服务器

一个用于与Google Calendar集成的MCP服务器,允许通过MCP工具管理Google Calendar事件。

  • by marcosf63
  • Python
  • 本地部署
  • 更新于
在 GitHub 查看 marcosf63/google-calendar-mcp

使用说明

Google 日历 MCP 服务器

MCP(模型上下文协议)服务器,用于与Google日历集成。它允许通过MCP工具管理Google日历中的事件。

功能

  • 列出事件按时间段过滤的日历事件列表
  • 创建事件创建新活动,包括标题、时间、描述、地点和参与者
  • 更新事件更新现有事件
  • **`delete_event` 翻译成中文是“删除事件”**从日历中移除事件
  • 获取事件获取特定事件的详细信息

要求

  • Python 3.13+(或“Python 3.13及以上版本”)
  • uv(Python包管理器)
  • 拥有访问Google日历权限的Google账户
  • Google Cloud OAuth2 凭证

安装

  1. 克隆仓库:
git clone <url-do-repositorio>
cd google-calendar-mcp
  1. 安装依赖项:
uv sync

配置

1. 在Google Cloud Console中创建项目

  1. 访问 https://console.cloud.google.com/
  2. 创建一个新项目或选择一个现有项目
  3. 在导航菜单中,转到“API 和服务”>“库”
  4. 搜索“Google Calendar API”并启用它

2. 配置OAuth2

  1. 在Google Cloud Console中,转到“APIs和服务”>“凭据”
  2. 点击“创建凭据”>“OAuth 2.0 客户端ID”
  3. 选择“电脑应用”作为应用类型
  4. 给客户起个名字(例如:“Google 日历 MCP”)
  5. 点击“创建”
  6. 下载JSON凭证文件

3. 保存凭据

将下载的JSON文件保存在:

~/.config/google-calendar-mcp/credentials.json

如果目录不存在,请创建它:

mkdir -p ~/.config/google-calendar-mcp
mv ~/Downloads/client_secret_*.json ~/.config/google-calendar-mcp/credentials.json

使用

运行服务器

uv run python main.py

首次运行时,浏览器将打开进行身份验证。授权访问后,一个令牌将被保存在…… ~/.config/google-calendar-mcp/token.json 以备将来使用。

在Claude桌面版中进行设置

添加到Claude桌面应用程序的配置文件中(claude_desktop_config.json):

{
  "mcpServers": {
    "google-calendar": {
      "command": "uv",
      "args": [
        "--directory",
        "/caminho/completo/para/google-calendar-mcp",
        "run",
        "python",
        "main.py"
      ]
    }
  }
}

使用示例

列出即将举行的活动

Liste meus próximos 5 eventos do calendário

创建一个活动

Crie um evento chamado "Reunião de equipe" amanhã às 14h por 1 hora

更新一个事件

Mude o horário do evento [ID] para começar às 15h

删除一个事件

Delete o evento [ID] do meu calendário

项目结构

google-calendar-mcp/
�� main.py              # Servidor MCP principal
�� pyproject.toml       # Configuração e dependências
�� README.md           # Documentação
�� .gitignore          # Arquivos ignorados pelo git

可用工具

列出事件

Google 日历的事件列表。

参数:

  • max_results (数字,可选):事件的最大数量(默认:10)
  • calendar_id (字符串,可选):日历ID(默认:“primary”)
  • time_min (字符串,可选):最小日期/时间 (RFC3339 格式)
  • time_max (字符串,可选):最大日期/时间 (RFC3339 格式)

创建事件

创建一个新事件。

参数:

  • summary (字符串,必填):活动标题
  • start_time (字符串,必填): 开始日期/时间 (RFC3339)
  • end_time (字符串,必填项):结束日期/时间 (RFC3339)
  • description (字符串,可选):事件描述
  • location (字符串,可选):活动地点
  • attendees (数组,可选):参与者电子邮件列表
  • calendar_id (字符串,可选):日历ID(默认:“primary”)

更新事件

更新一个现有的事件。

参数:

  • event_id (字符串,必填):事件ID
  • summary (字符串,可选):新标题
  • start_time (字符串,可选):新的开始日期/时间
  • end_time (字符串,可选):新的结束日期/时间
  • description (字符串,可选):新描述
  • location (字符串,可选):新位置
  • attendees (array, 可选): 新的参与者列表
  • calendar_id (字符串,可选):日历ID(默认:“primary”)

删除事件

移除一个事件。

参数:

  • event_id (字符串,必填):活动ID
  • calendar_id (字符串,可选):日历ID(默认:“primary”)

获取事件

获取事件的详细信息。

参数:

  • event_id (字符串,必填):活动ID
  • calendar_id (字符串,可选):日历的ID(默认:“primary”)

日期/时间格式

日期和时间应采用RFC3339格式:

  • 2025-01-15T14:00:00-03:00 (带时区)
  • 2025-01-15T17:00:00Z (协调世界时)

安全

  • OAuth2凭据本地存储于 ~/.config/google-calendar-mcp/
  • 访问令牌在过期时会自动更新。
  • 永远不要分享你的文件 credentials.json 或者 token.json

解决问题

错误:“未找到凭证文件”

检查文件 credentials.json 它在 ~/.config/google-calendar-mcp/credentials.json

认证错误

删除文件 ~/.config/google-calendar-mcp/token.json 然后再次执行以重新进行身份验证

权限不足

确保在Google Cloud Console中已启用Google日历API

许可证

麻省理工学院(MIT)

版本

0.1.0