Fix support for sending server notifications with request-specific McpServer instances used outside their original scope. (#832)

* Fix support for sending server notifications with request-specific McpServer instances used outside their original scope.

* Address feedback.

* Update src/ModelContextProtocol.Core/Server/SseWriter.cs
This commit is contained in:
Eirik Tsarpalis 2025-10-06 18:50:33 +03:00 • committed by GitHub
commit 93834d1aec
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -72,7 +72,13 @@ internal sealed class StreamableHttpPostTransport(StreamableHttpServerTransport
throw new InvalidOperationException("Server to client requests are not supported in stateless mode.");
}
await _sseWriter.SendMessageAsync(message, cancellationToken).ConfigureAwait(false);
bool isAccepted = await _sseWriter.SendMessageAsync(message, cancellationToken).ConfigureAwait(false);
if (!isAccepted)
{
// The underlying writer didn't accept the message because the underlying request has completed.
// Rather than drop the message, fall back to sending it via the parent transport.
await parentTransport.SendMessageAsync(message, cancellationToken).ConfigureAwait(false);
}
}
public async ValueTask DisposeAsync()