Skip to content

Commit

Permalink
Merge pull request #65 from modelcontextprotocol/justin/stderr-improv…
Browse files Browse the repository at this point in the history
…ements

Add way to get child process stderr pipe
  • Loading branch information
jspahrsummers authored Nov 20, 2024
2 parents 9662709 + 4103ef5 commit 25d3123
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@modelcontextprotocol/sdk",
"version": "0.6.1",
"version": "0.7.0",
"description": "Model Context Protocol implementation for TypeScript",
"license": "MIT",
"author": "Anthropic, PBC (https://anthropic.com)",
Expand Down
15 changes: 12 additions & 3 deletions src/client/stdio.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ChildProcess, spawn } from "node:child_process";
import { ChildProcess, IOType, spawn } from "node:child_process";
import process from "node:process";
import { ReadBuffer, serializeMessage } from "../shared/stdio.js";
import { JSONRPCMessage } from "../types.js";
Expand Down Expand Up @@ -28,7 +28,7 @@ export type StdioServerParameters = {
*
* The default is "inherit", meaning messages to stderr will be printed to the parent process's stderr.
*/
stderr?: "inherit" | "ignore" | Stream;
stderr?: IOType | Stream | number;
};

/**
Expand Down Expand Up @@ -123,7 +123,7 @@ export class StdioClientTransport implements Transport {
// (i.e. via `electron-forge start`) vs a production environment
// (i.e. YourApp.exe).
detached: process.platform === "win32" && isElectron(),
}
},
);

this._process.on("error", (error) => {
Expand Down Expand Up @@ -161,6 +161,15 @@ export class StdioClientTransport implements Transport {
});
}

/**
* The stderr stream of the child process, if `StdioServerParameters.stderr` was set to "pipe" or "overlapped".
*
* This is only available after the process has been started.
*/
get stderr(): Stream | null {
return this._process?.stderr ?? null;
}

private processReadBuffer() {
while (true) {
try {
Expand Down

0 comments on commit 25d3123

Please sign in to comment.