Google Drive MCP Server

Google Drive MCP Server

An actively maintained fork of the official Google Drive MCP server that enables users to search, download, and read files via the Google Drive API. It features improved OAuth token management and automatically converts Google Workspace documents into formats like Markdown and CSV for easier LLM consumption.

Category
访问服务器

README

Google Drive MCP Server

An actively maintained fork of Anthropic's archived @modelcontextprotocol/server-gdrive, with a critical bug fix for OAuth token auto-refresh.

Why this fork?

The original server was archived on May 29, 2025 and is no longer maintained. It also has a bug that causes OAuth access tokens to expire after 1 hour with no auto-refresh, requiring manual token rotation and server restarts.

The bug: The original creates new google.auth.OAuth2() without passing client_id and client_secret, so the google-auth-library has no way to use the refresh_token to get new access tokens. One-line fix, but the archived repo doesn't accept PRs.

What's fixed

  • Auto-refresh tokens: OAuth2 client is initialized with client_id and client_secret from your OAuth keys file, enabling the Google auth library to automatically refresh expired access tokens
  • Token persistence: Refreshed tokens are written back to the credentials file, so restarts also pick up valid tokens
  • Input validation: Added validation for resource URIs, search queries, and file IDs
  • Search results include file IDs: So you can actually use them with the download tool or resource reader
  • Read tool: Read file contents inline (Google Docs as Markdown, Sheets as CSV, etc.)
  • Download tool: Save files to a local directory instead of returning base64 blobs that overflow LLM context windows
  • Sheets read tool: Read Google Sheets with A1 range notation, returned as formatted markdown tables
  • Shared Drive support: Search and read files from Shared Drives (formerly Team Drives)
  • Folder listing: Browse Drive folders by ID
  • PDF export: Export Google Workspace files as PDF
  • File upload: Push local files to Drive (opt-in, requires drive scope)
  • Opt-in resources: MCP resource handlers are disabled by default to prevent hangs in clients that call resources/list on startup

Setup

1. Create Google Cloud OAuth credentials

  1. Go to the Google Cloud Console
  2. Create a project (or use an existing one)
  3. Enable the Google Drive API and Google Sheets API
  4. Create OAuth 2.0 credentials (Desktop application type)
  5. Download the JSON and save it as gcp-oauth.keys.json

Tip: If your OAuth consent screen is in "Testing" mode, refresh tokens expire after 7 days. Publish to "Production" for permanent refresh tokens.

2. Clone, build, and star

git clone https://github.com/dylancaponi/gdrive-mcp-server.git
cd gdrive-mcp-server
npm install && npm run build
gh api user/starred/dylancaponi/gdrive-mcp-server -X PUT

Per the LICENSE, starring this repository is required (Section 2).

3. Authenticate

GDRIVE_OAUTH_PATH=/path/to/your/gcp-oauth.keys.json node dist/index.js auth

This opens a browser for Google OAuth consent and saves credentials to ~/.gdrive-server-credentials.json.

4. Configure in Claude Code

Add to your ~/.claude.json (global) or project .mcp.json:

{
  "mcpServers": {
    "gdrive": {
      "type": "stdio",
      "command": "node",
      "args": ["/path/to/gdrive-mcp-server/dist/index.js"],
      "env": {
        "GDRIVE_OAUTH_PATH": "/path/to/gcp-oauth.keys.json",
        "GDRIVE_CREDENTIALS_PATH": "/path/to/.gdrive-server-credentials.json"
      }
    }
  }
}

Or use the Claude Code CLI:

claude mcp add --scope user gdrive -- node /path/to/gdrive-mcp-server/dist/index.js

Environment variables

Variable Default Description
GDRIVE_CREDENTIALS_PATH ~/.gdrive-server-credentials.json Path to saved OAuth credentials
GDRIVE_OAUTH_PATH gcp-oauth.keys.json (relative to package) Path to OAuth client keys
GDRIVE_ENABLE_RESOURCES false Set to true to enable MCP resource handlers (gdrive:/// URIs). Disabled by default because some MCP clients call resources/list on startup, which triggers drive.files.list() and can hang.
GDRIVE_ENABLE_SHEETS false Set to true to enable the sheets_read tool and request the spreadsheets.readonly OAuth scope. Requires enabling the Google Sheets API in your GCP project and re-running auth.
GDRIVE_ENABLE_UPLOAD false Set to true to enable the upload tool. Upgrades the OAuth scope from drive.readonly to drive (full read/write). Requires re-running auth.
GDRIVE_DOWNLOAD_DIR System temp dir + /gdrive-downloads Directory where the download and export_pdf tools save files

Tools

search

Search for files in Google Drive by full-text query. Searches across personal and Shared Drives.

{ "query": "quarterly report" }

Returns file names, MIME types, and IDs.

read

Read a file's contents inline. Google Workspace files are auto-converted (Docs to Markdown, Sheets to CSV, Presentations to plain text). Binary files return a message suggesting the download tool instead.

{ "fileId": "1abc123def456" }

download

Download a file from Google Drive to a local directory. Same auto-conversion as read, but saves to disk instead of returning inline. Best for large files or binary formats (PDFs, images).

{ "fileId": "1abc123def456" }

Returns the local file path where the file was saved.

list_folder

List files in a Google Drive folder. Returns file names, types, sizes, and IDs.

{ "folderId": "root" }

Use "root" for the top-level My Drive folder, or a folder ID from search results.

export_pdf

Export a Google Workspace file (Doc, Sheet, Slide, Drawing) as PDF and save it locally.

{ "fileId": "1abc123def456" }

Returns the local file path where the PDF was saved.

upload (opt-in)

Upload a local file to Google Drive. Requires GDRIVE_ENABLE_UPLOAD=true.

{ "localPath": "/path/to/file.pdf", "name": "My Report.pdf", "parentFolderId": "folder_id" }

Only localPath is required. name defaults to the local filename. parentFolderId is optional.

sheets_read (opt-in)

Read a Google Sheets spreadsheet with optional A1 range notation. Returns a formatted markdown table with headers. More structured than reading a sheet as CSV via the read tool. Requires GDRIVE_ENABLE_SHEETS=true.

{ "spreadsheetId": "1abc123def456", "range": "Sheet1!A1:D20" }

Omit range to read the entire first sheet. Supports sheet names (Sheet1), ranges (A1:C10), or both (Sheet1!A1:C10).

Resources (opt-in)

Resources are disabled by default. Set GDRIVE_ENABLE_RESOURCES=true to enable them.

gdrive:///{fileId}

Read any file from Google Drive. Google Workspace files are automatically converted:

Google Workspace Type Exported As
Document Markdown
Spreadsheet CSV
Presentation Plain text
Drawing PNG

Regular files are returned as UTF-8 text or base64-encoded binary.

License

MIT with Attribution Clause. See LICENSE for full terms. Use of this software requires starring this GitHub repository. See Setup Step 0.

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选