apps/mcp)Owner: WP-F (now M1). ADRs 0012, 0022, 0601, 0602, 0603, 0604. Contracts: MCP_TOOLS and output types in shared/src/mcp.ts; API routes in shared/src/api.ts; realtime connection from @linorahq/sync-client/connection (WP-D).
MCP_TOOLS run over stdio and Streamable HTTP./v1 and the realtime WebSocket: a PAT, no database, and no document replica.LINORA_MCP_REALTIME_URL replaces the origin of the token’s browser-facing realtime url (the prod-like compose joins through ws://edge:8080), and open_page waits at most 15 s, then answers unavailable with the url and the fix.apps/mcp/src/
main.ts entry: stdio (LINORA_URL + LINORA_TOKEN) or Streamable HTTP (LINORA_MCP_TRANSPORT=http)
http.ts Streamable HTTP host on /mcp (limits: see "Hosted limits"):
PAT shape checked first, then GET /v1/me on initialize (cached 30 s per token);
each session is bound to its token's SHA-256, checked before the body is read;
bodies capped while streaming; sessions capped per token/user/host;
tool calls gated per session and per user; idle sessions expire after 30 min;
X-Forwarded-For to the API; DNS-rebinding guard when bound to loopback
limits.ts Gate (bounded queue), ByteBudget, KeyedBuckets (per-IP), TtlCache
ids.ts the one id-list parser: ids, refs and runs within the 10,000-id budget per call
server.ts SDK low-level Server:
tools/list = MCP_TOOLS (+ readOnlyHint);
tools/call -> validate -> tool;
INSTRUCTIONS (shared conventions, sent once per session)
session.ts AgentSession / OpenPage:
API client, short handles;
the live connection (presence kind 'agent'; realtime origin override and
bounded join, ADR 0604);
undo/redo, refs, others' change log, top-key cache;
read helpers (paging, ancestor spaces)
api.ts typed /v1 client from the shared route table:
errors -> ToolErrors with fix hints;
503/429 retried per Retry-After within 6 s
validate.ts JSON Schema subset validator; messages written for agents (path, fix, "did you mean")
convert.ts MCP form <-> JSON-op form, local kind/range checks, text measuring (@linorahq/doc/text), creation defaults
geometry.ts affine math identical to packages/doc (rotation about the box center, children in parent space)
format.ts compact renderings (tables, id runs), conservative token estimator
handles.ts stable short ids for projects/files/pages (sorted; 20,000 per kind)
tools/ navigation.ts (navigation + files/pages), read.ts, edit.ts, common.ts
| Tool | Calls |
|—|—|
| list_projects / list_files / list_pages | listProjects, listFiles, getFile |
| open_page | getFile -> realtime token (origin replaced by LINORA_MCP_REALTIME_URL when set) + openRoom(sinceSeq = page head) (presence), both within LINORA_MCP_JOIN_TIMEOUT_MS (15 s) -> summary (topLevelLimit 25) |
| get_outline | outline (default depth 2; maxNodes sized to the token budget, see below) |
| find_nodes / get_nodes | searchNodes / getNodes (field selection; ["all"]) |
| get_changes | the live log of others’ broadcasts after a head check (changes?since=&limit=1); falls back to changes for older seqs |
| get_peers | presence of the open room (cursor, viewport, selection, tool) |
| render | render (PNG as an MCP image, SVG as text) |
| create_nodes | the top-key cache (one getNodes(parent, childDepth 1, [key]) the first time a parent is used) -> CREATE_BULK blocks with ids from the connection’s clientId -> OPS -> ACK |
| update_nodes | getNodes(ids, touched fields) (old values; current text/line geometry) -> SET -> ACK |
| delete_nodes | getNodes(ids, all, childDepth 64, paged) -> DELETE; undo = RESTORE blocks (<= 50,000 nodes per call) |
| transform_nodes | getNodes(geometry) + ancestor spaces (one getNodes per tree level) -> SET x/y/w/h/rotation (groups scale their content) |
| arrange_nodes | sibling keys (getNodes(parent, childDepth 1)) -> SET PARENT_INDEX (reparent re-expresses x/y/rotation in the new parent) |
| duplicate_nodes | getNodes(subtrees, all) -> CREATE_BULK with fresh ids, each copy right above its original (or on top of parentId) |
| set_selection | getNodes(bounds) -> presence (cursor at the center, selection = ids) |
| undo / redo | the agent’s own stack; property steps re-read current values first (ADR 0602) |
| create_file / create_page / update_page / delete_page | createFile, createPage, updatePage, deletePage |
Reads after edits pass minSeq = the newest seq the agent has seen (read-your-writes). Every result reports seq.
nKeysBetween.
REASON: hint per op.ref as layer name.@linorahq/doc/text, ADR 0014) and written in the same op:
x1,y1,x2,y2. Paths normalise points to the box top-left and size the box to them.agent). Collaborators see it at <= 20 Hz.x,y,w,h, - for null;5:1-1000);seq · created N + refs + top-level id bounds.structuredContent (the shared/src/mcp.ts output types) is opt-in (LINORA_MCP_STRUCTURED=1), so clients that forward both never pay twice.create_nodes and runs like "5:1-40" are accepted wherever ids are.render, whose ids go in the URL). A run wider than the budget left is refused before it expands.untrusted (for example ["rows[name]", "rows[text]"]).get_outline calls stay under 1,800 estimated tokens:
[+N: ...] keeps the hidden count visible.isError result code: what. Fix: what to do. Examples:
read_only: ... Fix: ask a project owner for editor access;nodes[0].colour: unknown property (did you mean fill?);bad_args: nodes[3].cornerRadius: not valid on text; valid: ....instructions, sent once. tools/list JSON shrank from 16,644 to 12,190 chars (-27%). A unit test pins the instructions to the schemas.get_changes instead of re-reading.
Nothing a client sends grows without a bound. Defaults are in HTTP_DEFAULTS (http.ts).
| What | Limit | When exceeded |
|---|---|---|
| Ids per call (runs expanded) | 10,000 (render: 500) |
bad_args, before anything is allocated |
| Request body on a session | 1 MiB (LINORA_MCP_MAX_BODY_BYTES). The 10,000-node benchmark tree is 923,066 bytes |
413: a declared length is refused unread, a stream is cut at the cap |
| Body before a session (initialize) | 64 KiB | 413 |
| Bodies being read, process-wide | 64 MiB | 503 + retry-after: 1 |
| Refused upload | the rest is discarded, never buffered, up to 8 MiB or 10 s | connection cut |
| Bearer value | must match linora_pat_ + 43 chars |
401, no API call, body not read |
/v1/me per token |
cached 30 s (401s too; 10,000 entries) | - |
initialize per client address |
2/s, burst 20 | 429 + retry-after |
| Sessions per token / per user / per host | 10 (LINORA_MCP_SESSIONS_PER_TOKEN) / 20 / 1,000 (LINORA_MCP_MAX_SESSIONS) |
the least recently used idle session is evicted (host-wide: only after 5 min idle); 429 / 503 if all are busy |
| Tool calls per session | 4 running, 16 waiting | busy: ... Fix: wait ... tool error |
| Tool calls per user | 16 running, 64 waiting | busy tool error |
| Idle session | 30 min (not while a call is in flight) | closed; the client gets 404 and initializes again |
| Refs per page | the latest 50,000; 128 chars each | the oldest are forgotten / bad_args |
| Undo + redo per page | 200 steps and 32 MiB (the newest step always kept) | oldest steps dropped |
| Short handles / page-to-file map | 20,000 per kind / 20,000 | oldest forgotten |
mcp-session-id) the session and token hash, and only then the body. Without a session, the per-address rate limit runs, then the 64 KiB body is read, then initialize is checked, then /v1/me, then the session caps.X-Forwarded-For: the well-formed inbound entries (the last 8) plus the socket peer. The API’s per-IP bucket sees agents once it trusts this hop (LINORA_TRUST_PROXY, an API setting). LINORA_MCP_TRUST_PROXY sets how many proxy hops in front of the adapter are trusted, for its own per-address limit.Setting up an agent against a running stack (token, transports, Claude Code and Claude Desktop, troubleshooting): guides/mcp.md. The notes below are for running the adapter by hand.
LINORA_URL=http://localhost:8787 LINORA_TOKEN=linora_pat_... node apps/mcp/src/main.ts.
POST /v1/tokens and scopes files:read files:write.LINORA_MCP_TRANSPORT=http LINORA_MCP_PORT=8789 node apps/mcp/src/main.ts.
Authorization: Bearer linora_pat_... on every request to http://host:8789/mcp..mcp.json):
{ "mcpServers": { "linora": { "command": "node", "args": ["apps/mcp/src/main.ts"], "env": { "LINORA_URL": "http://localhost:8787", "LINORA_TOKEN": "linora_pat_..." } } } }
Over HTTP: {"type": "http", "url": "http://localhost:8789/mcp", "headers": {"Authorization": "Bearer linora_pat_..."}}.
npx @modelcontextprotocol/inspector node apps/mcp/src/main.ts (with LINORA_URL/LINORA_TOKEN in the environment).Env: LINORA_MCP_TRANSPORT (stdio |
http), LINORA_URL, LINORA_TOKEN, LINORA_MCP_PORT (8789), LINORA_MCP_HOST (127.0.0.1), LINORA_MCP_STRUCTURED. |
LINORA_MCP_REALTIME_URL (a ws[s]://host[:port] origin that replaces the token url’s; set it when the adapter cannot reach the browser-facing LINORA_REALTIME_URL, e.g. ws://edge:8080 in docker-compose.prod.yml) and LINORA_MCP_JOIN_TIMEOUT_MS (15,000).LINORA_MCP_MAX_BODY_BYTES (1 MiB), LINORA_MCP_MAX_SESSIONS (1,000), LINORA_MCP_SESSIONS_PER_TOKEN (10), LINORA_MCP_TRUST_PROXY (0).Measured on an M4 Pro with a local stack (realtime + API + doc worker, Docker Postgres) by npm test -w @linorahq/mcp (e2e) and npm run bench -w @linorahq/mcp. The page is WP-A’s 4,000-page site, 662,190 nodes. Tokens use estimateTokens (format.ts): letter runs /4, digit runs /3, every symbol and newline 1. That over-counts structured text (2.35 chars/token here, against about 3.6 for real tokenizers).
| Criterion | Result |
|---|---|
Handshake over stdio and Streamable HTTP; tools/list returns every MCP_TOOLS entry |
met (e2e: SDK clients on both transports; PAT-bound HTTP sessions; 401/403 cases) |
| 1,000-node nested tree in one call < 1 s, visible to a browser session | met: median 10 ms in-process, 10 ms over stdio, 9 ms over HTTP (max 28 ms), ACK included. 10,000 nodes: 35 ms. A human peer receives all 1,000 nodes in one broadcast |
| Agent cursor visible | met (e2e: the human peer sees kind agent, the cursor on the new frame, its selection) |
| Undo reverts only agent edits | met (e2e: a human’s later value and a human’s node survive the agent’s undo; redo restores the same ids) |
| Outline of the 662K page with defaults <= 2,000 tokens | met: 1,779 estimated tokens (4,179 chars, 65 lines; about 1,160 at 3.6 chars/token), 17 ms. open_page: 673 tokens |
Viewer PAT gets clear read_only errors |
met (viewer member and files:read-only PAT: read_only: ... Fix: ask a project owner for editor access; reads still work) |
| No private paths | met (check-deps: shared, @linorahq/doc json/keys/inverse/text, @linorahq/sync-client/connection; the e2e test records every URL: only /v1/ and /v1/realtime) |
Also covered:
"c:0-100000", 552 bytes) answers bad_args from every id-taking tool, with the heap flat. Before the fix it cost 492 MiB RSS and 1.6 s CPU (438 MiB in the review); now it costs 5 MiB RSS, 0 MiB heap and 10 ms. 500,000 runs: 6 MiB and 15 ms.413, and a 32 MiB stream is cut off. Unauthenticated requests are answered without buffering. A 10,000-node create_nodes still fits./v1/me is cached; the per-address initialize limit holds; X-Forwarded-For reaches the API.busy errors.