Skip to content

Commit 558711c

Browse files
committed
Fix: Properly merge default and custom environment variables in StdioClientTransport
1 parent 592c91f commit 558711c

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

Diff for: src/client/cross-spawn.test.ts

+20-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,26 @@ describe("StdioClientTransport using cross-spawn", () => {
7272
"test-command",
7373
[],
7474
expect.objectContaining({
75-
env: customEnv
75+
env: expect.objectContaining(customEnv)
76+
})
77+
);
78+
});
79+
80+
test("should merge default and custom environment variables", async () => {
81+
const customEnv = { CUSTOM_VAR: "custom-value" };
82+
const transport = new StdioClientTransport({
83+
command: "test-command",
84+
env: customEnv
85+
});
86+
87+
await transport.start();
88+
89+
// verify environment variables are merged correctly
90+
expect(mockSpawn).toHaveBeenCalledWith(
91+
"test-command",
92+
[],
93+
expect.objectContaining({
94+
env: expect.objectContaining(customEnv)
7695
})
7796
);
7897
});

Diff for: src/client/stdio.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ export class StdioClientTransport implements Transport {
117117
this._serverParams.command,
118118
this._serverParams.args ?? [],
119119
{
120-
env: this._serverParams.env ?? getDefaultEnvironment(),
120+
env: { ...getDefaultEnvironment(), ...(this._serverParams.env ?? {}) },
121121
stdio: ["pipe", "pipe", this._serverParams.stderr ?? "inherit"],
122122
shell: false,
123123
signal: this._abortController.signal,

0 commit comments

Comments
 (0)