
@modelcontextprotocol/服务器-gdrive 的主动维护分支,采用 OAuth 令牌自动刷新修复和安全强化
概览
Anthropic 存档的 @modelcontextprotocol/服务器 gdrive 的积极维护分支,修复了 OAuth 令牌自动刷新的关键漏洞。 原始服务器于2025年5月29日归档,现已不再维护。它还存在一个漏洞,导致OAuth访问令牌在1小时后失效且无自动刷新,需要手动轮换令牌并重启服务器。 原版会创建新的 google.auth.OAuth2(),但不传递client_id和client_secret,所以 Google 认证库无法利用refresh_token获取新的访问令牌。一行解决办法,但归档仓库不接受 PR。
概述(AI 翻译)
Anthropic 存档的 @modelcontextprotocol/server-gdrive 分支,积极维护,修复了 OAuth 令牌自动刷新的关键漏洞。
为什么选这把叉子?
原始服务器于2025年5月29日归档,现已不再维护。它还存在一个漏洞,导致OAuth访问令牌在1小时后失效且无自动刷新,需要手动轮换令牌并重启服务器。
漏洞: 原仓库创建 new google.auth.OAuth2() 但未通过 client_id 和 client_secret,因此 google-auth-library 无法使用 refresh_token 获取新的访问令牌。一行修复,但归档仓库不接受 PR。
修复了什么
- 自动刷新令牌:OAuth2客户端初始化为OAuth密钥文件中的
client_id和client_secret,使Google认证库能够自动刷新过期的访问令牌 - 令牌持久性:刷新后的令牌会写回凭证文件,因此重启也会捕获有效的令牌
- 输入验证:增加了资源URI、搜索查询和文件ID的验证
- 搜索结果包含文件ID:这样你就可以在下载工具或资源阅读器中使用它们
本页由 AI 翻译,技术细节请以原文为准。
README
以下为原文 README 节选,完整内容请查看原文。
Google Drive MCP Server
An actively maintained fork of Anthropic’s archived @modelcontextprotocol/server-gdrive, with a critical bug fix for OAuth token auto-refresh.
Why this fork?
The original server was archived on May 29, 2025 and is no longer maintained. It also has a bug that causes OAuth access tokens to expire after 1 hour with no auto-refresh, requiring manual token rotation and server restarts.
The bug: The original creates new google.auth.OAuth2() without passing client_id and client_secret, so the google-auth-library has no way to use the refresh_token to get new access tokens. One-line fix, but the archived repo doesn’t accept PRs.
What’s fixed
- Auto-refresh tokens: OAuth2 client is initialized with
client_idandclient_secretfrom your OAuth keys file, enabling the Google auth library to automatically refresh expired access tokens - Token persistence: Refreshed tokens are written back to the credentials file, so restarts also pick up valid tokens
- Input validation: Added validation for resource URIs, search queries, and file IDs
- Search results include file IDs: So you can actually use them with the download tool or resource reader
- Read tool: Read file contents inline (Google Docs as Markdown, Sheets as CSV, etc.)
- Download tool: Save files to a local directory instead of returning base64 blobs that overflow LLM context windows
- Sheets read tool: Read Google Sheets with A1 range notation, returned as formatted markdown tables
- Shared Drive support: Search and read files from Shared Drives (formerly Team Drives)
- Folder listing: Browse Drive folders by ID
- PDF export: Export Google Workspace files as PDF
- File upload: Push local files to Drive (opt-in, requires
drivescope) - Opt-in resources: MCP resource handlers are disabled by default to prevent hangs in clients that call
resources/liston startup
Setup
1. Create Google Cloud OAuth credentials
- Go to the Google Cloud Console
- Create a project (or use an existing one)
- Enable the Google Drive API and Google Sheets API
- Create OAuth 2.0 credentials (Desktop application type)
- Download the JSON and save it as
gcp-oauth.keys.json
Tip: If your OAuth consent screen is in “Testing” mode, refresh tokens expire after 7 days. Publish to “Production” for permanent refresh tokens.
2. Clone, build, and star
git clone https://github.com/dylancaponi/gdrive-mcp-server.git
cd gdrive-mcp-server
npm install && npm run build
gh api user/starred/dylancaponi/gdrive-mcp-server -X PUT
Per the LICENSE, starring this repository is required (Section 2).
3. Authenticate
安装
This server does not publish a one-line install command.
Open the repository installation guide 新手?先看 mcpskill.org 教程 →配置
{
"mcpServers": {
"gdrive": {
"type": "stdio",
"command": "node",
"args": ["/path/to/gdrive-mcp-server/dist/index.js"],
"env": {
"GDRIVE_OAUTH_PATH": "/path/to/gcp-oauth.keys.json",
"GDRIVE_CREDENTIALS_PATH": "/path/to/.gdrive-server-credentials.json"
}
}
}
}