gdrive-mcp-server
Enables MCP-compatible AI assistants to interact with a user's Google Drive, including listing, searching, reading, creating, updating, and deleting files, with authentication via Google OAuth.
README
Personal Google Drive — Remote MCP Server
A production-style remote Model Context Protocol (MCP) server that connects an MCP-compatible AI assistant to a Google Drive account. It runs serverlessly on Cloudflare Workers, authenticates users with Google OAuth 2.0, and exposes Drive as a small set of safe, well-typed tools the assistant can call.
The interesting part is the auth: this single Worker is both an OAuth server and an OAuth client at the same time. It issues tokens to the AI client and logs the user into Google — a pattern that shows up in almost every real "connect my app to a third-party API on the user's behalf" integration.
New here? Read the two guides in
docs/:
docs/SETUP_GUIDE.md— build and deploy it yourself, step by step.docs/HOW_IT_WORKS.md— the concepts (MCP, OAuth, serverless) explained from scratch.
What it does
Once connected, the assistant gains these tools:
| Tool | What it does |
|---|---|
whoami |
Reports which Google account is connected (a quick sanity check). |
list_files |
Lists the most recently modified files. |
search_files |
Searches by file name or full-text content. |
read_file |
Reads a file by id. Google Docs/Sheets/Slides are exported to text/CSV. |
create_file |
Creates a new file from text — including native Google Docs. |
update_file |
Replaces a file's contents and/or renames it. |
delete_file |
Moves a file to the Drive trash (recoverable, not a hard delete). |
Each tool is a thin, validated wrapper over the Google Drive REST API, called with the signed-in user's access token.
Architecture at a glance
OAuth server OAuth client
┌───────────┐ (issues tokens) ┌──────────────┐ (logs you in) ┌─────────┐
│ AI client │ ◀────────────────▶ │ This Worker │ ◀───────────────▶ │ Google │
└───────────┘ MCP over /sse └──────────────┘ Drive API └─────────┘
│
┌──────┴───────┐
│ Durable Obj │ holds the live MCP session
│ + KV (grants)│ stores OAuth grants/tokens
└──────────────┘
- The AI client connects to
/sse, finds it protected, and runs an OAuth flow against this Worker. - The Worker shows a one-time approval screen, then redirects the user to Google to sign in and consent.
- Google redirects back to
/callback; the Worker exchanges the code for a Google access token and stores it (with the user's name/email) as encrypted session state. - The MCP tools call the Google Drive API using that token, on the user's behalf.
Tech stack
- Cloudflare Workers — serverless runtime (deploys globally, scales to zero, free tier).
- Durable Objects — host the stateful MCP session.
- Workers KV — stores OAuth grants.
@cloudflare/workers-oauth-provider— turns the Worker into a spec-compliant OAuth server.agents/McpAgent— the MCP server framework.@modelcontextprotocol/sdk— the MCP types and server.- Hono — tiny router for the
/authorizeand/callbackendpoints. - Zod — runtime validation of every tool's inputs.
- TypeScript throughout.
Repository map
| File | Responsibility |
|---|---|
src/index.ts |
The MCP server, all Drive tools, and the OAuthProvider wiring. |
src/google-handler.ts |
The /authorize + /callback routes that talk to Google. |
src/utils.ts |
Google authorize-URL builder and authorization-code → token exchange. |
src/workers-oauth-utils.ts |
Signed-cookie approval dialog (reference helper). |
wrangler.jsonc |
Worker config: bindings, Durable Object, KV namespace. |
Quick start
Full instructions live in docs/SETUP_GUIDE.md. The short version:
npm install
npx wrangler login
npx wrangler kv namespace create OAUTH_KV # paste the id into wrangler.jsonc
npx wrangler secret put GOOGLE_CLIENT_ID
npx wrangler secret put GOOGLE_CLIENT_SECRET
npx wrangler secret put COOKIE_ENCRYPTION_KEY # value: openssl rand -hex 32
npm run deploy
Then add the printed https://<your-worker>.workers.dev/sse URL as a custom connector in any MCP-compatible client and sign in with Google.
Local development
cp .dev.vars.example .dev.vars # fill in the three values
npm run dev # http://localhost:8788
npx @modelcontextprotocol/inspector@latest # point it at http://localhost:8788/sse
Design notes & limitations
- Scope is configurable. The default requests the full
drivescope so the write tools work. Narrow it todrive.file(only files this app creates) ordrive.readonlyinsrc/google-handler.tsto reduce risk. - Token lifetime. Uses Google's short-lived access token (no refresh token yet), so a periodic re-connect is needed. Adding offline/refresh-token support is the natural next enhancement.
read_filehandles text. Plain-text files and exportable Google formats (Docs/Sheets/Slides) work; arbitrary binary files are out of scope.delete_filetrashes, it doesn't purge. Files go to Drive trash and remain recoverable.
License
MIT
推荐服务器
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 模型以安全和受控的方式获取实时的网络信息。