Support progress notifications with McpClientTool and McpClientExtensions.CallToolAsync (#312)

This commit is contained in:
Stephen Toub 2025-04-16 09:03:07 -04:00 • committed by GitHub
commit 227f440ab9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 174 additions and 47 deletions

View file

@ -33,7 +33,7 @@ public class CancellationTests : ClientServerTestBase
[Fact]
public async Task PrecancelRequest_CancelsBeforeSending()
{
var client = await CreateMcpClientForServer();
await using var client = await CreateMcpClientForServer();
bool gotCancellation = false;
await using (Server.RegisterNotificationHandler(NotificationMethods.CancelledNotification, (notification, cancellationToken) =>
@ -51,7 +51,7 @@ public class CancellationTests : ClientServerTestBase
[Fact]
public async Task CancellationPropagation_RequestingCancellationCancelsPendingRequest()
{
var client = await CreateMcpClientForServer();
await using var client = await CreateMcpClientForServer();
var tools = await client.ListToolsAsync(cancellationToken: TestContext.Current.CancellationToken);
var waitTool = tools.First(t => t.Name == nameof(WaitForCancellation));

View file

@ -13,7 +13,7 @@ public class NotificationHandlerTests : ClientServerTestBase
public async Task RegistrationsAreRemovedWhenDisposed()
{
const string NotificationName = "somethingsomething";
IMcpClient client = await CreateMcpClientForServer();
await using IMcpClient client = await CreateMcpClientForServer();
const int Iterations = 10;
@ -40,7 +40,7 @@ public class NotificationHandlerTests : ClientServerTestBase
public async Task MultipleRegistrationsResultInMultipleCallbacks()
{
const string NotificationName = "somethingsomething";
IMcpClient client = await CreateMcpClientForServer();
await using IMcpClient client = await CreateMcpClientForServer();
const int RegistrationCount = 10;
@ -80,7 +80,7 @@ public class NotificationHandlerTests : ClientServerTestBase
public async Task MultipleHandlersRunEvenIfOneThrows()
{
const string NotificationName = "somethingsomething";
IMcpClient client = await CreateMcpClientForServer();
await using IMcpClient client = await CreateMcpClientForServer();
const int RegistrationCount = 10;
@ -122,7 +122,7 @@ public class NotificationHandlerTests : ClientServerTestBase
public async Task DisposeAsyncDoesNotCompleteWhileNotificationHandlerRuns(int numberOfDisposals)
{
const string NotificationName = "somethingsomething";
IMcpClient client = await CreateMcpClientForServer();
await using IMcpClient client = await CreateMcpClientForServer();
var handlerRunning = new TaskCompletionSource<bool>(TaskCreationOptions.RunContinuationsAsynchronously);
var releaseHandler = new TaskCompletionSource<bool>(TaskCreationOptions.RunContinuationsAsynchronously);
@ -163,7 +163,7 @@ public class NotificationHandlerTests : ClientServerTestBase
public async Task DisposeAsyncCompletesImmediatelyWhenInvokedFromHandler(int numberOfDisposals)
{
const string NotificationName = "somethingsomething";
IMcpClient client = await CreateMcpClientForServer();
await using IMcpClient client = await CreateMcpClientForServer();
var handlerRunning = new TaskCompletionSource<bool>(TaskCreationOptions.RunContinuationsAsynchronously);
var releaseHandler = new TaskCompletionSource<bool>(TaskCreationOptions.RunContinuationsAsynchronously);