Skip to content

MCP: Preserve Launch Working Directories Across Hosts - #330223

Merged
Dmitriy Vasyura (dmitrivMS) merged 39 commits into
mainfrom
dev/dmitriv/mcp-default-cwd-agent-host
Aug 18, 2026
Merged

Dmitriy Vasyura (dmitrivMS) merged 39 commits into
mainfrom
dev/dmitriv/mcp-default-cwd-agent-host

Conversation

@dmitrivMS

@dmitrivMS Dmitriy Vasyura (dmitrivMS) commented Aug 11, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #320167
Fixes #326622

Partially addresses #328001:

  • Agent Host sessions discover and launch root .mcp.json servers from every working directory in a multi-root workspace.
  • Workspace-specific .vscode/mcp.json servers continue to be synced with their working-directory provenance preserved.
  • This PR does not add workspace-folder grouping in the picker or complete pre-materialization listing for every Claude/Codex workspace root.

Partially addresses #321651:

  • Advances the multi-root Agent Host checklist item for .mcp.json MCP servers to be contributed by agents rather than clients.
  • Other multi-root work, including folder-picker and full SDK customization support, remains out of scope.

Partially addresses #328338:

  • Adds Codex MCP definitions from all session working directories and keeps MCP inventory, status, tools, resources, and OAuth state scoped per thread.
  • Multi-root custom agents, plugins, and instructions/rules remain out of scope.

Partially addresses #328021:

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.

  • Fixes Windows client to Linux remote .mcp.json launches without changing explicit cwd.
  • Keeps the Local extension-host path as a thin compatibility adapter and grants sandbox access to the effective target-side cwd, including relative explicit cwd values.
  • Moves multi-root workspace .mcp.json discovery into Agent Host with shared, reference-counted observation and parsing per file service/root.
  • Preserves working-directory provenance for synced .vscode/mcp.json servers and inline plugin MCP definitions.
  • Scopes synced .vscode/mcp.json servers by explicit collection origin against the session's working-directory set.
  • Integrates the shared behavior across Copilot, Codex, and Claude Agent Host providers.
  • Keeps Codex MCP inventory, status, tools, resources, and OAuth state scoped per thread/chat while retaining Codex-native servers on restored/forked threads and preserving the owning session configuration scope.
  • Preserves legacy native-discovery trust nonces and avoids duplicate provider discovery.

Provider details

  • Copilot: Uses native plugin/config discovery where possible and explicitly projects only servers that need a different default cwd. Disabled workspace servers remain disabled.
  • Claude: Retains native project and ordinary-plugin discovery, explicitly projects synced/additional-root servers where representable, and preserves SSE transport. Disabled primary-root servers are denied before native SDK discovery starts; disabled additional-root servers are omitted from explicit projection. Enablement changes force launch options to be rebuilt, so a server can be re-enabled safely. Additional-root stdio servers whose cwd cannot be represented by the Claude SDK are skipped rather than launched from the wrong directory.
  • Codex: Receives workspace and synced servers per thread, resolves relative cwd values against the owning root, and tolerates older/partial status-list responses.

Validation

  • npm run typecheck-client
  • npm run compile
  • npm run transpile-client
  • Targeted ESLint for the changed Agent Host implementation, merge resolutions, and tests.
  • All Agent Host node unit tests: 4,453 passing, 58 pending.
  • Focused Agent Host provider integration: 15 passing.
  • Claude end-to-end proxy pipeline integration: 5 passing.
  • Independent post-merge code review found no correctness issues.
  • Live Code OSS stdio probes:
    • Earlier direct multi-root run: Copilot and Codex called Root A, Root B, and synced .vscode/mcp.json probes with the expected process cwd. Claude launched Root A and synced .vscode/mcp.json at the expected primary cwd and safely omitted the unrepresentable Root B stdio server.
    • Post-merge Agents UI rerun: the UI currently supplied only the selected primary working directory to createSession; Copilot, Codex, and Claude each launched and called the Root A and synced .vscode/mcp.json probes 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.

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.

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

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.

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, and mcpChanged is only acted on for pre-turn threads, so adding/removing a root never reaches thread/resume. Mark the session dirty (and set needsResume for 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 with isAbsolute and joins it under defaultCwd. A cwd such as ~/workspace is 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

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.

Review details

Suppressed comments (1)

src/vs/workbench/contrib/mcp/common/discovery/pluginMcpDiscovery.ts:109

  • defaultCwd now affects where this server launches, but it is excluded from cacheNonce. 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 in launch.cwd and 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

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.

Review details

Suppressed comments (1)

src/vs/platform/agentHost/common/meta/clientPluginCustomizationMeta.ts:37

  • null is meant to preserve a server whose default is the session's primary directory, but when a workspaceless session has no primaryCwd this returns undefined. 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 to definition.defaultCwd in 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

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Séance council review: two blocking findings and one trust-scope question.

@dmitrivMS
Dmitriy Vasyura (dmitrivMS) requested a balanced review from Copilot August 16, 2026 21:08

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.

Review details

  • Files reviewed: 48/48 changed files
  • Comments generated: 0 new
  • Review effort level: Balanced

@dmitrivMS
Dmitriy Vasyura (dmitrivMS) merged commit d483f80 into main Aug 18, 2026
27 checks passed
@dmitrivMS
Dmitriy Vasyura (dmitrivMS) deleted the dev/dmitriv/mcp-default-cwd-agent-host branch August 18, 2026 00:00
@vs-code-engineering vs-code-engineering Bot added this to the 1.135.0 milestone Aug 18, 2026
@vs-code-engineering vs-code-engineering Bot locked and limited conversation to collaborators Oct 2, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

agent-host Issues for the agent-host implementation (not the protocol) chat-mcp

Projects

No open projects
Status: Done

Development

Successfully merging this pull request may close these issues.

Cannot find uvx when launching MCP comming from agents Plugin VS Code Remote-SSH Windows to Linux .mcp.json error ENOENT

5 participants