google-sheets-mcp

google-sheets-mcp

Connects Claude.ai to Google Sheets, allowing read, append, and update operations on spreadsheets directly from chat.

Category
访问服务器

README

Google Sheets MCP for Claude.ai

Connect Claude.ai to your Google Sheets via a custom MCP (Model Context Protocol) server hosted on Vercel. Once set up, Claude can read, append, and update your spreadsheet directly from the chat.


What you get

  • read_sheet — read any range from your sheet
  • append_row — add a new row
  • update_cell — update a specific cell

Prerequisites

  • A Vercel account
  • A Google Cloud account
  • A Google Sheet you want Claude to access
  • Node.js 18+ installed locally
  • Git

Step 1 — Clone and install

git clone <your-repo-url>
cd custom_mcp
npm install

Step 2 — Create a Google Cloud OAuth app

  1. Go to Google Cloud Console
  2. Create a new project (or use existing)
  3. Go to APIs & Services → Enable APIs → enable Google Sheets API
  4. Go to APIs & Services → Credentials → Create Credentials → OAuth 2.0 Client ID
  5. Application type: Web application
  6. Name it (e.g. Claude MCP)
  7. Under Authorized redirect URIs add:
    https://YOUR-VERCEL-APP.vercel.app/oauth/google/callback
    
    Replace YOUR-VERCEL-APP with your actual Vercel app name.
  8. Click Save — copy the Client ID and Client Secret

⚠️ Make sure the redirect URI matches your Vercel deployment URL exactly — no trailing slash, must be https.


Step 3 — Configure OAuth consent screen

  1. Go to APIs & Services → OAuth consent screen
  2. User type: External
  3. Fill in app name, support email
  4. Add scope: https://www.googleapis.com/auth/spreadsheets
  5. Under Audience → Test users add your Gmail address
  6. Click Publish app → Confirm

⚠️ You must publish the app (even unverified) or Google will block the login. When you see the "unverified app" warning during login, click Advanced → Go to app.


Step 4 — Deploy to Vercel

Option A — Via Vercel CLI

npm install -g vercel
vercel login
vercel --prod

Option B — Via GitHub

Push to GitHub → import project in Vercel dashboard → it auto-deploys.


Step 5 — Set environment variables in Vercel

Go to Vercel Dashboard → Your Project → Settings → Environment Variables and add:

JWT secret is a private random string only your server knows — it's used to sign and verify tokens so Claude can't be impersonated. It must be at least 32 characters, completely random, and never shared or committed to Git. Generate one with:

bashnode -e "console.log(require('crypto').randomBytes(32).toString('hex'))"

This outputs 64 random hex characters like a3f8c2... — copy that output directly as your JWT_SECRET value in Vercel. Never use a human-readable phrase like "mysecret123" — it's trivially guessable.|

Variable Value
GOOGLE_CLIENT_ID From Google Cloud Console OAuth client
GOOGLE_CLIENT_SECRET From Google Cloud Console OAuth client
GOOGLE_REDIRECT_URI https://YOUR-VERCEL-APP.vercel.app/oauth/google/callback
JWT_SECRET A long random string (generate below)
SPREADSHEET_ID Your Google Sheet ID (from the URL)

Generate a secure JWT secret:

node -e "console.log(require('crypto').randomBytes(32).toString('hex'))"

Get your Spreadsheet ID from the sheet URL:

https://docs.google.com/spreadsheets/d/SPREADSHEET_ID_IS_HERE/edit

⚠️ After adding env vars, you must redeploy for them to take effect:

vercel --prod

Step 6 — Verify deployment

Hit your health endpoint:

https://YOUR-VERCEL-APP.vercel.app/health

Should return:

{ "status": "ok", "message": "Google Sheets MCP OAuth Server" }

Step 7 — Connect to Claude.ai

  1. Go to claude.ai → Settings → Connectors
  2. Click Add connector
  3. Enter:
    • Name: Google Sheets MCP
    • URL: https://YOUR-VERCEL-APP.vercel.app
  4. Click Connect
  5. Google login screen appears → sign in with the account you whitelisted
  6. Authorize the Sheets scope
  7. Done — Claude now has access to your sheet ✅

Usage examples

Once connected, just ask Claude naturally:

Read the data in Sheet1!A1:D10
Append a row with ["John", "Doe", "john@example.com"] to Sheet1!A:Z
Update cell Sheet1!B3 to "Completed"

Project structure

├── api/
│   └── oauth.cjs        ← Main server (Vercel entry point)
├── public/
│   └── index.html       ← Dashboard UI
├── vercel.json          ← Vercel routing config
└── package.json

How it works

Claude.ai → POST / (tools/list)     → Your Vercel server → returns tool definitions
Claude.ai → GET /oauth/authorize    → Redirects to Google login
Google    → GET /oauth/google/callback → Issues JWT token back to Claude
Claude.ai → POST / (tools/call) + JWT → Your server → Google Sheets API → data

Troubleshooting

500 FUNCTION_INVOCATION_FAILED Your package.json likely has "type": "module" — remove it. The server uses CommonJS (require).

"This connector has no tools available" The tools/list method is behind auth middleware. Make sure it's handled in the unauthenticated first handler.

Error 400: redirect_uri_mismatch

  • Check GOOGLE_REDIRECT_URI in Vercel matches exactly what's registered in Google Console
  • Make sure you're using the OAuth Client ID, not a service account ID
  • Publish your OAuth app in Google Console (Testing mode blocks logins)

"Authorization with the MCP server failed" Disconnect and reconnect the Claude connector to force a fresh token. Cached tokens from failed attempts won't work.

POST returning 404 All JSON-RPC errors must return HTTP 200, not 404. Check that unknown methods return res.status(200).json(...).


Security notes

  • Change MCP_API_KEY from any placeholder value before sharing the deployment
  • JWT_SECRET should be at least 32 random characters
  • The Spreadsheet ID and OAuth credentials are tied to your Vercel deployment — don't commit .env files
  • For production use, replace in-memory pkceStore/tokenStore Maps with a database (Redis, Upstash, etc.) — they reset on cold starts

License

MIT

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选