HttpListener based SSE Server Support (#73)

This commit is contained in:
Peder Holdgaard Pedersen 2025-03-17 22:56:03 +01:00 • committed by GitHub
commit b5a26e4c33
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -21,7 +21,7 @@ public sealed class SseClientTransport : TransportBase, IClientTransport
private readonly SseClientTransportOptions _options;
private readonly Uri _sseEndpoint;
private Uri? _messageEndpoint;
private readonly CancellationTokenSource _connectionCts;
private CancellationTokenSource? _connectionCts;
private Task? _receiveTask;
private readonly ILogger _logger;
private readonly McpServerConfig _serverConfig;
@ -82,7 +82,7 @@ public sealed class SseClientTransport : TransportBase, IClientTransport
}
// Start message receiving loop
_receiveTask = ReceiveMessagesAsync(_connectionCts.Token);
_receiveTask = ReceiveMessagesAsync(_connectionCts!.Token);
_logger.TransportReadingMessages(EndpointName);
@ -168,7 +168,12 @@ public sealed class SseClientTransport : TransportBase, IClientTransport
/// <inheritdoc/>
public async Task CloseAsync()
{
await _connectionCts.CancelAsync().ConfigureAwait(false);
if (_connectionCts != null)
{
await _connectionCts.CancelAsync().ConfigureAwait(false);
_connectionCts.Dispose();
_connectionCts = null;
}
if (_receiveTask != null)
await _receiveTask.ConfigureAwait(false);