Merge pull request #455 from XiaofuHuang/xiaofhua/pid-StdioClientTransport

fix: Expose the MCP child process PID as an accessible property in StdioClientTransport
This commit is contained in:
Inna Harper 2025-06-30 14:46:21 +01:00 • committed by GitHub
commit a1a486de1c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 18 additions and 0 deletions

View file

@ -59,3 +59,12 @@ test("should read messages", async () => {
await client.close();
});
test("should return child process pid", async () => {
const client = new StdioClientTransport(serverParameters);
await client.start();
expect(client.pid).not.toBeNull();
await client.close();
expect(client.pid).toBeNull();
});

View file

@ -185,6 +185,15 @@ export class StdioClientTransport implements Transport {
return this._process?.stderr ?? null;
}
/**
* The child process pid spawned by this transport.
*
* This is only available after the transport has been started.
*/
get pid(): number | null {
return this._process?.pid ?? null;
}
private processReadBuffer() {
while (true) {
try {