From cd359edabc864884d0dc6a48050e895ec228c15b Mon Sep 17 00:00:00 2001 From: sunrabbit123 Date: Thu, 24 Apr 2025 21:14:08 +0900 Subject: [PATCH] fix(client): No such file or directory in StdioClientTransport(#393, #196) Signed-off-by: sunrabbit123 --- src/client/stdio.test.ts | 30 ++++++++++++++++++++++++++++++ src/client/stdio.ts | 6 +++++- 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/src/client/stdio.test.ts b/src/client/stdio.test.ts index 646f9ea5..e6ccb347 100644 --- a/src/client/stdio.test.ts +++ b/src/client/stdio.test.ts @@ -59,3 +59,33 @@ test("should read messages", async () => { await client.close(); }); + +test("should work with actual node mcp server", async () => { + const client = new StdioClientTransport({ + command: "npx", + args: ["-y", "@wrtnlabs/calculator-mcp"], + }); + + await client.start(); + await client.close(); +}); + +test("should work with actual node mcp server and empty env", async () => { + const client = new StdioClientTransport({ + command: "npx", + args: ["-y", "@wrtnlabs/calculator-mcp"], + env: {}, + }); + await client.start(); + await client.close(); +}); + +test("should work with actual node mcp server and custom env", async () => { + const client = new StdioClientTransport({ + command: "npx", + args: ["-y", "@wrtnlabs/calculator-mcp"], + env: {TEST_VAR: "test-value"}, + }); + await client.start(); + await client.close(); +}); diff --git a/src/client/stdio.ts b/src/client/stdio.ts index b83bf27c..cef12fd8 100644 --- a/src/client/stdio.ts +++ b/src/client/stdio.ts @@ -117,7 +117,11 @@ export class StdioClientTransport implements Transport { this._serverParams.command, this._serverParams.args ?? [], { - env: this._serverParams.env ?? getDefaultEnvironment(), + // merge default env with server env because mcp server needs some env vars + env: { + ...getDefaultEnvironment(), + ...this._serverParams.env, + }, stdio: ["pipe", "pipe", this._serverParams.stderr ?? "inherit"], shell: false, signal: this._abortController.signal,