Skip to content

[Client] Mark the client disconnected when the stdio server exits - #573

Merged
chr-hertel merged 1 commit into
modelcontextprotocol:mainfrom
chr-hertel:fix-client-stdio-dead-server
Oct 12, 2026
Merged

chr-hertel merged 1 commit into
modelcontextprotocol:mainfrom
chr-hertel:fix-client-stdio-dead-server

Conversation

@chr-hertel

Copy link
Copy Markdown
Member

Since #547 a call to an exited stdio server fails at once, but isConnected() stays true and later calls go against the dead process.

Fixes chr-hertel#71

🤖 Generated with Claude Code

@chr-hertel
chr-hertel requested a review from Nyholm as a code owner October 10, 2026 01:55
@chr-hertel chr-hertel added this to the 0.9.0 milestone Oct 10, 2026
@chr-hertel chr-hertel added bug Something isn't working Client Issues & PRs related to the Client component labels Oct 10, 2026
@chr-hertel
chr-hertel requested a balanced review from Copilot October 12, 2026 20:09

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The focused state-management fix is consistent with existing client behavior and has appropriate regression coverage.

0 open findings

What changed in this PR

Marks clients disconnected after stdio server output closes or writes fail.

Changes:

  • Invalidates client state on stdio connection loss.
  • Adds unit and integration regression coverage.
  • Documents the corrected behavior.
File Description
src/​Client/​Transport/​StdioTransport.php Invalidates state on connection loss.
tests/​Unit/​Client/​Transport/​StdioTransportTest.php Tests both failure paths.
tests/​Integration/​DeadServerTest.php Verifies client behavior after server exit.
tests/​Integration/​Fixture/​dead_server.php Provides the terminating server fixture.
CHANGELOG.md Records the fix.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@chr-hertel
chr-hertel force-pushed the fix-client-stdio-dead-server branch from a93f3a7 to d1dc9e8 Compare October 12, 2026 20:56
@chr-hertel
chr-hertel force-pushed the fix-client-stdio-dead-server branch from d1dc9e8 to 27ea33f Compare October 12, 2026 23:07
@chr-hertel
chr-hertel merged commit 10938db into modelcontextprotocol:main Oct 12, 2026
28 checks passed
@chr-hertel
chr-hertel deleted the fix-client-stdio-dead-server branch October 12, 2026 23:16
chr-hertel added a commit to chr-hertel/mcp-test that referenced this pull request Oct 18, 2026
A spawned server that exited before answering used to surface as "no longer
running" after the init timeout, and the connection went on claiming to be
connected. The SDK's client now reports the exit code and the end of stderr,
fails at once, and marks itself disconnected (modelcontextprotocol/php-sdk#573
and the stderr reporting next to it).

`dead_stdio` on the `minimal` client prints a reason and exits with 3; the test
asserts that both reach the bundle's ConnectionException, in well under the
5 s timeout, and that isConnected() is false afterwards. The regression command
never iterates `minimal`, so the dead server stays out of every suite run.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working Client Issues & PRs related to the Client component

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Client] A dead stdio server leaves the client connected

2 participants