by rohans2
mcp-google-sheets is a TypeScript-based Model Context Protocol (MCP) server that enables AI agents to securely interact with Google Sheets. It provides a comprehensive toolset for programmatic access and manipulation of Google Sheets data, supporting various use cases like automated data entry, reporting, and workflow automation.
mcp-google-sheets is a TypeScript-based Model Context Protocol (MCP) server that enables AI agents to securely interact with Google Sheets. It is built on Bun and the @modelcontextprotocol/sdk
, supporting both OAuth2 and Service-Account authentication flows.
To use mcp-google-sheets, you need to have Bun (v1.0+) installed and a Google Cloud project with the Sheets API & Drive API enabled. You'll also need an OAuth2 Client ID or a Service Account key. After cloning the repository and installing dependencies, configure your environment by creating a .env
file with your CREDENTIALS_CONFIG
(base64-encoded service-account key JSON) or by placing credentials.json
and token.json
next to index.ts
for OAuth2. You also need to provide the EMAIL_ID
you'll use to access the spreadsheet and optionally a DRIVE_FOLDER_ID
. Once configured, you can run the server using bun index.ts
.
CREDENTIALS_CONFIG
and OAuth2 using credentials.json
+ token.json
for user-scoped access.create
: Creates a new spreadsheet.listSheets
: Lists all sheet tabs in a given spreadsheet.renameSheet
: Renames an existing sheet tab.createSheet
: Adds a new sheet tab to a spreadsheet.spreadsheetInfo
: Fetches metadata for a spreadsheet.listSpreadsheets
: Lists all spreadsheets in your configured Drive folder.shareSpreadsheet
: Shares a spreadsheet with users.sheetData
: Reads cell values from a sheet.updateCells
: Writes a 2D array of values into an A1-style range.batchUpdate
: Applies multiple range updates in a single request.addRows
/ addColumns
: Inserts rows or columns.copySheet
: Copies a sheet tab between spreadsheets.mcp-google-sheets can be used in various scenarios where AI agents need to programmatically access and manipulate Google Sheets data. Some potential use cases include:
Q: What are the prerequisites for running mcp-google-sheets? A: You need Bun (v1.0+), a Google Cloud project with Sheets API & Drive API enabled, and either an OAuth2 Client ID or a Service Account key.
Q: How do I configure authentication?
A: You can use a base64-encoded service-account key via CREDENTIALS_CONFIG
in your .env
file, or place credentials.json
and token.json
(generated after the first OAuth run) next to index.ts
for OAuth2.
Q: How does the server work internally?
A: It initializes the context by picking an authentication method, builds Google Sheets and Drive clients, and registers each tool via server.tool(...)
. It uses StdioServerTransport
for tool invocation over stdin/stdout, and processes JSON requests from the agent to run handlers and return JSON-wrapped results.
Q: Can I contribute to the project? A: Yes, contributions for new tools, bug fixes, and enhancements are welcome via issues or PRs.
A TypeScript Model Context Protocol (MCP) server that lets AI agents securely interact with Google Sheets via well-typed “tools.” Built on Bun and the @modelcontextprotocol/sdk
, it supports both OAuth2 and Service-Account flows.
CREDENTIALS_CONFIG
credentials.json
+ token.json
for user-scoped accesscreate
listSheets
renameSheet
createSheet
spreadsheetInfo
listSpreadsheets
shareSpreadsheet
sheetData
updateCells
batchUpdate
addRows
/ addColumns
copySheet
PATH
credentials.json
) or a Service Account key (download service_account.json
)git clone https://github.com/yourusername/mcp-google-sheets.git
cd mcp-google-sheets
bun install
Create a .env (or export) with:
# Base64-encoded service-account key JSON (optional)
CREDENTIALS_CONFIG=BASE-64 ENCODED SERVICE_ACCOUNT.JSON
# Or put your OAuth2 JSON files next to index.ts:
# credentials.json (OAuth client secret)
# token.json (generated after first OAuth run)
# The google email address that you'll use to access the spreadsheet
EMAIL_ID="Enter the email address you’ll use to access the spreadsheet"
# (Optional) ID of the Drive folder to store new sheets
DRIVE_FOLDER_ID=1a2B3c4D5e6F...
Tip: On Linux/macOS you can do
export CREDENTIALS_CONFIG=$(base64 service_account.json | tr -d '\n')
bun index.ts
On first OAuth2 run (if using credentials.json), you’ll see a URL. Visit it, grant access, then paste the code back into your terminal. A token.json will be generated automatically.
Initialization
initContext() picks your auth method (Service-Account → OAuth2 → error).
Builds google.sheets & google.drive clients and stores them in a shared context.
MCP Tool Registration
Transport
Invocation
The agent sends a JSON request:
{ "tool": "create", "args": { "title": "Budget Q2" } }
The server runs your handler, calls Google APIs, and returns JSON-wrapped results.
Clone & configure as above.
Start the server:
bun index.ts
Invoke a tool via Claude
Feel free to open issues or PRs for new tools, bug fixes, and enhancements.
Reviews feature coming soon
Stay tuned for community discussions and feedback