googledrive-mcp-server
v2.4.0Model Context Protocol (MCP) server for Google Drive API
An MCP server providing secure Google Drive access to AI assistants using Least Privilege Key Authentication, Application Default Credentials (ADC), and Service Account Impersonation. Add to your MCP client configuration (e.g., claude_desktop_config.json, mcp_config.json, or Cursor): List files and folders in Google Drive within configured boundaries.
Summary extracted from the README.
π Google Drive MCP Server (Least Privilege Key)
Enterprise-grade Google Drive integration for AI assistants β seamless Shared Drive boundary control, Least Privilege Key Authentication, and real-time audit logging for Gemini, Claude, Cursor, and more.
An MCP server providing secure Google Drive access to AI assistants using Least Privilege Key Authentication, Application Default Credentials (ADC), and Service Account Impersonation.
β‘ Quick Start
Add to your MCP client configuration (e.g., claude_desktop_config.json, mcp_config.json, or Cursor):
{
"mcpServers": {
"googledrive": {
"command": "npx",
"args": ["-y", "@hydrochlorix/googledrive-mcp-server"],
"env": {
"GOOGLE_DRIVE_SHARED_DRIVE_ID": "<YOUR_SHARED_DRIVE_ID>",
"GOOGLE_DRIVE_ROOT_FOLDER_ID": "<OPTIONAL_ROOT_FOLDER_ID>"
}
}
}
}
[!CAUTION] MANDATORY BOUNDARY (v2.3.0+)
GOOGLE_DRIVE_SHARED_DRIVE_IDis MANDATORY. The server will refuse to start without a configured Shared Drive boundary.GOOGLE_DRIVE_ROOT_FOLDER_IDis optional for further narrowing the boundary.[!WARNING] STRUCTURED OPERATION LOGGING (v2.4.0+) Direct
console.error()calls have been eliminated. All process lifecycle events and crash tracebacks are written to a persistent NDJSON file at~/.mcp/logs/operation.logwith clean[LEVEL] messageoutput onstderr. Raw OAuth JSON responses (invalid_grant,invalid_rapt) are automatically sanitized into human-readable messages with actionablehintremediation steps.
β¨ Features
- π‘οΈ Least Privilege Key Security: Supports Service Account JSON keys alongside Application Default Credentials (ADC) while strongly enforcing Drive and Root Folder boundaries.
- π― Two-Layer Boundary Control: Combined mandatory Shared Drive boundary with an optional narrower Root Folder boundary (
GOOGLE_DRIVE_ROOT_FOLDER_ID). - π’ Google Workspace Shared Drive Support: Full support for enterprise Shared Drives (
supportsAllDrives: true) for 24/7 automation. - π Structured Operation Logger: Machine-readable NDJSON process log (
~/.mcp/logs/operation.log) with crash reporting, zero-dependency sync durability, and automatic credential sanitization. - π Automatic Local Destination Folders: Missing local directory structures are created automatically when downloading files.
- π Auto-Text Workspace Docs Export: Automatically converts Google Workspace Docs/Sheets to plain text (
text/plain) for immediate consumption by LLMs. - π Real-time Audit Dashboard: Built-in SQLite WAL logger (
~/.mcp/audit.db), REST API, SSE streaming, and a glassmorphism web SPA dashboard (defaulthttp://127.0.0.1:3001). - π Read-only Enforcement: Option to restrict tool registration to read-only tools via
GOOGLE_DRIVE_MODE="readonly".
π‘ Why @hydrochlorix/googledrive-mcp-server?
| Feature | Legacy SA Key JSON | OAuth 2.0 Client Secret | @hydrochlorix/googledrive-mcp-server |
|---|---|---|---|
| Authentication | Long-lived Private Key | User Refresh Tokens | Least Privilege Key / ADC / Impersonation |
| Credentials on Disk | β οΈ High Risk (.json) |
β οΈ Plaintext Tokens | β Supported (Keyless or Key-based) |
| Shared Drive Support | Partial | Partial | β Full Enterprise Support |
| Boundary Guardrail | β None | β None | β Shared Drive + Root Folder Boundary |
| Audit & Logging | β Console Log | β Console Log | β Embedded Dashboard & SQLite Engine |
| Read-Only Mode | β Manual Code Edit | β Scope Editing | β Environment Variable (GOOGLE_DRIVE_MODE) |
ποΈ How It Works
AI Assistant (e.g. Gemini / Claude / Cursor)
β MCP Protocol (stdio)
βΌ
googledrive-mcp-server (Node.js Process)
β Google Auth Application Default Credentials (ADC)
βΌ
Google Cloud IAM (Service Account Impersonation)
β Short-Lived Access Token (OAuth2)
βΌ
Google Drive API v3 (Shared Drive Boundary Enforcement)
π οΈ Tools
1. drive_list_files (Read)
List files and folders in Google Drive within configured boundaries.
pageSize(number, optional): Maximum number of items to return (1-100, default: 10).query(string, optional): Search query string (e.g.name contains 'Report').
2. drive_download_file (Read)
Download a file from Google Drive to local disk.
fileId(string, required): The ID of the file to download.destPath(string, required): Local file path where the file will be saved. Missing parent directories are created automatically.
3. drive_download_file_from_url (Read)
Download a file using a public/shared Google Drive URL.
url(string, required): Full Google Drive shareable link.destPath(string, required): Local file destination path.
4. drive_create_folder (Write)
Create a new folder inside Google Drive.
name(string, required): Name of the folder.parentId(string, required): Parent folder ID within boundary.
5. drive_upload_text_file (Write)
Upload a text file to Google Drive.
name(string, required): File name.content(string, required): Text file contents.parentId(string, required): Parent folder ID within Shared Drive.
Note: Setting GOOGLE_DRIVE_MODE="readonly" hides write tools (drive_create_folder, drive_upload_text_file).
π Setup & Authentication (3 Steps)
Step 1: One-Time Google Cloud IAM Setup
gcloud config set project <PROJECT_ID>
gcloud services enable drive.googleapis.com iamcredentials.googleapis.com --project="<PROJECT_ID>"
# Grant Impersonation Permission to your user account
gcloud iam service-accounts add-iam-policy-binding <SERVICE_ACCOUNT_EMAIL> \
--member="user:<YOUR_WORKSPACE_EMAIL>" \
--role="roles/iam.serviceAccountTokenCreator" \
--project="<PROJECT_ID>"
Step 2: Configure Shared Drive Permissions
Add your Service Account email (<SERVICE_ACCOUNT_EMAIL>) as a member of your target Google Workspace Shared Drive (Viewer for read-only, Contributor for write access).
Step 3: Authenticate (Choose A or B)
Option A: Local Desktop (ADC / Impersonation) Run Application Default Credentials (ADC) login with impersonation:
# Desktop (GUI)
gcloud auth application-default login --impersonate-service-account="<SERVICE_ACCOUNT_EMAIL>"
# Headless (WSL / SSH)
gcloud auth application-default login --no-browser --impersonate-service-account="<SERVICE_ACCOUNT_EMAIL>"
Verify setup:
gcloud auth application-default print-access-token
Option B: Server / 24-7 Headless (Least Privilege Key) For servers where session controls cause ADC to expire daily, use a Service Account JSON Key:
- Ensure your Service Account has no project-level IAM roles (this enforces Least Privilege). It only needs to be invited directly to the target Google Workspace Shared Drive.
- Download the JSON key file to your server.
- Set the environment variable in your MCP client config or shell:
export GOOGLE_APPLICATION_CREDENTIALS="/absolute/path/to/service-account-key.json"
π Real-Time Audit & Governance Dashboard
Logs all MCP tool calls to SQLite (~/.mcp/audit.db) with zero performance overhead.
- Dashboard Web UI:
http://127.0.0.1:3001?token=<TOKEN> - REST Logs API:
GET http://127.0.0.1:3001/api/audit/logs - SSE Stream:
GET http://127.0.0.1:3001/api/audit/stream - Environment Options:
MCP_DASHBOARD_ENABLED=falseβ Disable dashboard server.MCP_DASHBOARD_PORT=3001β Change HTTP port.MCP_DASHBOARD_TOKEN=<CUSTOM_TOKEN>β Set authentication token.
- Generate Token: Run
npx -- @hydrochlorix/googledrive-mcp-server --gen-token(or locally:npm run build && node dist/server.mjs --gen-token) to securely generate a 256-bit token.
π» Development & Testing
- Development Mode:
npm run dev - Build Production:
npm run build - Run Full Suite (Lint, Build & All Tests):
npm run test:all - Run Unit Tests:
npm test - Run Dashboard & Security Tests:
npm run test:dashboard
β Troubleshooting
insufficient authentication scopesor 401/403 Permission Denied: Re-rungcloud auth application-default login --impersonate-service-account="<SERVICE_ACCOUNT_EMAIL>"(add--no-browserfor headless/WSL).invalid_raptReauthentication Error / Token Expiration: Token expiration is typically governed by your Google Workspace Admin's Session Control policies.- Local/Desktop: Perform a clean reset using
gcloud auth revoke --allfollowed bygcloud auth application-default login --impersonate-service-account="<SERVICE_ACCOUNT_EMAIL>". - Server/Headless: If you need 24/7 uptime without manual re-auth, you may use a Service Account JSON Key as a fallback (ADR-0011) by setting
export GOOGLE_APPLICATION_CREDENTIALS="/path/to/key.json".
- Local/Desktop: Perform a clean reset using
- Service Account Storage Quota Error: Service accounts do not have personal Drive storage quota. Ensure uploads target a Google Workspace Shared Drive.
π Support
If this project helped you, please consider supporting its development!
π License
Distributed under the MIT License.