Restore gdrive server with search file ID fix and download tool #3302
+967
−2
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