mcp-gdrive-cf
Remote MCP server for Google Drive and Sheets running on Cloudflare Workers, providing 11 tools for file and sheet operations with full OAuth 2.0 and PKCE support for secure authentication.
README
mcp-gdrive-cf
Remote MCP server for Google Drive and Sheets running on Cloudflare Workers with full OAuth 2.0 support.
Production Ready ✅ | 11 Tools | OAuth 2.0 | PKCE | Global Edge Network
Adapted from isaacphi/mcp-gdrive to run as a remote HTTP/SSE MCP server on Cloudflare's edge network with complete OAuth 2.0 authorization server capabilities.
🚀 Quick Start
```bash
1. Clone and install
git clone https://github.com/brianmoney/mcp-gdrive-cf.git cd mcp-gdrive-cf npm install
2. Create KV namespaces
wrangler kv:namespace create KV_TOKENS wrangler kv:namespace create KV_CLIENTS
3. Update wrangler.toml with your namespace IDs
4. Configure Google OAuth credentials
wrangler secret put GOOGLE_CLIENT_SECRET
5. Deploy
wrangler deploy
6. Test with MCP Inspector
npx @modelcontextprotocol/inspector https://your-worker.workers.dev/sse ```
✨ Features
Drive Operations
- 🔍 Search - Basic and advanced search with filters (MIME type, owner, dates, shared drives)
- 📄 Read - Read any file with 22+ export formats (PDF, DOCX, XLSX, Markdown, etc.)
- 📁 Create Folders - Organize files with nested folder structures
- ⬆️ Upload - Upload files up to 5MB
- 🗑️ Delete - Move files to trash
- 📦 Move - Reorganize files between folders
- 🔐 Share - Add permissions (reader, writer, commenter, owner)
Sheets Operations
- 📊 Read - Batch read multiple ranges
- ✏️ Update - Update individual cells
- ➕ Append - Add rows to spreadsheets
Infrastructure
- ☁️ Global Edge Network - Runs on Cloudflare Workers worldwide
- 🔐 OAuth 2.0 Server - Full authorization server with PKCE support
- 🔑 Dynamic Client Registration - Automatic client onboarding
- 🔄 Auto Token Refresh - Seamless Google token renewal
- 📡 SSE Transport - Real-time Server-Sent Events
- 🛡️ Secure - HTTPS only, encrypted token storage
🎯 What Makes This Different
Unlike the original STDIO-based `mcp-gdrive`, this implementation:
- Runs remotely on Cloudflare Workers (no local process)
- Full OAuth 2.0 authorization server (not just OAuth client)
- Multi-client support via dynamic client registration
- PKCE security for public clients
- 22+ export formats for Drive files
- Write operations (create, delete, move, share, upload)
- Production tested with real workloads
📋 Prerequisites
Required
- Cloudflare Account with Workers enabled (free tier works)
- Google Cloud Project with Drive API and Sheets API enabled
- Node.js LTS (v18+)
- Wrangler CLI (`npm install -g wrangler`)
Google Cloud Setup
- Create a project at Google Cloud Console
- Enable APIs:
- Google Drive API
- Google Sheets API
- Create OAuth 2.0 credentials:
- Type: Web application
- Redirect URIs: `https://your-worker.workers.dev/google/callback`
- Required OAuth scopes:
- `https://www.googleapis.com/auth/drive`
- `https://www.googleapis.com/auth/spreadsheets`
🔧 Installation & Deployment
1. Install Dependencies
```bash npm install ```
2. Create KV Namespaces
```bash
For user session tokens
wrangler kv:namespace create KV_TOKENS
For OAuth client registrations
wrangler kv:namespace create KV_CLIENTS ```
Copy the namespace IDs to `wrangler.toml`:
```toml [[kv_namespaces]] binding = "KV_TOKENS" id = "your-tokens-namespace-id"
[[kv_namespaces]] binding = "KV_CLIENTS" id = "your-clients-namespace-id" ```
3. Configure Environment Variables
Add to `wrangler.toml`:
```toml [vars] GOOGLE_CLIENT_ID = "your-client-id.apps.googleusercontent.com" ```
Set secrets:
```bash
Google OAuth client secret
wrangler secret put GOOGLE_CLIENT_SECRET ```
4. Deploy
```bash wrangler deploy ```
Your worker will be available at: `https://your-worker-name.your-account.workers.dev`
🔐 OAuth 2.0 Flow
This server implements a complete OAuth 2.0 authorization server per the MCP specification.
Using MCP Inspector
The easiest way to test the OAuth flow:
```bash npx @modelcontextprotocol/inspector https://your-worker.workers.dev/sse ```
- Discovery - Inspector auto-discovers OAuth endpoints
- Registration - Click "Guided Setup" → registers client automatically
- Authorization - Redirects to Google → authenticates → redirects back
- Token Exchange - Automatically exchanges code for access token
- Use Tools - All 11 tools now available!
Security Features
- ✅ PKCE (RFC 7636) - Proof Key for Code Exchange
- ✅ State Parameter - CSRF protection
- ✅ HTTPS Only - Enforced by Cloudflare Workers
- ✅ Secure Token Storage - Encrypted in Workers KV
- ✅ Token Expiration - Access tokens expire in 1 hour
- ✅ Client Secret Hashing - SHA-256 hashed storage
- ✅ Authorization Code Single-Use - Codes deleted after exchange
🛠️ Available Tools
Drive Tools
- `gdrive_search` - Basic search across all files
- `gdrive_search_advanced` - Advanced search with filters
- `gdrive_read_file` - Read files with 22+ export formats
- `gdrive_create_folder` - Create folders
- `gdrive_upload_file` - Upload files (up to 5MB)
- `gdrive_delete_file` - Move files to trash
- `gdrive_move_file` - Move files between folders
- `gdrive_add_permission` - Share files/folders
Sheets Tools
- `gsheets_read` - Read multiple ranges
- `gsheets_update_cell` - Update single cells
- `gsheets_append_row` - Append rows
🔌 Client Configuration
VS Code with MCP Extension
Create `.vscode/settings.json`:
```json { "mcp.servers": { "gdrive": { "url": "https://your-worker.workers.dev/sse", "authorization": { "type": "oauth2" } } } } ```
Claude Desktop / Cline
macOS/Linux: `~/Library/Application Support/Claude/claude_desktop_config.json`
Windows: `%APPDATA%\Claude\claude_desktop_config.json`
```json { "mcpServers": { "gdrive": { "url": "https://your-worker.workers.dev/sse" } } } ```
🧪 Testing
Local Development
```bash npm start
Server available at http://localhost:8788
```
Test with MCP Inspector
```bash npx @modelcontextprotocol/inspector http://localhost:8788/sse ```
Check CloudFlare Logs
```bash wrangler tail --format pretty ```
🐛 Troubleshooting
"Failed to discover OAuth metadata"
Solution:
- Ensure `/.well-known/oauth-authorization-server` returns valid JSON
- Check CORS headers are present
- Verify latest version is deployed: `wrangler deploy`
"Token exchange failed: HTTP 400"
Solutions:
- Check code_verifier matches original code_challenge
- Ensure redirect_uri exactly matches registration
- Verify client credentials are correct
- Check CloudFlare logs: `wrangler tail`
Tools not working
Solutions:
- Check Google OAuth scopes include `drive` and `spreadsheets`
- Re-authenticate if scopes changed: visit `/google/authorize`
- Verify Worker has valid Google access token
- Check KV namespace bindings in `wrangler.toml`
📊 Performance & Limits
| Resource | Limit | Notes |
|---|---|---|
| Request Timeout | 30 seconds | CloudFlare Workers limit |
| File Upload | 5 MB | Simple upload API limit |
| File Export | 10 MB | Google Drive export limit |
| Token Storage | 30 days | Automatic cleanup |
| Authorization Code | 10 minutes | Single-use |
| Access Token | 1 hour | Auto-refreshed |
🔒 Security Best Practices
- Never commit secrets - Use `wrangler secret put`
- Rotate client secrets - Periodically regenerate OAuth credentials
- Monitor access - Use CloudFlare Analytics to track usage
- Limit OAuth scopes - Only request necessary Google permissions
- Use PKCE - Always use PKCE for public clients
- Validate redirect URIs - Whitelist exact URIs in Google Console
- Enable 2FA - Protect your CloudFlare and Google accounts
📄 License
MIT License
🙏 Acknowledgments
- isaacphi/mcp-gdrive - Original STDIO implementation
- Model Context Protocol - MCP specification
- CloudFlare Workers - Serverless platform
Made with ☁️ by Brian Money
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。