Skip to content

Migrate MCP servers that use inputs to environment variables - #341224

Merged
Vritant Bhardwaj (vritant24) merged 5 commits into
mainfrom
agents/mcp-input-env-fix
Oct 13, 2026
Merged

Vritant Bhardwaj (vritant24) merged 5 commits into
mainfrom
agents/mcp-input-env-fix

Conversation

@vritant24

@vritant24 Vritant Bhardwaj (vritant24) commented Oct 13, 2026 •

Copy link
Copy Markdown
Member

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.json to .mcp.json and from the user mcp.json to the Copilot mcp-config.json. Each input is replaced with an environment variable. The UI is unchanged.

Input Local (stdio) server Remote server (no env)
log-level, no default ${LOG_LEVEL} + "env": { "LOG_LEVEL": "" } ${LOG_LEVEL}
region, default us-east-1 ${REGION} + "env": { "REGION": "us-east-1" } ${REGION:-us-east-1}
path, 1st MCP_PATH, MCP_1ST (reserved, or starts with a digit) same
  • The variable name is the input id in uppercase, with other characters replaced by _. It gets an MCP_ 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 in mcpServerEnvironmentVariables.ts.
  • Input declarations that nothing left in the file uses are removed from the source. Declarations still used by other servers or by root properties such as sandbox are kept.
  • Input declarations are rechecked right before writing. If an input's type, password flag or options changed since planning, the server fails with SourceChanged. Whole-document verification and rollback work as before, and rollback now also restores removed input declarations.

…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]>
Copilot AI balanced review requested due to automatic review settings October 13, 2026 02:00

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.

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.

@github-actions

github-actions Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Base: e65a4a4e Current: 7fe8ceb0

No screenshot changes.

- 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]>
@vritant24
Vritant Bhardwaj (vritant24) merged commit 4ed5c2a into main Oct 13, 2026
35 checks passed
@vritant24
Vritant Bhardwaj (vritant24) deleted the agents/mcp-input-env-fix branch October 13, 2026 03:26
@vs-code-engineering vs-code-engineering Bot added this to the 1.143.0 milestone 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants