Skip to content

Commit 2425a83

Browse files
committed
fix: use all process.env values to launch MCP
Signed-off-by: Fred Bricon <[email protected]>
1 parent 91478d9 commit 2425a83

File tree

1 file changed

+21
-17
lines changed

1 file changed

+21
-17
lines changed

core/context/mcp/MCPConnection.ts

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -347,24 +347,28 @@ class MCPConnection {
347347
): Promise<Transport> {
348348
switch (options.transport.type) {
349349
case "stdio":
350-
const env: Record<string, string> = options.transport.env
351-
? { ...options.transport.env }
352-
: {};
353-
354-
if (process.env.PATH !== undefined) {
355-
// Set the initial PATH from process.env
356-
env.PATH = process.env.PATH;
357-
358-
// For non-Windows platforms, try to get the PATH from user shell
359-
if (process.platform !== "win32") {
360-
try {
361-
const shellEnvPath = await getEnvPathFromUserShell();
362-
if (shellEnvPath && shellEnvPath !== process.env.PATH) {
363-
env.PATH = shellEnvPath;
364-
}
365-
} catch (err) {
366-
console.error("Error getting PATH:", err);
350+
const processEnv: Record<string, string> = Object.fromEntries(
351+
Object.entries(process.env).filter(([_, v]) => v !== undefined) as [
352+
string,
353+
string,
354+
][],
355+
);
356+
357+
const env = {
358+
...processEnv,
359+
...(options.transport.env ?? {}),
360+
};
361+
362+
// For non-Windows platforms, try to get enhanced environment from user shell
363+
if (process.platform !== "win32") {
364+
try {
365+
// Get PATH from shell
366+
const shellEnvPath = await getEnvPathFromUserShell();
367+
if (shellEnvPath && shellEnvPath !== process.env.PATH) {
368+
env.PATH = shellEnvPath;
367369
}
370+
} catch (err) {
371+
console.error("Error getting PATH:", err);
368372
}
369373
}
370374

0 commit comments

Comments
 (0)