Repository navigation
MCP: Preserve Launch Working Directories Across Hosts - #330223
Conversation
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
There was a problem hiding this comment.
Pull request overview
Preserves MCP working-directory URIs until launch-host conversion and extends multi-root MCP discovery across Agent Host providers.
Changes:
- Adds URI-backed default working directories and cross-host conversion.
- Adds Agent Host discovery, metadata propagation, and provider integrations.
- Scopes Codex MCP inventory per thread and expands tests.
Show a summary per file
| File | Description |
|---|---|
src/vs/workbench/contrib/mcp/test/common/nativeMcpDiscoveryAdapters.test.ts |
Tests URI defaults and nonce compatibility. |
src/vs/workbench/contrib/mcp/test/common/mcpTypes.test.ts |
Tests default-CWD equality and serialization. |
src/vs/workbench/contrib/mcp/test/common/mcpSandboxService.test.ts |
Tests target-OS path conversion. |
src/vs/workbench/contrib/mcp/common/mcpTypes.ts |
Adds defaultCwd to server definitions. |
src/vs/workbench/contrib/mcp/common/mcpSandboxService.ts |
Converts URI defaults at sandbox launch. |
src/vs/workbench/contrib/mcp/common/discovery/workspaceMcpDiscoveryAdapter.ts |
Preserves Cursor workspace CWD URIs. |
src/vs/workbench/contrib/mcp/common/discovery/workspaceDotMcpDiscovery.ts |
Preserves root .mcp.json CWD URIs. |
src/vs/workbench/contrib/mcp/common/discovery/pluginMcpDiscovery.ts |
Propagates plugin default CWDs. |
src/vs/workbench/contrib/mcp/common/discovery/nativeMcpDiscoveryAdapters.ts |
Separates explicit and default CWD handling. |
src/vs/workbench/contrib/mcp/common/discovery/installedMcpServersDiscovery.ts |
Records workspace-folder defaults. |
src/vs/workbench/contrib/chat/test/common/plugins/agentPluginFormatDetection.test.ts |
Tests plugin CWD provenance. |
src/vs/workbench/contrib/chat/test/browser/agentSessions/syncedCustomizationBundler.test.ts |
Tests bundled CWD metadata and nonces. |
src/vs/workbench/contrib/chat/test/browser/agentSessions/resolveCustomizationRefs.test.ts |
Tests synced server defaults and exclusions. |
src/vs/workbench/contrib/chat/browser/agentSessions/agentHost/syncedCustomizationBundler.ts |
Serializes CWD provenance metadata. |
src/vs/workbench/contrib/chat/browser/agentSessions/agentHost/agentHostLocalCustomizations.ts |
Propagates defaults and removes root-MCP seeding. |
src/vs/workbench/contrib/chat/browser/agentSessions/agentHost/agentHostActiveClientService.ts |
Removes obsolete multi-root synchronization gate. |
src/vs/workbench/api/test/browser/mainThreadMcp.test.ts |
Tests extension-host CWD forwarding. |
src/vs/workbench/api/browser/mainThreadMcp.ts |
Prefers definition-level default CWD. |
src/vs/platform/mcp/common/mcpPlatformTypes.ts |
Adds remote transport selection. |
src/vs/platform/agentPlugins/test/common/pluginParsers.test.ts |
Tests transport and CWD parsing. |
src/vs/platform/agentPlugins/common/pluginParsers.ts |
Preserves plugin-root URI provenance. |
src/vs/platform/agentHost/test/node/shared/sessionMcpDiscovery.test.ts |
Tests multi-root MCP discovery. |
src/vs/platform/agentHost/test/node/copilotSessionLauncher.test.ts |
Tests Copilot MCP projection. |
src/vs/platform/agentHost/test/node/copilotPluginConverters.test.ts |
Tests effective Copilot CWD resolution. |
src/vs/platform/agentHost/test/node/codex/codexMcpServers.test.ts |
Tests thread inventory and CWD conversion. |
src/vs/platform/agentHost/test/node/codex/codexClientCustomizations.test.ts |
Tests session-relative Codex defaults. |
src/vs/platform/agentHost/test/node/claudeSdkOptions.test.ts |
Tests Claude MCP filtering and projection. |
src/vs/platform/agentHost/test/common/agentMetaReaders.test.ts |
Tests CWD metadata readers. |
src/vs/platform/agentHost/node/shared/sessionMcpDiscovery.ts |
Adds shared multi-root discovery and watching. |
src/vs/platform/agentHost/node/copilot/copilotSessionLauncher.ts |
Injects non-native MCP servers into Copilot. |
src/vs/platform/agentHost/node/copilot/copilotPluginConverters.ts |
Resolves Copilot CWDs at launch. |
src/vs/platform/agentHost/node/copilot/copilotAgent.ts |
Integrates session MCP discovery. |
src/vs/platform/agentHost/node/codex/codexMcpServers.ts |
Adds thread-scoped inventory and CWD resolution. |
src/vs/platform/agentHost/node/codex/codexClientCustomizations.ts |
Projects discovered and synced Codex servers. |
src/vs/platform/agentHost/node/codex/codexAgent.ts |
Integrates discovery and thread-scoped lifecycle state. |
src/vs/platform/agentHost/node/claude/claudeSdkOptions.ts |
Projects representable MCP servers to Claude. |
src/vs/platform/agentHost/node/claude/claudeAgentSession.ts |
Integrates discovery and avoids duplicate native discovery. |
src/vs/platform/agentHost/common/meta/clientPluginCustomizationMeta.ts |
Defines CWD provenance metadata. |
Review details
Tip
Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
- Files reviewed: 38/38 changed files
- Comments generated: 2
- Review effort level: Balanced
Co-authored-by: Copilot <[email protected]>
There was a problem hiding this comment.
Review details
Suppressed comments (2)
src/vs/platform/agentHost/node/codex/codexAgent.ts:1747
- Replacing the discovery when the workspace-root list changes does not mark the MCP configuration dirty. After a thread has sent its first turn, the new scan's initial
refresh()emits no change event, andmcpChangedis only acted on for pre-turn threads, so adding/removing a root never reachesthread/resume. Mark the session dirty (and setneedsResumefor an active thread) when installing the replacement discovery.
if (entry?.rootsSignature !== rootsSignature) {
entry?.dispose();
src/vs/platform/agentHost/node/claude/claudeSdkOptions.ts:217
- Explicit MCP cwd values support
~expansion at the existing extension-host boundary and in the Copilot/Codex provider converters, but this projection checks the raw value withisAbsoluteand joins it underdefaultCwd. A cwd such as~/workspaceis therefore misclassified and the server can be skipped even when it resolves to Claude's primary cwd. Untildify the explicit cwd before resolving and comparing it.
const effectiveCwd = config.cwd === undefined
? defaultCwd
: isAbsolute(config.cwd) ? normalize(config.cwd) : normalize(join(defaultCwd, config.cwd));
- Files reviewed: 40/40 changed files
- Comments generated: 0 new
- Review effort level: Balanced
There was a problem hiding this comment.
Review details
Suppressed comments (1)
src/vs/workbench/contrib/mcp/common/discovery/pluginMcpDiscovery.ts:109
defaultCwdnow affects where this server launches, but it is excluded fromcacheNonce. Moving a plugin (or changing its preserved URI) can therefore reuse tools/metadata cached for the old working directory; before this change the implicit plugin cwd lived inlaunch.cwdand was hashed. Build the nonce from an equivalent launch containing the default cwd for stdio servers, as the native discovery adapter does.
- Files reviewed: 42/42 changed files
- Comments generated: 0 new
- Review effort level: Balanced
Co-authored-by: Copilot <[email protected]>
There was a problem hiding this comment.
Review details
Suppressed comments (1)
src/vs/platform/agentHost/common/meta/clientPluginCustomizationMeta.ts:37
nullis meant to preserve a server whose default is the session's primary directory, but when a workspaceless session has noprimaryCwdthis returnsundefined. All three callers then use?? definition.defaultCwd, so they fall back to the synthetic plugin directory assigned by the parser and launch no-cwd/relative-cwd servers from the sync cache instead of the provider's default working directory. Preserve the distinction between “metadata says no concrete URI” and “metadata is absent/malformed” (for example, with a sentinel/result type) and only fall back todefinition.defaultCwdin the latter case.
const cwd = value[serverName];
if (cwd === null) {
return primaryCwd;
- Files reviewed: 42/42 changed files
- Comments generated: 0 new
- Review effort level: Balanced
Dmitriy Vasyura (dmitrivMS)
left a comment
There was a problem hiding this comment.
Séance council review: two blocking findings and one trust-scope question.
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
…lt-cwd-agent-host
Co-authored-by: Copilot <[email protected]>
…lt-cwd-agent-host
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
Fixes #320167
Fixes #326622
Partially addresses #328001:
.mcp.jsonservers from every working directory in a multi-root workspace..vscode/mcp.jsonservers continue to be synced with their working-directory provenance preserved.Partially addresses #321651:
.mcp.jsonMCP servers to be contributed by agents rather than clients.Partially addresses #328338:
Partially addresses #328021:
.vscode/mcp.jsonservers to the session's working-directory set and preserving per-server cwd provenance.Summary
Preserve MCP default working directories as URIs until the process-launch boundary so paths are converted on the operating system that actually launches each server.
.mcp.jsonlaunches without changing explicitcwd..mcp.jsondiscovery into Agent Host with shared, reference-counted observation and parsing per file service/root..vscode/mcp.jsonservers and inline plugin MCP definitions..vscode/mcp.jsonservers by explicit collection origin against the session's working-directory set.Provider details
Validation
npm run typecheck-clientnpm run compilenpm run transpile-client.vscode/mcp.jsonprobes with the expected process cwd. Claude launched Root A and synced.vscode/mcp.jsonat the expected primary cwd and safely omitted the unrepresentable Root B stdio server.createSession; Copilot, Codex, and Claude each launched and called the Root A and synced.vscode/mcp.jsonprobes at Root A. Probe-process logs confirmed every reported cwd. Root B is therefore covered by the multi-root provider unit/integration suites and the earlier direct multi-root run, not claimed as exercised by this UI rerun.