Skip to content

Stdio transport does not expose process exit code on server launch failure #1332

Closed

Description

@hulumane

When launching an MCP server via the Stdio transport, the SDK does not expose the process exit code if the server process terminates with a non-zero exit code. This makes it impossible for the client to distinguish between different failure modes based on the exit code.

Motivation
This is critical for scenarios like the Windows On-Device Registry (ODR), which returns specific exit codes to signal distinct error conditions (e.g., "Feature unavailable", permission errors, etc.). Without access to the exit code, the client cannot provide meaningful error messages or take appropriate recovery actions — all failures appear identical.

Expected Behavior
When the MCP server process exits with a non-zero exit code, the SDK should surface that exit code to the caller (e.g., via the exception, a result object, or an event), so the client can inspect it and react accordingly.

Current Behavior
The exit code is silently discarded. The client receives a generic failure indication with no way to determine the specific exit code returned by the server process.

Suggested Approach
Expose Process.ExitCode on the StdioClientTransport or include it in the exception thrown when the process terminates unexpectedly.
Consider adding an ExitCode property to a transport-level error/event type.
Environment
SDK: MCP C# SDK (latest)
OS: Windows

Activity

  1. added
    ready for workHas enough information to start
    P2Moderate issues, valuable feature requests
    on Feb 21, 2026
  2. added this to the milestone on Feb 21, 2026
  3. self-assigned this
    on Feb 23, 2026
  4. modified the milestones: , 1.0.0 (GA) on Feb 23, 2026
  5. stephentoub commented on Feb 24, 2026

    @stephentoub
    Contributor

    Does #1368 address the concern?

  6. hulumane commented on Feb 24, 2026

    @hulumane
    Author

    Thanks Stephen! This looks great — the Completion property on McpClient with StdioClientCompletionDetails exposing ExitCode, ProcessId, and
    StandardErrorTail is exactly what we needed. This addresses our concerns from #1332 around surfacing process exit codes for distinguishing
    failure modes. Really appreciate the thorough approach with the extensible ClientCompletionDetails base class too.

    Do you have a sense of which version/release this fix will land in?

  7. stephentoub commented on Feb 24, 2026

    @stephentoub
    Contributor

    Soon-ish 😄

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

Metadata

Metadata

Assignees

Labels

P2Moderate issues, valuable feature requestsready for workHas enough information to start

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions