Xinotrix-Home/google-sheets-mcp-server
If you are the rightful owner of google-sheets-mcp-server and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to henry@mcphub.com.
A Model Context Protocol (MCP) server for managing Google Sheets operations, providing tools for creating, reading, updating, and deleting spreadsheets, sheets, and rows.
Google Sheets MCP Server
A Model Context Protocol (MCP) server for Google Sheets operations. This server provides comprehensive tools for managing Google Spreadsheets, including creating, reading, updating, and deleting spreadsheets, sheets, and rows.
Features
-
🔧 Spreadsheet Management
- Create new spreadsheets
- Find spreadsheets by title
- Get spreadsheet information
-
📊 Sheet Operations
- Create new sheets in existing spreadsheets
- List all sheets in a spreadsheet
- Delete sheets
- Get detailed sheet information
-
📝 Row Operations
- Add rows to sheets (append or insert)
- Get data from sheets
- Update specific rows
- Delete rows
Installation
- Clone the repository:
git clone <repository-url>
cd google-sheets-mcp-server
- Create a virtual environment:
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
- Install dependencies:
pip install -r requirements.txt
-
Set up Google Cloud credentials:
- Go to Google Cloud Console
- Create a new project or select an existing one
- Enable the Google Sheets API and Google Drive API
- Create credentials (OAuth Client ID or Service Account)
- Download the credentials JSON file
-
Configure environment variables:
cp .env.example .env
# Edit .env with your configuration
Authentication Methods
Method 1: Service Account (Recommended for servers)
- Create a service account in Google Cloud Console
- Download the JSON key file
- Set the path in
.env
:
SERVICE_ACCOUNT_PATH=service_account.json
Method 2: OAuth (Recommended for desktop applications)
- Create OAuth 2.0 Client ID credentials
- Download the JSON file as
credentials.json
- Set the path in
.env
:
CREDENTIALS_PATH=credentials.json
Usage
Start the server:
python google_sheets_server.py
Available Tools
Spreadsheet Tools
create_spreadsheet
Create a new Google Spreadsheet.
{
"title": "My New Spreadsheet"
}
find_spreadsheets
Search for spreadsheets by title.
{
"title_search": "Budget" # Optional
}
Sheet Tools
create_sheet
Add a new sheet to an existing spreadsheet.
{
"spreadsheet_id": "1234567890",
"title": "New Sheet Name"
}
list_sheets
List all sheets in a spreadsheet.
{
"spreadsheet_id": "1234567890"
}
delete_sheet
Delete a sheet from a spreadsheet.
{
"spreadsheet_id": "1234567890",
"sheet": "Sheet1"
}
get_sheet_info
Get detailed information about a sheet.
{
"spreadsheet_id": "1234567890",
"sheet": "Sheet1"
}
Row Tools
add_rows
Add rows to a sheet.
{
"spreadsheet_id": "1234567890",
"sheet": "Sheet1",
"data": [
["John", "Doe", 30],
["Jane", "Smith", 25]
],
"start_row": 0 # Optional, omit to append
}
get_rows
Get data from a sheet.
{
"spreadsheet_id": "1234567890",
"sheet": "Sheet1",
"range": "A1:C10" # Optional
}
update_rows
Update specific rows in a sheet.
{
"spreadsheet_id": "1234567890",
"sheet": "Sheet1",
"range": "A1:C2",
"data": [
["UpdatedName", "UpdatedValue"],
["Another", "Row"]
]
}
delete_rows
Delete rows from a sheet.
{
"spreadsheet_id": "1234567890",
"sheet": "Sheet1",
"start_row": 0, # 0-indexed
"end_row": 2 # Exclusive
}
Examples
Python Example
import asyncio
from mcp.client import Client
async def main():
async with Client() as client:
# Create a new spreadsheet
result = await client.call_tool("create_spreadsheet", {
"title": "My New Budget"
})
spreadsheet_id = result['spreadsheetId']
# Add data to the spreadsheet
await client.call_tool("add_rows", {
"spreadsheet_id": spreadsheet_id,
"sheet": "Sheet1",
"data": [
["Category", "Amount"],
["Food", 500],
["Rent", 1000],
["Utilities", 200]
]
})
# Get the data back
data = await client.call_tool("get_rows", {
"spreadsheet_id": spreadsheet_id,
"sheet": "Sheet1"
})
print(data)
asyncio.run(main())
Security Considerations
- Credential Storage: Store credentials securely and never commit them to version control
- Access Control: Use service accounts with minimal required permissions
- Environment Variables: Use
.env
files for configuration (don't commit to git)
Troubleshooting
Common Issues
- Authentication Error: Ensure credentials file is properly configured
- Permission Error: Check if the API access is enabled in Google Cloud Console
- Quota Exceeded: Google Sheets API has rate limits, implement proper error handling
Error Codes
404
: Spreadsheet or sheet not found403
: Permission denied400
: Invalid request parameters
Development
To contribute to this project:
- Fork the repository
- Create a feature branch
- Make your changes
- Submit a pull request
License
MIT License
Support
For support, please open an issue in the GitHub repository.