Google服务的MCP服务器
一种模型上下文协议(MCP)服务器,将谷歌服务与克劳德桌面集成在一起。为Gmail、日历、驱动器、表格和文档操作提供80多种工具。
特性
- Gmail:搜索、阅读、发送、回复、标记和组织电子邮件
- 谷歌日历:创建、更新、删除事件;查找空闲插槽
- Google 云端硬盘:搜索、列出、读取文件和文件夹
- 谷歌表格:读取、写入、附加数据;管理电子表格
- 谷歌文档:创建和阅读文档
- 存储器系统:上下文和偏好的持久存储
- 数据库支持:可选的PostgreSQL和MongoDB集成
项目结构
mcpwithgoogle/
├── src/
│ ├── mcp_server.py # Main MCP server (80+ tools)
│ ├── google_auth.py # OAuth authentication
│ ├── google_gmail.py # Gmail operations
│ ├── google_calendar.py # Calendar operations
│ ├── google_drive.py # Drive operations
│ ├── google_sheets.py # Sheets operations
│ ├── google_docs.py # Docs operations
│ ├── memory_system.py # Persistent memory
│ ├── local_storage.py # Local data storage
│ └── setup.py # OAuth setup script
├── config/
│ └── claude_desktop_config.json # Example Claude config
├── scripts/
│ └── setup_my_profile.py
├── config.example.json # Google OAuth config template
├── authenticate.py # Authentication script
├── requirements.txt
├── .env.example
└── README.md先决条件
- Python 3.8+
- 克劳德桌面版
- 启用API的谷歌云项目:
- Gmail API - 谷歌日历API - Google Drive API - 谷歌网页API
安装
步骤1:克隆存储库
git clone https://github.com/pbulbule13/mcpwithgoogle.git
cd mcpwithgoogle步骤2:安装依赖项
pip install -r requirements.txt步骤3:谷歌云设置
- 首选 谷歌云控制台
- 创建新项目或选择现有项目
- 启用以下API:
- Gmail API - 谷歌日历API - Google Drive API - 谷歌网页API
- 首选 凭证 > 创建凭据 > OAuth 2.0客户端ID
- 选择 桌面应用 作为应用程序类型
- 下载凭据并另存为
credentials.json在项目根中
步骤4:配置
# Copy example config
cp config.example.json config.json
# Edit with your Google OAuth credentialsconfig.json:
{
"google": {
"clientId": "YOUR_CLIENT_ID.apps.googleusercontent.com",
"clientSecret": "YOUR_CLIENT_SECRET",
"redirectUri": "http://localhost",
"calendarId": "primary"
}
}步骤5:使用Google进行身份验证
python authenticate.py这将打开Google OAuth浏览器。授权后,令牌将保存在本地。
步骤6:配置Claude桌面
编辑您的Claude Desktop配置文件:
| 操作系统 | 路径 |
|---|---|
| 窗户 | %APPDATA%\Claude\claude_desktop_config.json |
| macOS | ~/Library/Application Support/Claude/claude_desktop_config.json |
| Linux | ~/.config/Claude/claude_desktop_config.json |
添加:
{
"mcpServers": {
"google-workspace": {
"command": "python",
"args": [
"C:\\path\\to\\mcpwithgoogle\\src\\mcp_server.py"
],
"env": {},
"cwd": "C:\\path\\to\\mcpwithgoogle"
}
}
}重要提示: 替换 C:\\path\\to\\ 你的实际绝对路径。
步骤7:重新启动克劳德桌面
- 完全退出Claude Desktop(检查系统托盘)
- 重新启动克劳德桌面
- 工具将自动可用
验证安装
在Claude Desktop中,键入:
Show me available tools您应该看到列出了80多种工具。
可用工具
电子邮件工具
search_emails-使用查询搜索Gmailget_email-通过ID获取电子邮件send_email-发送新电子邮件reply_to_email-回复电子邮件list_labels-列出Gmail标签create_label-创建新标签move_to_label-将电子邮件移动到标签
日历工具
get_calendar_events-列出事件create_calendar_event-创建事件update_calendar_event-更新事件delete_calendar_event-删除事件find_free_slots-查找可用时间
驱动工具
search_drive-搜索文件list_drive_files-列出文件夹中的文件get_file_content-读取文件内容create_folder-创建文件夹
图纸工具
read_sheet-读取电子表格数据write_sheet-写入电子表格append_sheet-添加行create_sheet-创建新的电子表格
文档工具
create_doc-创建文档read_doc-读取文档内容
内存工具
remember-店铺信息recall-检索信息forget-删除信息list_memories-列出所有存储的项目
示例用法
在克劳德桌面中:
"Show my unread emails from today"
"Schedule a meeting tomorrow at 2 PM with john@example.com"
"Find documents about 'project proposal' in my Drive"
"What meetings do I have this week?"
"Remember that my favorite color is blue"故障排除
MCP服务器未出现
- 验证中的路径
claude_desktop_config.json绝对正确 - 确保Python在您的系统PATH中
- 完全重新启动克劳德桌面
- 检查Claude Desktop日志是否有错误
身份验证错误
- 删除
tokens.json并重新运行python authenticate.py - 验证
credentials.json存在于项目根目录中 - 查看Google云控制台以了解API配额问题
导入错误
pip install --upgrade -r requirements.txt安全须知
- 永不承诺
credentials.json,tokens.json,或config.json转git - 这
.gitignore默认情况下,文件不包括敏感文件 - 尽可能将API密钥存储在环境变量中
许可证
MIT许可证
