-
Notifications
You must be signed in to change notification settings - Fork 196
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix and enhance cancellation operations across MCP Sessions. #179
Fix and enhance cancellation operations across MCP Sessions. #179
Conversation
The title and description of this PR are wrong, right? |
Did you remove the low level arbitrary notification handler registration option? If so I don't think that's a good idea. It's not something many will use but it should be possible, as MCP is an open standard and being to create servers and clients with arbitrary notifications should be possible. I also think it's important that the option to forego abstractions built on top of the protocol is always present. I might have misunderstood your last commit. In that case, disregard this. |
I just moved it to construction-time instead of runtime registration of arbitrary handlers. This avoids a race condition Stephen mentioned above.. |
So how would a server author register an arbitrary (ie custom notification) handler after this change? Also if this means removing the option to register arbitrary handlers at run-time that is a loss of low-level functionality, which I think is a shame - but on the other hand it's such a niche use-case that it's hard to justify keeping it if removing it avoids a race condition. |
What is the use case where, after you already have an established connection, you want to add a handler that you can then never remove? And why is that relevant to notifications but not to requests? It's also not a loss of functionality. If you really want to do that, you can register a handler that then consults whatever list it wants, and that list can be modified whenever to your heart's content :) |
Yeah, as I wrote above in the other comment it's weird and it's easy to work around (if one had a hypothetical need to use it). And I agree that the same would go for requests. Probably shouldn't have mentioned it. But the custom notification handler registration is important, I think, but maybe I misunderstood about that. It looks to have been removed from what I can see (the helper class is internal)? Maybe I should clarify that I'm talking about custom handlers for user-defined method notifications, not custom handlers for the "built-in" notifications. |
I'd told Tyler I would be doing the work to add handlers at construction time today. I think he was just prototyping it here. |
I was POC-ing for Stephen so he could have a jumping off point. new McpServerOptions()
{
RequestHandlers = {
["customRequest"] = [CustomRequestHandler, ...otherCustomRequestHandlers],
},
NotificationHandlers = {
["customNotification"] = [CustomNotificationHandler, ...otherCustomNotificationHandlers],
},
} You would either do this in your DI configuration, or wherever you construct an MCP server. Same goes for an MCP client for handlers to things like sampling. |
I'll likely roll back the last 3 commits when you're finished. Don't worry about trying to merge in my attempt to your work if it makes it more difficult for you :) |
@Tyler-R-Kendrick, now that the handler registration has been fixed up, can you rebase this on main? Thanks. |
Working on it now. |
ae90960
to
90536c2
Compare
tests/ModelContextProtocol.Tests/Client/McpClientExtensionsTests.cs
Outdated
Show resolved
Hide resolved
tests/ModelContextProtocol.Tests/Client/McpClientExtensionsTests.cs
Outdated
Show resolved
Hide resolved
tests/ModelContextProtocol.Tests/Client/McpClientExtensionsTests.cs
Outdated
Show resolved
Hide resolved
d744159
to
d195bd6
Compare
Motivation and Context
This helps adherence to the spec, specifically for requests - since notifications aren't cancellable according to the spec.
How Has This Been Tested?
Tests were added to cover the usage.
Breaking Changes
NA
Types of changes
Checklist
Additional context
NA