Context
This came from the closed PR #41656. The request there was to start by filing an issue.
While investigating long-lived browser automation processes on macOS, I noticed that the MCP stdio server wires process.stdin end to transport.close(), but not close. Some MCP client disconnect paths can surface as stdin close, not just EOF.
Current behavior
For stdio transport, Playwright currently relies on:
process.stdin.on('end', () => void transport.close()) in packages/playwright-core/src/tools/utils/mcp/server.ts
- the broader exit watchdog, which also watches stdin
close and calls graceful browser cleanup during process exit
That means stdin close is not routed through the MCP server transport close path. Backend disposal can rely on the process-level watchdog instead of the normal server close path.
Expected behavior
When stdin closes, the stdio transport should close as well, so the existing MCP server close handler disposes the backend and closes the launched browser promptly. The close path should be idempotent because both end and close may fire.
Suggested fix
Handle both stdin events with the same idempotent close function, e.g. close the StdioServerTransport on both end and close.
The regression test I used in PR #41656 launches the MCP server with --isolated, calls browser_navigate, closes the stdio client, and asserts that the debug log includes close browser.
Validation from the prototype PR
In the prototype branch from PR #41656, these checks passed locally:
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1 npm ci
npm run build
npm run tsc
npm run test-mcp -- launch.spec.ts --project=chrome
Environment
- macOS
- Node.js v24.x
- Playwright MCP / playwright-core main branch when prototyping the fix
Context
This came from the closed PR #41656. The request there was to start by filing an issue.
While investigating long-lived browser automation processes on macOS, I noticed that the MCP stdio server wires
process.stdinendtotransport.close(), but notclose. Some MCP client disconnect paths can surface as stdinclose, not just EOF.Current behavior
For stdio transport, Playwright currently relies on:
process.stdin.on('end', () => void transport.close())inpackages/playwright-core/src/tools/utils/mcp/server.tscloseand calls graceful browser cleanup during process exitThat means stdin
closeis not routed through the MCP server transport close path. Backend disposal can rely on the process-level watchdog instead of the normal server close path.Expected behavior
When stdin closes, the stdio transport should close as well, so the existing MCP server close handler disposes the backend and closes the launched browser promptly. The close path should be idempotent because both
endandclosemay fire.Suggested fix
Handle both stdin events with the same idempotent close function, e.g. close the
StdioServerTransporton bothendandclose.The regression test I used in PR #41656 launches the MCP server with
--isolated, callsbrowser_navigate, closes the stdio client, and asserts that the debug log includesclose browser.Validation from the prototype PR
In the prototype branch from PR #41656, these checks passed locally:
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1 npm cinpm run buildnpm run tscnpm run test-mcp -- launch.spec.ts --project=chromeEnvironment