Skip to content

[Client] Report the stdio server's exit code and stderr when it dies - #514

Merged
chr-hertel merged 2 commits into
modelcontextprotocol:mainfrom
ousamabenyounes:fix/332-stdio-fail-fast-on-process-exit
Oct 12, 2026
Merged

chr-hertel merged 2 commits into
modelcontextprotocol:mainfrom
ousamabenyounes:fix/332-stdio-fail-fast-on-process-exit

Conversation

@ousamabenyounes

@ousamabenyounes ousamabenyounes commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #332.

A stdio server dying on startup failed with "The server process closed its output; it is no longer running." - fast since #547, but without saying why. Now:

Initialization failed: The server process exited with code 7: Fatal: missing extension ext-foo
  • keeps the last 8 KiB of stderr, still logged at debug level
  • the exit code is reported if the process exited within 100 ms of closing its output
  • a respawned process on retry starts with a clean slate

@chr-hertel chr-hertel added the Client Issues & PRs related to the Client component label Oct 6, 2026
@chr-hertel chr-hertel added this to the 0.9.0 milestone Oct 7, 2026
@chr-hertel

Copy link
Copy Markdown
Member

Hi @ousamabenyounes, thanks for the patch - we missed some higher level integration tests for the client which I fixed with #540 and also catched some issues with our implementation.

Please rebase your branch on main, so your PR runs with that new testsuite - thanks already!

@chr-hertel chr-hertel added the enhancement Request for a new feature that's not currently supported label Oct 8, 2026
Fixes modelcontextprotocol#332.

Co-authored-by: Christopher Hertel <mail@christopher-hertel.de>
@chr-hertel
chr-hertel force-pushed the fix/332-stdio-fail-fast-on-process-exit branch from 7d6186f to b50d80f Compare October 12, 2026 21:31
@chr-hertel chr-hertel changed the title [Client] Fail fast when the stdio server process exits before responding [Client] Report the stdio server's exit code and stderr when it dies Oct 12, 2026
@chr-hertel

Copy link
Copy Markdown
Member

Hi @ousamabenyounes, I took this over and rebased it on main - meanwhile #547 made the client fail at once when the stdio server closes its output, so the exit detection in processFiber() and the full stdout drain weren't needed anymore.

What #332 really asks for was still missing tho: the exit code and stderr in the error. So I kept your stderr tail and the reset on respawn, and attached both to the existing failure. You stay the author.

Thanks for your work on this! 🙏

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.

🟡 Changes recommended

Unbounded stderr draining can hang requests, and signal termination is incorrectly reported as exit code -1.

2 open findings
What changed in this PR

Improves stdio server startup diagnostics by reporting exit status and recent stderr output.

Changes:

  • Buffers the latest 8 KiB of stderr.
  • Reports process exit details and resets diagnostics on retries.
  • Adds regression tests and updates documentation.
File Description
src/​Client/​Transport/​StdioTransport.php Captures stderr and determines process exit reasons.
tests/​Unit/​Client/​Transport/​StdioTransportTest.php Tests exit reporting, buffer limits, and retries.
tests/​Integration/​IntegrationTestCase.php Updates failure-diagnostic commentary.
CHANGELOG.md Documents improved stdio diagnostics.

🧠 Review effort: Balanced


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

Comment thread src/Client/Transport/StdioTransport.php Outdated
Comment thread src/Client/Transport/StdioTransport.php
@ousamabenyounes

ousamabenyounes commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor Author

Hi @chr-hertel ! i was fixing it and just saw your message now so i just stopped the fix :) so happy to contribute on this project :)...

@chr-hertel
chr-hertel merged commit 8d0063d into modelcontextprotocol:main Oct 12, 2026
28 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Client Issues & PRs related to the Client component enhancement Request for a new feature that's not currently supported

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Client] Print contents of stderr when command in StdioTransport fails to start

3 participants