Repository navigation
Migrate MCP servers that use inputs to environment variables - #341224
Merged
Merged
Conversation
…variables (#340161) The Copilot harness can't prompt for `${input:}` values. The regular MCP migration now also moves servers that use them, from `.vscode/mcp.json` to `.mcp.json` and from the user `mcp.json` to the Copilot configuration: - `${input:id}` becomes `${NAME}`, where NAME is the id in uppercase with other characters replaced by `_`, prefixed with `MCP_` when reserved or starting with a digit. - A local server declares each variable in its `env`, set to the input's default, or empty if it has none. A remote server has no `env`, so its references become `${NAME:-default}`. - Input declarations that nothing left in the file uses are removed. - Input declarations are revalidated before writing, and the whole source document is verified and rolled back as before. Servers whose inputs can't be replaced are listed for manual review with a reason: password, command and undeclared inputs, inputs in names, inputs that would share a variable, and defaults that VS Code never uses or that can't be written. `${config:}` and `${command:}` are still not migrated. Co-authored-by: Copilot <[email protected]>
Contributor
There was a problem hiding this comment.
Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.
Note
This error may be related to your runner configuration. You can now configure runners for Copilot code review separately from Copilot cloud agent by creating a copilot-code-review.yml file with your setup steps. Read the docs for details.
Contributor
|
Base:
|
- Return the migrated input variables directly instead of wrapping them. - Find variables with ConfigurationResolverExpression instead of a custom walker. - Share the source file, JSON object and parsing helpers between the migrator and the variables module. - Verify the source by comparing it with the expected document only, which already covers the migrated servers. Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
Vritant Bhardwaj (vritant24)
marked this pull request as ready for review
October 13, 2026 02:47
Vritant Bhardwaj (vritant24)
enabled auto-merge (squash)
October 13, 2026 02:47
21 of 42 tasks
Bhavya U (bhavyaus)
approved these changes
Oct 13, 2026
Vritant Bhardwaj (vritant24)
added a commit
that referenced
this pull request
Oct 13, 2026
…341349) <!-- 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 (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 existing `MCP_` prefix for reserved names. A `${config:}` with no key becomes `MCP_CONFIG`. A setting used several times maps to one variable. - **Rewrite:** same fields as inputs (stdio `command`, `args` and `env` values; remote URL and header values). Stdio servers get `${NAME}` and an `env` entry 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: - unset, unnamed, structured or boolean settings; - values that contain a variable; - for workspace servers, values that don't come from the workspace or folder settings. The last rule exists because `<root>/.mcp.json` is 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 existing `env` keys. A server is still excluded when a setting reference is in an `env` or 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.json` servers 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 with `SourceChanged`. - **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 stdio `command`/`args` only from its process environment, not from the server's `env`. A migrated reference there stays literal in VS Code's chat; Copilot fills it from `env`. ## Open questions for review - Workspace servers leave extension defaults empty too, because those values aren't in the repo. They aren't private, so writing them may be preferable. - In multi-root workspaces, values from a `.code-workspace` file count as workspace settings, even though the file may be outside the repo. - The warning says "set to their current values" even when a workspace server's value is left empty. ## How to test 1. Add a server that uses `${config:...}` to `.vscode/mcp.json` or the user `mcp.json`, e.g. `"args": ["--port=${config:mcp.port}"]`, and set the setting in workspace or user settings. 2. Open the customization migration view for an Agent Host Copilot session. The server is offered with the new warning. 3. Migrate it. The destination contains `${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`: passed - `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/chat/test/browser/aiCustomization/customizationMigration.test.ts --run src/vs/workbench/contrib/chat/test/browser/aiCustomization/aiCustomizationManagementEditor.test.ts`: 207 passing - `npm run eslint -- <changed files>`: passed
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.
The Copilot harness can't prompt for
${input:}values, so MCP servers that use them were left out of the MCP migration. With this change, the regular Migrate in the Migrations view also moves them, from.vscode/mcp.jsonto.mcp.jsonand from the usermcp.jsonto the Copilotmcp-config.json. Each input is replaced with an environment variable. The UI is unchanged.env)log-level, no default${LOG_LEVEL}+"env": { "LOG_LEVEL": "" }${LOG_LEVEL}region, defaultus-east-1${REGION}+"env": { "REGION": "us-east-1" }${REGION:-us-east-1}path,1stMCP_PATH,MCP_1ST(reserved, or starts with a digit)_. It gets anMCP_prefix when it would otherwise be reserved, for example names the OS or shell sets, names the Copilot runtime or Claude filters out, or names starting with a digit. The list is inmcpServerEnvironmentVariables.ts.sandboxare kept.passwordflag or options changed since planning, the server fails withSourceChanged. Whole-document verification and rollback work as before, and rollback now also restores removed input declarations.