py-mcp谷歌工具箱
](https://smithery.ai/server/@jikime/py-mcp-google-toolbox) 
一个MCP服务器,为人工智能助手提供与谷歌服务交互的强大工具,包括Gmail、谷歌日历、谷歌云端硬盘和谷歌搜索。
概述
py-mcp谷歌工具箱提供以下与谷歌相关的功能:
- Gmail操作(读取、搜索、发送、修改)
- 谷歌日历管理(事件创建、列出、更新、删除)
- Google Drive交互(搜索、读取文件)
- 谷歌搜索集成(搜索网络)
目录
- Gmail工具 - 日历工具 - 驱动工具 - 搜索工具
先决条件
- python:安装Python 3.12或更高版本
- 谷歌云控制台设置:
- 首选 谷歌云控制台 - 创建新项目或选择现有项目 - 启用服务API: 1. 转到“API和服务”>“库” 1. 搜索并启用“Gmail API” 1. 搜索并启用“Google日历API” 1. 搜索并启用“Google Drive API” 1. 搜索格式并启用“自定义搜索API” - 从GCP设置OAuth 2.0凭据: 1. 转到“API和服务”>“凭据” 1. 点击“创建凭据”>“OAuth客户端ID” 1. 选择“Web应用程序” 1. 记下客户端ID和客户端密码 - 客户端ID - 客户端密钥 1. 下载secret json并重命名为credentials.json - 生成API密钥
- 首选 自定义搜索引擎 并获取其ID
安装
克隆
git clone https://github.com/jikime/py-mcp-google-toolbox.git
cd py-mcp-google-toolbox配置
- 安装UV包管理器:
curl -LsSf https://astral.sh/uv/install.sh | sh- 创建并激活虚拟环境:
uv venv -p 3.12
source .venv/bin/activate # On MacOS/Linux
# or
.venv\Scripts\activate # On Windows- 安装依赖项:
uv pip install -r requirements.txt- 获取刷新令牌(如果令牌已过期,则可以运行此令牌)
uv run get_refresh_token.py这将:
- 打开浏览器进行Google OAuth身份验证
- 请求以下权限:
- https://www.googleapis.com/auth/gmail.modify - https://www.googleapis.com/auth/calendar - https://www.googleapis.com/auth/gmail.send - https://www.googleapis.com/auth/gmail.readonly - https://www.googleapis.com/auth/drive - https://www.googleapis.com/auth/drive.file - https://www.googleapis.com/auth/drive.readonly
- 将凭据保存到
token.json - 在控制台中显示刷新令牌
- 环境变量:
cp env.example .env
vi .env
# change with your key
GOOGLE_API_KEY=your_google_api_key
GOOGLE_CSE_ID=your_custom_search_engine_id
GOOGLE_CLIENT_ID=your_google_client_id
GOOGLE_CLIENT_SECRET=your_google_client_secret
GOOGLE_REFRESH_TOKEN=your_google_refresh_token- 将credentials.json复制到项目根文件夹(py-mcp-google工具箱)
使用Docker
- 构建Docker镜像:
docker build -t py-mcp-google-toolbox .- 运行容器:
docker run py-mcp-google-toolbox使用本地
- 运行服务器:
mcp run server.py- 运行MCP检查器
mcp dev server.py配置MCP设置
将服务器配置添加到MCP设置文件中:
Claude桌面应用程序
- 通过自动安装 史密瑟里:
npx -y @smithery/cli install @jikime/py-mcp-google-toolbox --client claude- 手动安装
打开 ~/Library/Application Support/Claude/claude_desktop_config.json
将此添加到 mcpServers 对象:
{
"mcpServers": {
"Google Toolbox": {
"command": "/path/to/bin/uv",
"args": [
"--directory",
"/path/to/py-mcp-google-toolbox",
"run",
"server.py"
]
}
}
}光标IDE
打开 ~/.cursor/mcp.json
将此添加到 mcpServers 对象:
{
"mcpServers": {
"Google Toolbox": {
"command": "/path/to/bin/uv",
"args": [
"--directory",
"/path/to/py-mcp-google-toolbox",
"run",
"server.py"
]
}
}
}Docker
{
"mcpServers": {
"Google Toolbox": {
"command": "docker",
"args": [
"run",
"-i",
"--rm",
"py-mcp-google-toolbox"
]
}
}
}工具文档
Gmail工具
list_emails:列出Gmail收件箱中最近的电子邮件,并提供过滤选项search_emails:通过详细的电子邮件内容检索执行高级Gmail搜索send_email:撰写和发送支持CC、BCC收件人的电子邮件modify_email:通过修改标签更改电子邮件状态(已读/未读、已存档、已丢弃)
日历工具
list_events:检索指定时间范围内即将发生的日历事件create_event:创建包含与会者、位置和描述的新日历事件update_event:通过灵活的参数更新修改现有日历事件delete_event:按事件ID删除日历事件
驱动工具
read_gdrive_file:从Google Drive文件读取和检索内容search_gdrive:使用可自定义的查询在Google Drive中搜索文件
搜索工具
search_google:执行谷歌搜索并返回格式化结果
发展
对于本地测试,您可以使用附带的客户端脚本:
# Example: List emails
uv run client.py list_emails max_results=5 query="is:unread"
# Example: Search emails
uv run client.py search_emails query="from:test@example.com"
# Example: Send email
uv run client.py send_email to="test@example.com" subject="test mail" body="Hello"
# Example: Modify email
uv run client.py modify_email id=MESSAGE_ID remove_labels=INBOX add_labels=ARCHIVED
# Example: List events
uv run client.py list_events time_min=2025-05-01T00:00:00+09:00 time_max=2025-05-02T23:59:59+09:00 max_results=5
# Example: Create event
uv run client.py create_event summary="new event" start=2025-05-02T10:00:00+09:00 end=2025-05-02T11:00:00+09:00 attendees="user1@example.com,user2@example.com"
# Example: Update event
uv run client.py update_event event_id=EVENT_ID summary="update event" start=2025-05-02T10:00:00+09:00 end=2025-05-02T11:00:00+09:00 attendees="user1@example.com,user2@example.com"
# Example Delete event
uv run client.py delete_event event_id=EVENT_ID
# Example: Search Google
uv run client.py search_google query="what is the MCP?"
# Example: Search Google Drive
uv run client.py search_gdrive query=mcp
# Example: Read file
uv run client.py read_gdrive_file file_id=1234567890许可证
MIT许可证
