Skip to content

stderr is not available until after start is called #174

@punkpeye

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    P1Significant bug affecting many users, highly requested featurebugSomething isn't workingready 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