
Mcp Gsheets
io.github.freema由 GitHub 账号 freema 发布v1.11.1更新于 Nov 7, 2026
MCP server for Google Sheets API — read, write, format, batch operations.
概览
本地 MCP 服务器,让助手通过 Google 服务账号读取、写入、格式化和管理 Google Sheets 表格。
- 可以做什么
- 读取单个或多个区域的单元格值,以及表格元数据和访问权限检查
- 写入、追加、清空和插入值、行、链接与日期
- 创建、复制、跨表复制、删除和重命名工作表与标签页
- 设置单元格格式、边框、合并、条件格式规则和原生表格
- 创建、更新和删除图表
- 查看结构、尺寸、格式、筛选器和数据验证,并支持紧凑快照
- 适用场景
- 当你希望助手直接处理 Google Sheets 文件时使用:提取数据、填写或清理区域、调整工作表结构,或应用格式和图表。只读模式和工具集限制也适合以读取为主的轻量会话。
- 运行要求
- 通过 npx 在本地运行,需要 Node.js v22 或更高版本。需要启用 Sheets API 的 Google Cloud 项目和服务账号密钥,可通过密钥文件路径(GOOGLE_APPLICATION_CREDENTIALS)、JSON 字符串(GOOGLE_SERVICE_ACCOUNT_KEY)或私钥加邮箱(GOOGLE_PRIVATE_KEY、GOOGLE_CLIENT_EMAIL)提供;部分方式需要 GOOGLE_PROJECT_ID。每个表格都需共享给服务账号邮箱。
安装
在 SourceWeft 中
- 打开 控制台中的 Mcp Gsheets,将其添加到工作区。
- 为需要使用其工具的对话启用该服务。
Desktop only,通过 STDIO。 STDIO 服务会启动本地进程,因此需要 SourceWeft 桌面宿主。
其他 MCP 客户端
参照 仓库 中的启动说明。
README
MCP Google Sheets Server
[图片][npm version] [CI] [Coverage] [License: MIT] [TypeScript] [Node] [code style: prettier]
A Model Context Protocol (MCP) server for Google Sheets API integration. Enables reading, writing, and managing Google Sheets documents directly from your MCP client (e.g., Claude Code, Claude Desktop, Cursor, etc.).
Key Features
- Complete Google Sheets Integration: Read, write, and manage spreadsheets
- Advanced Operations: Batch operations, formatting, charts, and conditional formatting
- Flexible Authentication: Support for both file-based and JSON string credentials
- Production Ready: Built with TypeScript, comprehensive error handling, and full test coverage
Requirements
- Node.js v22 or higher
- Google Cloud Project with Sheets API enabled
- Service Account with JSON key file
- npm
Getting Started
Quick Install (Recommended)
Add the following config to your MCP client:
[!NOTE] Using
mcp-gsheets@latestensures that your MCP client will always use the latest version of the MCP Google Sheets server.
MCP Client Configuration
Claude Code
Use the Claude Code CLI to add the MCP Google Sheets server (guide):After adding, edit your Claude Code config to add the required environment variables:
Claude Desktop
Add to your Claude Desktop config:
- macOS:
~/Library/Application Support/Claude/claude_desktop_config.json - Windows:
%APPDATA%\Claude\claude_desktop_config.json - Linux:
~/.config/claude/claude_desktop_config.json
Cursor
Go to Cursor Settings → MCP → New MCP Server. Use the config provided above.
Cline
Follow https://docs.cline.bot/mcp/configuring-mcp-servers and use the config provided above.
Other MCP Clients
For other MCP clients, use the standard configuration format shown above. Ensure the command is set to npx and include the environment variables for Google Cloud authentication.
Google Cloud Setup
- Go to Google Cloud Console
- Create a new project or select existing
- Enable Google Sheets API:
- Navigate to "APIs & Services" → "Library"
- Search for "Google Sheets API" and click "Enable"
- Create Service Account:
- Go to "APIs & Services" → "Credentials"
- Click "Create Credentials" → "Service Account"
- In the service accounts list, click the three dots in the
Actionscolumn →Manage keys→Add key→Create new key→ select JSON format - Download the JSON key file
- Share your spreadsheets:
- Open your Google Sheet
- Click Share and add the service account email (from JSON file)
- Grant "Editor" permissions
Alternative Authentication Methods
Option 1: JSON String Authentication
Instead of using a file path for credentials, you can provide the service account credentials directly as a JSON string. This is useful for containerized environments, CI/CD pipelines, or when you want to avoid managing credential files.
Note: When using GOOGLE_SERVICE_ACCOUNT_KEY:
- The entire JSON must be on a single line
- All quotes must be escaped with backslashes
- Newlines in the private key must be represented as
\\n - If the JSON includes a
project_id, you can omitGOOGLE_PROJECT_ID
Option 2: Private Key Authentication (Simplified)
For the most user-friendly approach, you can provide just the private key and email directly. This is the simplest method and requires only two fields from your service account JSON:
Note: When using GOOGLE_PRIVATE_KEY:
- Newlines in the private key should be represented as
\\n - The private key must include the
-----BEGIN PRIVATE KEY-----and-----END PRIVATE KEY-----markers - The client email should be the service account email from your JSON file
GOOGLE_PROJECT_IDis optional when using this method
Local Development Setup
If you want to develop or contribute to this project, you can clone and build it locally:
Interactive Setup Script
Run the interactive setup script to configure your local MCP client:
This will:
- Guide you through the configuration
- Automatically detect your Node.js installation (including nvm)
- Find your Claude Desktop config
- Create the proper JSON configuration
- Optionally create a .env file for development
Manual Local Configuration
If you prefer manual configuration with a local build, add to your MCP client config:
📦 Build & Development
Development Commands
Task Runner (Alternative)
If you have Task installed:
Development Setup
- Create
.envfile for testing:
- Run in development mode:
🎚️ Reducing context cost with toolsets
All 44 tools together cost about 9,900 tokens of context in every session,
before the model does anything. Most workflows need a fraction of that.
GSHEETS_TOOLSETS limits which tools the server exposes:
Measured tools/list cost:
Notes:
- The default is unchanged — leave
GSHEETS_TOOLSETSunset and you get every tool, exactly as before. coreis always included.GSHEETS_TOOLSETS=chartsmeans "charts as well as core", not "charts only" — without core the server cannot read a cell.- A typo is a startup error, not a silently smaller tool list.
GSHEETS_READ_ONLY=truedrops every writing tool and can be combined withGSHEETS_TOOLSETS. It is enforced when a tool is called, not just when the list is built, so a client cannot write by naming a hidden tool.
All tools also carry MCP annotations (readOnlyHint, destructiveHint,
idempotentHint), so clients can skip confirmation prompts on reads and warn
before destructive operations.
📋 Available Tools
Reading Data
Writing Data
Sheet Management
Cell Formatting
Native Tables
Charts
Read / Snapshot Tools
🔧 Code Quality
Linting
Formatting
Type Checking
❗ Troubleshooting
Common Issues
"Authentication failed"
- If using file-based auth: Verify JSON key path is absolute and correct
- If using JSON string auth: Ensure JSON is properly escaped and valid
- If using private key auth: Check that the private key includes BEGIN/END markers and newlines are escaped as
\\n - Verify GOOGLE_CLIENT_EMAIL is a valid service account email
- Check GOOGLE_PROJECT_ID matches your project (or is included in JSON for full JSON auth)
- Ensure Sheets API is enabled
"Permission denied"
- Share spreadsheet with service account email
- Service account needs "Editor" role
- Check email in JSON file (client_email field)
"Spreadsheet not found"
- Verify spreadsheet ID from URL
- Format:
https://docs.google.com/spreadsheets/d/[SPREADSHEET_ID]/edit
MCP Connection Issues
- Ensure you're using the built version (
dist/index.js) - Check that Node.js path is correct in Claude Desktop config
- Look for errors in Claude Desktop logs
- Use
npm run inspectorto debug
🔍 Finding IDs
Spreadsheet ID
From the URL:
Sheet ID
Use sheets_get_metadata to list all sheets with their IDs.
📝 Tips
- Always test with a copy of your data
- Use batch operations for better performance
- Set appropriate permissions (read-only vs edit)
- Check rate limits for large operations
- Use
sheets_check_accessto verify permissions before operations
📘 Tool Details
sheets_get_sheet_structure
Returns lightweight structural/dimensional metadata for a sheet without any per-cell data. Much faster and cheaper than sheets_get_full_sheet_snapshot when you only need layout information.
Parameters:
spreadsheetId(required): The ID of the spreadsheetsheetName(required): Name of the sheet (tab)
Returns: sheetName, sheetId, sheetIndex, tabColor, tabColorStyle, dimensions (rowCount, columnCount), frozen (rowCount, columnCount), columnWidths (array of pixel sizes), rowHeights (array of pixel sizes), hiddenColumns (0-based indices), hiddenRows (0-based indices), mergeCount, merges (A1 notation array)
sheets_get_formatting_compact
Read cell formatting for a range and return it as compact A1Range → format pairs. Adjacent cells with identical formatting are collapsed into rectangular ranges (run-length encoded), reducing output by 90 %+ compared to per-cell data.
Parameters:
spreadsheetId(required): The ID of the spreadsheetsheetName(required): Name of the sheet (tab)range(required): Range without sheet prefix, e.g."A1:Z85"useEffectiveFormat(optional):false(default) = userEnteredFormat (only explicit overrides, smaller output);true= effectiveFormat (all inherited defaults)fields(optional): Array of format field names to include, e.g.["backgroundColor", "textFormat", "borders"]
Returns: { range, formatType, rangeCount, data: { "A1:C3": { backgroundColor: {...} }, ... } }
Supported fields: backgroundColor, backgroundColorStyle, textFormat, horizontalAlignment, verticalAlignment, wrapStrategy, textRotation, numberFormat, padding, borders
sheets_get_full_sheet_snapshot
Master one-shot tool that returns all structural and formatting metadata in a single API call.
Parameters:
spreadsheetId(required): The ID of the spreadsheetsheetName(required): Name of the sheet (tab)includeFormattingRange(optional): If provided (e.g."A1:Z100"), per-cell formatting is included in the responseuseEffectiveFormat(optional): Use effectiveFormat instead of userEnteredFormat when including cell formatting (default:false)fields(optional): Array of format field names to return, e.g.["backgroundColor", "textFormat"]— reduces API transfer size and response sizecompactMode(optional): Whentrue, identical adjacent cells are collapsed into rectangular ranges (RLE). Reduces a typical 85×28 sheet from ~60 000 lines to ~500 lines (default:false)
sheets_insert_rows
Insert new rows at a specific position in a spreadsheet with optional data.
Parameters:
spreadsheetId(required): The ID of the spreadsheetrange(required): A1 notation anchor point where rows will be inserted (e.g., "Sheet1!A5")rows(optional): Number of rows to insert (default: 1)position(optional): 'BEFORE' or 'AFTER' the anchor row (default: 'BEFORE')inheritFromBefore(optional): Whether to inherit formatting from the row before (default: false)values(optional): 2D array of values to fill the newly inserted rowsvalueInputOption(optional): 'RAW' or 'USER_ENTERED' (default: 'USER_ENTERED')
Examples:
sheets_delete_columns
Delete one or more columns from a sheet using a full-column A1 range.
Parameters:
spreadsheetId(required): The ID of the spreadsheetrange(required): Full-column A1 range to delete (e.g., "Sheet1!B:D" or "Sheet1!C:C")
Examples:
sheets_delete_rows
Delete one or more rows from a sheet using a full-row A1 range.
Parameters:
spreadsheetId(required): The ID of the spreadsheetrange(required): Full-row A1 range to delete (e.g., "Sheet1!2:4" or "Sheet1!3:3")
Examples:
📋 Changelog
See CHANGELOG.md for a list of changes in each version.
🤝 Contributing
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Run tests and linting (
npm run check) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
👤 Author
Tomáš Grásl - tomasgrasl.cz
📄 License
This project is licensed under the MIT License - see the LICENSE file for details.
来源:README.md,提交 48435ef
工具
0版本历史
4- v1.11.1最新Nov 7, 2026
- v1.11.0Oct 25, 2026
- v1.10.3Sep 19, 2026
- v1.10.1Sep 16, 2026
评分
已满足适用检查项的 50%
该评分衡量此收录条目的完整程度,依据注册中心条目、端点与公开来源计算得出。它不是对服务器本身的评价,也不表示服务器安全或当前可用:可连通性是带日期的检查结果,评分也不包含安装量或用户评价。
- 近 30 天内可连通25 分
请保持端点能够响应 MCP 握手;SourceWeft 每 30 天探测一次。
- 已声明认证方式10 分
请在注册中心条目中声明凭据请求头,或保持端点能够响应探测,以便判定其认证方式。
- 已列出工具15 分
请让服务器在无凭据时响应 tools/list,或发布可在沙箱中无凭据启动的软件包。
- 描述必需15 分
- 图标10 分
- 文档15 分
- 许可证10 分