Configurable messages endpoint for SSE transport (#109)
This commit is contained in:
parent
c77e78394d
commit
d1217c57af
1 changed files with 5 additions and 3 deletions
|
|
@ -1,4 +1,5 @@
|
|||
using System.Buffers;
|
||||
using System.Text;
|
||||
using System.Buffers;
|
||||
using System.Net.ServerSentEvents;
|
||||
using System.Text.Json;
|
||||
using System.Threading.Channels;
|
||||
|
|
@ -11,7 +12,8 @@ namespace ModelContextProtocol.Protocol.Transport;
|
|||
/// Implements the MCP SSE server transport protocol using the SSE response <see cref="Stream"/>.
|
||||
/// </summary>
|
||||
/// <param name="sseResponseStream">The stream to write the SSE response body to.</param>
|
||||
public sealed class SseResponseStreamTransport(Stream sseResponseStream) : ITransport
|
||||
/// <param name="messageEndpoint">The endpoint to send JSON-RPC messages to. Defaults to "/message".</param>
|
||||
public sealed class SseResponseStreamTransport(Stream sseResponseStream, string messageEndpoint = "/message") : ITransport
|
||||
{
|
||||
private readonly Channel<IJsonRpcMessage> _incomingChannel = CreateSingleItemChannel<IJsonRpcMessage>();
|
||||
private readonly Channel<SseItem<IJsonRpcMessage?>> _outgoingSseChannel = CreateSingleItemChannel<SseItem<IJsonRpcMessage?>>();
|
||||
|
|
@ -34,7 +36,7 @@ public sealed class SseResponseStreamTransport(Stream sseResponseStream) : ITran
|
|||
{
|
||||
if (item.EventType == "endpoint")
|
||||
{
|
||||
writer.Write("/message"u8);
|
||||
writer.Write(Encoding.UTF8.GetBytes(messageEndpoint));
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue