Reauthorize tools changed by call-tool filters#1737
Open
PranavSenthilnathan wants to merge 2 commits into
Open
Reauthorize tools changed by call-tool filters#1737PranavSenthilnathan wants to merge 2 commits into
PranavSenthilnathan wants to merge 2 commits into
Conversation
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 5feb0906-73fc-4e1a-8cf2-c9a99c588487
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 5feb0906-73fc-4e1a-8cf2-c9a99c588487
jeffhandley
approved these changes
Jul 27, 2026
halter73
reviewed
Jul 27, 2026
| { | ||
| #pragma warning disable MCPEXP002 // Authorization must run in the alternate-result pipeline before task dispatch. | ||
| options.Filters.Request.CallToolWithAlternateFilters.Insert(0, async (context, next, cancellationToken) => | ||
| options.Filters.Request.CallToolFilters.Add(next => async (context, cancellationToken) => |
Contributor
There was a problem hiding this comment.
This drops the authorization pass outside Tasks. An anonymous call to an [Authorize] tool now reaches CreateTaskAsync and gets a task ID, which regresses #1722 and #1733's requirement that denial happen before task creation. Can we keep one alternate-result authorization check before Tasks and add this ordinary checkpoint alongside it?
| } | ||
|
|
||
| [Fact] | ||
| public async Task Authorize_Tool_ReauthorizesPrimitiveChangedByInterveningFilter() |
Contributor
There was a problem hiding this comment.
Can this also cover a task-backed call where an ordinary filter replaces an anonymous tool with an authorized one? The direct call proves the new checkpoint order, but not that the replacement is reauthorized inside Tasks.
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.
Summary
AddAuthorizationFilters()registration so intervening call-tool filters can replace and reauthorize the matched toolNote
Tool authorization is intentionally not performed at the outer task-dispatch level. A caller may register a filter that replaces the initially matched tool before the next authorization checkpoint. Authorizing outside the ordinary filter pipeline would instead authorize—and potentially reject—the original tool before that replacement can occur. For task-backed calls, this means task creation can precede authorization during background execution.
Closes #1733
Testing
dotnet builddotnet test tests\ModelContextProtocol.AspNetCore.Tests\ModelContextProtocol.AspNetCore.Tests.csproj --no-build --filter "FullyQualifiedName~AuthorizeAttributeTests|FullyQualifiedName~HttpTaskIntegrationTests"dotnet test --no-build(all ASP.NET Core tests pass; existing Core integration tests fail becauseTestServer.exeis not available on PATH)