Google Sheets MCP Server
MCP server for Google Sheets integration that enables AI assistants to read, write, and manage Google Spreadsheets.
README
Google Sheets MCP Server
MCP (Model Context Protocol) server for Google Sheets integration. Allows AI assistants to read, write, and manage Google Spreadsheets.
Features
Core Features
- TOON Format - Token-Optimized Output Notation for 40-80% token savings
- Create spreadsheets - Create new Google Spreadsheets with custom sheets
- Read data - Read cell ranges and formulas from spreadsheets
- Write data - Write values and formulas to cell ranges
- Append rows - Add new rows to existing data
- Clear data - Clear cell ranges
- Manage sheets - Add, delete, and duplicate sheets within spreadsheets
- Batch updates - Perform multiple updates in one request
Formula Support
- Read formulas - Extract formulas from cells (not just calculated values)
- Write formulas - Insert formulas into cells
Named Ranges
- Create named ranges - Define named ranges for easier reference
- List named ranges - Get all named ranges in a spreadsheet
- Delete named ranges - Remove named ranges
Advanced Formatting
- Basic formatting - Bold, italic, background colors
- Text alignment - Horizontal and vertical alignment
- Fonts - Font size, font family, text color
- Number formats - Currency, percentage, date, custom formats
- Borders - Cell borders with custom styles and colors
- Text wrapping - Control how text wraps in cells
Data Management
- Data validation - Dropdown lists, number ranges, date ranges, text validation
- Find and replace - Search and replace text across sheets
- Sort ranges - Sort data by one or more columns
- Merge/unmerge cells - Merge cells and unmerge them
Column & Row Operations
- Insert columns/rows - Add new columns or rows
- Delete columns/rows - Remove columns or rows
- Auto-resize - Auto-resize columns/rows to fit content** - Perform multiple updates in one request
Installation
# Using uv (recommended)
uv sync
# Or using pip
pip install -e .
Google Cloud Setup
Option 1: OAuth 2.0 (for personal use)
- Go to Google Cloud Console
- Create a new project or select existing one
- Enable the Google Sheets API:
- Go to "APIs & Services" > "Library"
- Search for "Google Sheets API"
- Click "Enable"
- Configure OAuth consent screen:
- Go to "APIs & Services" > "OAuth consent screen"
- Select "External" user type
- Fill in required fields
- Add scope:
https://www.googleapis.com/auth/spreadsheets
- Create OAuth credentials:
- Go to "APIs & Services" > "Credentials"
- Click "Create Credentials" > "OAuth client ID"
- Select "Desktop app"
- Download the JSON file
- Save credentials:
mkdir -p ~/.config/google-sheets-mcp mv ~/Downloads/client_secret_*.json ~/.config/google-sheets-mcp/credentials.json
Option 2: Service Account (for automated/server use)
- Go to Google Cloud Console
- Create a new project or select existing one
- Enable the Google Sheets API
- Create a Service Account:
- Go to "APIs & Services" > "Credentials"
- Click "Create Credentials" > "Service account"
- Fill in details and create
- Create a key:
- Click on the service account
- Go to "Keys" tab
- "Add Key" > "Create new key" > JSON
- Save the key:
mkdir -p ~/.config/google-sheets-mcp mv ~/Downloads/*.json ~/.config/google-sheets-mcp/service_account.json - Important: Share your spreadsheets with the service account email (found in the JSON file under
client_email)
Configuration
Credentials
Credentials are stored in ~/.config/google-sheets-mcp/:
| File | Description |
|---|---|
credentials.json |
OAuth 2.0 client credentials |
token.json |
OAuth 2.0 access token (auto-generated) |
service_account.json |
Service account credentials |
The server will automatically use service account if available, otherwise falls back to OAuth.
TOON Format (Token-Optimized Output Notation)
The server supports configurable output formats to minimize token usage when working with LLMs. Create a config.json file in ~/.config/google-sheets-mcp/:
{
"output_format": "compact"
}
(See config.example.json for a complete example)
Available Formats:
| Format | Description | Use Case | Token Savings |
|---|---|---|---|
minimal |
Absolute minimum data only | Maximum token efficiency, basic operations | ~60-80% |
compact |
Essential data with abbreviated keys (default) | Best balance of efficiency and readability | ~40-60% |
standard |
Readable but efficient output | Human-readable while still optimized | ~20-30% |
detailed |
Full verbose output | Debugging, development | 0% (full output) |
Format Examples:
Creating a spreadsheet:
- Detailed:
{"spreadsheet_id": "abc123", "spreadsheet_url": "https://...", "title": "My Sheet", "sheets": ["Sheet1", "Sheet2"]} - Compact:
{"id":"abc123","url":"https://..."} - Minimal:
{"id":"abc123"}
Reading data:
- Detailed:
{"range": "Sheet1!A1:C3", "values": [[...]]} - Compact:
{"values":[[...]]} - Minimal:
{"v":[[...]]}
Environment Variable Override:
You can override the format setting using the SHEETS_MCP_FORMAT environment variable:
export SHEETS_MCP_FORMAT=minimal
Configuration in Claude Desktop:
{
"mcpServers": {
"google-sheets": {
"command": "uv",
"args": ["run", "--directory", "/path/to/google-sheets-mcp-server", "python", "main.py"],
"env": {
"SHEETS_MCP_FORMAT": "compact"
}
}
}
}
Usage with Claude Desktop
Add to your Claude Desktop configuration (claude_desktop_config.json):
{
"mcpServers": {
"google-sheets": {
"command": "uv",
"args": ["run", "--directory", "C:\\Users\\salna\\local-mcp-servers\\google-sheets-mcp-server", "python", "main.py"]
}
}
}
Or if installed globally:
{
"mcpServers": {
"google-sheets": {
"command": "google-sheets-mcp"
}
}
}
Available Tools
create_spreadsheet
Create a new Google Spreadsheet.
{
"title": "My Spreadsheet",
"sheets": ["Sheet1", "Data", "Summary"]
}
get_spreadsheet
Get metadata about a spreadsheet.
{
"spreadsheet_id": "1BxiMVs0XRA5nFMdKvBdBZjgmUUqptlbs74OgvE2upms"
}
read_range
Read data from a range.
{
"spreadsheet_id": "...",
"range": "Sheet1!A1:D10"
}
write_range
Write data to a range.
{
"spreadsheet_id": "...",
"range": "Sheet1!A1:C3",
"values": [
["Name", "Age", "City"],
["Alice", 30, "NYC"],
["Bob", 25, "LA"]
]
}
append_rows
Append rows to existing data.
{
"spreadsheet_id": "...",
"range": "Sheet1!A:C",
"values": [
["Charlie", 35, "Chicago"],
["Diana", 28, "Boston"]
]
}
clear_range
Clear values from a range.
{
"spreadsheet_id": "...",
"range": "Sheet1!A1:D10"
}
add_sheet
Add a new sheet to spreadsheet.
{
"spreadsheet_id": "...",
"title": "New Sheet"
}
delete_sheet
Delete a sheet (use sheet_id from get_spreadsheet).
{
"spreadsheet_id": "...",
"sheet_id": 123456789
}
format_cells
Apply formatting to cells.
{
"spreadsheet_id": "...",
"sheet_id": 0,
"start_row": 0,
"end_row": 1,
"start_column": 0,
"end_column": 3,
"bold": true,
"background_color": {"red": 0.9, "green": 0.9, "blue": 0.9}
}
batch_update
Multiple updates in one request.
{
"spreadsheet_id": "...",
"data": [
{"range": "Sheet1!A1", "values": [["Header"]]},
{"range": "Sheet1!B1", "values": [["Value"]]}
]
}
read_formulas
Read formulas from cells (not just their calculated values).
{
"spreadsheet_id": "...",
"range": "Sheet1!A1:B5"
}
write_formulas
Write formulas to cells.
{
"spreadsheet_id": "...",
"range": "Sheet1!C1:C5",
"formulas": [
["=SUM(A1:B1)"],
["=SUM(A2:B2)"],
["=SUM(A3:B3)"],
["=SUM(A4:B4)"],
["=SUM(A5:B5)"]
]
}
create_named_range
Create a named range for easier reference in formulas.
{
"spreadsheet_id": "...",
"name": "SalesData",
"sheet_id": 0,
"start_row": 0,
"end_row": 10,
"start_column": 0,
"end_column": 5
}
list_named_ranges
List all named ranges in a spreadsheet.
{
"spreadsheet_id": "..."
}
delete_named_range
Delete a named range.
{
"spreadsheet_id": "...",
"named_range_id": "..."
}
format_cells_advanced
Apply advanced formatting including alignment, fonts, borders, and number formats.
{
"spreadsheet_id": "...",
"sheet_id": 0,
"start_row": 0,
"end_row": 1,
"start_column": 0,
"end_column": 5,
"horizontal_alignment": "CENTER",
"vertical_alignment": "MIDDLE",
"font_size": 12,
"font_family": "Arial",
"text_color": {"red": 0, "green": 0, "blue": 0},
"number_format": "$#,##0.00",
"wrap_strategy": "WRAP",
"border_bottom": {
"style": "SOLID",
"color": {"red": 0, "green": 0, "blue": 0}
}
}
set_data_validation
Set data validation rules (dropdown lists, number ranges, etc.).
{
"spreadsheet_id": "...",
"sheet_id": 0,
"start_row": 1,
"end_row": 100,
"start_column": 2,
"end_column": 3,
"validation_type": "ONE_OF_LIST",
"values": ["Option 1", "Option 2", "Option 3"],
"show_dropdown": true,
"strict": true
}
For number validation:
{
"spreadsheet_id": "...",
"sheet_id": 0,
"start_row": 1,
"end_row": 100,
"start_column": 3,
"end_column": 4,
"validation_type": "NUMBER_BETWEEN",
"min_value": "0",
"max_value": "100"
}
insert_dimension
Insert columns or rows.
{
"spreadsheet_id": "...",
"sheet_id": 0,
"dimension": "ROWS",
"start_index": 5,
"end_index": 10
}
delete_dimension
Delete columns or rows.
{
"spreadsheet_id": "...",
"sheet_id": 0,
"dimension": "COLUMNS",
"start_index": 2,
"end_index": 4
}
auto_resize_dimensions
Auto-resize columns or rows to fit content.
{
"spreadsheet_id": "...",
"sheet_id": 0,
"dimension": "COLUMNS",
"start_index": 0,
"end_index": 5
}
find_replace
Find and replace text in a sheet.
{
"spreadsheet_id": "...",
"sheet_id": 0,
"find": "old text",
"replace": "new text",
"match_case": false,
"match_entire_cell": false,
"search_formulas": false
}
duplicate_sheet
Duplicate an existing sheet.
{
"spreadsheet_id": "...",
"source_sheet_id": 0,
"new_sheet_name": "Copy of Sheet1"
}
sort_range
Sort a range by one or more columns.
{
"spreadsheet_id": "...",
"sheet_id": 0,
"start_row": 1,
"end_row": 100,
"start_column": 0,
"end_column": 5,
"sort_specs": [
{"dimension_index": 0, "ascending": true},
{"dimension_index": 1, "ascending": false}
]
}
merge_cells
Merge cells in a range.
{
"spreadsheet_id": "...",
"sheet_id": 0,
"start_row": 0,
"end_row": 1,
"start_column": 0,
"end_column": 3,
"merge_type": "MERGE_ALL"
}
unmerge_cells
Unmerge cells in a range.
{
"spreadsheet_id": "...",
"sheet_id": 0,
"start_row": 0,
"end_row": 1,
"start_column": 0,
"end_column": 3
}
Running Manually
# Run the server
uv run python main.py
# Or after installation
google-sheets-mcp
Development
# Install dev dependencies
uv sync --extra dev
# Run all tests
uv run pytest
# Run tests with verbose output
uv run pytest -v
# Run specific test file
uv run pytest tests/test_new_tools.py -v
# Run tests with coverage
uv run pytest --cov=src/google_sheets_mcp
# Type checking
uv run mypy main.py
Test Coverage
The test suite includes:
- 51 unit tests covering all 26 tools (10 original + 16 new)
- Tool execution tests - Verify each tool's logic and API calls
- TOON formatter tests - Ensure token optimization works correctly
- Mock-based testing - No real API calls required
Test files:
tests/test_new_tools.py- Tests for all 16 new tools (25 tests)tests/test_formatters.py- Tests for TOON formatters (26 tests)tests/conftest.py- Shared fixtures and configuration
License
MIT
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。