refactor(mcp): move the session tools out of mcp/ so the runner can reuse them

Merged
SA
5d ago
+125-75

A refactor with no behavior change. It's the base for #1972, which runs the MCP session's tools in the runner's worker to attach to a held test.

  • The session tools moved from packages/e2e/src/mcp/ to packages/e2e/src/session-tools/: tools.ts, catalog.ts, test-lines.ts, run-code.ts, code-parse.ts, code-surface.ts, and recording.ts. Nothing in session-tools/ imports from mcp/, so run/ can use them without importing from mcp/.
  • RunCodeSession and CatalogOptions now ask only for the members the code reads. A host with a different kind of attempt can supply them. mcp/session.ts still passes the full objects.
  • createStepExecution in packages/core/src/agent/step-execution.ts builds the StepAccounting, ObservationFeed, and ActionDispatcher that act.ts built inline, on one shared queue, and returns the context bindings. act.ts calls it. #1972 can call it too, where it copied this wiring by hand before.
// packages/core/src/agent/step-execution.ts
export function createStepExecution(runtime: AgentContext, options: StepExecutionOptions): StepExecution;

The public .d.ts files of e2e and @e2e-dev/core are unchanged, so there's no changeset.

Verified

Ran it locally: yes

  • Testbed, the built e2e mcp over stdio. A normal session opens and the moved tools run:
> open_session {target: "web"}
Session <id> open on target "web" (platform web, engine web 0.16.1), headless

> tools
Session <id> on target "web": 32 tools. Run one with call {tool, args}; tools {tool} shows a tool's arguments.

> call {tool: "locate", args: {role: "link", name: "Todos"}}
1 node matches getByRole("link", name: "Todos"). | Use: screen.getByRole("link", "Todos")

> call {tool: "run_code"}
All 2 statements passed. | 1. passed: await screen.getByRole("link", "Todos").tap(); | 2. passed: await expect(screen.getByRole("heading", "Todos")).toBeVisible();

> call {tool: "test_lines"}
Draft test body from this session's actions, in order (3 lines): await app.open(); await screen.getByRole("link", "Todos").tap(); ...

> call {tool: "screenshot"}
Screenshot attached: 768 by 432 pixels

> close_session
Session <id> closed (closed by the agent); 4 tool calls ran.
  • A fresh-context review compared the old act.ts wiring with createStepExecution line by line: the construction order, the shared queue, the option values, and the lazy trace callback are the same.