Skip to content

Commit 7f4596d

Browse files
Merge pull request #221 from modelcontextprotocol/fix/platform-overrides-env-merge
Fixes #217 — platform_overrides.*.env was replacing base mcp_config.env instead of merging. One-line fix: spread-merge instead of overwrite.
2 parents cf1f956 + cb052a2 commit 7f4596d

File tree

2 files changed

+51
-1
lines changed

2 files changed

+51
-1
lines changed

src/shared/config.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,9 @@ export async function getMcpConfigForManifest(
117117

118118
result.command = platformConfig.command || result.command;
119119
result.args = platformConfig.args || result.args;
120-
result.env = platformConfig.env || result.env;
120+
result.env = platformConfig.env
121+
? { ...result.env, ...platformConfig.env }
122+
: result.env;
121123
}
122124
}
123125

test/config.test.ts

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,54 @@ describe("getMcpConfigForManifest", () => {
269269
expect(result?.args).toEqual(["server.js", "/user/path1", "/user/path2"]);
270270
});
271271

272+
it("should merge platform override env with base env instead of replacing", async () => {
273+
const manifest: McpbManifestAny = {
274+
...baseManifest,
275+
user_config: {
276+
data_directory: {
277+
type: "directory",
278+
title: "Data Directory",
279+
description: "Where data lives",
280+
required: true,
281+
},
282+
},
283+
server: {
284+
type: "node",
285+
entry_point: "server.js",
286+
mcp_config: {
287+
command: "node",
288+
args: ["server.js"],
289+
env: {
290+
DATA_DIR: "${user_config.data_directory}",
291+
EXISTING_VAR: "keep-me",
292+
},
293+
platform_overrides: {
294+
[process.platform]: {
295+
env: {
296+
PATH: "/usr/local/bin:${HOME}/.local/bin",
297+
},
298+
},
299+
},
300+
},
301+
},
302+
};
303+
304+
const result = await getMcpConfigForManifest({
305+
manifest,
306+
extensionPath: "/ext/path",
307+
systemDirs: { ...mockSystemDirs, HOME: "/home/user" },
308+
userConfig: { data_directory: "/custom/data" },
309+
pathSeparator: "/",
310+
logger: mockLogger,
311+
});
312+
313+
// Base env vars should be preserved after platform override merge
314+
expect(result?.env?.DATA_DIR).toBe("/custom/data");
315+
expect(result?.env?.EXISTING_VAR).toBe("keep-me");
316+
// Platform override env should also be present
317+
expect(result?.env?.PATH).toBe("/usr/local/bin:/home/user/.local/bin");
318+
});
319+
272320
it("should convert boolean user config values to strings", async () => {
273321
const manifest: McpbManifestAny = {
274322
...baseManifest,

0 commit comments

Comments
 (0)