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
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.
E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.