Add SubscribeToResourceAsync overload with handler delegate#1069
Merged
stephentoub merged 5 commits intomainfrom Dec 5, 2025
Merged
Add SubscribeToResourceAsync overload with handler delegate#1069stephentoub merged 5 commits intomainfrom
stephentoub merged 5 commits intomainfrom
Conversation
- Add new overloads for SubscribeToResourceAsync that accept a handler delegate - Handler is invoked only for notifications matching the subscribed resource URI - Return IAsyncDisposable that unsubscribes and removes the handler when disposed - Add comprehensive tests for the new functionality - Update documentation with remarks explaining usage patterns Co-authored-by: stephentoub <[email protected]>
…ing disposal Co-authored-by: stephentoub <[email protected]>
Copilot
AI
changed the title
[WIP] Add overload to SubscribeToResourceAsync for easier use
Add SubscribeToResourceAsync overload with handler delegate
Dec 5, 2025
stephentoub
approved these changes
Dec 5, 2025
tests/ModelContextProtocol.Tests/Client/McpClientResourceSubscriptionTests.cs
Show resolved
Hide resolved
- Change Uri overload to non-async to avoid unnecessary async state machine - Register handler before subscribing and cleanup on subscribe failure - Use UriTemplateComparer.Instance.Equals for URI comparison - Invert disposal check to early return pattern - Use finally block for handler disposal instead of swallowing exceptions - Add test for multiple handlers on same URI Co-authored-by: stephentoub <[email protected]>
halter73
approved these changes
Dec 5, 2025
stephentoub
reviewed
Dec 5, 2025
tests/ModelContextProtocol.Tests/Client/McpClientResourceSubscriptionTests.cs
Outdated
Show resolved
Hide resolved
tests/ModelContextProtocol.Tests/Client/McpClientResourceSubscriptionTests.cs
Outdated
Show resolved
Hide resolved
- Moved handler2CalledAgain TaskCompletionSource to top of test - Modified handler2 to set handler2CalledAgain on second invocation - Replaced Task.Delay with proper WaitAsync on handler2CalledAgain - Test now correctly validates handler2 is invoked after handler1 disposal Co-authored-by: stephentoub <[email protected]>
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.
Original prompt
💡 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.