Skip to content

.NET: fix(dotnet): validate MCP invocation headers - #9539

Merged
Vincent Biret (baywet) merged 1 commit into
mainfrom
fix/mcp-header-validation
Oct 19, 2026
Merged

Vincent Biret (baywet) merged 1 commit into
mainfrom
fix/mcp-header-validation

Conversation

@baywet

Copy link
Copy Markdown
Member

Motivation & Context

Apply consistent HTTP header validation when invoking declarative MCP tools, before creating or selecting a client.

Description & Review Guide

  • What are the major changes? Reuse the existing shared HTTP header validator for MCP header names and values, with focused regression tests for both client-creation paths.
  • What is the impact of these changes? Invalid headers produce an argument error before client creation or cache lookup. Valid invocations retain their existing behavior; no public signatures change.
  • What do you want reviewers to focus on? Consistency with the existing HTTP action and validation ordering for provider-backed and cached clients.

Validation from dotnet:

  • dotnet test --project tests\Microsoft.Agents.AI.Workflows.Declarative.Mcp.UnitTests -f net10.0 --filter-method '*InvokeToolAsync_WithInvalidHeader_ShouldRejectBeforeClientCreationAsync*' --no-ansi: 12 failed before the change for the expected missing-validation behavior; 12 passed afterward.
  • dotnet test --project tests\Microsoft.Agents.AI.Workflows.Declarative.Mcp.UnitTests -f net10.0 --no-ansi: passed, 102 tests.
  • dotnet test --project tests\Microsoft.Agents.AI.Workflows.Declarative.UnitTests -f net10.0 --filter-class '*InvokeMcpToolExecutorTest' --no-ansi: passed, 88 tests.
  • dotnet build src\Microsoft.Agents.AI.Workflows.Declarative.Mcp --no-restore --tl:off: passed across all five target frameworks, no warnings or errors.
  • dotnet format src\Microsoft.Agents.AI.Workflows.Declarative.Mcp --no-restore: passed.
  • dotnet format tests\Microsoft.Agents.AI.Workflows.Declarative.Mcp.UnitTests --no-restore: passed.

Related Issue

N/A - trivial change: apply the existing shared HTTP header validation consistently to the MCP handler without introducing a new API or validation policy. No matching open PR was found.

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, regression tests, 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 a 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: b7854637-38f5-42cd-8e94-bd46f8c06f01
Copilot AI balanced review requested due to automatic review settings October 19, 2026 15:04
@agent-framework-automation agent-framework-automation Bot added the .NET Usage: [Issues, PRs], Target: .Net label Oct 19, 2026
@github-actions github-actions Bot changed the title fix(dotnet): validate MCP invocation headers .NET: fix(dotnet): validate MCP invocation headers Oct 19, 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.

🟢 Approval recommended

The focused change reuses established validation, tests both client paths, and has no identified blocking issues.

No open issues 🎉

What changed in this PR

Applies shared HTTP header validation to declarative MCP invocations before client creation or cache lookup, without changing public APIs.

Changes:

  • Validates header names and values using the existing shared validator.
  • Adds 12 regression cases covering provider-backed and cached-client creation paths.
File Description
dotnet/​tests/​Microsoft.Agents.AI.Workflows.Declarative.Mcp.UnitTests/​DefaultMcpToolHandlerTests.cs Tests invalid-header rejection before client creation.
dotnet/​src/​Microsoft.Agents.AI.Workflows.Declarative.Mcp/​Microsoft.Agents.AI.Workflows.Declarative.Mcp.csproj Enables the shared header validator.
dotnet/​src/​Microsoft.Agents.AI.Workflows.Declarative.Mcp/​DefaultMcpToolHandler.cs Validates headers before selecting a client.

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: No findings
Scope: full PR (1 commit(s)): e78be891a694
Model: gpt-5.6-sol

Overview

The PR applies the shared CR/LF/NUL header policy before either MCP client path and wires the shared validator into the package without changing public signatures. The regression theory covers header names and values across provider-backed and cached-client modes and verifies rejection occurs before client creation. Existing direct and approval-resume tests also preserve valid-header forwarding, leaving no publishable Critical, High, or Medium concern.

Reviewed the supplied pull-request change set across correctness, security/reliability, architecture, and failure behavior.
No publishable findings remained after source verification for this scope.

@github-code-quality

Copy link
Copy Markdown
Contributor

Code coverage overview

Languages: C#

C# / code-coverage/dotnet

main f7a5fcb fix/mcp-header-valid... e78be89 +/-
86% 86% 0%
View coverage of the 2 most impacted files.
File main f7a5fcb fix/mcp-header-valid... e78be89 +/-
/home/runner/wo...SessionStore.cs 100% 53% -47%
/home/runner/wo...erValidation.cs 100% 100% 0%

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

@baywet
Vincent Biret (baywet) added this pull request to the merge queue Oct 19, 2026
Merged via the queue into main with commit bb4a743 Oct 19, 2026
44 checks passed
@baywet
Vincent Biret (baywet) deleted the fix/mcp-header-validation branch October 19, 2026 16:49

This branch was successfully deployed

2 active deployments
github-app-auth — e78be891 Deployed Oct 19, 2026 by baywet via team_check #7068
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

.NET Usage: [Issues, PRs], Target: .Net

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants