Skip to content

[MCP] Stdio server should dispose browser when stdin closes #41664

Description

@qingye-lab

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

No activity

Activity on this issue will appear here.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions