google-drive-mcp
Google Drive MCP Server
用于从 Claude Code 会话中读写 Google Sheets、Slides 和 Drive 的本地 Python MCP 服务器。
工作原理
该服务器使用 GCP 的 OAuth 2.0 Desktop App。首次使用时,会打开浏览器进行同意流程。批准后,会在本地保存一个 token.json。后续运行时,会复用该令牌并在过期时自动刷新——无需再次打开浏览器。
认证文件:
文件 | 说明 |
| 从 GCP Console 下载的 OAuth 应用凭据 |
| 首次登录后生成的访问令牌(自动刷新) |
Related MCP server: google-workspace-mcp-with-script
初始配置(首次)
1. GCP 凭据
访问 GCP Console → APIs & Services → Credentials
创建一个 OAuth 2.0 Client ID(类型:Desktop App)
下载 JSON 并保存为
credentials.json放在此文件夹中在 GCP 项目中启用以下 API:
Google Sheets API
Google Slides API
Google Drive API
2. 安装依赖
Windows (PowerShell):
cd "C:\Users\<usuario>\Documents\MCP_Servers\googleDrive"
python -m venv .venv
.venv\Scripts\activate
pip install -r requirements.txtmacOS / Linux:
cd ~/Documents/MCP_Servers/googleDrive
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt3. 首次登录(OAuth)
手动运行以打开浏览器并授权:
Windows:
.venv\Scripts\activate
python main.pymacOS / Linux:
source .venv/bin/activate
python main.py在浏览器中批准后,会创建 token.json 并启动服务器。可以用 Ctrl+C 结束——令牌会保存,供下次使用。
在 Claude Code 中注册
有两种注册 MCP 服务器的方式:
选项 A — 按项目(.mcp.json)
在项目根目录创建 .mcp.json 文件。MCP 仅在该项目中生效。
Windows:
{
"mcpServers": {
"google-drive": {
"type": "stdio",
"command": "C:\\Users\\<usuario>\\Documents\\MCP_Servers\\googleDrive\\.venv\\Scripts\\python.exe",
"args": [
"C:\\Users\\<usuario>\\Documents\\MCP_Servers\\googleDrive\\main.py"
]
}
}
}macOS / Linux:
{
"mcpServers": {
"google-drive": {
"type": "stdio",
"command": "/Users/<usuario>/Documents/MCP_Servers/googleDrive/.venv/bin/python",
"args": [
"/Users/<usuario>/Documents/MCP_Servers/googleDrive/main.py"
]
}
}
}选项 B — 用户全局(~/.claude/settings.json)
将 MCP 添加到 Claude Code 的全局设置中——在所有项目中均可用。
编辑 ~/.claude/settings.json(Windows:C:\Users\<usuario>\.claude\settings.json)并添加 mcpServers 键:
Windows:
{
"mcpServers": {
"google-drive": {
"type": "stdio",
"command": "C:\\Users\\<usuario>\\Documents\\MCP_Servers\\googleDrive\\.venv\\Scripts\\python.exe",
"args": [
"C:\\Users\\<usuario>\\Documents\\MCP_Servers\\googleDrive\\main.py"
]
}
}
}macOS / Linux:
{
"mcpServers": {
"google-drive": {
"type": "stdio",
"command": "/Users/<usuario>/Documents/MCP_Servers/googleDrive/.venv/bin/python",
"args": [
"/Users/<usuario>/Documents/MCP_Servers/googleDrive/main.py"
]
}
}
}当 MCP 仅针对特定项目时,使用选项 A。当需要在任何项目中访问时,使用选项 B。
环境变量(可选)
默认情况下,服务器会在自身文件夹中查找 credentials.json 和 token.json。要更改路径,请基于 .env.example 创建 .env:
GOOGLE_CREDENTIALS_PATH=credentials.json
GOOGLE_TOKEN_PATH=token.json可用工具(17 个工具)
Google Sheets (7)
工具 | 说明 |
| 读取单元格区域的值 |
| 在区域中写入值 |
| 在数据末尾添加行 |
| 一次写入多个区域 |
| 返回元数据(标题、工作表) |
| 创建新电子表格 |
| 向电子表格添加工作表 |
Google Slides (7)
工具 | 描述 |
| 返回幻灯片的结构和标题 |
| 返回某张幻灯片的文本和形状 |
| 添加新幻灯片 |
| 在形状中插入文本 |
| 查找并替换文本 |
| 删除幻灯片 |
| 执行 API 原始批量操作 |
Google Drive (3)
工具 | 描述 |
| 列出/筛选文件(按类型、查询) |
| 按名称搜索文件 |
| 返回文件的详细元数据 |
所有工具都接受直接 ID 或完整的 Google URL:
1BxiMVs0XRA5nFMdKvBdBZjgmUUqptlbs74OgVE2upmshttps://docs.google.com/spreadsheets/d/1BxiMVs0XRA5nFMdKvBdBZjgmUUqptlbs74OgVE2upms/edit
故障排查
invalid_grant / 令牌过期且未自动刷新
删除 token.json 并重新运行 python main.py 以重新执行 OAuth 流程。
Windows:
Remove-Item ".\token.json"
python main.pymacOS / Linux:
rm token.json
python main.pyAPI 未启用
检查 GCP Console 中三个 API 是否已启用:Google Sheets API、Google Slides API、Google Drive API。
MCP 未出现在 Claude Code 中
检查 Python 可执行文件的路径是否正确:
Windows:
.venv\Scripts\python.exemacOS/Linux:
.venv/bin/python
在 .mcp.json 或 settings.json 中使用绝对路径——相对路径无效。
This server cannot be installed
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Related MCP Servers
- AlicenseNot gradedqualityFmaintenanceMCP server that enables Claude to interact with Google Workspace services including Drive, Docs, Sheets, Slides, Calendar, Gmail, and Contacts.43438MIT
- AlicenseNot gradedqualityCmaintenanceMCP server for Claude Code CLI that integrates with Google Workspace, enabling management of Docs, Sheets, Drive, Gmail, Calendar, and Apps Script.92MIT
- AlicenseNot gradedqualityBmaintenanceMCP server for Google Drive, Docs, and Sheets — built for Claude Code. Gives Claude Code direct read/write access to Google Sheets (cell-level edits, formatting, structure), Google Docs (insert, replace, append), and Drive (search).521MIT
- AlicenseNot gradedqualityBmaintenanceA local MCP server that lets Claude read and write Google Sheets through the Google Sheets API v4, using OAuth2 authentication with your own Google account.261MIT
Related MCP Connectors
Streamable HTTP MCP server for Google Calendar and Sheets with OAuth login.
Augments MCP Server - A comprehensive framework documentation provider for Claude Code
Hosted MCP server connecting claude.ai, ChatGPT and other AI apps to your own computer
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/JovemDaniel/google-drive-mcp'
If you have feedback or need assistance with the MCP directory API, please join our Discord server