Repository navigation
mcp: discover Copilot CLI user MCP config by default without forwarding it - #340181
Merged
Vritant Bhardwaj (vritant24) merged 4 commits intoOct 8, 2026
Merged
Vritant Bhardwaj (vritant24) merged 4 commits into
Vritant Bhardwaj (vritant24) merged 4 commits into
Conversation
Servers migrated out of `.vscode/mcp.json` and user `mcp.json` disappeared from local chat (#339955, tracked in #340161): - Workspace `.mcp.json` entries written by the migrator use Copilot's `"type": "local"` for stdio servers, which `parseWorkspaceRootMcpConfiguration` silently dropped. Parse entries with `fromCopilotMcpServerConfiguration` so `"local"` maps to stdio. `.vscode/mcp.json` parsing is unchanged. - User servers are migrated to `~/.copilot/mcp-config.json`, but the `copilot` source of `chat.mcp.discovery.enabled` defaulted to off. Default it to on (other sources stay off) and fall back to per-source defaults for sources the user has not set, while still honouring explicit `false` and the legacy boolean form. Co-authored-by: Copilot <[email protected]>
Contributor
There was a problem hiding this comment.
Copilot review overview
🔵 Needs a closer look
Default-on discovery expands forwarding of credential-bearing configuration across providers and remote hosts, requiring human security review.
Review effort: Balanced
Findings: 1
What changed in this PR
Restores migrated MCP server visibility in local chat by accepting Copilot-format workspace entries and enabling Copilot user-config discovery.
Changes:
- Accepts
"type": "local"in workspace.mcp.json. - Enables Copilot discovery by default while preserving explicit opt-outs.
- Adds parsing, discovery, and configuration-default regression tests.
| File | Description |
|---|---|
| src/vs/workbench/contrib/mcp/test/common/workspaceDotMcpDiscovery.test.ts | Tests discovery of migrated workspace servers. |
| src/vs/workbench/contrib/mcp/test/common/nativeMcpDiscoveryAdapters.test.ts | Tests defaults, partial settings, and opt-outs. |
| src/vs/workbench/contrib/mcp/common/mcpConfiguration.ts | Defines source defaults and enablement resolution. |
| src/vs/workbench/contrib/mcp/common/discovery/nativeMcpDiscoveryAbstract.ts | Applies shared enablement resolution. |
| src/vs/workbench/contrib/chat/browser/chat.shared.contribution.ts | Updates the setting default and description. |
| src/vs/platform/mcp/test/common/mcpWorkspaceConfiguration.test.ts | Tests parsing migration output. |
| src/vs/platform/mcp/common/mcpWorkspaceConfiguration.ts | Uses Copilot-compatible server parsing. |
💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Vritant Bhardwaj (vritant24)
marked this pull request as draft
October 6, 2026 23:34
auto-merge was automatically disabled
October 6, 2026 23:34
Pull request was converted to draft
With Copilot CLI user config discovery now on by default, Copilot-home servers (which may contain literal env and header credentials) would be forwarded to Claude/Codex agent-host sessions and to Copilot sessions on another remote authority without the user having approved them. Keep local discovery separate from forwarding: Copilot-home servers are only runtime-discovered by the window's own Copilot CLI on the same machine and are otherwise reported as not delivered, with a dedicated reason explaining why. Refs #339955, #340161 Co-authored-by: Copilot <[email protected]>
Vritant Bhardwaj (vritant24)
added a commit
that referenced
this pull request
Oct 7, 2026
#340369) <!-- Thank you for submitting a Pull Request. Please: * Read our Pull Request guidelines: https://github.com/microsoft/vscode/wiki/How-to-Contribute#pull-requests * Associate an issue with the Pull Request. * Ensure that the code is up-to-date with the `main` branch. * Include a description of the proposed changes and how to test them. --> Part of #340161 (task E2). #340161 plans for the migration from `.vscode/mcp.json` to `.mcp.json` to rewrite VS Code inputs and `${env:X}` as `${NAME}` / `${NAME:-default}`. Copilot agent sessions expand those references, but VS Code's own (local) MCP harness passes them to the server as literal text. A migrated server would therefore break if the user switched back from the agent host. It's also worse than a no-op. The server starts with the host environment and the configured `env` is applied on top, so a literal `"API_KEY": "${API_KEY}"` **replaces** the real `API_KEY` the server would otherwise inherit. ## Changes Workspace `.mcp.json` servers now expand `${VAR}` and `${VAR:-default}` with the Copilot runtime's rules. | | Expanded | Never expanded | |---|---|---| | Local (stdio) | `command`, each of `args`, `env` values | `env` names, `cwd` | | Remote (HTTP) | URL (host, path, query), header values | header names | - **Unset with no default:** left as written. **Set but empty:** the empty value is used, not the default. - **Defaults:** inserted literally and never expanded again. - **Long strings:** anything over 1000 characters is left unchanged. - **Where values come from:** the extension host that runs or connects to the server (local or remote), using its own `process.env`. On Windows, names match case-insensitively, as `${env:X}` does. How it works: 1. `WorkspaceDotMcpDiscovery` marks each server with a new `environmentVariableExpansion` field on the definition, keeping the URL exactly as written. Parsing it as a `URI` would encode `https://${HOST}/mcp` as `https://%24%7Bhost%7D/mcp`. 2. `McpRegistry.resolveConnection` asks the host delegate to expand any marked launch that contains a reference. This runs after VS Code's own variable resolution and before the dev-mode, sandbox and allowed/denied-servers checks. 3. `MainThreadMcp` forwards the request over a new `$expandEnvironmentVariables` RPC. The Node extension host expands it; the web worker extension host has no environment and returns the launch unchanged. The resolver in `src/vs/platform/mcp/common/envVarResolution.ts` is a port of the runtime's `env_var_resolution.rs`, and its tests are ported too, so the two stay in sync. The field mapping is in `src/vs/workbench/contrib/mcp/common/mcpEnvironmentVariableExpansion.ts`. ## Unchanged - **Bare `$VAR`** stays literal. The migrator copies it unchanged from `.vscode/mcp.json`, where VS Code never expanded it (for example a shell-quoted `echo '$HOME'` in `args`). - **`${env:X}`, `${input:x}` and `${secret:x}`** stay literal: they don't match the `${NAME}` grammar. - **Trust:** the cache/trust nonce is still computed from the unexpanded config, so changing an env var never re-prompts for trust. - **Other sources:** `.vscode/mcp.json`, user `mcp.json`, `~/.copilot/mcp-config.json`, plugins, extensions, Claude Desktop, Cursor and Windsurf are unchanged. ## Notes for reviewers - **Doesn't affect migrated servers yet.** Today the migrator skips any server that uses `${env:}` or `${input:}`, and replaces `${workspaceFolder}` and similar variables with literal values. This PR is groundwork for B1 and A1–A7 in #340161. Until those land, it only changes hand-written `.mcp.json` files that use `${VAR}`. - **Why expand through the delegate rather than only at spawn time:** the allowed/denied-servers check and other renderer consumers read `connection.launchDefinition`, so they need the expanded values. As with `${env:}` today, expanded env and header values travel back to the renderer over RPC. - **Where this differs from the Copilot runtime:** - bare `$VAR` isn't expanded; - `command` and `args` are resolved against the host environment, not the server's own `env` block, matching how `${env:X}` behaved before migration; - `cwd` isn't honored or expanded, because the migrator skips servers that set it; - the runtime-only environment handling isn't ported (blocked-variable filter, `GITHUB_TOKEN` and `GIT_CONFIG_*` injection, OIDC tokens, `${secret:}`). - **New delegate method:** `IMcpHostDelegate.expandEnvironmentVariables`, implemented by `MainThreadMcp` and the test delegates. - **Overlap with #340181:** both touch `workspaceDotMcpDiscovery.test.ts` and `nativeMcpDiscoveryAdapters.test.ts`. This branch merges cleanly with `main` today, and the hunks are independent.
This was referenced Oct 7, 2026
Vritant Bhardwaj (vritant24)
added a commit
that referenced
this pull request
Oct 7, 2026
<!-- Thank you for submitting a Pull Request. Please: * Read our Pull Request guidelines: https://github.com/microsoft/vscode/wiki/How-to-Contribute#pull-requests * Associate an issue with the Pull Request. * Ensure that the code is up-to-date with the `main` branch. * Include a description of the proposed changes and how to test them. --> Refs #340161 (task **B1**). Builds on #340369 (merged) and matches #340379. ## Problem The MCP customization migrator refused every server that used `${env:NAME}`, so those servers stayed in `.vscode/mcp.json` and the user `mcp.json`. ## Changes **Rewrite.** `${env:NAME}` becomes `${NAME}`, never the variable's current value, in the fields that both the Copilot runtime and the local harness expand: - stdio `command`, `args` and `env` values; - the remote URL and header values. Other portable variables (`${workspaceFolder}`, `${/}`, …) are still resolved to literals exactly as before. **Implementation** (`mcpServerCustomizationMigration.ts`): - `analyzeSourceConfiguration` replaces `resolveSourceConfiguration`. Planning, the check before writing, and rollback all use this one function, so they always agree. - Portable variables are resolved one at a time and `${env:}` is skipped. Resolving `${env:FOO}` to `${FOO}` inside a `ConfigurationResolverExpression` would make it re-parse `${FOO}` as a new, unknown variable. - Candidates get an optional `migratedConfiguration`: the content written to the destination. It's separate from `projectedConfiguration`, which still holds the current env values and is used to detect stale candidates. **Exclusions.** These servers stay behind, each with a localized reason: | Case | Reason | |---|---| | `${env:}` in an env or header **name**; neither the runtime nor the harness expands names (C4, C9) | `environmentVariableInName` | | Name isn't `[A-Za-z_][A-Za-z0-9_]*`, e.g. `${env:ProgramFiles(x86)}`, `${env:my-var}`, `${env:HOST:-x}` | `invalidEnvironmentVariableName` | | Rewritten value is over 1000 UTF-16 code units; the runtime skips expansion above that | `environmentVariableValueTooLong` | | URL fails `URL.canParse` after the rewrite: a port, the scheme, or the whole URL (C7; same rule as #340379) | `unsupportedEnvironmentVariableInUrl` | | `${env:}` mixed with a non-portable variable (`${input:}`, `${config:}`, `${userHome}`, …), or `${env:}` in `cwd` | `unrepresentableConfiguration` (unchanged) | | A referenced variable's value itself contains a `${...}` variable: VS Code resolves it, but the destination keeps the value as is | `unrepresentableConfiguration` | **User scope** (`mcp.json` → `~/.copilot/mcp-config.json`): - User servers are forwarded with their variables unresolved. Those whose only compatibility problem is `UnresolvedConfiguration` can now be planned. - They're compared against the source with `${env:}` left as written; any other variable still excludes the server. - `CopilotMpcDiscoveryAdapter` now sets `environmentVariableExpansion`, using the raw URL, so a migrated `${NAME}` keeps working in VS Code's own chat. ## Notes for reviewers - **Behaviour change for unset variables (decision a):** VS Code resolves an unset `${env:FOO}` to `""`, but the runtime and the local harness leave an unset `${FOO}` as literal text. We chose `${NAME}` over `${NAME:-}` for readability, for consistency with the issue's Decision, and because a host with a `:-` default is rejected (C7). D5/E3 will add the unset-variable warning. - **Copilot user config expansion (decision b):** existing literal `${FOO}` strings in `~/.copilot/mcp-config.json` are now expanded in VS Code, matching the Copilot runtime. Trust nonces are still computed from the unexpanded launch. - **URLs are still blocked by E11 in practice:** the forwarded projection builds `url` from `launch.uri.toString()`, which percent-encodes `${env:…}`, so it never matches the source. The URL rewrite and C7 exclusion are implemented and tested, but real URL servers with `${env:}` stay excluded (as unrepresentable) until E11 is fixed. Header values are unaffected. - No changes to `parseWorkspaceRootMcpConfiguration` or the `chat.mcp.discovery.enabled` default (#340181). ## How to test I ran each of these on this branch: - `npm run build-fast -- --client-only`: **passed** - `./scripts/test.sh --reporter dot --run src/vs/workbench/contrib/chat/test/browser/aiCustomization/mcpServerCustomizationMigration.test.ts --run src/vs/workbench/contrib/chat/test/browser/aiCustomization/customizationMigrationServiceImpl.test.ts --run src/vs/workbench/contrib/mcp/test/common/nativeMcpDiscoveryAdapters.test.ts --run src/vs/workbench/contrib/mcp/test/common/workspaceDotMcpDiscovery.test.ts --run src/vs/workbench/contrib/mcp/test/common/mcpEnvironmentVariableExpansion.test.ts --run src/vs/workbench/contrib/mcp/test/common/mcpRegistry.test.ts --run src/vs/platform/mcp/test/common/envVarResolution.test.ts --run src/vs/workbench/api/test/browser/mainThreadMcp.test.ts`: **passed, 226 passing** - The same three migration/discovery files with `--grep 'env:|Copilot user configuration'`: **passed, 7 passing**. These are all the new tests: - rewriting in every supported position, mixed with `${workspaceFolder}`, a shared variable, and a value at exactly 1000 characters; - every exclusion case, checked at both planning and execution; - user-scope servers; - a source that changed between planning and writing; - rollback followed by a successful retry; - provider exclusion details; - Copilot adapter expansion. - `npm run typecheck-client`: **passed** - `npm run eslint -- <8 changed files>`: **passed**; the pre-commit hygiene check also passed. The tests ran before merging #340375 (agent-host structured tool results) from `main`, which doesn't touch these files. Not tested manually end to end against a live Copilot agent-host session. Manual check: in a workspace whose `.vscode/mcp.json` has a stdio server with `"env": { "TOKEN": "${env:TOKEN}" }`, run the customization migration from an agent-host Copilot session. The server should move to `.mcp.json` as `"TOKEN": "${TOKEN}"` with no secret value in the file, and should still start in VS Code chat.
…json-discovery-defaults # Conflicts: # src/vs/workbench/contrib/mcp/test/common/nativeMcpDiscoveryAdapters.test.ts
Contributor
|
Base:
|
Drop the `parseWorkspaceRootMcpConfiguration` change that accepted the Copilot `"local"` type, along with its tests. #340034 makes the same change, so this PR now only covers Copilot CLI user configuration discovery and keeping Copilot-home servers from being forwarded. Refs #339955, #340161 Co-authored-by: Copilot <[email protected]>
Vritant Bhardwaj (vritant24)
marked this pull request as ready for review
October 8, 2026 18:02
roblourens
approved these changes
Oct 8, 2026
Connor Peet (connor4312)
approved these changes
Oct 8, 2026
Connor Peet (connor4312)
left a comment
Member
There was a problem hiding this comment.
Reviewed the full diff and relevant discovery, configuration, and agent-host delivery context. No actionable P1 or P2 defects found in the current revision.
TABISH AYUB RAZA (Tabisharaza)
added a commit
to Tabisharaza/vscode
that referenced
this pull request
Oct 8, 2026
Remove the agent-host reader change and its two added tests as requested in review. Preserve the original workspace parser fix and wrapped/flat multi-root migration coverage; PR microsoft#340181 handles Copilot CLI user configuration discovery separately. The exact two-file revision passed 134 checks in the official focused Node suites, client transpilation, changed-file hygiene/ESLint and git diff --check. No full local Electron or platform-matrix validation was run. AI-assisted implementation, validation and review using OpenAI Codex.
Vritant Bhardwaj (vritant24)
deleted the
agents/fix-local-mcp-json-discovery-defaults
branch
October 8, 2026 20:32
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Part of #340161. Together with #340034, fixes #339955.
Servers migrated from user
mcp.jsonto~/.copilot/mcp-config.jsonstopped showing up in local chat. This PR makes the local harness discover that file by default, without forwarding its servers to other agents or hosts. The workspace.mcp.jsonside (accepting"type": "local") is handled in #340034.Changes
~/.copilot/mcp-config.jsonis discovered by defaultMigration moves user-level servers into the Copilot CLI user config, but the
copilotsource ofchat.mcp.discovery.enabledwas off by default.defaultDiscoverySourceEnablement, with onlycopilot: true. Claude Desktop, Cursor and Windsurf stay off.isDiscoverySourceEnabled, used by_isDiscoveryEnabled. A source the user hasn't set falls back to its default. An explicitfalseand the legacy boolean form are still respected.{ "claude-desktop": true }) with the default object, socopilotstays on in that case too.Copilot-home servers are never forwarded to other agents or hosts
RuntimeDiscovered).NotDelivered, with a newCopilotHomeNotForwardedreason and message.envand header credentials inmcp-config.jsonfrom being copied to another provider or machine without approval, now that the source is on by default.Notes for reviewers
chat.mcp.collisionBehavior: disable, a server with the same name in usermcp.json(order 200) takes priority, and themcp-config.jsoncopy (order 400) is disabled.~/.copilot/mcp-config.jsonwill now see them in local chat. This includes the remote machine's file in remote windows. These servers are trusted only after the user approves them, so expect a trust prompt.copilotsource lose forwarding of these servers to Claude/Codex sessions and other remote hosts."copilot": false, or the legacyfalse, will still not see their migrated user servers.How to test
chat.mcp.discovery.enabledunset, add a server to~/.copilot/mcp-config.json. It should appear as "GitHub Copilot CLI".chat.mcp.discovery.enabledto{ "copilot": false }orfalse. The server should disappear.Validation
npm run typecheck-client: passednpm run build-fast -- --client-only: passed./scripts/test.sh --reporter dot --run src/vs/platform/mcp/test/common/mcpWorkspaceConfiguration.test.ts --run src/vs/platform/mcp/test/common/mcpResourceScannerService.test.ts --run src/vs/workbench/contrib/mcp/test/common/workspaceDotMcpDiscovery.test.ts --run src/vs/workbench/contrib/mcp/test/common/nativeMcpDiscoveryAdapters.test.ts --run src/vs/workbench/contrib/chat/test/browser/agentSessions/agentHostMcpServerSupport.test.ts --run src/vs/workbench/contrib/chat/test/browser/agentSessions/resolveCustomizationRefs.test.ts --run src/vs/workbench/contrib/chat/test/browser/aiCustomization/mcpServerCustomizationMigration.test.ts: 181 passingnpm run eslint -- <changed files>: clean