Skip to content

Make stderr behavior configurable #56

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

Merged
merged 1 commit into from
Nov 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/client/stdio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import process from "node:process";
import { ReadBuffer, serializeMessage } from "../shared/stdio.js";
import { JSONRPCMessage } from "../types.js";
import { Transport } from "../shared/transport.js";
import { Stream } from "node:stream";

export type StdioServerParameters = {
/**
Expand All @@ -21,6 +22,13 @@ export type StdioServerParameters = {
* If not specified, the result of getDefaultEnvironment() will be used.
*/
env?: Record<string, string>;

/**
* How to handle stderr of the child process. This matches the semantics of Node's `child_process.spawn`.
*
* The default is "inherit", meaning messages to stderr will be printed to the parent process's stderr.
*/
stderr?: "inherit" | "ignore" | Stream;
};

/**
Expand Down Expand Up @@ -102,7 +110,7 @@ export class StdioClientTransport implements Transport {
this._serverParams.args ?? [],
{
env: this._serverParams.env ?? getDefaultEnvironment(),
stdio: ["pipe", "pipe", "inherit"],
stdio: ["pipe", "pipe", this._serverParams.stderr ?? "inherit"],
shell: false,
signal: this._abortController.signal,
},
Expand Down