Repository navigation
agentHost: preserve MCP App tool-result _meta for restored cards - #344856
Conversation
Fixes #343243. Agent Host rebuilt MCP App ui/notifications/tool-result from state without the server's result _meta, so app-only data was lost on live reconstruction and after restoring a session. Carry the runtime's tool.execution_complete result.mcpResultMeta in a namespaced vscode.mcpToolResultMeta tool-call meta slot on live completion and history replay, and rebuild it as the MCP result _meta, including metadata-only and error results. It stays isolated from host-owned meta and out of model-facing content. The SDK field is read through a narrow cast until the pinned @github/copilot-sdk declares it. Co-authored-by: Copilot <[email protected]>
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are reported for the change preserving MCP App result metadata across session restoration.
No open issues 🎉
What changed in this PR
Addresses #343243 by preserving MCP App result _meta through Agent Host session state, so restored cards retain app-only data without exposing it to the model. This relies on a runtime that supplies mcpResultMeta; older runtimes remain unchanged.
Changes:
- Capture result metadata during live completion and history replay in an isolated, namespaced slot.
- Restore metadata in completed MCP results, including metadata-only and error results.
- Add coverage for validation, persistence, live/restored parity, and model-facing exclusion.
| File | Description |
|---|---|
src/vs/workbench/contrib/chat/test/browser/agentSessions/stateToProgressAdapter.test.ts |
Tests live/restored metadata parity and running-tool exclusion. |
src/vs/workbench/contrib/chat/test/browser/agentSessions/agentHostMcpAppToolsService.test.ts |
Verifies app-only metadata stays out of model-facing content. |
src/vs/workbench/contrib/chat/browser/agentSessions/agentHost/stateToProgressAdapter.ts |
Restores _meta when rebuilding completed MCP results. |
src/vs/platform/agentHost/test/node/mapSessionEvents.test.ts |
Tests metadata preservation during history replay. |
src/vs/platform/agentHost/test/node/copilotTestEvents.ts |
Adds result metadata to the test event shape. |
src/vs/platform/agentHost/test/node/copilotAgentSession.test.ts |
Tests live completion metadata for success and error results. |
src/vs/platform/agentHost/test/common/agentMetaReaders.test.ts |
Tests validation, host-key isolation, and presentation fallbacks. |
src/vs/platform/agentHost/test/common/agentHostCreateSessionImportMeta.test.ts |
Tests metadata survival through serialization and staged import. |
src/vs/platform/agentHost/node/copilot/mapSessionEvents.ts |
Adds an SDK compatibility reader and preserves metadata during replay. |
src/vs/platform/agentHost/node/copilot/copilotAgentSession.ts |
Captures result metadata on live tool completion. |
src/vs/platform/agentHost/common/meta/vscode/agentToolCallMeta.ts |
Defines and validates the namespaced result metadata slot. |
Review effort: Balanced
Replace the namespaced vscode.mcpToolResultMeta tool-call meta slot with a first-class AHP ToolCallResult.resultMetadata field mirroring MCP CallToolResult._meta. Mirrors microsoft/agent-host-protocol; the field is copied through the protocol reducer, result confirmation, and conversation import like structuredContent. Co-authored-by: Copilot <[email protected]>
# Conflicts: # src/vs/platform/agentHost/node/copilot/copilotAgentSession.ts
8e28e2c
|
Merged Written by Connor's agent |
Fixes #343243
Agent Host rebuilt MCP App
ui/notifications/tool-resultnotifications from session state without the server's result_meta. App-only data (e.g._meta.flint.boardin the issue) was lost when a card was reconstructed, including after reopening a session or restarting.Changes
CallToolResult._metaontool.execution_completeasresult.mcpResultMeta, for MCP App tools only (github/copilot-agent-runtime#30458). It is separate from the IFC-onlymcpMeta.resultMetadata?: Record<string, unknown>to AHPToolCallResult, mirroring MCPCallToolResult._metathe same waystructuredContentmirrorsstructuredContent. The canonical protocol change is chat: add ToolCallResult.resultMetadata mirroring MCP CallToolResult._meta agent-host-protocol#549; the synced types here are updated to match. The protocol reducer, result confirmation (agentSideEffects), and conversation import validation carry it likestructuredContent.copilotAgentSession.ts(live completion) andmapSessionEvents.ts(history replay) setresultMetadatafrom the runtime'smcpResultMeta. Host-owned tool-call_meta(ui,toolKind, ...) is untouched.stateToProgressAdapter.ts(toMcpCallToolResult) rebuildsresultMetadataas the MCP result_metafor completed tools only. Metadata-only (content: []) and error results count as real results.agentHostMcpAppToolsService._convertResult) is unchanged and does not include result_meta.@github/copilot-sdkdoes not declaremcpResultMetayet, sogetSdkMcpResultMetareads it through a narrow cast (TODO to remove after the SDK bump). With an older runtime the field is absent and behavior is unchanged.How to test
_meta. The ext-appsbasic-server-vanillajsexample with a per-call_meta.example.verificationTokenworks; it displays the received token.Validation
scripts/test.bat --runon agentMetaReaders, agentHostCreateSessionImportMeta, copilotAgentSession, mapSessionEvents, reducers, agentSideEffects, stateToProgressAdapter, and agentHostMcpAppToolsService tests: 2334 passing.npm run typecheck-client: passes against the pinned SDK, and against a local SDK that declares the field.npm run eslinton the changed files: clean.Written by Connor's agent