perf(mcp): name the first screen in open_session, not list it

Merged
OK
4d ago
+174-100

What

  • open_session over MCP no longer lists the first screen. Its reply ends with one line:
    Screen: revision b2, path /, 638 nodes, not listed. Action results report changes against it; call {tool: "observe"} lists its nodes.
    This applies to standalone, test, and attach sessions.
  • A first screen with no tree ends with ...semantic capture unavailable; call {tool: "screenshot"} shows it.
  • The server instructions and the descriptions of open_session, tools, call, and close_session are shorter.

Why

On a real page the first screen was most of the open_session reply, and an agent that navigates or runs code first never reads it. Tokens are chars / 4:

mainthis PR
open_session reply, Hacker News front page (638 nodes)9.5k1.1k
open_session reply, a Wikipedia article (listing truncated)15.9k1.1k
open_session reply, testbed home1.5k1.2k
Server instructions (loaded in every conversation)468232
tools/list, four schemas (loaded in every conversation)1.7k1.4k

How it works

  1. ScreenPresenter.unlisted (packages/core/src/agent/screen-update.ts:201) takes the screen as the baseline for later updates and returns only revision, path, N nodes. initial and unlisted share a private hold (:185) that sets the baseline.
  2. firstScreenLine (packages/e2e/src/session-tools/tools.ts:98) builds the MCP sentence from that, and points at screenshot when the observation has no tree.
  3. Standalone and test sessions call it in firstScreen (packages/e2e/src/mcp/session.ts:601, :622); held-test attachments call it in packages/e2e/src/run/worker/held-test-tools.ts:172. It sits in tools.ts because the worker must not value-import catalog.ts, which pulls zod into CLI startup.
  4. Because the baseline is set, the first action result is a diff against the unlisted screen. A full listing there would only move the cost to the first run_code. The opening line says so, and observe still returns everything and resets the baseline.
  5. INSTRUCTIONS (packages/e2e/src/mcp/server.ts:54) and the tool descriptions in session.ts drop the text the opening catalog already carries. The run_code API block stays in the opening: fetching it with tools {tool: "run_code"} costs more than the inline copy.
  6. docs/reference/mcp.mdx and skills/e2e/references/mcp.md (plus the synced plugin copy) describe the new reply. Translated pages are not updated.

Not in this PR: a navigate or run_code that loads a new document still reprints the whole tree, since node ids change per document.

Verified

Ran it locally: yes

  • Built CLI as an MCP server over stdio from apps/testbed (node node_modules/e2e/dist/cli/bin.js mcp), with a scratch config for the two public pages. Reply sizes are in the table above, main against this head.
  • open_session, then run_code before any observe, then observe:
Screen: revision b2, path /, 28 nodes, not listed. Action results report changes against it; call {tool: "observe"} lists its nodes.

Screen unchanged since revision b2 (re-observed as revision b4, path /); the ids you have stay valid.

Current screen (revision b6, path /, 28 nodes):
#root document "Playground"
 #n2 navigation "Main"
  #n3 link "Home" href="/"
  • Two rounds of fresh-context review. Fixed: the no-tree opening pointed at observe, the opening did not say results diff against the unlisted screen, stale comments, and a redaction test for the opening that could no longer fail (it now puts the secret in the path). Left as is: "the ids you have stay valid" in a diff before any observe, which is true of an agent that holds none.