Repository navigation
mcp: preserve structured tool results in agent host apps - #340375
Merged
Merged
Conversation
Pass SDK structuredContent directly through to MCP Apps. - Preserve structured results in live tool completions and restored history. - Forward structured-only results and results from tools with no input to MCP Apps. - Add tests for null-valued properties, empty objects, and live and restored results. Fixes #340165 (Commit message generated by Copilot) Co-authored-by: Copilot <[email protected]>
Contributor
roblourens
approved these changes
Oct 7, 2026
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
The focused implementation covers both live and restored paths with comprehensive boundary tests.
0 open findings
What changed in this PR
Preserves MCP structured tool results across Agent Host live execution, history restoration, and MCP App notifications.
Changes:
- Propagates SDK
structuredContentinto tool-call state. - Supports structured-only results and tools without input.
- Adds live/restored coverage for empty objects, null properties, and failures.
No actionable defects found.
| File | Description |
|---|---|
copilotAgentSession.ts |
Preserves live structured results. |
mapSessionEvents.ts |
Restores structured results from history. |
stateToProgressAdapter.ts |
Forwards structured results to MCP Apps. |
copilotAgentSession.test.ts |
Tests live SDK result mapping. |
mapSessionEvents.test.ts |
Tests restored result mapping. |
stateToProgressAdapter.test.ts |
Tests live/restored MCP output combinations. |
🧠 Review effort: Balanced
💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
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.
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.
mcp: preserve structured tool results in agent host apps
Pass SDK structuredContent directly through to MCP Apps.
Fixes #340165
(Commit message generated by Copilot)
Co-authored-by: Copilot [email protected]
Validation:
npm run build-fast -- --client-only— passed../scripts/test.sh --reporter dot --run src/vs/platform/agentHost/test/node/copilotAgentSession.test.ts --run src/vs/platform/agentHost/test/node/mapSessionEvents.test.ts --run src/vs/workbench/contrib/chat/test/browser/agentSessions/stateToProgressAdapter.test.ts— 1,301 tests passed.npm run typecheck-client— passed.npm run eslint -- src/vs/platform/agentHost/node/copilot/copilotAgentSession.ts src/vs/platform/agentHost/node/copilot/mapSessionEvents.ts src/vs/platform/agentHost/test/node/copilotAgentSession.test.ts src/vs/platform/agentHost/test/node/mapSessionEvents.test.ts src/vs/workbench/contrib/chat/browser/agentSessions/agentHost/stateToProgressAdapter.ts src/vs/workbench/contrib/chat/test/browser/agentSessions/stateToProgressAdapter.test.ts— passed.Live provider and MCP App webview flows were not exercised.