Refactor transports to help enable graceful shutdown (#142)

- This also paves the way for better multi-session support
- We should definitely rethink names for the transport API
- For now, I kept the names similar as possible, so we can
  focus on the API shape

Co-authored-by: Stephen Toub <stoub@microsoft.com>
This commit is contained in:
Stephen Halter 2025-03-30 17:10:14 -07:00 • committed by GitHub
commit 2ab9db0878
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -82,7 +82,14 @@ public static class McpClientFactory
}
catch
{
await transport.DisposeAsync().ConfigureAwait(false);
if (transport is IAsyncDisposable asyncDisposableTransport)
{
await asyncDisposableTransport.DisposeAsync().ConfigureAwait(false);
}
else if (transport is IDisposable disposableTransport)
{
disposableTransport.Dispose();
}
throw;
}
}