article
README
🚀 Google 日历 MCP 服务器
Google 日历 MCP 服务器是一个模型上下文协议(MCP)服务器,它提供了与 Google Calendar API 交互的工具。通过 MCP 接口,该服务器能够实现对日历事件的程序化管理,让用户更便捷地操作日历。
🚀 快速开始
本服务器可帮助你通过 MCP 接口程序化管理 Google 日历事件。在使用前,请确保满足先决条件并完成安装。
✨ 主要特性
日历工具
list_events:按日期范围筛选显示即将来临的日历活动。create_event:创建新的日历事件并添加参与者。update_event:更新现有日历事件。delete_event:删除日历事件。
📦 安装指南
先决条件
- Node.js:安装 Node.js 版本 14 或更高。
- Google Cloud Console 设置:
- 访问Google Cloud Console。
- 创建新项目或选择现有项目。
- 启用 Google Calendar API:
- 进入"APIs & Services" > "Library"。
- 搜索并启用"Google Calendar API"。
- 设置 OAuth 2.0 凭证:
- 进入"APIs & Services" > "Credentials"。
- 点击"Create Credentials" > "OAuth client ID"。
- 选择"Web 应用程序"。
- 将"Authorized redirect URIs"设为:
http://localhost:3000/code。 - 记录下 Client ID 和 Client Secret。
安装步骤
-
克隆并安装:
git clone https://github.com/yourusername/google-calendar-mcp-server.git cd google-calendar-mcp-server npm install -
创建 OAuth 凭证: 在根目录下创建
credentials.json文件:{ "web": { "client_id": "YOUR_CLIENT_ID", "client_secret": "YOUR_CLIENT_SECRET", "redirect_uris": ["http://localhost:3000/code"], "auth_uri": "https://accounts.google.com/o/oauth2/auth", "token_uri": "https://oauth2.googleapis.com/token" } } -
获取刷新令牌:
node get-refresh-token.js此命令将:
- 打开浏览器进行 Google OAuth 身份验证。
- 请求以下权限:
https://www.googleapis.com/auth/calendar。
- 将凭证保存到
token.json。 - 在控制台显示刷新令牌。
-
配置 MCP 设置: 将服务器配置添加到您的 MCP 设置文件中:
- 对于 VSCode Claude 扩展:
~/Library/Application Support/Code/User/globalStorage/saoudrizwan.claude-dev/settings/cline_mcp_settings.json。 - 对于 Claude 桌面应用:
~/Library/Application Support/Claude/claude_desktop_config.json。
在
mcpServers对象中添加如下配置:{ "mcpServers": { "google-calendar": { "command": "node", "args": ["index.js"], "cwd": "/path/to/server/directory" } } } - 对于 VSCode Claude 扩展:
💻 使用示例
基础用法
列出即将来临的事件
{
"action": "list_events",
"params": {
"calendarId": "primary", // 可选,默认为"primary"
"timeMin": "2023-12-01T00:00:00Z", // 开始时间
"timeMax": "2023-12-31T23:59:59Z", // 结束时间
"maxResults": 50, // 最大结果数,默认为25
"orderBy": "startTime" // 按开始时间排序,可选值:startTime, endDate
}
}
创建新事件
{
"action": "create_event",
"params": {
"calendarId": "primary",
"event": {
"summary": "会议", // 事件标题
"location": "在线会议", // 事件地点
"description": "参加团队会议", // 事件描述
"start": {
"dateTime": "2023-12-10T10:00:00Z", // 开始时间
"timeZone": "Asia/Shanghai" // 时间区
},
"end": {
"dateTime": "2023-12-10T11:00:00Z",
"timeZone": "Asia/Shanghai"
}
}
}
}
更新事件
{
"action": "update_event",
"params": {
"calendarId": "primary",
"eventId": "abc123", // 要更新的事件ID
"event": {
"summary": "更新会议", // 新标题
"description": "更新会议内容" // 新描述
}
}
}
删除事件
{
"action": "delete_event",
"params": {
"calendarId": "primary",
"eventId": "abc123"
}
}
📄 许可证
本项目使用 MIT 许可证,详情请查看LICENSE文件。
Scan to join WeChat group