Repository navigation
.NET: [BREAKING] fix(dotnet): revalidate MCP tool approvals - #10243
Vincent Biret (baywet) wants to merge 15 commits into
Conversation
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 427a0082-3d8b-44df-adbf-e5407e36b6ac
There was a problem hiding this comment.
🟡 Changes recommended
The default handler omits annotations from the metadata used for fingerprinting, allowing a tool to change from read-only to destructive without invalidating pending approval.
3 open issues
What changed in this PR
This PR adds metadata revalidation to approval-gated MCP tool calls in .NET declarative workflows, preventing pending approvals from being reused when discovered tool definitions change.
Changes:
- Persist tool-definition fingerprints and compare them before approved invocation.
- Request fresh approval for changed metadata or legacy snapshots without fingerprints, and fail closed when discovery cannot verify the tool.
- Document the handler discovery requirement and expand approval and checkpoint tests.
| File | Description |
|---|---|
dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.UnitTests/ObjectModel/InvokeMcpToolExecutorTest.cs |
Adds metadata-change and unavailable-definition tests; updates mocks and legacy approval expectations. |
dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/ObjectModel/InvokeMcpToolExecutor.cs |
Adds discovery, fingerprint persistence, revalidation, and reapproval notices. |
dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/IMcpToolHandler.cs |
Documents the tools/list requirement for approval-gated handlers. |
Review effort: Balanced
There was a problem hiding this comment.
MAF Automated Review — Iteration 1
Result: Findings reported
Scope: full PR (1 commit(s)): 927bbe96c1be
Model: gpt-5.6-sol
Overview
The change snapshots a tool-definition fingerprint and revalidates it before invoking an approved MCP tool, with strong fail-closed handling for missing, malformed, ambiguous, legacy, and changed definitions. Pending-response matching, replay prevention, header redaction, and restore-time reapproval provide useful guardrails. The implementation nevertheless breaks legacy target builds, sends configured credentials before approval, permits incomplete tool representations to bypass metadata-change detection, and compares JSON representation rather than semantic metadata.
Reviewed the supplied pull-request change set across correctness, security/reliability, architecture, and failure behavior.
4 verified findings remained after source verification (3 high, 1 medium) across 2 files. Details are attached to the affected lines below.
Affected areas: dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/IMcpToolHandler.cs, dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/ObjectModel/InvokeMcpToolExecutor.cs
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 427a0082-3d8b-44df-adbf-e5407e36b6ac
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 427a0082-3d8b-44df-adbf-e5407e36b6ac
Code coverage overviewLanguages: C# C# / code-coverage/dotnet
View coverage of the 10 most impacted files.
ℹ️ Calculations represent line coverage. Results may change as calculations are updated. Updated |
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 427a0082-3d8b-44df-adbf-e5407e36b6ac
Include discovered MCP definitions in approval requests and retain pending approval routing and checkpoints when key validation fails, allowing retry after session restore. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 86cc2d6e-6b2a-4fdc-b620-f2df6ab8df6b
There was a problem hiding this comment.
🟡 Changes recommended
A downstream failure after a successful, checkpointed MCP invocation leaves the consumed approval pending and retains an earlier checkpoint, allowing retries to repeat potentially destructive external operations.
1 open issue
2 resolved since last review
Review effort: Balanced
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 86cc2d6e-6b2a-4fdc-b620-f2df6ab8df6b
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 86cc2d6e-6b2a-4fdc-b620-f2df6ab8df6b
Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 20be8d08-3950-42c1-913a-3c5b3cf173bb
There was a problem hiding this comment.
🔵 Needs a closer look
Human assessment is needed because checkpoint tracking can miss completed response consumers and approval handlers, allowing retries after downstream failures to repeat external effects or tool calls.
No open issues 🎉
1 resolved since last review
Review effort: Balanced
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 20be8d08-3950-42c1-913a-3c5b3cf173bb
|
Follow-up to the latest review: addressed in 81c80a8. Wrapped response delivery and response-consumer tracking are no longer mutually exclusive, so a handler that accepts ExternalResponse directly is recorded as completed before later checkpoint progress is retained. The regression covers typed responses and one or two wrapped-response consumers, including serialized recovery after a downstream failure. Before the fix, the two wrapped-response cases repeated their handlers; all three cases now pass without changing assertions. Validation passed: Workflows unit suites (929 on net10.0, 910 on net472), existing approval executor tests (126 on net10.0), all five Workflows Release target builds with zero warnings/errors, and dotnet format for both changed projects. The unrelated Foundry persistence-file CI failure also passed on its authorized rerun without source changes. |
There was a problem hiding this comment.
🔵 Needs a closer look
Human assessment is needed because checkpoint inconsistencies can cause crash recovery to redispatch consumed approvals or retries after downstream failures to repeat approved tool calls.
No open issues 🎉
Review effort: Balanced
|
Confirmed a recovery-state mismatch in a local serialized-session probe: selecting the emitted post-routing checkpoint causes the session to resend an already-consumed approval and fail with |
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 20be8d08-3950-42c1-913a-3c5b3cf173bb


Motivation & Context
An MCP tool's published metadata can change while an approval is pending. Revalidate that metadata before invoking the approved tool, and request a new approval when it has changed.
Description & Review Guide
_meta, and fail closed for missing or invalid input schemas.tools/listitself needs only discovery consent. Configured headers are not sent before discovery consent. A stable host-supplied key supports checkpoint recovery across processes; the process-local default fails closed if lost. Header values and the key are never checkpointed, changed headers require fresh consent, andWorkflowSessionpreserves explanatory text alongside approval content. Older checkpoints without the required state restart discovery approval. Comparison covers published metadata, not server identity or changes between discovery and invocation.net10.0); focused executor tests passed (124 each onnet10.0andnet472); both affected libraries built for all target frameworks with zero warnings/errors; formatting passed for all changed projects. Full-solution tests were not run. The separate Workflows UnitTests project could not run with the pinned SDK because it still uses VSTest instead of Microsoft Testing Platform; hosted regressions cover the changed session path.Related Issue
N/A - maintainer-directed change; no linked issue.
AI Assistance
AI assistance details: implementation, tests, documentation, and PR description.
Contribution Checklist
breaking changelabel (or add "[BREAKING]" to the title prefix, before or after any language prefix) — a workflow keeps the label and title prefix in sync automatically.