Skip to content

Commit a5cd149

Browse files
Update notification handlers to include cancellation token in McpClient and McpServer tests
1 parent d5ffe1f commit a5cd149

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

tests/ModelContextProtocol.Tests/Client/McpClientExtensionsTests.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ public async Task Can_Handle_Notify_Cancel()
386386
var token = TestContext.Current.CancellationToken;
387387
TaskCompletionSource<JsonRpcNotification> clientReceived = new();
388388
await using var client = await CreateMcpClientForServer(
389-
options: CreateClientOptions([new(NotificationMethods.CancelledNotification, notification =>
389+
options: CreateClientOptions([new(NotificationMethods.CancelledNotification, (notification, cancellationToken) =>
390390
{
391391
clientReceived.TrySetResult(notification);
392392
return clientReceived.Task;
@@ -422,7 +422,7 @@ public async Task Should_Not_Intercept_Sent_Notifications()
422422
var token = TestContext.Current.CancellationToken;
423423
TaskCompletionSource<JsonRpcNotification> clientReceived = new();
424424
await using var client = await CreateMcpClientForServer(
425-
options: CreateClientOptions([new(NotificationMethods.CancelledNotification, notification =>
425+
options: CreateClientOptions([new(NotificationMethods.CancelledNotification, (notification, cancellationToken) =>
426426
{
427427
var exception = new InvalidOperationException("Should not intercept sent notifications");
428428
clientReceived.TrySetException(exception);
@@ -452,9 +452,9 @@ public async Task Can_Notify_Cancel()
452452
var token = TestContext.Current.CancellationToken;
453453
TaskCompletionSource clientReceived = new();
454454
await using var client = await CreateMcpClientForServer(
455-
options: CreateClientOptions(new Dictionary<string, Func<JsonRpcNotification, Task>>()
455+
options: CreateClientOptions(new Dictionary<string, Func<JsonRpcNotification, CancellationToken, Task>>()
456456
{
457-
[NotificationMethods.CancelledNotification] = notification =>
457+
[NotificationMethods.CancelledNotification] = (notification, cancellationToken) =>
458458
{
459459
InvalidOperationException exception = new("Should not intercept sent notifications");
460460
clientReceived.TrySetException(exception);
@@ -480,7 +480,7 @@ await Assert.ThrowsAsync<TimeoutException>(
480480
}
481481

482482
private static McpClientOptions CreateClientOptions(
483-
IEnumerable<KeyValuePair<string, Func<JsonRpcNotification, Task>>>? notificationHandlers = null)
483+
IEnumerable<KeyValuePair<string, Func<JsonRpcNotification, CancellationToken, Task>>>? notificationHandlers = null)
484484
=> new()
485485
{
486486
Capabilities = new()

tests/ModelContextProtocol.Tests/Server/McpServerTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -704,7 +704,7 @@ public async Task NotifyCancel_Should_Be_Handled()
704704
};
705705
var options = CreateOptions(new()
706706
{
707-
NotificationHandlers = [new(NotificationMethods.CancelledNotification, notification =>
707+
NotificationHandlers = [new(NotificationMethods.CancelledNotification, (notification, cancellationToken) =>
708708
{
709709
InvalidOperationException exception = new("The sender of a notification shouldn't handle the notification.");
710710
notificationIntercepted.TrySetException(exception);

0 commit comments

Comments
 (0)