gworkspace-mcp
# gworkspace-mcp
A Google **Sheets** and **Docs** MCP server with full API coverage, over stdio, acting as you.
The first-party Google MCP connectors can read an approximation of a file and cannot write to one.
This server closes that gap: range reads including formulas, in-place cell writes, the whole Sheets
structural surface, and index-safe editing of Google Docs.
[Quickstart](#quickstart) · [Tools](#tools) · [Safety](#safety) · [Configuration](#configuration) ·
GCP setup: [`docs/setup-gcp.md`](docs/setup-gcp.md) · Design: [`docs/design.md`](docs/design.md) ·
Known gaps: [`docs/open-tasks.md`](docs/open-tasks.md)
> **Naming.** The project was called `gsheets-mcp` before it gained Docs support. Environment
> variables (`GSHEETS_*`), the config directory (`~/.config/gsheets-mcp/`) and the Keychain service
> (`gsheets-mcp`) keep the old name so existing installs keep working.
---
## Prerequisites
| Need | Notes |
|---|---|
| Node.js **22+** | `node --version` |
| A Google account | Personal Gmail or Workspace |
| A Google Cloud project you control | Free; used only to own the OAuth client. Walkthrough: [`docs/setup-gcp.md`](docs/setup-gcp.md) |
| An MCP client | Claude Code, Claude Desktop, or any stdio MCP client |
### Platform support
| OS | Refresh-token storage | Login browser | Status |
|---|---|---|---|
| macOS | Keychain (service `gsheets-mcp`) | opens automatically | used daily |
| Linux | `~/.config/gsheets-mcp/tokens/<email>.json`, mode 0600 | open the printed URL yourself | should work, not tested |
| Windows | same file store; POSIX file modes are not enforced | open the printed URL yourself | not tested |
---
## Quickstart
### 1. Create an OAuth client (one time, ~10 minutes)
Follow **[`docs/setup-gcp.md`](docs/setup-gcp.md)**. In short: enable the Sheets, Docs and Drive APIs,
set the consent screen to **External**, add the scopes, add yourself as a **test user**, create a
**Desktop app** client, and save its JSON:
```bash
mkdir -p ~/.config/gsheets-mcp && chmod 700 ~/.config/gsheets-mcp
mv ~/Downloads/client_secret_*.json ~/.config/gsheets-mcp/client.json
chmod 600 ~/.config/gsheets-mcp/client.json
```
Or set `GSHEETS_CLIENT_ID` and `GSHEETS_CLIENT_SECRET` instead of the file.
### 2. Install and build
```bash
git clone https://github.com/ctschak/gworkspace-mcp.git
cd gworkspace-mcp
npm install
npm run build
```
### 3. Create a profile
A profile is a `config/<name>.env` file saying which account an instance acts as and what it may
touch. It holds **no credentials**.
```bash
cp config/example.env config/work.env # edit: GSHEETS_DEFAULT_ACCOUNT=you@example.com
```
Only `config/example.env` is tracked by git; every other `*.env` is ignored. Details and precedence:
[`config/README.md`](config/README.md). Profiles are optional — without one, the server uses the
only (or default) authorised account.
### 4. Authorise
```bash
node dist/cli.js login --profile work # browser consent, once per account
node dist/cli.js accounts # confirm
```
Google shows *"Google hasn't verified this app"* — expected for your own unverified client. Choose
**Advanced → Go to … (unsafe)** and grant.
### 5. Register with your MCP client
**Claude Code** — one instance per profile, so the account follows from the tool you reach for:
```bash
claude mcp add -s user gws-work -- node "$(pwd)/dist/index.js" --profile work
```
**Claude Desktop / other stdio clients** — add to the client's MCP config (Claude Desktop:
`claude_desktop_config.json`), using an absolute path:
```json
{
"mcpServers": {
"gws-work": {
"command": "node",
"args": ["/absolute/path/to/gworkspace-mcp/dist/index.js", "--profile", "work"]
}
}
}
```
Restart the client so it connects.
### 6. First call
Ask your agent to run `sheets_describe` (or `docs_describe`) on a spreadsheet (or document) URL you
own. It returns the tabs and used ranges (or the outline) without any cell data.
### Recommended shape
A read-only profile for daily use and a read-write one enabled deliberately — `GSHEETS_READ_ONLY=1`
in the first, `GSHEETS_ALLOWED_IDS` in the second. See [`config/README.md`](config/README.md#a-useful-pair).
---
## Re-authorisation and token lifetime
> **Disclaimer — token lifetime is Google's policy, not this project's.** The figures below are
> Google's published rules, checked against
> [Google's OAuth 2.0 docs](https://developers.google.com/identity/protocols/oauth2#expiration) on
> 2026-11-29. Google can change them without notice, and observed lifetimes vary (tokens have been seen
> surviving past 7 days and dying sooner). Plan for re-authorisation at any time; **do not build
> unattended automation on a user refresh token from a Testing app.**
### Why your client stays in Testing
Publishing an OAuth app to production requires a homepage and a privacy-policy URL on a domain you're
authorised for, because `spreadsheets` is a **sensitive** scope. That's a poor trade for a local tool,
so your client stays in Testing. Google's rule for that state: an **External** app in **Testing** is
issued refresh tokens that **expire in 7 days**, unless it requests only `openid` / `email` /
`profile` — this server also needs `spreadsheets`, `documents` and `drive.file`, so the rule applies.
### When you will need to log in again
| Scenario | What you see | Fix |
|---|---|---|
| 7-day expiry (External + Testing app) — the common one | `Google credentials for … have expired or been revoked` | `node dist/cli.js login --profile <name>` |
| You revoked access at [myaccount.google.com/permissions](https://myaccount.google.com/permissions) | same | same |
| Token unused for 6 months | same | same |
| More than 100 refresh tokens for one account on one OAuth client (e.g. logging in repeatedly, many machines) — Google silently invalidates the **oldest** | same, on the older machine/profile | log in again there; avoid needless re-logins |
| Workspace account: admin set a Google Cloud **session length** (can be 1–24 h) | same (Google's underlying subtype is `invalid_rapt`; the server shows the generic message) | log in again; ask the admin about session policy if it recurs |
| Workspace admin marks Sheets/Docs/Drive as **Restricted** | `admin_policy_enforced` at login or on calls | admin must allow the app; re-login won't help |
| Time-based access granted at consent has expired | `expired or been revoked` | log in again |
| A scope was added (e.g. `GSHEETS_ENABLE_TITLE_SEARCH=1`, or an upgrade that needs a new scope) | Google 403 `insufficient authentication scopes` | log in again — the new scope is requested at login |
| OAuth client deleted, recreated, or its secret reset | an OAuth client error at login or on calls (`invalid_client` / `deleted_client` / `invalid_grant` — Google's wording varies) | install the new `client.json`, log in again for every account |
| New machine, Keychain entry removed, or `logout` | `no stored credentials for …` | `node dist/cli.js login --account <email>` |
Password changes do **not** revoke this server's tokens — per Google that applies only to tokens
holding Gmail scopes, which this server never requests.
The expiry message always says *"Expected roughly weekly"*: the server sees only `invalid_grant` and
cannot tell which of the causes above fired. If re-authorising doesn't fix it, work down the table.
Which accounts are dead, and how to add a new account: the
[`gworkspace-auth` skill](.claude/skills/gworkspace-auth/SKILL.md), usable by Claude Code or as a
checklist.
---
## Tools
| Tool | Purpose |
|---|---|
| `sheets_describe` | **Start here.** Tabs with `sheetId`, index, allocated **and used** ranges, frozen panes, named ranges, protected ranges, chart and conditional-format counts. No cell data. |
| `sheets_accounts` | Authorised accounts, active default, granted scopes, write configuration. |
| `sheets_read` | Several A1 ranges in one call. `valueRender: FORMATTED \| UNFORMATTED \| FORMULA`. TSV by default, capped, reports `nextRange` when truncated. |
| `sheets_inspect` | Per-cell detail values cannot express: formulas, notes, data validation, effective formatting, hyperlinks. |
| `sheets_write` | Batch writes to A1 ranges. `USER_ENTERED` (default) parses like typing; `RAW` stores literal text. |
| `sheets_append` | Append rows below a table's last populated row. |
| `sheets_clear` | Clear values, retain formatting. |
| `sheets_find_replace` | Scoped find/replace, optional regex, returns occurrences changed. |
| `sheets_create` | New spreadsheet with tabs. |
| `sheets_manage_tabs` | Add, delete, duplicate, rename, reorder, hide/show, resize. |
| `sheets_format` | Number formats, fonts, colours, borders, alignment, wrapping, merges, freezes, column/row sizing. |
| `sheets_data_tools` | Data validation, conditional formatting, basic filters, sorting. |
| `sheets_named_ranges` | Named ranges; protected ranges. |
| `sheets_batch_update_raw` | **Escape hatch.** Literal Sheets v4 `Request[]` — charts, pivots, slicers, developer metadata, anything Google ships later. |
### Docs
| Tool | Purpose |
|---|---|
| `docs_describe` | **Start here.** Outline without the full text: heading tree with index ranges, table positions, body length, named styles, tabs. |
| `docs_read` | Document text, sliceable by index range and capped. `withIndices` returns per-run boundaries. |
| `docs_find` | Locate exact text, return its index ranges. **The safe way to get indices** — measured now, not guessed, and matches spanning formatting boundaries are handled. |
| `docs_insert` | Insert at an index, at the end, or before/after existing text. |
| `docs_replace_text` | Find and replace. Carries no indices, so immune to drift — the safest way to change wording. |
| `docs_delete` | Delete index ranges. |
| `docs_format` | Text styling, links, paragraph named styles (headings), alignment, spacing, bullets. |
| `docs_table` | Insert a table, optionally populated. |
| `docs_create` | New document with optional initial text. |
| `docs_batch_update_raw` | **Escape hatch.** Literal Docs v1 `Request[]` — inline images, headers/footers, footnotes, bookmarks, positioned objects. |
#### Docs indices shift under you
A document is one flat run of characters, addressed by absolute offset. Inserting 5 characters at
index 10 invalidates every index after it — and within a single `batchUpdate` the requests apply in
order, so request #2 sees a document you never measured.
Three defences, so this mostly does not need thinking about:
1. **Every batch is reordered back-to-front** before sending, so an edit only disturbs text after
itself. Stable, so same-index requests keep your order. The response says when reordering happened.
2. **`docs_find` measures indices immediately before use.**
3. **`docs_replace_text` carries no indices at all.** Prefer it for wording changes.
Never reuse an index across separate calls. Batch instead, or re-run `docs_find`.
Every mutating tool takes `dryRun: true`, which returns the exact request it would send plus an
impact summary and sends nothing.
### Workflow
`sheets_describe` first, always. It supplies the `sheetId`s that structural edits need and the used
range that keeps a read from asking for `A:ZZ` and paying for empty cells.
---
## Safety
| Control | Effect |
|---|---|
| `--read-only` / `GSHEETS_READ_ONLY=1` | Registers only the 7 discovery and read tools: `sheets_describe`, `sheets_accounts`, `sheets_read`, `sheets_inspect`, `docs_describe`, `docs_read`, `docs_find`. |
| `GSHEETS_ALLOWED_IDS` | Comma-separated spreadsheet and document ids; writes to anything else are refused. Reads are unaffected. |
| `dryRun: true` | Returns the request instead of sending it. |
| `~/.config/gsheets-mcp/audit.log` | One JSON line per write: time, account, tool, file id, ranges, cell count. |
Google's own version history is the undo mechanism. The audit log is how you find *which* revision.
What is stored where, and how to report a vulnerability: [`SECURITY.md`](SECURITY.md).
---
## Configuration
Set these in a `config/<name>.env` profile, or pass them with `--env` at registration. A real
environment variable always wins over a profile file.
| Variable | Effect |
|---|---|
| `GSHEETS_PROFILE` | Profile to load, same as `--profile`. |
| `GSHEETS_CONFIG_DIR` | Where profiles live. Defaults to `config/` beside `dist/`. |
| `GSHEETS_CLIENT_ID` / `GSHEETS_CLIENT_SECRET` | OAuth client, instead of `client.json`. |
| `GSHEETS_CLIENT_FILE` | Alternative path to the client JSON. |
| `GSHEETS_DEFAULT_ACCOUNT` | Account to act as when a tool call does not name one. |
| `GSHEETS_ALLOWED_IDS` | Write allowlist. |
| `GSHEETS_READ_ONLY=1` | Same as `--read-only`. |
| `GSHEETS_AUDIT_LOG` | Alternative audit log path. |
| `GSHEETS_FORCE_FILE_TOKENS=1` | Skip the Keychain and use the 0600 file store. |
| `GSHEETS_ENABLE_TITLE_SEARCH=1` | Reserved: adds the `drive.metadata.readonly` scope at next login, but **no tool uses it yet** ([open tasks](docs/open-tasks.md)). Off by default. |
### Scopes
| Scope | Why |
|---|---|
| `auth/spreadsheets` | Read and write a spreadsheet whose id you already have |
| `auth/documents` | Read and write a document whose id you already have |
| `openid`, `email` | Identity only, no data access — returns the consenting account's email so credentials cannot be filed under the wrong account |
| `auth/drive.file` | Per-file, and reaches **only files this OAuth client created**. Present so the live test suite can delete its own scratch spreadsheets; it cannot list, read or touch anything else in your Drive |
`drive.readonly` is **not** requested and never will be — it would grant read of every file you own
to buy a filename lookup. Pass a spreadsheet URL or id, or use the Google Drive MCP to find one.
The Sheets, Docs and Drive APIs must all be enabled **on the project that owns the OAuth client** —
its number is your client id's prefix. See [`docs/setup-gcp.md`](docs/setup-gcp.md).
---
## Development
```bash
npm run typecheck
npm run build # tests run against dist/, so build first
npm test # unit, no network
node dist/cli.js profiles # what is configured locally
```
Live smoke tests create a scratch spreadsheet, exercise every tool against it, and delete it. They
never touch an existing spreadsheet, and run only when asked:
```bash
GSHEETS_LIVE_TEST=1 node --test test/live.test.js # Sheets
GSHEETS_LIVE_TEST=1 node --test test/live-docs.test.js # Docs
```
Both create a scratch file, exercise every tool against it, and delete it via `drive.file`.
No real spreadsheet ids or sheet content belong in this repo. Fixtures are synthetic.
Contributing: [`CONTRIBUTING.md`](CONTRIBUTING.md). Agents working in this repo: [`CLAUDE.md`](CLAUDE.md).
---
## License
[MIT](LICENSE)
TDQS
Scored across 24 tools
Most tools target a clearly distinct resource+action, and the docs/sheets prefix plus explicit guidance (describe before read, find before format/delete) keeps selection predictable. The main soft spots are the catch-all groupings — sheets_data_tools vs sheets_format vs sheets_named_ranges, and sheets_write vs sheets_append vs the two *_batch_update_raw escape hatches — where an agent must read descriptions carefully to know which wrapper owns a given operation.
Every tool follows the same snake_case prefix_action pattern (docs_*, sheets_*), with consistent verb placement and parallel operations across the two surfaces (describe/read/format/create/batch_update_raw). Minor outliers like sheets_accounts and sheets_data_tools are still readable and clearly namespaced.
24 tools is on the heavy side but is defensible for two large Google APIs, with grouped wrappers and a raw escape hatch rather than one tool per API endpoint. A few grouped tools (sheets_data_tools, sheets_named_ranges) could plausibly be merged, so it is slightly over the ideal band rather than badly scoped.
Both domains have full lifecycle coverage: create/read/describe, insert/append/write, find, replace, delete/clear, format, and structural edits, plus *_batch_update_raw to reach anything unwrapped. No obvious dead ends for document or spreadsheet editing workflows.