Skip to content

Commit 169fb45

Browse files
committed
fix: correct fix
Signed-off-by: sunrabbit123 <[email protected]>
1 parent bf2310a commit 169fb45

File tree

3 files changed

+35
-6
lines changed

3 files changed

+35
-6
lines changed

src/client/cross-spawn.test.ts

+1-4
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,7 @@ describe("StdioClientTransport using cross-spawn", () => {
7272
"test-command",
7373
[],
7474
expect.objectContaining({
75-
env: {
76-
PATH: process.env.PATH,
77-
...customEnv,
78-
}
75+
env: customEnv
7976
})
8077
);
8178
});

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

+4-2
Original file line numberDiff line numberDiff line change
@@ -113,13 +113,15 @@ export class StdioClientTransport implements Transport {
113113
}
114114

115115
return new Promise((resolve, reject) => {
116+
// const defaultEnv = getDefaultEnvironment();
116117
this._process = spawn(
117118
this._serverParams.command,
118119
this._serverParams.args ?? [],
119120
{
121+
// merge default env with server env because mcp server needs some env vars
120122
env: {
121-
PATH: process.env.PATH,
122-
...this._serverParams.env ?? getDefaultEnvironment(),
123+
...getDefaultEnvironment(),
124+
...this._serverParams.env,
123125
},
124126
stdio: ["pipe", "pipe", this._serverParams.stderr ?? "inherit"],
125127
shell: false,

0 commit comments

Comments
 (0)