diff --git a/core/context/mcp/MCPConnection.ts b/core/context/mcp/MCPConnection.ts index 593042519..e9f801ddf 100644 --- a/core/context/mcp/MCPConnection.ts +++ b/core/context/mcp/MCPConnection.ts @@ -563,10 +563,15 @@ Org-level secrets can only be used for MCP by Background Agents (https://docs.co // Set the initial PATH from process.env env.PATH = process.env.PATH; - // For non-Windows platforms, try to get the PATH from user shell - if (process.platform !== "win32") { + // For non-Windows platforms or WSL remotes, try to get the PATH from user shell + const ideInfo = await this.extras?.ide?.getIdeInfo(); + const isWindowsHostWithWslRemote = + process.platform === "win32" && ideInfo?.remoteName === "wsl"; + if (process.platform !== "win32" || isWindowsHostWithWslRemote) { try { - const shellEnvPath = await getEnvPathFromUserShell(); + const shellEnvPath = await getEnvPathFromUserShell( + ideInfo?.remoteName, + ); if (shellEnvPath && shellEnvPath !== process.env.PATH) { env.PATH = shellEnvPath; } diff --git a/core/util/shellPath.ts b/core/util/shellPath.ts index a33eeb45e..961307c28 100644 --- a/core/util/shellPath.ts +++ b/core/util/shellPath.ts @@ -2,9 +2,12 @@ import { exec } from "child_process"; import { promisify } from "util"; const execAsync = promisify(exec); -export async function getEnvPathFromUserShell(): Promise { - if (process.platform === "win32") { - console.warn(`${getEnvPathFromUserShell.name} not implemented for Windows`); +export async function getEnvPathFromUserShell( + remoteName?: string, +): Promise { + const isWindowsHostWithWslRemote = + process.platform === "win32" && remoteName === "wsl"; + if (process.platform === "win32" && !isWindowsHostWithWslRemote) { return undefined; }