Skip to content

fix: Expose the MCP child process PID as an accessible property in StdioClientTransport #455

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
9 changes: 9 additions & 0 deletions src/client/stdio.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
9 changes: 9 additions & 0 deletions src/client/stdio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down