perf(mcp): name the first screen in open_session, not list it
Merged
OK
4d ago+174+174+012345678901234567890123456789-100-100-012345678901234567890123456789
What
open_sessionover 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, andattachsessions.- 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, andclose_sessionare 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:
| main | this PR | |
|---|---|---|
open_session reply, Hacker News front page (638 nodes) | 9.5k | 1.1k |
open_session reply, a Wikipedia article (listing truncated) | 15.9k | 1.1k |
open_session reply, testbed home | 1.5k | 1.2k |
| Server instructions (loaded in every conversation) | 468 | 232 |
tools/list, four schemas (loaded in every conversation) | 1.7k | 1.4k |
How it works
ScreenPresenter.unlisted(packages/core/src/agent/screen-update.ts:201) takes the screen as the baseline for later updates and returns onlyrevision, path, N nodes.initialandunlistedshare a privatehold(:185) that sets the baseline.firstScreenLine(packages/e2e/src/session-tools/tools.ts:98) builds the MCP sentence from that, and points atscreenshotwhen the observation has no tree.- Standalone and
testsessions call it infirstScreen(packages/e2e/src/mcp/session.ts:601,:622); held-test attachments call it inpackages/e2e/src/run/worker/held-test-tools.ts:172. It sits intools.tsbecause the worker must not value-importcatalog.ts, which pulls zod into CLI startup. - 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, andobservestill returns everything and resets the baseline. INSTRUCTIONS(packages/e2e/src/mcp/server.ts:54) and the tool descriptions insession.tsdrop the text the opening catalog already carries. Therun_codeAPI block stays in the opening: fetching it withtools {tool: "run_code"}costs more than the inline copy.docs/reference/mcp.mdxandskills/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, thenrun_codebefore anyobserve, thenobserve:
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 anyobserve, which is true of an agent that holds none.