Restore gdrive server with search file ID fix and download tool#3302
Open
aaronpolhamus wants to merge 5 commits intomodelcontextprotocol:mainfrom
Open
Restore gdrive server with search file ID fix and download tool#3302aaronpolhamus wants to merge 5 commits intomodelcontextprotocol:mainfrom
aaronpolhamus wants to merge 5 commits intomodelcontextprotocol:mainfrom
Conversation
The gdrive server was archived in May 2025, but it has two critical issues for LLM workflows: 1. Search results discard file IDs — the Drive API returns them but the output only includes file name and MIME type, making it impossible to act on search results programmatically. 2. Binary files (PDFs, images) can only be read via the resource handler, which returns base64 blobs that overflow LLM context windows. This commit restores the server from the pre-archive state and applies: - Search output now includes file IDs as `[id:...]` in results - New `download` tool that saves files to a local temp directory (configurable via GDRIVE_DOWNLOAD_DIR env var) instead of returning base64 blobs, enabling LLMs to read files with native tools - Google Workspace files are auto-exported (Docs→MD, Sheets→CSV, etc.) - Standalone tsconfig.json (no longer depends on root tsconfig) - Version bump to 0.7.0 Prior community PRs modelcontextprotocol#1092 and modelcontextprotocol#1353 attempted similar improvements but were closed when the server was archived. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Google Drive timestamps use U+202F (narrow no-break space) and other Unicode whitespace in file names (e.g., "11:59 AM"). The previous regex only stripped ASCII special characters, causing filenames with invisible Unicode characters that break path resolution in LLM tools. Extend the sanitization regex to also replace: - U+00A0 (no-break space) - U+202F (narrow no-break space) - U+2000-U+200A (typographic spaces) - U+2028-U+2029 (line/paragraph separators) - U+205F (medium mathematical space) - U+3000 (ideographic space) - U+FEFF (BOM / zero-width no-break space) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…constructor The server was creating `new google.auth.OAuth2()` without client_id or client_secret, which meant the refresh_token was unusable once the access_token expired. Google's token endpoint returned `invalid_request` because the refresh grant requires client credentials. Now reads client_id/client_secret from the OAuth keys file (same file used for the initial auth flow) and passes them to the OAuth2 constructor, enabling automatic token refresh. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Some MCP clients (e.g., Gemini CLI) call resources/list during initialization, which triggers drive.files.list() and can hang or timeout. Default to tools-only mode (search + download) for cross-client compatibility. Set GDRIVE_ENABLE_RESOURCES=true to re-enable the ListResources/ReadResource handlers. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
src/gdrive/server (removed in May 2025)files(id, name, mimeType, ...)but the output only included name and MIME type, making results unusable for downstream operationsdownloadtool that saves files to a local temp directory instead of returning base64 blobs via the resource handler, which overflow LLM context windowsnew google.auth.OAuth2()without client credentials, so the refresh_token was unusable once the access_token expired (~1 hour). Now reads client_id/secret from the OAuth keys file.GDRIVE_ENABLE_RESOURCESenv var — some MCP clients (e.g., Gemini CLI) callresources/listduring initialization, which triggersdrive.files.list()and can hang. Default is tools-only mode (search + download) for cross-client compatibility.Motivation
The gdrive server is essential for LLM workflows that need to search and read Drive files (especially PDFs, images, and other binary formats). Two prior community PRs attempted similar improvements:
Both were closed when the server was archived. The underlying issues remain: without file IDs in search output, clients can't act on results; without a download tool, binary files either overflow context (base64 blobs) or are inaccessible.
Changes
1. Search output includes file IDs
2. New
downloadtoolfileId(from search results) and saves the file to a local directoryGDRIVE_DOWNLOAD_DIRenv var (default:/tmp/gdrive-downloads)3. OAuth token auto-refresh fix
The original server created
new google.auth.OAuth2()withoutclient_idorclient_secret. This meant therefresh_tokenin the stored credentials was unusable — when the access token expired (~1 hour), Google's token endpoint returnedinvalid_requestbecause the refresh grant requires client credentials. Now readsclient_id/client_secretfrom the same OAuth keys file used during the initial auth flow (GDRIVE_OAUTH_PATH) and passes them to theOAuth2constructor.4. MCP resources opt-in (
GDRIVE_ENABLE_RESOURCES)Some MCP clients invoke
resources/listduring initialization, which triggersdrive.files.list()and can hang or timeout. Resources are now disabled by default — the server advertises onlytoolscapability. SetGDRIVE_ENABLE_RESOURCES=trueto re-enableListResourcesandReadResourcehandlers.This is a clean capability negotiation: the server honestly advertises what it supports based on the env var, and the MCP SDK validates that handlers match declared capabilities.
5. Standalone build
tsconfig.jsonis self-contained (no longer extends root tsconfig)Test plan
npm run buildsearchreturns file IDs in output format[id:...]downloadsaves binary files (PDFs) to local temp directorydownloadexports Google Docs as markdownGDRIVE_ENABLE_RESOURCES)GDRIVE_ENABLE_RESOURCES=true)Notes
We've been running these fixes in production for Claude Code and Gemini CLI MCP workflows (searching and reading ~300 signed compliance PDFs on Google Drive). Happy to maintain this server going forward.
Contact: aaron@mivest.io
🤖 Generated with Claude Code