feat(mcp)!: e2e mcp is headless by default, and open_session takes headed

Merged
KR
2mo ago
+87-27

e2e run and e2e explore are headless by default and take --headed. e2e mcp did the opposite: it was headed outside CI and took --headless. So e2e mcp --headed was an unknown option, and on a machine with no display (a Linux box, a container) every open_session failed until you passed the other flag. Showing or hiding the browser also meant editing the MCP client config, when it's really the agent's call: the user says "let me watch" in the chat, not in .mcp.json.

  • open_session takes an optional headed boolean (packages/e2e/src/mcp/session.ts). headed: true shows this session's browser or simulator, false hides it. Each session keeps its own value, so two sessions on one server can differ. The opening line (..., headed;) and the session telemetry report the session's value, not the server's.
  • e2e mcp --headed sets the default for sessions that don't pass headed. Without it, sessions are headless, the same as run and explore (packages/e2e/src/cli/mcp.ts). The CI check is gone because run doesn't do one either.
  • --headless is still accepted but hidden from --help and the docs (packages/e2e/src/cli/index.ts). It now asks for the default. Rejecting it would break any client config that passes it, and MCP hosts mostly hide stderr, so the user would only see a failed connection.
  • The agent wins: neither the default nor a leftover --headless stops open_session {headed: true}. On a machine with no display that open fails with ENGINE_FAILURE (Missing X server or $DISPLAY), and the agent can retry headless.
  • The schema description and the server instructions tell the agent to pass headed: true when the user wants to watch. docs/reference/mcp.mdx and skills/e2e/references/mcp.md document the argument and the new default.
open_session({})                  // headless, or headed under e2e mcp --headed
open_session({ headed: true })    // the user wants to watch
open_session({ headed: false })   // headless even under --headed

Tests that fail on main: mcp-session-host.test.ts overrides the server default both ways on the fake engine and checks what reached the engine and the telemetry. mcp-server.test.ts runs with CI unset, asserts the default session opens headless, starts the CLI with --headed and with --headless on the fake engine, and checks that headed is in the schema the client receives.

Verified

Ran it locally: yes

  • e2e mcp surface: the built CLI served the testbed to an MCP client over stdio with CI unset. For each case it called open_session and read the opening line.
  • Every headless case opens a session. Every headed case gets as far as launching a headed Chromium, which fails here (Linux, no $DISPLAY), the same way e2e run tests/smoke.e2e.ts --headed does on this machine.
$ e2e mcp            ->  open_session {}
  Session 01a10b49-... open on target "web" (platform web, engine web 0.12.0), headless; config .../apps/testbed/e2e.config.ts.
$ e2e mcp            ->  open_session {"headed":true}
  ENGINE_FAILURE: browser launch failed: browserType.launch: Target page, context or browser has been closed
$ e2e mcp --headed   ->  open_session {"headed":false}
  Session 01a10b49-... open on target "web" (platform web, engine web 0.12.0), headless; config .../apps/testbed/e2e.config.ts.
$ e2e mcp --headed   ->  open_session {}
  ENGINE_FAILURE: browser launch failed: browserType.launch: Target page, context or browser has been closed
$ e2e mcp --headless ->  open_session {}
  Session 01a10b1a-... open on target "web" (platform web, engine web 0.12.0), headless; config .../apps/testbed/e2e.config.ts.

The headed property the client sees on open_session:

{"type":"boolean","description":"Show the browser or simulator, when the engine supports it; pass true when the user wants to watch. Default: headless, unless the server was started with --headed"}

Changes made by Claude Opus 5.5 (claude-opus-5-5) in Claude Code.