Skip to content

stderr is not available until after start is called #174

Closed

Description

@punkpeye
const transport = new StdioClientTransport({
  command: argv.command,
  args: argv.args,
  env: process.env as Record<string, string>,
  stderr: 'pipe',
});

const client = new Client(
  {
    name: "mcp-proxy",
    version: "1.0.0",
  },
  {
    capabilities: {},
  },
);

Here, transport.stderr is gonna be null, which is a problem if the intent is to capture the error messages at the start time.

A somewhat workaround is something like this:

let stderrOutput = '';

try {
  console.info('connecting to the MCP server...');

  const connectionPromise = client.connect(transport);

  transport?.stderr?.on('data', (chunk) => {
    stderrOutput += chunk.toString();
  });

  await connectionPromise;

  console.info('connected to the MCP server');
} catch (error) {
  console.error('could not connect to the MCP server', error, prefixLines(stderrOutput, '> '));

  await setTimeout(1000);

  process.exit(1);
}

I've used it here punkpeye/mcp-proxy@4933267

Activity

  1. BobDickinson commented on Mar 25, 2025

    @BobDickinson

    I've been pulling my hair out on this for a couple of hours. Thanks for this! I tried every permutation of error event and handler on the client and transport to capture startup failure errors with no luck. It's hard to believe that nobody working on the SDK ever had to debug failed start. Maybe they didn't pipe the transport stderr.

    That workaround is scary, but it does work for me also (presumably the connect code sets the transport stderr before it yields).

  2. msfeldstein commented on Apr 30, 2025

    @msfeldstein

    This is extremely annoying for people trying to debug servers that have issues at startup, would love to see this supported by the SDK

  3. added this to the release 1.10.3 milestone on Apr 30, 2025
  4. added a commit that references this issue on May 2, 2025
  5. added
    ready for workEnough information for someone to start working on
    P1Significant bug affecting many users, highly requested feature
    on Oct 24, 2025
  6. ghost added
    potentially closeBot recommends closing — needs maintainer review
    on Apr 17, 2026
  7. mattzcarey commented on Sep 11, 2026

    @mattzcarey
    Member

    Closed as already fixed in PR #437: StdioClientTransport creates a PassThrough in its constructor when stderr: 'pipe', so transport.stderr is available before start() and early startup output is captured. See the constructor and getter on main, and the same on v1.x.

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

    P1Significant bug affecting many users, highly requested featurebugSomething isn't workingpotentially closeBot recommends closing — needs maintainer reviewready for workEnough information for someone to start working on

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions