Google Sheets MCP Server
This MCP server provides tools to interact with Google Sheets, allowing you to read, write, and update data in your spreadsheets.
Prerequisites
- Python 3.8 or higher
- Google Cloud Platform account
- A Google Sheet that you want to interact with
Installation
- Clone this repository:
git clone <your-repository-url>
cd mcp-server-demo
- Install the required packages:
pip install google-auth-oauthlib google-auth-httplib2 google-api-python-client
- Download and place credentials.json:
- Download the
credentials.jsonfile from your Google Cloud Console - Place the
credentials.jsonfile in the same directory asmain.py - Make sure the file is named exactly
credentials.json
- Download the
Setting up Google Cloud Platform Credentials
-
Go to the Google Cloud Console
-
Create a new project or select an existing one
-
Enable the Google Sheets API:
- Go to "APIs & Services" > "Library"
- Search for "Google Sheets API"
- Click "Enable"
-
Create credentials:
- Go to "APIs & Services" > "Credentials"
- Click "Create Credentials" > "Service Account"
- Fill in the service account details:
- Name: Choose a descriptive name
- ID: Will be auto-generated
- Description: Optional description
- Click "Create and Continue"
- For Role, select "Editor" (or appropriate role for your needs)
- Click "Continue" and then "Done"
-
Create and download the key:
- In the service account list, click on your newly created account
- Go to the "Keys" tab
- Click "Add Key" > "Create new key"
- Choose "JSON" format
- Click "Create"
- The JSON file will be downloaded automatically
-
Save the credentials:
- Rename the downloaded JSON file to
credentials.json - Place it in the
mcp-server-demodirectory
- Rename the downloaded JSON file to
-
Share your Google Sheet:
- Open your Google Sheet
- Click the "Share" button
- Add the service account email (found in the
client_emailfield of yourcredentials.json) - Give it "Editor" access
Running the Server
- Install the MCP server:
uv run mcp install main.py
- The server will start and be ready to accept commands.
Adding to Cursor
To add this MCP server to Cursor, follow these steps:
- Open Cursor
- Go to Cursor -> Preferences -> Cursor Settings -> MCP -> Add new global MCP Server
- Add the following configuration to your Cursor config file:
{
"mcpServers": {
"GoogleSheets": {
"command": "python",
"args": [
"main.py"
]
}
}
}
- Restart Cursor for the changes to take effect
Screenshots
Available Tools
List Spreadsheets
/tool list_spreadsheets
Lists all spreadsheets shared with the service account.
Get Spreadsheet Info
/tool get_spreadsheet_info "spreadsheet_id"
Gets information about a specific spreadsheet.
Get Sheet Content
/tool get_sheet_content "spreadsheet_id"
Retrieves the content of a specific sheet.
Generate Sheet Data
/tool generate_sheet_data "spreadsheet_id" number_of_records
Generates realistic data based on the sheet's attributes.
Add Data to Sheet
/tool add_data_to_sheet "spreadsheet_id" "data_string"
Adds pre-generated data to a sheet.
Update Sheet Record
/tool update_sheet_record "spreadsheet_id" "identifier" "updates"
Updates a record in the sheet based on id or name matching.
Data Formats
For Adding Data
The data string can be in one of these formats:
- List of lists format:
[["value1", "value2"], ["value3", "value4"]] - CSV format:
value1,value2
value3,value4
For Updates
Provide the changes in format: column1=value1 column2=value2
Example: age=25 [email protected] phone=1234567890
Security Notes
- Never commit
credentials.jsonto version control - Keep your credentials secure
- Only share your Google Sheet with necessary service accounts
- Regularly rotate your credentials
Troubleshooting
Common Issues
-
Authentication Errors
- Ensure the service account email has been added as an editor to the spreadsheet
- Verify that the
credentials.jsonfile is valid and not corrupted - Check if the Google Sheets API is enabled in your Google Cloud project
-
Permission Errors
- Make sure the service account has the correct permissions
- Verify the spreadsheet is shared with the service account email
- Check if the spreadsheet ID is correct
-
Data Format Errors
- Ensure the data format matches the expected structure
- Check if the sheet has the required columns (id or name)
- Verify the number of columns in the data matches the sheet
Support
If you encounter any issues or have questions, please:
- Check the error messages in the logs
- Verify your setup following the instructions above
- Ensure all prerequisites are met
- Contact [email protected]
Recommend MCP Servers 💡
antymijaljevic/k8s-doc-mcp
A Kubernetes documentation assistant MCP server that fetches and converts docs to Markdown and provides recommendations.
glean-mcp-server
An MCP server implementation integrating Glean API for Search and Chat functions.
@riza-io/riza-mcp
The Riza MCP server wraps the Riza API to provide an isolated code interpreter for LLM-generated code, exposing functionalities like creating, fetching, executing, editing, and listing tools, as well as executing arbitrary code safely.
keep-mcp
MCP server for Google Keep
github-actions-mcp-server
MCP Server for GitHub Actions API, enabling AI assistants to manage workflows
exa-mcp-server
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches.