From b1f147c12e42b33a9667f083f15221ab3c73f73c Mon Sep 17 00:00:00 2001 From: Fred Bricon Date: Thu, 11 Sep 2025 14:34:05 +0200 Subject: [PATCH] fix: use common process.env values to launch MCP Signed-off-by: Fred Bricon --- core/context/mcp/MCPConnection.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/core/context/mcp/MCPConnection.ts b/core/context/mcp/MCPConnection.ts index b79647c57..fceff11ca 100644 --- a/core/context/mcp/MCPConnection.ts +++ b/core/context/mcp/MCPConnection.ts @@ -38,6 +38,8 @@ const WINDOWS_BATCH_COMMANDS = [ "bunx", ]; +const COMMONS_ENV_VARS = ["HOME", "USER", "USERPROFILE", "LOGNAME", "USERNAME"]; + function is401Error(error: unknown) { return ( (error instanceof SseError && error.code === 401) || @@ -461,7 +463,16 @@ class MCPConnection { private async constructStdioTransport( options: InternalStdioMcpOptions, ): Promise { - const env: Record = options.env ? { ...options.env } : {}; + const commonEnvVars: Record = Object.fromEntries( + COMMONS_ENV_VARS.filter((key) => process.env[key] !== undefined).map( + (key) => [key, process.env[key] as string], + ), + ); + + const env = { + ...commonEnvVars, + ...(options.env ?? {}), + }; if (process.env.PATH !== undefined) { // Set the initial PATH from process.env