Repository navigation
chat: Migrate MCP servers that use settings to environment variables - #341349
Merged
Vritant Bhardwaj (vritant24) merged 10 commits intoOct 13, 2026
Merged
Vritant Bhardwaj (vritant24) merged 10 commits into
Vritant Bhardwaj (vritant24) merged 10 commits into
Conversation
`${config:key}` references in `.vscode/mcp.json` and user `mcp.json` servers
are now migrated instead of excluding the server (case B3 in #340161). Each
setting becomes an environment variable named after its key (for example
`mcp.command` -> `MCP_COMMAND`), set to the setting's current value: declared
in `env` for stdio servers and written as `${NAME:-value}` for remote servers.
- Read the value with the configuration resolver in the folder scope VS Code
uses; only string and number values are migrated
- Apply the existing reserved-name, collision, name, URL, length and cwd rules
- Record the values on the candidate and fail with `sourceChanged` if a
setting changes before writing
- Add the `unsupportedSettingValue` exclusion reason and a migration warning
Refs #340161
Co-authored-by: Copilot <[email protected]>
A `${config:key}` setting that is unset, not a string or number, or whose
value contains a variable no longer excludes the MCP server. It migrates to an
environment variable with an empty value instead, like an input without a
default. When VS Code can't resolve such a setting, it projects the server as
written, which the planner now accounts for.
`unsupportedSettingValue` now only covers a reference without a setting name
and a value that a remote `${NAME:-value}` reference can't carry.
Refs #340161
Co-authored-by: Copilot <[email protected]>
Matches the `${config:}` references in the MCP configuration.
Refs #340161
Co-authored-by: Copilot <[email protected]>
A setting's value in a remote server's `${NAME:-value}` reference is no
longer checked to read back exactly, so a rare value such as one with a `}`
no longer keeps the server from migrating. `unsupportedSettingValue` now only
covers a `${config:}` reference without a setting name.
Refs #340161
Co-authored-by: Copilot <[email protected]>
A `${config:}` reference without a setting name now migrates to an empty
`MCP_CONFIG` environment variable instead of excluding the server. With that,
every setting reference migrates, so the `unsupportedSettingValue` exclusion
reason is removed.
Refs #340161
Co-authored-by: Copilot <[email protected]>
The client never resolves user servers, so a setting it can't resolve only means a `.vscode/mcp.json` server is projected as written. Also stop exporting `getSettingVariableName`, which is only used in its module. Refs #340161 Co-authored-by: Copilot <[email protected]>
A workspace server moves to `<root>/.mcp.json`, which is usually committed.
A `${config:}` setting's value is now only written there if it comes from the
workspace or folder settings, which are already in the repository. A value
from the user's settings, a policy or memory becomes an empty environment
variable instead. User servers, which move to the user's own configuration,
keep every value.
Refs #340161
Co-authored-by: Copilot <[email protected]>
Justin Chen (justschen)
previously approved these changes
Oct 13, 2026
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Unresolved nested variables and local environment-value rewrites can produce excluded or ineffective migrations, while the warning overstates value preservation.
3 open findings
What changed in this PR
Migrates MCP ${config:...} references to portable environment variables while preserving current setting values where possible.
Changes:
- Adds setting-variable analysis, collision detection, rewriting, and revalidation.
- Adds migration warnings and updated exclusion messages.
- Expands unit and integration-style migration coverage.
| File | Description |
|---|---|
mcpServerCustomizationMigration.test.ts |
Tests setting migration and validation. |
customizationMigrationServiceImpl.test.ts |
Tests end-to-end migration behavior. |
customizationMigration.test.ts |
Tests candidate warnings. |
customizationMigrationService.ts |
Adds setting-variable metadata. |
mcpServerEnvironmentVariables.ts |
Adds setting names and collisions. |
mcpServerCustomizationMigration.ts |
Implements setting migration. |
customizationMigrationCategories.ts |
Adds the setting migration warning. |
agentHostMcpServerMigrationProvider.ts |
Injects configuration and revalidates settings. |
🧠 Review effort: Balanced
💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
- Write a setting's value directly in a stdio server's `env` values, since
those are expanded from the host's environment, not from the other `env`
entries. Only settings that `command` or `args` read are declared in `env`.
- Accept variables that the client keeps as text when it resolves a setting's
value, such as an `${input:}`, instead of rejecting the workspace server.
Like the client, treat a setting whose resolution leaves a variable
unresolved as one it can't resolve.
- Only say that configs are set to their current values when a value is
copied, and explain when they become empty instead.
Refs #340161
Co-authored-by: Copilot <[email protected]>
Contributor
|
Base:
|
Martin Aeschlimann (aeschli)
previously approved these changes
Oct 13, 2026
Refs #340161 Co-authored-by: Copilot <[email protected]>
… form Empty environment variable rows showed `API_KEY` and `your-api-key`, which suggested an API key even for unrelated variables, such as the empty ones the MCP customization migration creates. They now show `Key` and `Value`. Refs #340161 Co-authored-by: Copilot <[email protected]>
roblourens
approved these changes
Oct 13, 2026
Vritant Bhardwaj (vritant24)
deleted the
agents/migrate-config-references-to-env-vars
branch
October 13, 2026 21:32
21 of 42 tasks
2 tasks done
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 (case B3). Follows #341224, which did the same for
${input:}.The MCP customization migrator used to exclude any server that uses
${config:key}. It now migrates the reference to an environment variable set to the setting's current value, the same way inputs are migrated.What changed
Name: derived from the setting key with
getVariableName, e.g.mcp.command→MCP_COMMAND, with the existingMCP_prefix for reserved names. A${config:}with no key becomesMCP_CONFIG. A setting used several times maps to one variable.Rewrite: same fields as inputs (stdio
command,argsandenvvalues; remote URL and header values). Stdio servers get${NAME}and anenventry with the value. Remote servers get${NAME:-value}, or${NAME}when the value is empty. Remote values are written without a round-trip check, so a rare value containing}is written as is.Value: read in the folder scope VS Code resolves the server in. Strings and numbers are kept, numbers as text. These become an empty variable instead of excluding the server:
The last rule exists because
<root>/.mcp.jsonis usually committed, and a value from the user's settings could be private, such as a token. User servers move to the user's own configuration and keep every value.Exclusions: the existing collision checks now cover setting names too, against inputs,
${env:}names, other settings and existingenvkeys. A server is still excluded when a setting reference is in anenvor header name,cwd, or a URL position the destination rejects, or when the value makes it too long. No new exclusion reason was needed.Projection: VS Code resolves
${config:}for.vscode/mcp.jsonservers before forwarding them, so the projection holds the value. When VS Code can't resolve a setting, it forwards the server as written, and the planner compares against that. User servers are always forwarded unresolved.Revalidation: the candidate records each setting's key, name and value (
settingVariables). If a value changes between planning and writing, the migration fails withSourceChanged.Migration view: a new localized warning: "Configs will become environment variables set to their current values. Later changes to the configs won't apply." The collision and name-position exclusion messages now mention settings.
Known limitation (tracked separately)
VS Code's own chat expands
${NAME}in stdiocommand/argsonly from its process environment, not from the server'senv. A migrated reference there stays literal in VS Code's chat; Copilot fills it fromenv.Open questions for review
.code-workspacefile count as workspace settings, even though the file may be outside the repo.How to test
${config:...}to.vscode/mcp.jsonor the usermcp.json, e.g."args": ["--port=${config:mcp.port}"], and set the setting in workspace or user settings.${MCP_PORT}with"env": { "MCP_PORT": "<value>" }for stdio, or${MCP_PORT:-<value>}for remote. The value is empty for a workspace server whose setting is only in user settings.Validation
npm run typecheck-client: passednpm 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/chat/test/browser/aiCustomization/customizationMigration.test.ts --run src/vs/workbench/contrib/chat/test/browser/aiCustomization/aiCustomizationManagementEditor.test.ts: 207 passingnpm run eslint -- <changed files>: passed