Rename AspNetCoreMcpServerPerUserTools to AspNetCoreMcpPerSessionTools with route-based filtering #2
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.
This PR addresses the feedback from @halter73 in modelcontextprotocol#724 by refactoring the sample to avoid pseudo-authentication patterns and instead demonstrate route-based tool filtering using the MCP SDK's
ConfigureSessionOptions
capability.Key Changes
Sample Renamed
AspNetCoreMcpServerPerUserTools
AspNetCoreMcpPerSessionTools
Authentication Approach Replaced
The sample previously used header-based pseudo-authentication which could be confusing and fragile. Following @halter73's suggestion, it now uses route-based tool category selection:
Before (header-based):
curl -H "X-User-Role: admin" https://localhost:5001/mcp
After (route-based):
Tool Categories Redesigned
Replaced role-based tools with functional categories as suggested:
/clock
): Time and date operations (GetTime
,GetDate
,ConvertTimeZone
)/calculator
): Mathematical operations (Calculate
,CalculatePercentage
,SquareRoot
)/userinfo
): Session and system information (GetSessionInfo
,GetSystemInfo
,EchoWithContext
)Route-Based Implementation
The sample now uses
MapMcp("/{toolCategory?}")
and filters tools based on route parameters:Benefits
This implementation maintains the educational value of demonstrating per-session tool filtering while addressing the concerns about authentication patterns in samples.
Testing
The sample includes test endpoints to verify route detection:
/test-category/clock
- Verify clock category detection/test-category/calculator
- Verify calculator category detection/test-category/userinfo
- Verify userinfo category detectionFixes the concerns raised in modelcontextprotocol#724 while preserving the core demonstration of
ConfigureSessionOptions
for per-session tool filtering.✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.