Skip to content

stderr is not available until after start is called #174

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
punkpeye opened this issue Mar 8, 2025 · 2 comments
Open

stderr is not available until after start is called #174

punkpeye opened this issue Mar 8, 2025 · 2 comments
Labels
bug Something isn't working
Milestone

Comments

@punkpeye
Copy link

punkpeye commented Mar 8, 2025

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

@punkpeye punkpeye added the bug Something isn't working label Mar 8, 2025
@BobDickinson
Copy link

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).

@msfeldstein
Copy link

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

@ihrpr ihrpr added this to the release 1.10.3 milestone Apr 30, 2025
Pizzaface pushed a commit to RewstApp/mcp-inspector that referenced this issue May 2, 2025
…ar-parsing

Fix environment variable parsing to handle values with equals signs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants