Skip to content

Commit cd359ed

Browse files
committed
fix(client): No such file or directory in StdioClientTransport(#393, #196)
Signed-off-by: sunrabbit123 <[email protected]>
1 parent 1317767 commit cd359ed

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

src/client/stdio.test.ts

+30
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,33 @@ test("should read messages", async () => {
5959

6060
await client.close();
6161
});
62+
63+
test("should work with actual node mcp server", async () => {
64+
const client = new StdioClientTransport({
65+
command: "npx",
66+
args: ["-y", "@wrtnlabs/calculator-mcp"],
67+
});
68+
69+
await client.start();
70+
await client.close();
71+
});
72+
73+
test("should work with actual node mcp server and empty env", async () => {
74+
const client = new StdioClientTransport({
75+
command: "npx",
76+
args: ["-y", "@wrtnlabs/calculator-mcp"],
77+
env: {},
78+
});
79+
await client.start();
80+
await client.close();
81+
});
82+
83+
test("should work with actual node mcp server and custom env", async () => {
84+
const client = new StdioClientTransport({
85+
command: "npx",
86+
args: ["-y", "@wrtnlabs/calculator-mcp"],
87+
env: {TEST_VAR: "test-value"},
88+
});
89+
await client.start();
90+
await client.close();
91+
});

src/client/stdio.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,11 @@ export class StdioClientTransport implements Transport {
117117
this._serverParams.command,
118118
this._serverParams.args ?? [],
119119
{
120-
env: this._serverParams.env ?? getDefaultEnvironment(),
120+
// merge default env with server env because mcp server needs some env vars
121+
env: {
122+
...getDefaultEnvironment(),
123+
...this._serverParams.env,
124+
},
121125
stdio: ["pipe", "pipe", this._serverParams.stderr ?? "inherit"],
122126
shell: false,
123127
signal: this._abortController.signal,

0 commit comments

Comments
 (0)