Skip to content

Commit d1217c5

Browse files
authored
Configurable messages endpoint for SSE transport (#109)
1 parent c77e783 commit d1217c5

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/ModelContextProtocol/Protocol/Transport/SseResponseStreamTransport.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Buffers;
1+
using System.Text;
2+
using System.Buffers;
23
using System.Net.ServerSentEvents;
34
using System.Text.Json;
45
using System.Threading.Channels;
@@ -11,7 +12,8 @@ namespace ModelContextProtocol.Protocol.Transport;
1112
/// Implements the MCP SSE server transport protocol using the SSE response <see cref="Stream"/>.
1213
/// </summary>
1314
/// <param name="sseResponseStream">The stream to write the SSE response body to.</param>
14-
public sealed class SseResponseStreamTransport(Stream sseResponseStream) : ITransport
15+
/// <param name="messageEndpoint">The endpoint to send JSON-RPC messages to. Defaults to "/message".</param>
16+
public sealed class SseResponseStreamTransport(Stream sseResponseStream, string messageEndpoint = "/message") : ITransport
1517
{
1618
private readonly Channel<IJsonRpcMessage> _incomingChannel = CreateSingleItemChannel<IJsonRpcMessage>();
1719
private readonly Channel<SseItem<IJsonRpcMessage?>> _outgoingSseChannel = CreateSingleItemChannel<SseItem<IJsonRpcMessage?>>();
@@ -34,7 +36,7 @@ void WriteJsonRpcMessageToBuffer(SseItem<IJsonRpcMessage?> item, IBufferWriter<b
3436
{
3537
if (item.EventType == "endpoint")
3638
{
37-
writer.Write("/message"u8);
39+
writer.Write(Encoding.UTF8.GetBytes(messageEndpoint));
3840
return;
3941
}
4042

0 commit comments

Comments
 (0)