Skip to content

Commit 5890f53

Browse files
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. Return undefined for non-file:// URIs so the spawn uses its default cwd instead. Fixes #10842 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 9b88c27 commit 5890f53

2 files changed

Lines changed: 17 additions & 0 deletions

File tree

core/context/mcp/MCPConnection.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,13 @@ Org-level secrets can only be used for MCP by Background Agents (https://docs.co
476476
if (resolved.startsWith("file://")) {
477477
return fileURLToPath(resolved);
478478
}
479+
// Remote URIs (e.g. vscode-remote://ssh-remote+host/path) cannot be
480+
// used as a local cwd for child_process.spawn(). When the extension
481+
// runs in the Local Extension Host on Windows while connected to a
482+
// remote workspace, let the spawn use its default cwd instead.
483+
if (resolved.includes("://")) {
484+
return undefined;
485+
}
479486
return resolved;
480487
}
481488
return resolved;

core/context/mcp/MCPConnection.vitest.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,16 @@ describe("MCPConnection", () => {
175175
);
176176
expect(mockResolve).toHaveBeenCalledWith("src", ide);
177177
});
178+
179+
it("should return undefined for remote URIs that cannot be used as local cwd", async () => {
180+
const ide = {} as any;
181+
vi.spyOn(ideUtils, "resolveRelativePathInDir").mockResolvedValue(
182+
"vscode-remote://ssh-remote+192.168.137.2/home/user/project",
183+
);
184+
const conn = new MCPConnection(baseOptions, { ide });
185+
186+
await expect((conn as any).resolveCwd("src")).resolves.toBeUndefined();
187+
});
178188
});
179189

180190
describe("connectClient", () => {

0 commit comments

Comments
 (0)