mcp-google-sheets
repository·main·Indexed 21 days ago
https://github.com/xing5/mcp-google-sheetsA Python-based Model Context Protocol (MCP) server that integrates with Google Drive and Google Sheets via the Google Sheets API. It provides AI assistants with tools for automation, data manipulation, and CRUD operations, including reading/writing cell data, managing tabs, creating spreadsheets, and adding charts. Supports multiple authentication methods including Service Accounts, OAuth 2.0, and Application Default Credentials.
What's inside mcp-google-sheets
- mcp-google-sheets is a Python-based Model Context Protocol (MCP) server that acts as a bridge between MCP-compatible clients (such as Claude Desktop) and the Google Sheets API. It enables AI assistants to interact with Google Spreadsheets through a set of specialized tools for automation, data manipulation, and CRUD operations.
Reduce context usage with Tool Filtering
mainBy default, the server exposes 19 tools, consuming approximately 13,000 tokens. To save context window space in your AI conversations, you can enable only the specific tools you need using either a command-line argument or an environment variable.
Method 1: Using
--include-toolsargumentAdd the
--include-toolsflag followed by a comma-separated list of tool names to theargsarray in your client configuration.Method 2: Using
ENABLED_TOOLSenvironment variableSet the
ENABLED_TOOLSenvironment variable in your client configuration with a comma-separated list of tool names.Note: Tool names must be exact and contain no spaces.
{ "mcpServers": { "google-sheets": { "command": "uvx", "args": [ "mcp-google-sheets@latest", "--include-tools", "get_sheet_data,update_cells,list_spreadsheets,list_sheets" ], "env": { "SERVICE_ACCOUNT_PATH": "/path/to/credentials.json" } } } }Google Cloud Platform Setup Requirements
mainBefore using the MCP Google Sheets server, you must complete the following GCP configuration:
- Create/Select a GCP Project in the Google Cloud Console.
- Enable APIs: In the 'APIs & Services' -> 'Library' section, you must enable:
Google Sheets APIGoogle Drive API
- Configure Credentials: Choose an authentication method (Service Account is recommended).
Configure uvx with Application Default Credentials (ADC)
mainYou can use Google's Application Default Credentials (ADC) in two ways:
- Via Environment Variable: Set
GOOGLE_APPLICATION_CREDENTIALSto the path of your service account JSON. - Via gcloud CLI: If you have already authenticated via
gcloud, no environment variables are needed in the config.
Prerequisites for gcloud method:
- Run:
gcloud auth application-default login --scopes=https://www.googleapis.com/auth/cloud-platform,https://www.googleapis.com/auth/spreadsheets,https://www.googleapis.com/auth/drive - Set quota project:
gcloud auth application-default set-quota-project <project_id>
{ "mcpServers": { "google-sheets": { "command": "uvx", "args": ["mcp-google-sheets@latest"], "env": { "GOOGLE_APPLICATION_CREDENTIALS": "/path/to/service-account.json" } } } }- Via Environment Variable: Set
Configure uvx with CREDENTIALS_CONFIG (Base64 Service Account)
mainInstead of a file path, you can provide a Base64 encoded string of your service account configuration via the
CREDENTIALS_CONFIGenvironment variable.DRIVE_FOLDER_IDis still required for Service Account context.{ "mcpServers": { "google-sheets": { "command": "uvx", "args": ["mcp-google-sheets@latest"], "env": { "CREDENTIALS_CONFIG": "ewogICJ0eXBlIjogInNlcnZpY2VfYWNjb3VudCIsCiAgInByb2plY3RfaWQiOiAi...", "DRIVE_FOLDER_ID": "your_shared_folder_id_here" } } } }Configure mcp-google-sheets for Claude Desktop
mainTo use this MCP server with Claude Desktop, add a configuration block to your
claude_desktop_config.jsonunder themcpServerskey.Important for macOS Users: If you encounter a
spawn uvx ENOENTerror, you must use the absolute path to theuvxbinary (e.g.,/Users/yourusername/.local/bin/uvx) instead of justuvx.{ "mcpServers": { "google-sheets": { "command": "uvx", "args": ["mcp-google-sheets@latest"], "env": { "SERVICE_ACCOUNT_PATH": "/full/path/to/your/service-account-key.json", "DRIVE_FOLDER_ID": "your_shared_folder_id_here" } } } }Configure uvx with OAuth 2.0
mainUse OAuth 2.0 if you want to act as a specific user. You must provide the path to your
credentials.jsonand atoken.jsonfile.Note: A browser window may open for Google login during the first use. Ensure the
TOKEN_PATHdirectory is writable.{ "mcpServers": { "google-sheets": { "command": "uvx", "args": ["mcp-google-sheets@latest"], "env": { "CREDENTIALS_PATH": "/full/path/to/your/credentials.json", "TOKEN_PATH": "/full/path/to/your/token.json" } } } }Configure local development environment
mainIf you are developing the server from a cloned repository, use
uv runwith the--directoryflag to point to the project root.{ "mcpServers": { "mcp-google-sheets-local": { "command": "uv", "args": [ "run", "--directory", "/path/to/your/mcp-google-sheets", "mcp-google-sheets" ], "env": { "SERVICE_ACCOUNT_PATH": "/path/to/your/mcp-google-sheets/service_account.json", "DRIVE_FOLDER_ID": "your_drive_folder_id_here" } } } }Quick Start with uvx
mainThe fastest way to run the server is using
uvx, which automatically downloads and runs the latest version.Prerequisites
- Google Cloud Setup: You must configure Google Cloud Platform credentials and enable the necessary APIs. Using a Service Account is strongly recommended.
- Install
uv:uvxis part of theuvpackage manager.
Installation Steps
1. Install
uv- macOS / Linux:
curl -LsSf https://astral.sh/uv/install.sh | sh - Windows:
powershell -c "irm https://astral.sh/uv/install.ps1 | iex" - via pip:
pip install uv
2. Set Environment Variables (Service Account method) Replace the placeholders with your actual service account JSON path and Google Drive folder ID.
- Linux/macOS:
export SERVICE_ACCOUNT_PATH="/path/to/your/service-account-key.json" export DRIVE_FOLDER_ID="YOUR_DRIVE_FOLDER_ID" - Windows CMD:
set SERVICE_ACCOUNT_PATH="C:\path\to\your\service-account-key.json" set DRIVE_FOLDER_ID="YOUR_DRIVE_FOLDER_ID" - Windows PowerShell:
$env:SERVICE_ACCOUNT_PATH = "C:\path\to\your\service-account-key.json" $env:DRIVE_FOLDER_ID = "YOUR_DRIVE_FOLDER_ID"
3. Run the Server
uvx mcp-google-sheets@latest4. Connect your MCP Client Configure your client (e.g., Claude Desktop) to launch the server. It is recommended to run the command manually once to verify the setup works.
uvx mcp-google-sheets@latestConfigure uvx with Service Account (Recommended)
mainThe recommended way to run the server is using a Google Service Account. You must provide the path to your service account JSON key and a
DRIVE_FOLDER_IDto provide context for the files the service account can access.macOS Note: Use the full path to
uvxif the command is not found.{ "mcpServers": { "google-sheets": { "command": "uvx", "args": ["mcp-google-sheets@latest"], "env": { "SERVICE_ACCOUNT_PATH": "/full/path/to/your/service-account-key.json", "DRIVE_FOLDER_ID": "your_shared_folder_id_here" } } } }Configure Authentication for mcp-google-sheets
mainThe server requires Google credentials to access Sheets and Drive. You can choose from four authentication methods depending on your environment. The server checks for credentials in the following priority order:
CREDENTIALS_CONFIG(Base64 encoded JSON content)SERVICE_ACCOUNT_PATH(Path to Service Account JSON)CREDENTIALS_PATH(Path to OAuth JSON)- Application Default Credentials (ADC) (Automatic fallback)
Method A: Service Account (Recommended for Servers/Automation)
Best for headless environments.
- Create a Service Account in the GCP Console and download the JSON key.
- Create a folder in Google Drive and note its Folder ID.
- Share the folder with the Service Account's
client_emailand grant Editor access. - Set
SERVICE_ACCOUNT_PATH(path to JSON) andDRIVE_FOLDER_ID.
Method B: OAuth 2.0 (Interactive / Personal Use)
Best for local development where a browser login is acceptable.
- Configure an OAuth consent screen in GCP with
.../auth/spreadsheetsand.../auth/drivescopes. - Create an OAuth client ID (Desktop app type) and download the JSON.
- Set
CREDENTIALS_PATH(path to JSON) andTOKEN_PATH(where to save the refresh token).
Method C: Direct Credential Injection (Advanced)
Best for Docker, Kubernetes, or CI/CD to avoid managing secret files.
- Convert your credentials JSON file to a Base64 string.
- Set the
CREDENTIALS_CONFIGenvironment variable to that Base64 string.
Method D: Application Default Credentials (ADC)
Best for Google Cloud environments (GKE, Compute Engine, etc.).
- Use
gcloud auth application-default loginlocally with required scopes. - Or, set the standard
GOOGLE_APPLICATION_CREDENTIALSenvironment variable. - Or, attach a service account to your Google Cloud resource.
# Example: Service Account setup export SERVICE_ACCOUNT_PATH="/path/to/service-account.json" export DRIVE_FOLDER_ID="your_folder_id_here" # Example: OAuth 2.0 setup export CREDENTIALS_PATH="/path/to/credentials.json" export TOKEN_PATH="/path/to/token.json # Example: Direct Injection (Base64) export CREDENTIALS_CONFIG="ewogICJ0eXBlIjogInNlcnZpY2VfYWNjb..."Run the mcp-google-sheets server
mainDepending on your use case, you can run the server using
uvx, local development mode, or Docker.Using
uvx(Recommended for Users)This is the easiest method for most users. It fetches and runs the package temporarily.
For Development (Cloning the Repo)
If you need to modify the source code:
- Clone the repository.
- Set your authentication environment variables.
- Run using
uv run.
Using Docker (SSE transport)
To run the server in a container using SSE (Server-Sent Events) transport. It is recommended to use
CREDENTIALS_CONFIG(Base64) in Docker to avoid mounting files.# Quick Start with uvx uvx mcp-google-sheets@latest # Development mode git clone https://github.com/yourusername/mcp-google-sheets.git && cd mcp-google-sheets uv run mcp-google-sheets # Docker (SSE on port 8000) docker build -t mcp-google-sheets . docker run --rm -p 8000:8000 \ -e HOST=0.0.0.0 \ -e PORT=8000 \ -e CREDENTIALS_CONFIG=YOUR_BASE64_CREDENTIALS \ -e DRIVE_FOLDER_ID=YOUR_DRIVE_FOLDER_ID \ mcp-google-sheets