Skip to content

mcp: use URI-backed defaultCwd for home-directory discovery adapters - #345650

Merged
Connor Peet (connor4312) merged 1 commit into
microsoft:mainfrom
ericbaum:mcp-native-discovery-default-cwd
Nov 5, 2026
Merged

Connor Peet (connor4312) merged 1 commit into
microsoft:mainfrom
ericbaum:mcp-native-discovery-default-cwd

Conversation

@ericbaum

Copy link
Copy Markdown
Contributor

Fixes #345646

The Claude Desktop, Copilot, Cursor and Windsurf native discovery adapters passed { cwd: homedir } to claudeConfigToServerDefinition, which sets the stdio launch.cwd to homedir.fsPath on the client. On a Windows client connected to a Linux remote (e.g. WSL), this yields a Windows-style path (\home\<user>), and spawn on the Linux extension host fails with ENOENT.

This passes { defaultCwd: homedir } instead, the same approach #330223 took for workspace .mcp.json. The cwd stays a URI and is resolved by the extension host. The cache nonce is still computed from defaultCwd.fsPath, so existing trust decisions are preserved.

A per-entry cwd in these files is still not read; that's unchanged and out of scope.

Testing

  • Added a unit test covering all four adapters with a vscode-remote:// home: stdio servers get no launch.cwd, defaultCwd is the home URI, and the nonce matches the previous behavior. The test fails without the fix.
  • node test/unit/node/index.js --run src/vs/workbench/contrib/mcp/test/common/nativeMcpDiscoveryAdapters.test.ts: 13 passing.
The Claude Desktop, Copilot, Cursor and Windsurf discovery adapters set the stdio launch cwd from homedir.fsPath on the client. On a Windows client connected to a Linux remote this produced a Windows-style path, making spawn fail with ENOENT. Pass the home directory as defaultCwd instead so the extension host resolves it; the cache nonce is unchanged so existing trust is preserved.

Fixes microsoft#345646
Copilot AI balanced review requested due to automatic review settings November 2, 2026 20:28
@ericbaum

Copy link
Copy Markdown
Contributor Author

@microsoft-github-policy-service agree

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues were identified for the change preserving remote home-directory URIs during MCP discovery.

No open issues 🎉

What changed in this PR

Fixes home-directory MCP discovery on Windows clients connected to Linux remotes by preserving the default working directory as a URI until the extension host resolves it.

Changes:

  • Uses defaultCwd for Claude Desktop, Copilot, Cursor, and Windsurf discovery, following the existing workspace discovery approach.
  • Adds regression coverage for all four adapters, checking URI preservation, unchanged trust nonces, and unaffected HTTP definitions.
File Description
src/​vs/​workbench/​contrib/​mcp/​test/​common/​nativeMcpDiscoveryAdapters.test.ts Tests remote home-directory handling and trust nonce compatibility across all four adapters.
src/​vs/​workbench/​contrib/​mcp/​common/​discovery/​nativeMcpDiscoveryAdapters.ts Replaces client-resolved cwd with URI-backed defaultCwd.

Review effort: Balanced

@connor4312
Connor Peet (connor4312) merged commit 438933f into microsoft:main Nov 5, 2026
55 checks passed
@vs-code-engineering vs-code-engineering Bot added this to the 1.146.0 milestone Nov 5, 2026
@ericbaum
Eric Baum (ericbaum) deleted the mcp-native-discovery-default-cwd branch November 11, 2026 20:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

6 participants