Address asymmetry in McpServerHandlers/McpClientHandlers and make all filter properties settable#1337
Address asymmetry in McpServerHandlers/McpClientHandlers and make all filter properties settable#1337
Conversation
…r consistency - McpClientHandlers is now sealed, matching McpServerHandlers - McpServerOptions.Handlers now has get+set with null validation, matching McpClientOptions.Handlers Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
…table - McpServerOptions.Filters is now get+set with null validation - McpServerFilters.Message and McpServerFilters.Request are now get+set with null validation - No other get-only/get-init properties found that should be get/set (IList<T> filter collections and internal McpServerImpl properties are correctly get-only) Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
jeffhandley
left a comment
There was a problem hiding this comment.
Before we merge the setters all back in, we need to get @halter73's review on this to make sure we don't have to restore the logic from here:
|
I'm fine making these both settable instead for maximum backwards compatibility. I still don't think we need to bring back any of the logic from OverwriteWithSetHandlers though. This does technically make something order dependent that wasn't previously, but previously configuring It might be worth reverting the changes we made to TestSseServer in #1308 though to make sure we still have test coverage for completely replacing the |
| /// Gets or sets the filters for request-specific MCP handler pipelines. | ||
| /// </summary> | ||
| public McpRequestFilters Request { get; } = new(); | ||
| public McpRequestFilters Request |
There was a problem hiding this comment.
Should we also make all the IList of filters in McpRequestFilters and McpMessageFilters settable for maximum consistency?
I'm leaning towards yes, because otherwise I think you have to use the { ... } collection initializer syntax rather, but not the new [] collection expression syntax, and it'd be nice to be able to use both.
There was a problem hiding this comment.
…sageFilters; revert TestSseServer to use Handlers setter
- All IList<T> filter properties in McpRequestFilters (11 properties) and
McpMessageFilters (2 properties) now have get+set with null validation
- Reverted TestSseServer to use `options.Handlers = new() { ... }` pattern
to provide test coverage for the restored Handlers setter
Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
Fixes asymmetries between server and client handler/options types and makes all filter properties settable for consistency.
Changes Made
McpClientHandlers: Now sealed to match the already-sealedMcpServerHandlers, since both are configuration containers that shouldn't be subclassed.McpServerOptions.Handlers: Now has get+set with null validation usingThrow.IfNull, matching the existingMcpClientOptions.Handlerspattern.McpServerOptions.Filters: Now has get+set with null validation, consistent with theHandlersproperty.McpServerFilters.MessageandMcpServerFilters.Request: Sub-container properties now follow the same settable pattern with null validation.IList<T>filter properties settable: All 11 filter list properties inMcpRequestFiltersand both filter list properties inMcpMessageFiltersnow have get+set with null validation, enabling both{ ... }collection initializer syntax and[]collection expression syntax.Handlerssetter: RevertedTestSseServer/Program.csto useoptions.Handlers = new() { ... }object initializer pattern to provide test coverage for completely replacing theMcpServerHandlersinstance.All settable properties use the same field-backed lazy initialization pattern (
get => field ??= new()orget => field ??= []) already established byMcpClientOptions.Handlers.💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.