diff --git a/core/context/mcp/MCPConnection.ts b/core/context/mcp/MCPConnection.ts index 4caaa921b..7836e8591 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) || @@ -464,7 +466,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