gdocs-mcp-noapi
by jekooo2814
README.md
# gdocs-mcp-noapi
An MCP server that reads and edits **real Google Docs** by driving a signed-in Chrome tab over the DevTools Protocol.
No Google Cloud project. No OAuth client. No service account. No API key. If you can use Google Docs in a browser, this server can use it too — including accounts on school or work tenants that block third-party API access.
- 40 tools: read, write, format, tables, images, comments, headers, exports, Apps Script.
- Every write goes through a per-tab mutex, so parallel tool calls cannot interleave keystrokes.
- The document stays the source of truth: text is read from the DOM, from the clipboard, or from Google's own HTML export.
- Works with any MCP client: OpenCode, Claude Desktop, Cursor, Windsurf, or a hand-rolled client.
---
## Requirements
| Thing | Why |
| --- | --- |
| Node.js 20 or newer | the server and the bundle |
| Google Chrome or Chromium | the tab the server drives |
| A Google account signed in to that browser | Docs needs a session |
| A document you can open in that account | obviously |
The server never sees your password. It attaches to a Chrome instance that you signed in to yourself.
---
## Install
```bash
git clone https://github.com/jekooo2814/gdocs-mcp-noapi.git
cd gdocs-mcp-noapi
npm install
npm run build
```
`npm run build` bundles `src/google-docs.mjs` into `dist/google-docs.mjs` with esbuild. The bundle is what the MCP client runs; `dist/` is committed so you can skip the build if you trust the source.
### Start Chrome with the debugging port
```bash
npm run launch
```
This opens Chrome with a dedicated profile in `~/.gdocs-mcp/profile` and remote debugging on port 9222. Sign in to Google once in that window. The profile persists, so you only do this once.
Already have Chrome running with a debugging port? Skip `launch` and set `GDOCS_PORT` to that port.
| Variable | Default | Meaning |
| --- | --- | --- |
| `GDOCS_PORT` | `9222` | DevTools port to attach to |
| `GDOCS_PROFILE` | `~/.gdocs-mcp/profile` | Chrome profile used by `launch` |
---
## Wire it into an MCP client
Any client that speaks MCP over stdio works. The command is `node` and the argument is the absolute path to the bundle.
### OpenCode
`opencode.json`:
```json
{
"$schema": "https://opencode.ai/config.json",
"mcp": {
"google-docs": {
"type": "local",
"command": ["node", "/absolute/path/to/gdocs-mcp-noapi/dist/google-docs.mjs"],
"enabled": true
}
}
}
```
### Claude Desktop
`claude_desktop_config.json`:
```json
{
"mcpServers": {
"google-docs": {
"command": "node",
"args": ["/absolute/path/to/gdocs-mcp-noapi/dist/google-docs.mjs"]
}
}
}
```
### Anything else
Spawn `node /absolute/path/to/dist/google-docs.mjs` and speak MCP on stdin/stdout. No flags, no ports of its own, no HTTP.
Windows paths go in as `C:\\Users\\you\\gdocs-mcp-noapi\\dist\\google-docs.mjs`.
---
## First run
1. `launch` — Chrome opens with the dedicated profile.
2. Sign in to Google in that window.
3. `open` with a document URL or a bare document id.
4. `read` — you get the text with line numbers.
`open` is only needed once per document. Every later call reattaches from `~/.gdocs-mcp/state.json`, so a fresh MCP process still knows which tab and which document you meant. `forget` clears that record.
If `status` says `signedIn: false`, the Chrome window is not signed in or the tab is not on a document. Fix that in the browser, then call `open` again.
---
## Tools
`help` returns this same catalog as JSON, plus the shortest recipe for each common job. Call it first when a client is unsure which tool to use.
### Document lifecycle
| Tool | What it does |
| --- | --- |
| `open` | attach to a document by URL or id |
| `status` | tab, account, line count, remembered document, queue state |
| `forget` | drop the remembered document |
| `launch` | start Chrome with the debugging port and dedicated profile |
### Reading
| Tool | What it does |
| --- | --- |
| `read` | text with line numbers; `source`: `auto`, `dom`, `clipboard`, `html`, `export_html`, `raw`, `pdf`, `export` |
| `styles` | exact formatting of a text match, or the caret's toolbar state |
| `outline` | headings with level and text |
| `word_count` | words, characters, lines, paragraphs |
| `probe` | what the live page actually exposes — use it when a selector fails |
`read source:"export_html"` is the fast full read: Google's HTML export fetched inside the page with your cookies, no clipboard, no caret movement, roughly 300 ms. It returns markdown with `**bold**`, `*italic*`, `++underline++`, `~~strike~~`, `<sup>`, `<sub>`.
### Writing
| Tool | What it does |
| --- | --- |
| `insert` | type at the caret |
| `append` | type at the end of the document |
| `replace` | find a match, type over it; empty replacement deletes |
| `replace_all` | bulk find/replace through Docs' own dialog; returns the count |
| `delete` | find and delete |
| `build` | write a whole document from markdown or HTML, with `replace` to wipe first |
| `replace_html` | replace everything with one HTML paste |
| `insert_html` | paste HTML at the caret |
| `import_file` | local file: text pastes, binary uploads |
| `history` | undo, redo |
| `backup` | save the text to `~/.gdocs-mcp/backups` |
### Formatting
| Tool | What it does |
| --- | --- |
| `format` | any combination in one call: bold, italic, underline, strike, sup/sub, heading, font, size, color, background, align, line spacing, list, indent, link, clear, uppercase |
| `find` | select the nth match and leave it selected |
| `insert_link` | turn the selection into a link |
| `insert_break` | page break, horizontal line, footnote, bookmark |
| `mode` | editing, suggesting, viewing |
`format` takes `find` to select exactly what to style, so one call does the whole job:
```json
{ "find": "Chapter 1", "bold": true, "size": 18, "color": "red", "align": "center" }
```
### Structure
| Tool | What it does |
| --- | --- |
| `insert_toc` | insert or refresh the table of contents |
| `insert_table` | empty table at the caret |
| `table` | add/delete rows and columns, merge, unmerge, fill |
| `headers_footers` | header, footer, page numbers |
| `comments` | add, list, reply, resolve |
| `insert_image` | upload a local image |
| `insert_image_url` | download and upload an image from a URL |
### Escape hatches
The named tools cover the common paths. These cover everything else, which means the server can do anything the UI can do.
| Tool | What it does |
| --- | --- |
| `menu` | click any menu path, e.g. `["Format","Text","Superscript"]` |
| `keys` | send a key chord, e.g. `ctrl+shift+7` |
| `type` | type into whatever has focus |
| `click` | click by CSS selector or visible text |
| `input` | fill a visible field by label or placeholder |
| `apps_script` | bound Apps Script: check, open, run code with `{{doc}}` |
| `export` | docx, pdf, txt, epub, rtf, odt, html to disk |
| `screenshot` | PNG of the tab |
---
## Recipes
**Write a document from scratch**
```json
{ "tool": "build", "args": { "markdown": "# Report\n\nText with **bold** and a [link](https://example.com).\n\n- one\n- two", "replace": true } }
```
**Read it back fast**
```json
{ "tool": "read", "args": { "source": "export_html" } }
```
**Find and edit one paragraph**
```json
{ "tool": "find", "args": { "text": "old sentence" } }
{ "tool": "replace", "args": { "find": "old sentence", "replacement": "new sentence" } }
```
**Style a heading**
```json
{ "tool": "format", "args": { "find": "Results", "heading": "h1", "bold": true, "color": "blue" } }
```
**Verify what actually landed**
```json
{ "tool": "styles", "args": { "text": "Results" } }
```
**Table with content**
```json
{ "tool": "insert_table", "args": { "rows": 3, "columns": 2 } }
{ "tool": "table", "args": { "action": "fill", "rows": [["Name","Score"],["Ana","10"],["Luis","9"]] } }
```
**Header, footer, page numbers**
```json
{ "tool": "headers_footers", "args": { "header": "Internal report", "footer": "Confidential", "page_numbers": true } }
```
**Comment on a phrase**
```json
{ "tool": "find", "args": { "text": "revenue" } }
{ "tool": "comments", "args": { "action": "add", "text": "Check this number" } }
```
**Anything the tools do not cover**
```json
{ "tool": "menu", "args": { "path": ["Format", "Columns", "2"] } }
```
---
## How it works
```
MCP client ──stdio──▶ server ──WebSocket──▶ Chrome DevTools Protocol ──▶ docs.google.com
```
1. The server lists Chrome targets and finds the Docs tab.
2. It attaches with `Target.attachToTarget` and sends `Runtime.evaluate` and `Input.*` commands.
3. Text is read three ways: the DOM mirror Docs keeps for accessibility, the clipboard's HTML flavor, or Google's own export endpoint fetched from inside the page.
4. Writes go through a mutex per tab. Two tools never type at the same time.
5. Every mutating tool clears the export cache, so a read after a write sees the new state.
Nothing is stored in the cloud. The only local state is `~/.gdocs-mcp/`: the remembered document, the Apps Script project map, backups and downloaded images.
---
## Limitations
These are real, and the notes say what to do about them.
- **Export rate limit.** Google returns HTTP 429 when the HTML export is hit in bursts. The server caches exports for 1.5 s and retries with backoff, but rapid alternating reads and writes can still hit it. Wait a second and retry.
- **Drive file picker.** On some accounts the Drive picker never raises its file chooser, so `import_file mode:"picker"` cannot complete. Use `drop` with a local path, or `insert_image` for images.
- **Image width.** Google does not expose a stable control for exact image width through the toolbar; width is best-effort and not reported.
- **Autosave lag.** The export reflects what Google has autosaved. `styles` waits ~250 ms after a mutation before reading; a very large document may need a moment more.
- **One tab at a time.** The mutex is per tab. Two documents in two tabs are fine; two agents on the same tab queue up.
- **Localized UI.** Menu paths are matched in English and Spanish. A different UI language needs new aliases in `BUTTONS` and `MENU_ALIASES` in `src/google-docs.mjs`.
---
## Troubleshooting
| Symptom | Fix |
| --- | --- |
| `Could not focus the document body` | a modal is open — call `keys` with `escape`, then retry |
| `Chrome is not running on port 9222` | `npm run launch`, or set `GDOCS_PORT` to the right port |
| `signedIn: false` | sign in to Google in the Chrome window, then `open` again |
| `Text not found in the export` | the text has different spacing or is not saved yet; `read` first |
| A tool reports `(chord)` | the menu path failed and a keyboard shortcut was used instead; verify with `styles` |
| `HTTP 429` on read | wait a second, or use `source:"export"` / `source:"dom"` |
---
## Development
```bash
npm test # selftest: parsers, HTML to markdown, style resolution
npm run build # rebuild dist/google-docs.mjs
npm run probe # open a URL and dump what the page exposes
npm run format # biome
npm run lint
```
`src/google-docs.mjs` is the whole server: CDP client, gate, document helpers, tools, selftest. `dist/google-docs.mjs` is generated — edit the source and rebuild.
Add a tool with the `tool(name, description, schema, handler)` helper. Handlers that mutate must not be marked `readOnly`, because that flag controls the export cache and the mutex reporting.
---
## Guía rápida en español
```bash
git clone https://github.com/jekooo2814/gdocs-mcp-noapi.git
cd gdocs-mcp-noapi
npm install
npm run build
npm run launch # abre Chrome con el perfil dedicado, inicia sesión una vez
```
Configuración para OpenCode:
```json
{
"mcp": {
"google-docs": {
"type": "local",
"command": ["node", "/ruta/absoluta/a/gdocs-mcp-noapi/dist/google-docs.mjs"]
}
}
}
```
Uso típico:
1. `open` con la URL del documento.
2. `read` para leerlo con números de línea.
3. `build` para escribir un documento entero desde markdown.
4. `find` + `replace` para cambiar un texto concreto.
5. `format` con `find` para aplicar negrita, tamaño, color, alineación o estilo de párrafo en una sola llamada.
6. `styles` con `text` para comprobar que el formato se aplicó de verdad.
7. `export` para descargar en docx, pdf o txt.
La UI de Docs se maneja en español o en inglés; las rutas de menú están traducidas para ambos. Si usas otro idioma, añade los alias en `src/google-docs.mjs`.
---
## License
MIT. See [LICENSE](LICENSE).
This server cannot be deployed
Maintenance
ActivityMaintained
ResponsivenessNo recent community issues