Skip to content

perf(mcp): keep Playwright and type-only imports off MCP startup - #1691

Merged
kaoru0822-kitauji merged 2 commits into
mainfrom
perf/mcp-startup-module-resolution
Oct 11, 2026
Merged

kaoru0822-kitauji merged 2 commits into
mainfrom
perf/mcp-startup-module-resolution

Conversation

@kaoru0822-kitauji

Copy link
Copy Markdown
Collaborator

Closes #1685.

What changed

MCP startup resolved 1,598 modules (6,076 resolutions) before it read the first request. 279 of those modules came from playwright-core, which no-target startup never uses. There were two causes:

  1. Imports used only for types still ran at runtime. With verbatimModuleSyntax, an import whose specifiers all use inline type modifiers compiles to import {} from "…", which still resolves and evaluates the module. 78 compiled modules had one, including import {} from "playwright-core" in PlaywrightScenarioSession. These now use top-level import type, and typescript/no-import-type-side-effects is enabled in .oxlintrc.json so the pattern can't come back.
  2. Playwright launchers were bound when the module loaded. The browser-scenario and Electron-active providers are built before the stdio server starts serving. PlaywrightScenarioBrowser and PlaywrightElectronActiveProvider now load chromium / _electron from playwright-core when a capture opens, the same way NativeModuleResolver already did.

Measurements (macOS arm64, Node 26.5, built package, pinned MCP SDK 2.3.1 client)

Before first request main this PR
Unique modules 1,598 1,312
…from node_modules 667 388
Resolve calls 6,076 4,902 (−19%)
playwright-core loaded yes no
client.connect (median of 5) ~490 ms ~400 ms

Both builds advertise all 170 tools. The first and repeated tools/list timings did not change (~102 ms / ~20 ms). Modules were counted with a module.registerHooks resolve hook passed through --import.

Not verified: Windows timing. I didn't reproduce the 45 s Windows capture. Playwright is CommonJS internally, so each require there costs extra stat probes, and removing it should cut a bigger share on Windows than the resolve count suggests. The remaining ~4,900 resolutions are mostly REA's own dist/ graph (959 modules), and this PR doesn't change packaging.

Behavior preserved

  • Provider construction, the tool catalog, and the capability inventory are unchanged. Optional providers still load at startup; only Playwright's engine module is deferred.
  • If playwright-core itself can't be imported, the error now appears inside the existing launch failure path when a capture runs, instead of as an optional-provider load failure at startup. Every other optional-provider load failure is reported as before.
  • Module and resource locations, worker and native-helper entrypoints, and shutdown are unchanged. No packaging change.

Validation

  • New boundary test (tests/boundary/cli/cliStartupImports.test.ts, "MCP startup imports"): spawns scripts/rea.mjs mcp over stdio, initializes, runs a complete tools/list, and asserts that neither playwright-core nor isomorphic-git was resolved. With the two adapter changes reverted, it fails.
  • The CLI positive probe now runs the real openPlaywrightScenarioBrowser launch path with a missing executable to show that detection still works (previously it only imported the composition module).
  • npm run check:fast, npm run lint (incl. module boundaries), format:check, knip, docs:check
  • npm run test:changed: 127 files / 1,387 tests passed
  • vitest run src/browser tests/composition: 48 files / 454 tests passed
  • test:focused: browserScenarioMcp, electronMcp, optionalProviderIsolation, compactInputSchemaMcp, scenarioCliInputDiagnostics, electronBlankPathCli, localToolContracts, cliStartupImports all passed

Real-provider scope: a real capture_browser_scenario call with cached Chrome for Testing 1208 reached playwright-core through the deferred import. The launch then failed with TargetClosedError because the local sandbox blocks Chrome; plain Playwright with no REA code fails the same way there, so no successful real Chromium or Electron launch was verified locally.

🤖 Generated with Claude Code

kaoru0822-kitauji and others added 2 commits October 11, 2026 03:50
Under verbatimModuleSyntax, an import whose specifiers all carry inline
`type` modifiers compiles to `import {} from "..."`, a side-effect import
that still resolves and evaluates the module. 78 compiled modules carried
one, including `import {} from "playwright-core"` in the browser scenario
session, which loaded Playwright's module graph at MCP startup.

Use top-level `import type` for these bindings and enable oxlint's
typescript/no-import-type-side-effects rule so the pattern cannot return.

Refs #1685

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The browser scenario and Electron active providers are constructed before
the stdio server serves, and both bound Playwright's launchers at module
load. Resolve `chromium` and `_electron` from playwright-core when a
capture opens instead, as the web module resolver already does.

MCP startup now resolves 1,312 modules (4,902 resolutions) instead of
1,598 (6,076) before reading the first request, and no longer loads
playwright-core. Provider construction, the tool catalog, and capability
inventory are unchanged.

A boundary test spawns the stdio server, initializes, lists tools, and
asserts playwright-core and isomorphic-git were not resolved; the CLI
probe now exercises the real launch path to prove detection.

Closes #1685

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

@CassieFox23

Copy link
Copy Markdown
Contributor

I timed MCP startup on Linux after this merged. From process start to the tool list, main (13e03e9) took 16 to 18 percent less time than 6.4.0 on Node 22, 24 and 26. Main has three other commits since 6.4.0, so I did not time this PR alone.

The full numbers and how to rerun them are in my benchmark comment.

Thanks, Kaoru0822!

🤖 Generated with Claude Code (Sonnet 5.5, verified by Opus 5.5) 🦊

@morluto morluto added performance Performance regressions, scaling limits, and bounded-resource work area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior labels Oct 14, 2026
@morluto morluto added the area: mcp MCP server, transport, and tool registration label Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: mcp MCP server, transport, and tool registration area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior performance Performance regressions, scaling limits, and bounded-resource work

Projects

None yet

Development

Successfully merging this pull request may close these issues.

perf(mcp): reduce Windows startup module-resolution I/O

3 participants