Skip to content

.NET: [BREAKING] fix(dotnet): revalidate MCP tool approvals - #10243

Open
Vincent Biret (baywet) wants to merge 15 commits into
mainfrom
fix/approval-binding
Open

Vincent Biret (baywet) wants to merge 15 commits into
mainfrom
fix/approval-binding

Conversation

@baywet

@baywet Vincent Biret (baywet) commented Nov 10, 2026 •

Copy link
Copy Markdown
Member

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

  • What are the major changes? Request consent before discovery, then a separate tool approval bound to a canonical fingerprint of its published definition. Revalidate before invocation and reissue approval when the definition changes. Serialize complete SDK protocol metadata, including annotations and _meta, and fail closed for missing or invalid input schemas.
  • What is the impact of these changes? Approval-gated calls require discovery consent followed by tool approval; tools/list itself 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, and WorkflowSession preserves 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.
  • What do you want reviewers to focus on? The two-stage consent, keyed-header restore behavior, and delivery of approval notices alongside request content. The full declarative suite passed (1,411 tests on net10.0); focused executor tests passed (124 each on net10.0 and net472); 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

  • No material AI assistance was used.
  • This is an AI-assisted contribution. I reviewed, understood, and verified all submitted content and accept responsibility for it.

AI assistance details: implementation, tests, documentation, and PR description.

Contribution Checklist

  • The code builds clean without any errors or warnings
  • All unit tests pass, and I have added new tests where possible
  • The PR follows the Contribution Guidelines
  • This PR links to an agreed issue with no competing open PR, or the Related Issue section documents a trivial-change or repository-automation exception.
  • This is not a breaking change. If it is a breaking change, add the breaking change label (or add "[BREAKING]" to the title prefix, before or after any language prefix) — a workflow keeps the label and title prefix in sync automatically.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 427a0082-3d8b-44df-adbf-e5407e36b6ac
@baywet Vincent Biret (baywet) added the breaking change Usage: [PRs], Target: all PRs that introduce changes that are not backward compatible label Nov 10, 2026
Copilot AI balanced review requested due to automatic review settings November 10, 2026 17:49
@github-actions github-actions Bot changed the title fix(dotnet): revalidate MCP tool approvals [BREAKING] fix(dotnet): revalidate MCP tool approvals Nov 10, 2026
@agent-framework-automation agent-framework-automation Bot added .NET Usage: [Issues, PRs], Target: .Net workflows Usage: [Issues, PRs], Target: Workflows labels Nov 10, 2026
@github-actions github-actions Bot changed the title [BREAKING] fix(dotnet): revalidate MCP tool approvals .NET: [BREAKING] fix(dotnet): revalidate MCP tool approvals Nov 10, 2026

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.

🟡 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

@github-actions github-actions Bot 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.

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
@agent-framework-automation agent-framework-automation Bot added the documentation Usage: [Issues, PRs], Target: documentation in the code base and learn docs label Nov 10, 2026
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 427a0082-3d8b-44df-adbf-e5407e36b6ac

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.

🟡 Changes recommended

Name-only tool definitions can receive fingerprints and authorize invocation without an inputSchema, violating the required fail-closed validation contract.

1 open issue
3 resolved since last review

Review effort: Balanced

@github-code-quality

github-code-quality Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Code coverage overview

Languages: C#

C# / code-coverage/dotnet

main 1080130 fix/approval-binding 37b5f38 +/-
86% 86% 0%
View coverage of the 10 most impacted files.
File main 1080130 fix/approval-binding 37b5f38 +/-
/home/runner/wo...SessionStore.cs 100% 56% -44%
/home/runner/wo...pToolHandler.cs 84% 83% -1%
/home/runner/wo...geExtensions.cs 93% 93% 0%
/home/runner/wo...ToolExecutor.cs 97% 97% 0%
/home/runner/wo...kflowOptions.cs 100% 100% 0%
/home/runner/wo...ctionVisitor.cs 81% 82% +1%
/home/runner/wo...InputRequest.cs 82% 83% +1%
/home/runner/wo...SkillsSource.cs 97% 100% +3%
/home/runner/wo...kflowSession.cs 87% 94% +7%
/home/runner/wo...ingerprinter.cs 0% 88% +88%

ℹ️ Calculations represent line coverage. Results may change as calculations are updated.


Updated November 16, 2026 17:54 UTC

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

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.

🟡 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

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.

🔵 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
@baywet

Copy link
Copy Markdown
Member Author

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.

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.

🔵 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

@baywet

Copy link
Copy Markdown
Member Author

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 No pending request ... found. Both control paths complete once. This reproduces recovery failure, not duplicate tool execution. No additional code changes have been made.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 20be8d08-3950-42c1-913a-3c5b3cf173bb

This branch was successfully deployed

1 active (outdated) and 1 inactive deployments
integration — 37b5f386 Deployed Nov 16, 2026 by baywet via dotnet-foundry-hosted-it #33103
github-app-auth — 8263e83a Deployed Nov 16, 2026 by baywet via add_label #27909
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking change Usage: [PRs], Target: all PRs that introduce changes that are not backward compatible documentation Usage: [Issues, PRs], Target: documentation in the code base and learn docs .NET Usage: [Issues, PRs], Target: .Net workflows Usage: [Issues, PRs], Target: Workflows

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants