Version
Issue occurs on 0.8.0-preview.1 and 0.7.0-preview.1
Describe the bug
When HttpClientTransportOptions.OwnsSession is set to false, McpClient.DisposeAsync() hangs indefinitely
To Reproduce
Steps to reproduce the behavior:
var httpClient = httpClientFactory.CreateClient("McpClient");
var httpTransportOptions = new HttpClientTransportOptions
{
Endpoint = new Uri(_config.Uri),
OwnsSession = false // set to false so that we don't delete the session when the MCP client is disposed
};
var client = await McpClient.CreateAsync(new HttpClientTransport(httpTransportOptions, httpClient),
new McpClientOptions(), cancellationToken: ct);
var response = await client.CallToolAsync(Name, arguments, cancellationToken: ct);
// Dispose hangs forever in StreamableHttpClientSessionTransport.DisposeAsync();
await client.DisposeAsync();
Expected behavior
I'm expecting McpClient.DisposeAsync() to return eventually
Additional context
When HttpClientTransportOptions.OwnsSession is true, DisposeAsync() doesn't hang. But then it deletes the session on the server which is not what we want