fix: skip remote URIs when resolving MCP server cwd (#10844)
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 <noreply@anthropic.com>
This commit is contained in:
parent
948f0ebea7
commit
5ddd0d37a1
2 changed files with 19 additions and 0 deletions
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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", () => {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue