mcp
v0.11.1MCP server for open-doc — lets any agent framework list, read, write, and file documents over Streamable HTTP or stdio.
An MCP server for an open-doc workspace. Any agent framework that speaks Model Context Protocol can list, read, write, and file documents — and because it runs on the dev server, the page in the browser hot-reloads as the agent works. Point a client at http://localhost:5273/mcp. There is no session handshake — every call is independent, which is the stateless shape the 2026-07-28 revision expects. legacy: 'stateless' is left on, so 2025-era clients are served from the same endpoint.
Summary extracted from the README.
@open-document/mcp
English · 繁體中文
An MCP server for an open-doc workspace. Any agent framework that speaks Model Context Protocol can list, read, write, and file documents — and because it runs on the dev server, the page in the browser hot-reloads as the agent works.
pnpm add -D @open-document/mcp
open-doc dev --mcp
➜ MCP: http://localhost:5273/mcp
➜ Local: http://localhost:5273/
Point a client at http://localhost:5273/mcp. There is no session handshake — every call is independent, which is the stateless shape the 2026-07-28 revision expects. legacy: 'stateless' is left on, so 2025-era clients are served from the same endpoint.
Over stdio
For clients that launch their own MCP servers (Antigravity plugins, Claude Code, Gemini CLI), the package ships an open-doc-mcp bin with the same tools:
{ "command": "npx", "args": ["-y", "-p", "@open-document/mcp@latest", "open-doc-mcp"] }
It works on the workspace given by --cwd (or OPEN_DOC_CWD), else the first root the client reports, else the launch directory or one of its parents — whichever holds an open-doc.config.* or depends on @open-document/core. Until it finds one, every tool refuses, so it never writes into a folder that is not an open-doc workspace. Pass --server-origin http://localhost:5273 (or OPEN_DOC_SERVER_ORIGIN) to let the rendering tools reuse a running dev server.
The Antigravity plugin in plugins/open-doc uses exactly this.
Tools
| Tool | What it does |
|---|---|
list_documents |
Every document with id, title, theme, folder. Start here. |
read_document |
TSX source of one document, whole or fromLine–toLine. |
outline_document |
Line count, top-level blocks with their line ranges, and h1–h3 with their lines — no source. |
search_document |
Every source line containing some exact text, with its line number. |
edit_document |
Exact find-and-replace in the source; find must occur once (within fromLine–toLine when given) unless all is set. |
create_document |
Write a new docs/<id>/index.tsx. Refuses a taken id. |
write_document |
Replace the source. Pass expected for a conflict check. |
rename_document |
Rewrite meta.title. The id never changes. |
duplicate_document |
Copy to a fresh id, into the same folder. |
delete_document |
Remove the folder from disk. |
read_text |
The editable text runs at a line:column. |
write_text |
Replace one text run, leaving surrounding markup alone. |
add_comment |
Anchor a @doc-comment note for a later pass. |
list_themes / read_theme |
The house styles, and the full theme document. |
list_assets / upload_asset / find_asset_usages / delete_asset |
Images per document or global. |
list_folders / create_folder / file_document |
The folder manifest. |
check_layout |
Render the sheets and report layout faults, with source locations; maxPages adds a page budget per section. |
proofread_document |
Report text slips in the printed words — punctuation width, mixed Chinese scripts, doubled words, term casing. |
render_page |
PNG of one sheet at true page size. |
export_document |
Write pdf / html / png to disk, headlessly. |
import_markdown |
Turn Markdown into a document under docs/. |
translation_status / mark_translated |
Translations (meta.translationOf) that fell behind their source, with the source's diff; mark one caught up. |
import_docx |
Turn a Word .docx into a document under docs/, with warnings for what Word had that it could not keep. |
check_layout, render_page and export_document render the document in a headless browser and need playwright in the workspace (pnpm add -D playwright && pnpm exec playwright install chromium). They reuse the running dev server, so repeat calls are cheap.
Writing a document
A document is a React module, not a form. The flow that works:
list_themes, thenread_themefor the one you want — the palette, type scale, and paste-ready components are all in the body.create_documentwith a complete TSX source that declaresexport const design, the pages, andexport const metawiththeme: '<id>'.- Look at it in the browser; the dev server already reloaded.
For edits, prefer read_text → write_text over rewriting the file: it touches one text run and leaves the markup untouched.
check_layout. You cannot see the pages you wrote. It reports content clipped by the page edge, blank sheets, headings stranded at the foot of a page, and type too small to print — each with theline:columnto fix.render_pagegives you a picture of one sheet when the report is not enough.
Starting from Markdown the user already has? import_markdown writes the whole document — flow() body, cover, contents, images — and you refine from there. A Word file goes through import_docx the same way.
Concurrent edits
Long document? Every tool result an agent reads is sent again on each later model call, so read the outline, then only the lines you change: outline_document → read_document with fromLine/toLine (or search_document) → edit_document. Rewrite with write_document only when most of the file changes.
write_document and write_text both accept expected — the content you last read. If disk no longer matches, the call is refused with 409 instead of overwriting whatever the other agent (or the person in the browser) just did. Read, then write with expected; on a 409, re-read and reconcile.
Security
The tools write to the user's disk, so the endpoint defends itself:
- Host and Origin are validated against loopback. A page on another origin cannot drive the tools, which closes the DNS-rebinding path onto a local endpoint. Both rejections are
403. - Extra hostnames go through
allowedHosts, and only make sense when the endpoint is deliberately exposed. - Nothing here authenticates a caller. Anything beyond loopback needs a reverse proxy that does.
Embedding
open-doc dev --mcp covers the usual case. To mount it yourself:
import { createOpenDocMcpMiddleware } from '@open-document/mcp';
app.use('/mcp', createOpenDocMcpMiddleware({ userCwd: process.cwd() }));
createOpenDocMcpHandler returns the web-standard { fetch } form for runtimes that want a Request in and a Response out.