From a3d6f96a45d25d52169a5833b5c650a58eb05660 Mon Sep 17 00:00:00 2001 From: shanevcantwell <153727980+shanevcantwell@users.noreply.github.com> Date: Wed, 25 Feb 2026 23:00:13 -0700 Subject: [PATCH] fix: skip remote URIs when resolving MCP server cwd When the extension runs in the Local Extension Host on Windows while connected to a remote workspace (SSH, Dev Container, etc.), getWorkspaceDirs() returns vscode-remote:// URIs. These cannot be used as a cwd for child_process.spawn(), causing "spawn cmd.exe ENOENT" when starting MCP stdio servers. Fall back to the user's home directory for non-file:// URIs so the spawn has a valid local working directory. Fixes #10842 Co-Authored-By: Claude Opus 4.6 --- core/context/mcp/MCPConnection.ts | 8 ++++++++ core/context/mcp/MCPConnection.vitest.ts | 11 +++++++++++ 2 files changed, 19 insertions(+) diff --git a/core/context/mcp/MCPConnection.ts b/core/context/mcp/MCPConnection.ts index f1199066f2..d25e9f6a0e 100644 --- a/core/context/mcp/MCPConnection.ts +++ b/core/context/mcp/MCPConnection.ts @@ -1,5 +1,6 @@ import { Client } from "@modelcontextprotocol/sdk/client/index.js"; import { Transport } from "@modelcontextprotocol/sdk/shared/transport.js"; +import { homedir } from "os"; import { fileURLToPath } from "url"; import { @@ -476,6 +477,13 @@ Org-level secrets can only be used for MCP by Background Agents (https://docs.co if (resolved.startsWith("file://")) { return fileURLToPath(resolved); } + // Remote URIs (e.g. vscode-remote://ssh-remote+host/path) cannot be + // used as a local cwd for child_process.spawn(). When the extension + // runs in the Local Extension Host on Windows while connected to a + // remote workspace, fall back to the user's home directory. + if (resolved.includes("://")) { + return homedir(); + } return resolved; } return resolved; diff --git a/core/context/mcp/MCPConnection.vitest.ts b/core/context/mcp/MCPConnection.vitest.ts index 7920a9a1dd..adb4b9c549 100644 --- a/core/context/mcp/MCPConnection.vitest.ts +++ b/core/context/mcp/MCPConnection.vitest.ts @@ -175,6 +175,17 @@ describe("MCPConnection", () => { ); expect(mockResolve).toHaveBeenCalledWith("src", ide); }); + + it("should fall back to homedir for remote URIs that cannot be used as local cwd", async () => { + const ide = {} as any; + vi.spyOn(ideUtils, "resolveRelativePathInDir").mockResolvedValue( + "vscode-remote://ssh-remote+192.168.137.2/home/user/project", + ); + const conn = new MCPConnection(baseOptions, { ide }); + + const { homedir } = require("os"); + await expect((conn as any).resolveCwd("src")).resolves.toBe(homedir()); + }); }); describe("connectClient", () => {