This repository implements a v4 MCP server for Google Workspace with a Code Mode runtime:
- The server exposes exactly 2 MCP tools:
searchandexecute - Workspace operations are executed through
sdk.*in sandboxed JavaScript - The SDK surface includes 47 operations across 6 services:
drive(7),sheets(12),forms(4),docs(5),gmail(10),calendar(9)
The architecture is intentionally split between:
- Discovery (
search) to find operation signatures and examples - Execution (
execute) to run agent-authored code withsdkaccess
MCP Client
-> tools/list
-> [search, execute]
-> tools/call(search)
-> SDK spec subset from src/sdk/spec.ts
-> tools/call(execute)
-> NodeSandbox (vm context)
-> sdk.<service>.<operation>(...)
-> Google APIs
-> { result, logs }
index.tsis the CLI entry point- Supported commands:
node ./dist/index.js(start stdio MCP server)node ./dist/index.js authnode ./dist/index.js healthnode ./dist/index.js rotate-keynode ./dist/index.js verify-keysnode ./dist/index.js migrate-tokens
src/server/transports/stdio.ts- loads OAuth config
- initializes
AuthManager - creates logger/cache/perf monitor
- connects
StdioServerTransport
src/server/factory.ts- registers
searchandexecute - creates Google API clients (Drive, Sheets, Forms, Docs, Gmail, Calendar)
- builds runtime context for SDK execution
- registers
src/sdk/spec.tscontains static operation metadata used bysearchsrc/sdk/runtime.tsmaps runtime context tosdk.*methodssrc/sdk/sandbox-node.tsruns user code in a Nodevmcontext- blocked globals include
process,require, timers, andfetch console.*output is captured and returned aslogs
- blocked globals include
All operation implementations live under src/modules/:
src/modules/drivesrc/modules/sheetssrc/modules/formssrc/modules/docssrc/modules/gmailsrc/modules/calendar
Purpose: discover available services and operations before execution.
Input shape:
{
"service": "drive | sheets | forms | docs | gmail | calendar (optional)",
"operation": "string (optional)"
}Behavior:
- no params -> returns service -> operation summary
service-> returns operations for that serviceservice+operation-> returns metadata for one operation
Purpose: run JavaScript with sdk in the sandbox.
Input shape:
{
"code": "JavaScript string"
}Output shape:
{
"result": "any returned value",
"logs": ["captured console output"]
}If execution fails, tool returns an error payload with captured logs.
search, enhancedSearch, read, createFile, createFolder, updateFile, batchOperations
listSheets, readSheet, createSheet, renameSheet, deleteSheet, updateCells, updateFormula, formatCells, addConditionalFormat, freezeRowsColumns, setColumnWidth, appendRows
createForm, readForm, addQuestion, listResponses
createDocument, insertText, replaceText, applyTextStyle, insertTable
listMessages, listThreads, getMessage, getThread, searchMessages, createDraft, sendMessage, sendDraft, listLabels, modifyLabels
listCalendars, getCalendar, listEvents, getEvent, createEvent, updateEvent, deleteEvent, quickAdd, checkFreeBusy
Auth stack:
src/auth/AuthManager.tssrc/auth/TokenManager.tssrc/auth/KeyRotationManager.ts
Key characteristics:
- OAuth tokens are encrypted at rest
- key rotation supports versioned keys (
v1..v4patterns via env vars) - health command validates token state and refresh readiness
- auth flow stores tokens for non-interactive server startup
Required env:
GDRIVE_TOKEN_ENCRYPTION_KEY
The stdio transport requests these scopes:
https://www.googleapis.com/auth/drivehttps://www.googleapis.com/auth/spreadsheetshttps://www.googleapis.com/auth/documentshttps://www.googleapis.com/auth/formshttps://www.googleapis.com/auth/script.projects.readonlyhttps://www.googleapis.com/auth/gmail.readonlyhttps://www.googleapis.com/auth/gmail.sendhttps://www.googleapis.com/auth/gmail.composehttps://www.googleapis.com/auth/gmail.modifyhttps://www.googleapis.com/auth/calendar.readonlyhttps://www.googleapis.com/auth/calendar.events
Note: Apps Script scope is requested, but there is no exposed sdk.script service in the current v4 tool surface.
- optional cache via
REDIS_URL - graceful fallback when Redis is unavailable
- default TTL: 300 seconds
- Winston structured logging
- file logs and console transport
- configurable via
LOG_LEVEL
node ./dist/index.js health- Dockerfile health check uses
node dist/health-check.js - docker-compose health check uses
node dist/index.js health
- Node.js
>=22.0.0 - TypeScript build output in
dist/
Dockerfilebase image:node:22-slim- build installs native deps needed by dependencies
- credentials mounted at
/credentials - logs mounted at
/app/logs
See docs/Deployment/DOCKER.md for complete deployment steps.
index.ts
src/
auth/
modules/
drive/
sheets/
forms/
docs/
gmail/
calendar/
sdk/
spec.ts
runtime.ts
sandbox-node.ts
server/
factory.ts
bootstrap.ts
transports/stdio.ts
health-check.ts
Dockerfile
docker-compose.yml
- Keep MCP surface minimal (
search,execute) - Keep business logic in modules, not in transport handlers
- Make operation discovery deterministic via static spec metadata
- Prefer explicit, typed operation signatures and stable error messages
- Keep deployment paths and env vars aligned across docs and runtime