0601. MCP context economy: text-first results, short handles, budgeted outlines
Status: Accepted (2026-11-27). Implements the context-management part of 0012 (WP-F, wave 2).
Context
Everything the MCP returns, and the tool list itself, sits in the agent’s context window. Three things weighed against the shape 0012 sketched:
- The tool list is resent on every turn.
- Clients differ on whether they forward
content, structuredContent or both.
- On the 662K-node page, one outline line costs about 15-28 tokens. With the old default of 200 lines, a single outline came to about 3,700 tokens.
Decision
- Text first. Every tool answers with compact text in
content:
- tables are a header line plus space-separated rows: strings JSON-quoted, numbers to 0.01, bounds
x,y,w,h, - for null;
- id lists become runs (
5:1-1000);
- edits answer
seq · created N, refs and top-level id bounds, never an echo of the request.
structuredContent (the shared/src/mcp.ts output types) is returned only with LINORA_MCP_STRUCTURED=1.
- Conventions said once. Ids, coordinates, rotation, colors, child order, paging and seq go in the server
instructions, sent once per session. Property descriptions in MCP_TOOLS stay only where a name is not self-explanatory.
- tools/list shrank 27% (16,644 -> 12,190 chars).
- A unit test pins the instructions to the schemas.
- The open_page default
topLevelLimit drops to 25.
- Short, stable handles. Projects, files and pages show the shortest unique prefix of their UUID, at least 8 hex chars. It is deterministic, so no session table is needed and handles stay valid across sessions; ambiguity is an error that lists the candidates.
- Node ids (“3:1042”) are already short.
create_nodes refs work as ids on the page for the rest of the session, and unnamed nodes take their ref as layer name.
- Budgeted outline. A default
get_outline targets 1,800 estimated tokens:
- the first request uses maxNodes 100 and re-asks smaller when over budget;
- later requests are sized from the tokens/line measured on that page.
- The worker’s breadth-first fill plus its root
[+N: ...] trailer keeps what is hidden visible.
- Self-correcting errors. Failures are
isError results of the form code: what. Fix: what to do.
- Local validation reports every problem in one answer, with JSON paths, valid alternatives and “did you mean” (including common CSS and design-tool synonyms such as
colour -> fill and borderRadius -> cornerRadius).
- Token estimator.
estimateTokens (letter runs /4, digit runs /3, every symbol and newline 1) is deliberately conservative and needs no tokenizer dependency. Budgets measured with it hold for real tokenizers.
Alternatives
- JSON results (the contract objects as text): about 2x the tokens of the tables for the same rows.
- Both
content and structuredContent always: doubles the cost on clients that forward both.
- Session-local handles (
p1, f2): shorter, but they break across sessions and need state per session.
- A shorter outline line format (no bounds below depth 1): would need a contract change and loses layout information agents use. Budgeting the line count was enough.
Consequences
- Programmatic clients set
LINORA_MCP_STRUCTURED=1.
- Agents learn the conventions from the instructions. Clients that drop server instructions still get correct but less self-explanatory schemas.
- Changing a convention means updating
INSTRUCTIONS and its unit test together.