diff --git a/src/client/stdio.test.ts b/src/client/stdio.test.ts index 646f9ea5..b2132446 100644 --- a/src/client/stdio.test.ts +++ b/src/client/stdio.test.ts @@ -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(); +}); diff --git a/src/client/stdio.ts b/src/client/stdio.ts index 9e35293d..af29614e 100644 --- a/src/client/stdio.ts +++ b/src/client/stdio.ts @@ -184,6 +184,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 {