Google Shared Drive File Writer MCP Server
Allows writing and updating files in a Google Shared Drive target folder via the Google Drive API v3, with support for shared drive folders, subfolder aliases, conflict handling, and file creation/overwrite.
Google Shared Drive File Writer MCP Server
A Python Model Context Protocol (MCP) server engineered to run privately on Google Cloud Run and be invoked headlessly by Gemini Enterprise Workflow Builder scheduled workflows to write files directly into a Google Shared Drive folder—without triggering Human-in-the-Loop (HITL) review cards, 421 Invalid Host header rejections, or storageQuotaExceeded errors.
This is not an official Google product.
Problem Statement
The standard Google Drive connector in Gemini Enterprise requires human-in-the-loop confirmation for mutating operations. This prevents scheduled or background workflows from running completely headlessly when writing or updating files.
Related MCP server: google-mcp
Architecture & Design Highlights
flowchart TD
subgraph GEW["Gemini Enterprise Workflow"]
direction TB
Step1["Step 1: Gemini Agent\n- Generates report (Markdown/Text/CSV/JSON)\n- Drive 'Add or Update Data' connector toggled OFF"]
Step2["Step 2: Custom MCP Server Step (save_drive_file)\n- Input: ${gemini_agent.output}\n- readOnlyHint: true -> Headless execution (Zero HITL confirmation cards)"]
Step1 --> Step2
end
subgraph CR["Google Cloud Run (Private Service)"]
direction TB
FastMCP["FastMCP Server (/mcp)\n- StreamableHTTP transport\n- host='0.0.0.0' -> Cloud Run *.run.app Host header accepted (no 421)\n- Ingress: roles/run.invoker restricted to Discovery Engine SA\n- Runtime Identity: drive-file-writer@${PROJECT_ID}.iam.gserviceaccount.com"]
end
subgraph GSD["Google Shared Drive"]
direction TB
SharedDrive["Google Shared Drive Target Folder\n- Target Folder (DRIVE_FOLDER_ID or ALLOWED_SUBFOLDER_MAP alias)\n- Service account added as 'Contributor' (bypasses 0-byte personal SA quota)"]
end
Step2 -->|"HTTPS (X-Serverless-Authorization)\nservice-${GE_PROJECT_NUMBER}@gcp-sa-discoveryengine.iam.gserviceaccount.com"| FastMCP
FastMCP -->|"Google Drive API v3 (Application Default Credentials)\nsupportsAllDrives=True, includeItemsFromAllDrives=True"| SharedDrivesequenceDiagram
autonumber
participant GE as Gemini Enterprise Workflow
participant CR as Cloud Run (FastMCP /mcp)
participant GD as Google Drive API v3
participant SD as Google Shared Drive
Note over GE: Scheduled Workflow Trigger
GE->>GE: Step 1: Gemini Agent generates report content
GE->>+CR: Step 2: POST /mcp (save_drive_file)\nAuth: X-Serverless-Authorization (Discovery Engine SA)
Note over CR: Validates Host header (0.0.0.0) & checks folder allowlist
CR->>+GD: files.create / files.update (supportsAllDrives=true)\nAuth: ADC (drive-file-writer SA)
GD->>SD: Write report to target Shared Drive folder
GD-->>-CR: File metadata & webViewLink
CR-->>-GE: MCP Tool Result (status: 'created', file_id, web_view_link)
Note over GE: Headless completion (readOnlyHint=true, zero HITL pause)Why This Architecture Solves Key Pitfalls
Problem | Root Cause | Solution Implemented |
Workflow Pauses on HITL Card | Gemini Enterprise assumes all external MCP tool calls mutate external state unless declared read-only. | MCP tool explicitly declares |
HTTP 421 Misdirected Request |
| Initialized with |
| GCP service accounts have 0 bytes of personal Google Drive quota in "My Drive". | Target folder lives in a Google Shared Drive, service account is added as Contributor, and all calls use |
Security / Blast Radius | Arbitrary folder IDs passed by an LLM could overwrite unintended corporate data. | Server enforces a fail-closed allowlist ( |
Ingress Security | Exposing MCP servers publicly creates authentication attack surfaces. | Cloud Run is deployed with |
Project Structure
gdrive-mcp/
├── app/
│ ├── __init__.py
│ ├── config.py # Pydantic Settings (DRIVE_FOLDER_ID, ALLOWED_SUBFOLDER_MAP, etc.)
│ ├── drive_client.py # Encapsulated Google Drive v3 client with Shared Drive support
│ └── server.py # FastMCP StreamableHTTP server, /healthz route, and Uvicorn entrypoint
├── Dockerfile # Minimal non-root python:3.12-slim container
├── .dockerignore
├── deploy.sh # Parameterized deployment script for Cloud Run & IAM
├── pyproject.toml # Project metadata and test configuration
├── requirements.txt # Pinned production and test dependencies
└── README.mdEnvironment Variables Reference
Variable | Required | Default | Description |
| Yes |
| Primary Google Shared Drive target folder ID. |
| No |
| JSON string mapping aliases to approved folder IDs (e.g. |
| No |
| OAuth scope. Set to |
| No |
| Maximum allowed content size in bytes before rejecting the tool call. |
| No |
| Port for the HTTP server (set automatically by Cloud Run). |
| No |
| Logging level ( |
Prerequisites & Google Cloud Setup
1. Google Workspace Shared Drive Permissions (Critical)
GCP service accounts do not possess personal Drive storage quota (storageQuotaExceeded).
Open Google Drive and navigate to your Shared Drive (or create a new one).
Note the Folder ID from the URL (e.g.
https://drive.google.com/drive/folders/0AB1c2D3e4F5...-> ID is0AB1c2D3e4F5...).Click Manage members on the Shared Drive.
Add the runtime service account as a member:
drive-file-writer@<PROJECT_ID>.iam.gserviceaccount.comAssign the role: Contributor (allows adding and editing files) or Content manager.
2. Gemini Enterprise Organization Policy Prerequisites
If your organization restricts custom MCP servers or enforces VPC Service Controls:
Disable Custom MCP Connector Constraint: Ensure the organization policy
constraints/discoveryengine.disableCustomMcpServerConnectoris set to Enforce: Off (or overridden for your Gemini Enterprise project).VPC-SC / Egress Restrictions (if applicable): If egress controls are enforced, add
custom_mcptoallowedDataSourcesand add the Cloud Run FQDN (*.run.app) toallowedEgressFqdns.
Deployment to Google Cloud Run
The included deploy.sh script handles:
Creating the dedicated least-privilege service account
drive-file-writer@${PROJECT_ID}.iam.gserviceaccount.com(0 project-level IAM roles).Deploying the container to Cloud Run with
--no-allow-unauthenticated.Binding
roles/run.invokerto the Gemini Enterprise Discovery Engine service agent (service-<GE_PROJECT_NUMBER>@gcp-sa-discoveryengine.iam.gserviceaccount.com).
Deployment Command
# Set required deployment parameters
export PROJECT_ID="your-gcp-project-id"
export GE_PROJECT_NUMBER="your-gemini-enterprise-project-number"
export REGION="us-central1"
export DRIVE_FOLDER_ID="0AB1c2D3e4F5G6H7"
# Optional subfolder aliases
export ALLOWED_SUBFOLDER_MAP='{"monthly": "0AB1111", "finance": "0AB2222"}'
# Run deployment script
./deploy.shThe script will output the deployed service URL:
Service URL: https://ge-drive-file-mcp-xyz-uc.a.run.app
MCP Endpoint: https://ge-drive-file-mcp-xyz-uc.a.run.app/mcp
Health Check: https://ge-drive-file-mcp-xyz-uc.a.run.app/healthzGemini Enterprise Setup Guide
1. Register the Custom MCP Server in Gemini Enterprise
In the Google Cloud Console / Gemini Enterprise Admin Console, navigate to Connected Data Stores > Custom MCP Server.
Click Add Custom MCP Server.
Fill in the connection settings:
Name:
Google Shared Drive File WriterServer URL:
https://<service-name>-<hash>.a.run.app/mcpTransport:
Streamable HTTPAuthentication: No authentication (Do not select OAuth or Bearer Token: Cloud Run privately authenticates Gemini Enterprise automatically via the Discovery Engine service agent and IAM
roles/run.invoker)
Save and click Actions > Reload custom actions.
Toggle Enable actions for
save_drive_file.
2. Configure the Workflow Builder Canvas
Build a 2-step scheduled workflow in Gemini Enterprise Workflow Builder:
Step 1: Gemini Agent
Prompt: Prompts the model to synthesize the report, analytics, or summary table.
Tools: Ensure the built-in Drive Add Or Update Data action is toggled OFF (to prevent accidental personal drive writes or unexpected mutations).
Output: Generates report text (Markdown, plain text, CSV, or JSON).
Step 2: Custom MCP Server Step (save_drive_file)
Step Type: MCP Server Tool Call (
save_drive_file)Parameters:
file_name:${step_1.date}-weekly-summary.md(or static name)content:${step_1.output}output_format:"md"(or"txt","csv","json","google_doc")folder_alias:"monthly"(or leave blank to useDRIVE_FOLDER_ID)on_conflict:"overwrite"or"create_new"
Becausesave_drive_file advertises readOnlyHint: true, Gemini Enterprise executes Step 2 headlessly on scheduled triggers without halting for human review confirmation.
14-Day Schedule Credential Refresh: If Step 1 uses user-delegated credentials or connectors, Gemini Enterprise requires schedule credentials to be refreshed every 14 days per security policy. When Step 1 runs purely on the Gemini Agent and Step 2 calls the MCP server via the Discovery Engine service agent, runs execute uninterrupted.
Tool Specification: save_drive_file
Inputs
Parameter | Type | Required | Default | Description |
|
| Yes | — | Target file name (e.g. |
|
| Yes | — | UTF-8 file content produced by the workflow. |
|
| No |
| One of: |
|
| No |
| Optional alias looked up in |
|
| No |
|
|
Output (SaveDriveFileResult)
{
"status": "created",
"file_id": "1A2B3C4D5E6F7G8H9I0J",
"file_name": "2026-11-report.txt",
"mime_type": "text/plain",
"web_view_link": "https://drive.google.com/file/d/1A2B3C4D5E6F7G8H9I0J/view",
"folder_id": "0AB1c2D3e4F5G6H7"
}Gemini Enterprise Workflow Builder can reference these attributes downstream as ${save_drive_file.file_id} or ${save_drive_file.web_view_link}.
License
This project is licensed under the Apache License, Version 2.0. See LICENSE and NOTICE for details.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
This server cannot be deployed
Maintenance
Related MCP Connectors
Meta Ads MCP: bulk-create Facebook & Instagram ads across accounts from Drive folders, guardrailed.
Google Docs MCP Pack — read, create, and edit Google Docs via OAuth. Reuses the google_sheets…
Docs, decks, forms, apps you build and deploy, automations, and AI images, video and voice.
Spreadsheets that fill themselves from your emails and webhooks, the same way every time.
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceGoogle Drive + Workspace MCP — 98 tools for Docs, Sheets, Slides, Shared Drives, Labels, Approvals. Supports OAuth2 and Service Account + Domain-Wide Delegation.519 npm1MIT
- FlicenseNot gradedqualityCmaintenanceMCP server for Google Drive, Docs, and Sheets — built for Claude Code. Gives Claude Code direct read/write access to Google Sheets (cell-level edits, formatting, structure), Google Docs (insert, replace, append), and Drive (search).1-
- FlicenseNot gradedqualityNot gradedmaintenanceEnables Claude to update existing Google Drive files in place via a service account, preserving file ID, link, and revision history. Supports finding, creating, listing revisions, and updating files through a Streamable HTTP MCP server.-
- AlicenseAqualityDmaintenanceEnables Claude to search, list, and download files from any Google Drive folder shared with a service account, without OAuth or browser login.3MIT