谷歌服务MCP服务器
用于Claude Desktop的MCP(模型上下文协议)服务器,提供对Google表格、Gmail和Google日历的访问。
特性
- 13 MCP工具:
- 谷歌表格(4个工具):读取、写入、附加和获取工作表信息 - Gmail(4个工具):列出、搜索、获取详细信息和发送电子邮件 - 谷歌日历(5个工具):列出、创建、更新、删除和获取事件详细信息
先决条件
- Python 3.8或更高版本
- 启用API的谷歌云项目:
- 谷歌网页API - Gmail API - 谷歌日历API
- OAuth 2.0凭据(
credentials.json) - 已安装Claude Desktop
安装
1.克隆和安装依赖项
# Navigate to project directory
cd mcplatestv1
# Install dependencies
pip install -r requirements.txt2.设置Google OAuth
- 下载
credentials.json从 谷歌云控制台 - 地方
credentials.json在项目根目录中 - 运行安装脚本进行身份验证:
python src/setup.py- 按照提示授权访问您的Google帐户
- 脚本将创建
tokens.json使用您的访问令牌
3.配置您的服务
编辑 config.json:
{
"google": {
"clientId": "your-client-id",
"clientSecret": "your-client-secret",
"redirectUri": "http://localhost",
"spreadsheetId": "your-spreadsheet-id",
"calendarId": "primary"
}
}备注: spreadsheetId 和 calendarId 是可选的-您可以在每次工具调用时指定它们。
Claude桌面设置
步骤1:查找Claude桌面配置文件
窗户:
%APPDATA%\Claude\claude_desktop_config.json例子: C:\Users\YourName\AppData\Roaming\Claude\claude_desktop_config.json
雨衣:
~/Library/Application Support/Claude/claude_desktop_config.jsonLinux:
~/.config/Claude/claude_desktop_config.json步骤2:编辑配置文件
打开配置文件(如果不存在,则创建它)并添加:
{
"mcpServers": {
"google-services": {
"command": "python",
"args": [
"D:\\mcplatestv1\\src\\mcp_server.py"
],
"env": {}
}
}
}重要:
- 更新路径以匹配您的实际项目位置
- 在Windows上,使用双反斜杠(
\\)在路上 - 在Mac/Linux上,使用正斜杠(
/)
步骤3:重新启动克劳德桌面
完全退出并重新启动Claude Desktop 以使更改生效。
步骤4:验证连接
重新启动后:
- Claude Desktop将自动启动MCP服务器
- 所有13个工具都应该可用
- 通过问克劳德来测试: *“你有什么工具可以使用?”*
用法
连接后,您可以要求Claude:
- 从表格中读取:“从表1读取数据!A1:B10”
- 写入表格:“将这些值写入我的电子表格:\[\['姓名','年龄',\['约翰','30'\]\]”
- 列出电子邮件:“显示我最近10封电子邮件”
- 发送邮件:“发送电子邮件至john@example.com主题为“你好”,正文为“测试消息”
- 创建事件:“为明天下午2点创建一个名为“会议”的日历活动”
可用工具
谷歌表格
read_sheet-从某个范围读取数据write_sheet-将数据写入范围append_sheet-将数据附加到工作表get_sheet_info-获取电子表格信息
Gmail
list_emails-列出收件箱中的电子邮件get_email_detail-获取详细的电子邮件信息send_email-发送电子邮件search_emails-使用查询搜索电子邮件
谷歌日历
list_calendar_events-列出即将举行的活动create_calendar_event-创建新事件update_calendar_event-更新现有事件delete_calendar_event-删除事件get_calendar_event-获取活动详细信息
故障排除
服务器无法启动
- 检查Python路径:确保Python在您的系统PATH中
- 测试:开放式端子和类型 python --version - 如果未找到,请使用完整路径: "C:\\Python\\python.exe"
- 检查文件路径:验证路径
mcp_server.py是正确的
- 在配置文件中使用绝对路径 - 窗户: D:\\mcplatestv1\\src\\mcp_server.py - Mac/Linux: /path/to/mcplatestv1/src/mcp_server.py
- 检查相关性:确保所有软件包都已安装
pip install -r requirements.txt工具未出现
- 检查克劳德桌面日志:
- 在Claude Desktop控制台中查找错误消息 - 检查服务器进程是否正在运行
- 验证身份验证:
- 确保 tokens.json 存在且有效 - 重新运行 python src/setup.py 如有需要
- 重新启动克劳德桌面:
- 完全退出(不仅仅是关闭窗口) - 重新启动并再次检查
身份验证错误
- 重新验证:运行
python src/setup.py再次 - 检查凭据:验证
credentials.json有效 - 检查范围:确保在Google Cloud控制台中启用了所有必需的API
项目结构
mcplatestv1/
├── src/
│ ├── mcp_server.py # Main MCP server (stdio protocol)
│ ├── google_auth.py # Google OAuth handling
│ ├── google_sheets.py # Google Sheets functions
│ ├── google_gmail.py # Gmail functions
│ ├── google_calendar.py # Calendar functions
│ ├── agent.py # Automatic decision logic
│ └── setup.py # Initial setup script
├── config.json # Configuration (your credentials)
├── config.example.json # Configuration template
├── credentials.json # Google OAuth credentials (download from Cloud Console)
├── tokens.json # OAuth tokens (generated by setup.py)
├── requirements.txt # Python dependencies
├── claude_desktop_config.json # Example Claude Desktop config
└── README.md # This file许可证
这个项目是供个人使用的。确保你的 credentials.json 和 config.json 文件是安全的,永远不会将其提交给版本控制。
