MCP Google Sheets
An MCP server providing read/write access to Google Spreadsheets through a set of tools for managing sheets, rows, columns, and data.
README
MCP Google Sheets
An MCP (Model Context Protocol) server that gives AI agents read/write access to Google Spreadsheets. Built for use with Claude Code and other MCP-compatible clients.
Features
- 9 tools for spreadsheet interaction — read metadata, read cells, extract schemas, create/rename tabs, append rows, insert columns, set column validation, update rows
- Per-user OAuth (recommended) — each user signs in with their own Google account; sheet edit history shows who actually made each change
- Service Account auth (legacy) — fully headless, no OAuth popups
- No fixed spreadsheet — every tool takes a
spreadsheetparameter (paste a Sheets URL or ID); any sheet the signed-in user can edit just works - Tool filtering — expose only the tools you need via the
TOOLSvariable - Audit trail — optionally stamp each written row with a user name
Available Tools
Every tool takes a required spreadsheet parameter: a full Google Sheets URL (https://docs.google.com/spreadsheets/d/<ID>/edit...) or a bare spreadsheet ID.
| Tool | Description |
|---|---|
get_spreadsheet_info |
Returns spreadsheet title, sheet names, IDs, and dimensions |
get_sheet_schema |
Returns column schema: dropdowns, checkboxes, data types, formulas, notes |
get_sheet_data |
Reads cell values from a range (e.g. Sheet1!A1:D10) |
find_rows |
Finds rows matching a value in a column (or any column); returns 1-based row indices |
create_sheet |
Creates a new sheet tab |
rename_sheet |
Renames a sheet tab (by ID or current name) |
add_rows |
Appends rows to the bottom of a sheet |
add_columns |
Inserts empty columns at a 1-based position, or appends at the right edge |
update_row |
Overwrites cells in a row starting at a 1-based column (update specific columns without rewriting the whole row) |
delete_rows |
Deletes a contiguous block of rows (rows below shift up) |
Install
If you use Claude Code, add the server with one command. You need an OAuth Client ID and Client Secret — ask whoever set up your team's Google Cloud project, or create them yourself via OAuth Setup below.
claude mcp add \
--scope user \
--env GOOGLE_OAUTH_CLIENT_ID=<your-client-id>.apps.googleusercontent.com \
--env GOOGLE_OAUTH_CLIENT_SECRET=<your-client-secret> \
--transport stdio \
google-sheets \
-- npx -y @toantran201/mcp-google-sheets
On Windows PowerShell, put it on a single line (drop the
\line breaks), or replace\with a backtick`.
--scope usermakes the server available in all your projects. Use--scope projectinstead to write it into a shared.mcp.json(checked into the repo for your whole team), or omit--scopefor the current project only.--transport stdiois the default; it's shown here mainly so the server name doesn't sit directly after--env(the CLI rejects that).
That's it. On the first tool call, your browser opens for Google sign-in; your personal token is cached at ~/.google-sheets-mcp/tokens.json. There is no fixed spreadsheet — just paste a Google Sheets URL into the conversation.
<details> <summary>Prefer editing config by hand, or using another MCP client?</summary>
Add this to your .mcp.json (Claude Code) or your client's MCP config:
{
"mcpServers": {
"google-sheets": {
"type": "stdio",
"command": "npx",
"args": ["-y", "@toantran201/mcp-google-sheets"],
"env": {
"GOOGLE_OAUTH_CLIENT_ID": "xxxxx.apps.googleusercontent.com",
"GOOGLE_OAUTH_CLIENT_SECRET": "GOCSPX-xxxxx"
}
}
}
}
Optional env keys: TOOLS (comma-separated allowlist, blank = all — see Restricting Tools), USER_NAME (stamped onto add_rows writes). Pin a version with @toantran201/mcp-google-sheets@1.2.3.
</details>
Prerequisites
- Node.js 20+ (only needed locally;
npxhandles it automatically) - A Google Cloud project with the Sheets API enabled
- OAuth client credentials (recommended) or a Google Service Account
OAuth Setup (recommended — one-time, per team)
With OAuth, each team member authenticates with their own Google account. Edits show up under their name in the sheet's version history, and they can access any sheet they already have permission on — no sharing to a robot account needed.
1. Create a Google Cloud Project
- Go to Google Cloud Console
- Click the project dropdown at the top and select New Project
- Give it a name (e.g.
mcp-sheets) and click Create
2. Enable the Google Sheets API
- Go to APIs & Services > Library
- Find Google Sheets API and click Enable
3. Configure the OAuth Consent Screen
- Go to APIs & Services > OAuth consent screen
- Choose the user type:
- Internal (available if your team uses Google Workspace) — recommended. No verification needed, refresh tokens never expire, and only members of your organization can sign in.
- External — works with any Google account, but while the app is in Testing status you must add each teammate as a test user, and refresh tokens expire every 7 days (the server detects this and simply re-opens the browser to sign in again).
- Fill in the app name and contact emails, save
4. Create an OAuth Client ID
- Go to APIs & Services > Credentials
- Click + CREATE CREDENTIALS > OAuth client ID
- Application type: Desktop app
- Copy the Client ID and Client Secret. Supply them via your MCP client's
envconfig — the--envflags in the Install command, or theenvblock in.mcp.json. (Only when developing locally do you put them in a.envfile — see Local development.)
Per Google's documentation, a Desktop-app client secret is not treated as a confidential secret (installed apps can't keep secrets). It's fine to share it within your team, but keep it out of version control — don't commit a
.envor a checked-in.mcp.jsonthat contains it.
First run
The first time any tool is called, the server opens your browser for Google sign-in. After you approve, tokens are cached at ~/.google-sheets-mcp/tokens.json and later runs are silent. To switch Google accounts, delete that file.
Changing
TOOLSfrom a read-only set to one that includes write tools requires a broader OAuth scope — the server detects this and re-prompts in the browser once.
Security notes
- The sign-in flow uses the OAuth installed-app pattern with PKCE (S256) and a CSRF
statecheck; the loopback server binds only to127.0.0.1on an ephemeral port. - The refresh token is cached in plaintext at
~/.google-sheets-mcp/tokens.json, protected by file permissions (0600, directory0700; on Windows, your profile's NTFS ACLs). This is the same model used bygcloudandgh. Any process running as your OS user can read it — treat your user account as the trust boundary, and delete the file to revoke local access. - The OAuth client secret is never written to disk by the server; it comes from the environment your MCP client passes in (the
envconfig), or from.envduring local development. - All cell writes are sanitized against formula/CSV injection (leading
=,+,-,@, tab, CR are neutralized with a'prefix).
Service Account Setup (legacy alternative)
Headless auth with a shared robot account. Edits are attributed to the service account, not individual users, and every target sheet must be shared with it.
<details> <summary>Expand instructions</summary>
1. Create a Service Account
- In your Google Cloud project (Sheets API enabled), go to APIs & Services > Credentials
- Click + CREATE CREDENTIALS > Service account
- Enter a name (e.g.
mcp-agent) and click Create and Continue, then Done - Note the email address (e.g.
mcp-agent@mcp-sheets.iam.gserviceaccount.com)
2. Generate a Private Key
- Click on the service account, go to the Keys tab
- Click Add Key > Create new key, select JSON, click Create
- From the downloaded JSON:
client_email→GOOGLE_SERVICE_ACCOUNT_EMAIL,private_key→GOOGLE_PRIVATE_KEY
3. Share Your Spreadsheet
- Open the Google Sheet, click Share
- Paste the service account email
- Set the role to Editor (Viewer is enough for read-only tools)
Tip: The private key from the JSON file contains literal
\ncharacters. Paste it as-is — the server handles the conversion.
</details>
Local development
Clone and install only if you want to modify the server:
git clone <repo-url>
cd google-sheets-mcp
npm install
cp .env.example .env # fill in ONE auth mode below
# Mode A (recommended): per-user OAuth
GOOGLE_OAUTH_CLIENT_ID="xxxxx.apps.googleusercontent.com"
GOOGLE_OAUTH_CLIENT_SECRET="GOCSPX-xxxxx"
# Mode B (legacy): service account
# GOOGLE_SERVICE_ACCOUNT_EMAIL="mcp-agent@your-project.iam.gserviceaccount.com"
# GOOGLE_PRIVATE_KEY="-----BEGIN PRIVATE KEY-----\nMIIEv...\n-----END PRIVATE KEY-----\n"
# Optional — comma-separated list of tools to expose (blank = all)
TOOLS=""
# Optional — name appended to each row written by add_rows
USER_NAME=""
If both modes are configured, OAuth wins. There is no SPREADSHEET_ID — just paste a sheet link into your conversation and the agent passes it to the tools.
npm run dev # run from TypeScript, no build
npm run build # bundle to dist/index.js
npm start # run the built server
Point .mcp.json at your local checkout while developing:
{
"mcpServers": {
"google-sheets": {
"type": "stdio",
"command": "npx",
"args": ["tsx", "/absolute/path/to/google-sheets-mcp/src/index.ts"]
}
}
}
Publishing a new version
Maintainers only. The package is public on npm under the @toantran201 scope.
npm login # once per machine; sign in as the scope owner (toantran201)
npm version patch # or minor / major — bumps package.json + git tag
npm publish # prepublishOnly runs the build automatically
git push --follow-tags
files in package.json limits the tarball to dist/ (plus README + LICENSE) — source, .env, and docs are never published. Verify with npm pack --dry-run before publishing.
Restricting Tools
Use the TOOLS environment variable to expose only specific tools. This reduces token usage when the agent doesn't need all capabilities, and in OAuth mode a read-only tool set requests the narrower read-only scope.
# Read-only mode
TOOLS=get_spreadsheet_info,get_sheet_data
# Write-only (no reads)
TOOLS=add_rows,update_row
# All tools (default)
TOOLS=
Project Structure
src/
index.ts Server bootstrap & stdio transport
config.ts Env var loading, auth-mode detection & validation
sheets-client.ts Google Sheets API wrapper (per-call spreadsheet ID)
spreadsheet-ref.ts Spreadsheet URL/ID parsing
auth/
auth-manager.ts Auth entry point (OAuth or Service Account)
oauth-flow.ts Browser loopback sign-in flow
token-store.ts Per-user token cache (~/.google-sheets-mcp/)
scopes.ts Read-only vs read/write scope resolution
tools/
index.ts Tool registry & TOOLS filter
shared/ Non-tool helpers shared across tools
types.ts Shared ToolDefinition interface
sanitize.ts Formula-injection guard for cell writes
result.ts CallToolResult factory (success/error shapes)
get-spreadsheet-info.ts
get-sheet-schema.ts
get-sheet-data.ts
find-rows.ts
create-sheet.ts
rename-sheet.ts
add-rows.ts
add-columns.ts
update-row.ts
delete-rows.ts
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 模型以安全和受控的方式获取实时的网络信息。