Repository navigation
perf(mcp): keep Playwright and type-only imports off MCP startup - #1691
Merged
Merged
Conversation
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]>
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
3 tasks done
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) 🦊 |
2 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:verbatimModuleSyntax, an import whose specifiers all use inlinetypemodifiers compiles toimport {} from "…", which still resolves and evaluates the module. 78 compiled modules had one, includingimport {} from "playwright-core"inPlaywrightScenarioSession. These now use top-levelimport type, andtypescript/no-import-type-side-effectsis enabled in.oxlintrc.jsonso the pattern can't come back.PlaywrightScenarioBrowserandPlaywrightElectronActiveProvidernow loadchromium/_electronfromplaywright-corewhen a capture opens, the same wayNativeModuleResolveralready did.Measurements (macOS arm64, Node 26.5, built package, pinned MCP SDK 2.3.1 client)
node_modulesplaywright-coreloadedclient.connect(median of 5)Both builds advertise all 170 tools. The first and repeated
tools/listtimings did not change (~102 ms / ~20 ms). Modules were counted with amodule.registerHooksresolve hook passed through--import.Not verified: Windows timing. I didn't reproduce the 45 s Windows capture. Playwright is CommonJS internally, so each
requirethere 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 owndist/graph (959 modules), and this PR doesn't change packaging.Behavior preserved
playwright-coreitself 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.Validation
tests/boundary/cli/cliStartupImports.test.ts, "MCP startup imports"): spawnsscripts/rea.mjs mcpover stdio, initializes, runs a completetools/list, and asserts that neitherplaywright-corenorisomorphic-gitwas resolved. With the two adapter changes reverted, it fails.openPlaywrightScenarioBrowserlaunch 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:checknpm run test:changed: 127 files / 1,387 tests passedvitest run src/browser tests/composition: 48 files / 454 tests passedtest:focused:browserScenarioMcp,electronMcp,optionalProviderIsolation,compactInputSchemaMcp,scenarioCliInputDiagnostics,electronBlankPathCli,localToolContracts,cliStartupImportsall passedReal-provider scope: a real
capture_browser_scenariocall with cached Chrome for Testing 1208 reachedplaywright-corethrough the deferred import. The launch then failed withTargetClosedErrorbecause 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