You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
/// <param name="cancellationToken">The <see cref="CancellationToken"/> to monitor for cancellation requests. The default is <see cref="CancellationToken.None"/>.</param>
562
562
/// <returns>The result of the request.</returns>
563
563
/// <exception cref="ArgumentNullException"><paramref name="requestParams"/> is <see langword="null"/>.</exception>
564
+
/// <remarks>
565
+
/// <para>
566
+
/// This method subscribes to resource update notifications but does not register a handler.
567
+
/// To receive notifications, you must separately call <see cref="McpSession.RegisterNotificationHandler(string, Func{JsonRpcNotification, CancellationToken, ValueTask})"/>
568
+
/// with <see cref="NotificationMethods.ResourceUpdatedNotification"/> and filter for the specific resource URI.
569
+
/// To unsubscribe, call <see cref="UnsubscribeFromResourceAsync(UnsubscribeRequestParams, CancellationToken)"/> and dispose the handler registration.
570
+
/// </para>
571
+
/// <para>
572
+
/// For a simpler API that handles both subscription and notification registration in a single call,
573
+
/// use <see cref="SubscribeToResourceAsync(Uri, Func{ResourceUpdatedNotificationParams, CancellationToken, ValueTask}, RequestOptions?, CancellationToken)"/>.
574
+
/// </para>
575
+
/// </remarks>
564
576
publicTaskSubscribeToResourceAsync(
565
577
SubscribeRequestParamsrequestParams,
566
578
CancellationTokencancellationToken=default)
@@ -575,6 +587,140 @@ public Task SubscribeToResourceAsync(
575
587
cancellationToken:cancellationToken).AsTask();
576
588
}
577
589
590
+
/// <summary>
591
+
/// Subscribes to a resource on the server and registers a handler for notifications when it changes.
592
+
/// </summary>
593
+
/// <param name="uri">The URI of the resource to which to subscribe.</param>
594
+
/// <param name="handler">The handler to invoke when the resource is updated. It receives <see cref="ResourceUpdatedNotificationParams"/> for the subscribed resource.</param>
595
+
/// <param name="options">Optional request options including metadata, serialization settings, and progress tracking.</param>
596
+
/// <param name="cancellationToken">The <see cref="CancellationToken"/> to monitor for cancellation requests. The default is <see cref="CancellationToken.None"/>.</param>
597
+
/// <returns>
598
+
/// A task that completes with an <see cref="IAsyncDisposable"/> that, when disposed, unsubscribes from the resource
599
+
/// and removes the notification handler.
600
+
/// </returns>
601
+
/// <exception cref="ArgumentNullException"><paramref name="uri"/> or <paramref name="handler"/> is <see langword="null"/>.</exception>
602
+
/// <remarks>
603
+
/// <para>
604
+
/// This method provides a convenient way to subscribe to resource updates and handle notifications in a single call.
605
+
/// The returned <see cref="IAsyncDisposable"/> manages both the subscription and the notification handler registration.
606
+
/// When disposed, it automatically unsubscribes from the resource and removes the handler.
607
+
/// </para>
608
+
/// <para>
609
+
/// The handler will only be invoked for notifications related to the specified resource URI.
610
+
/// Notifications for other resources are filtered out automatically.
/// Subscribes to a resource on the server and registers a handler for notifications when it changes.
626
+
/// </summary>
627
+
/// <param name="uri">The URI of the resource to which to subscribe.</param>
628
+
/// <param name="handler">The handler to invoke when the resource is updated. It receives <see cref="ResourceUpdatedNotificationParams"/> for the subscribed resource.</param>
629
+
/// <param name="options">Optional request options including metadata, serialization settings, and progress tracking.</param>
630
+
/// <param name="cancellationToken">The <see cref="CancellationToken"/> to monitor for cancellation requests. The default is <see cref="CancellationToken.None"/>.</param>
631
+
/// <returns>
632
+
/// A task that completes with an <see cref="IAsyncDisposable"/> that, when disposed, unsubscribes from the resource
633
+
/// and removes the notification handler.
634
+
/// </returns>
635
+
/// <exception cref="ArgumentNullException"><paramref name="uri"/> or <paramref name="handler"/> is <see langword="null"/>.</exception>
636
+
/// <exception cref="ArgumentException"><paramref name="uri"/> is empty or composed entirely of whitespace.</exception>
637
+
/// <remarks>
638
+
/// <para>
639
+
/// This method provides a convenient way to subscribe to resource updates and handle notifications in a single call.
640
+
/// The returned <see cref="IAsyncDisposable"/> manages both the subscription and the notification handler registration.
641
+
/// When disposed, it automatically unsubscribes from the resource and removes the handler.
642
+
/// </para>
643
+
/// <para>
644
+
/// The handler will only be invoked for notifications related to the specified resource URI.
645
+
/// Notifications for other resources are filtered out automatically.
0 commit comments