谷歌日历MCP服务器(Go)
Go中的模型上下文协议(MCP)服务器实现,提供Google日历与HTTP传输的集成。
特性
- 活动管理:创建、读取、更新和删除日历事件
- 日历管理:管理多个日历
- 忙/闲查询:检查日历上的可用性
- 全天活动:支持定时和全天活动
- 与会者管理:添加和管理活动参与者
- 时区支持:处理跨越不同时区的事件
- OAuth2身份验证:保护Google OAuth2流
- JSON-RPC 2.0:标准MCP协议实施
可用工具
活动操作
create_event-创建包含与会者和提醒的新日历事件get_event-按ID检索事件详细信息update_event-修改现有事件delete_event-从日历中删除事件list_events-搜索和筛选日历事件
日历管理
list_calendars-列出所有可访问的日历get_calendar-获取特定日历的详细信息create_calendar-创建新日历delete_calendar-删除日历
可用性
get_freebusy-跨日历查询忙/闲信息
安装
- 克隆存储库:
git clone https://github.com/phildougherty/mcp-google-calendar-go.git
cd mcp-google-calendar-go- 安装依赖项:
go mod tidy- 设置Google OAuth2凭据:
配置
- OAuth设置
- 转到 谷歌云控制台 - 创建新项目或选择现有项目 - 启用Google日历API - 创建OAuth 2.0凭据(OAuth客户端ID) - 记下客户端ID和客户端密码 - 添加 http://localhost:8080/callback 作为OAuth同意屏幕中的授权重定向URI
创建一个 .env 包含以下变量的文件:
# Required
GOOGLE_CLIENT_ID=your-client-id
GOOGLE_CLIENT_SECRET=your-client-secret
# Optional (default: http://localhost:8080/callback)
# REDIRECT_URL=http://your-callback-url或者将它们设置为系统中的环境变量。
用法
1.身份验证
运行以下命令以启动服务器并向Google进行身份验证:
go run main.go -auth然后打开 http://localhost:8080/login 在浏览器中启动OAuth流。验证后,您将被重定向回回调URL。
2.启动服务器
go run main.go -port 8080可选标志:
-port-服务器端口(默认:8080)-debug-启用调试日志记录
3.测试服务器
检查服务器运行状况:
curl http://localhost:8080/health4.使用MCP工具
服务器通过HTTP实现JSON-RPC 2.0。请求示例:
初始化连接:
curl -X POST http://localhost:8080/ \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"id": 1,
"method": "initialize",
"params": {
"protocolVersion": "2024-11-05",
"capabilities": {},
"clientInfo": {"name": "test-client", "version": "1.0.0"}
}
}'列出可用工具:
curl -X POST http://localhost:8080/ \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"id": 2,
"method": "tools/list"
}'创建日历事件:
curl -X POST http://localhost:8080/ \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"id": 3,
"method": "tools/call",
"params": {
"name": "create_event",
"arguments": {
"summary": "Team Meeting",
"description": "Weekly team sync",
"location": "Conference Room A",
"startTime": "2024-01-15T10:00:00Z",
"endTime": "2024-01-15T11:00:00Z",
"timeZone": "America/New_York",
"attendees": ["colleague@example.com"]
}
}
}'列出即将发生的事件:
curl -X POST http://localhost:8080/ \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"id": 4,
"method": "tools/call",
"params": {
"name": "list_events",
"arguments": {
"timeMin": "2024-01-01T00:00:00Z",
"timeMax": "2024-12-31T23:59:59Z",
"maxResults": 10,
"orderBy": "startTime"
}
}
}'发展
建筑
go build -o calendar-mcp-server main.go运行测试
go test ./...项目结构
├── main.go # Application entry point
├── internal/
│ ├── config/ # Configuration management
│ │ └── config.go
│ ├── calendar/ # Google Calendar API client
│ │ ├── client.go # OAuth2 and service setup
│ │ └── operations.go # Calendar operations
│ ├── mcp/ # MCP protocol implementation
│ │ ├── server.go # HTTP server and JSON-RPC
│ │ ├── tools.go # Tool registry and handlers
│ │ └── types.go # Data structures and schemas
│ └── types/ # Shared type definitions
│ └── types.go
├── go.mod
└── README.mdapi参考
身份验证流程
- 使用启动服务器
-auth旗帜 - Google OAuth2浏览器打开
- 向日历API授予权限
- 在本地保存凭据以供将来使用
工具架构
所有工具都遵循JSON模式规范。看 internal/mcp/types.go 以获取完整的模式定义。
事件时间格式
- 定时事件:使用RFC3339格式(例如。,
2024-01-15T10:00:00Z) - 全天活动:使用日期格式(例如。,
2024-01-15) - 时区:使用IANA时区名称(例如。,
America/New_York)
错误处理
- JSON-RPC 2.0协议错误的错误响应
- 响应时返回工具执行错误
isError: true - 为调试提供了详细的错误消息
安全
- OAuth2令牌安全地存储在用户主目录中
- HTTPS建议用于生产部署
- 为跨源请求配置CORS标头
集成示例
此服务器可以与Claude Desktop等MCP客户端集成。添加到MCP配置中:
{
"mcpServers": {
"google-calendar": {
"command": "/path/to/calendar-mcp-server",
"args": ["-port", "8080"]
}
}
}贡献
- 复刻仓库
- 创建要素分支
- 进行更改
- 如果适用,添加测试
- 提交拉取请求
许可证
此项目根据MIT许可证获得许可-有关详细信息,请参阅许可证文件。
支持
对于问题和疑问:
- 在GitHub上创建问题
- 查看Google日历API文档
- 审查MCP协议规范#MCP_GO_GOOGLE_CALENDAR
