Skip to content

Commit 4062b23

Browse files
halter73Copilot
andcommitted
Add SSE backpressure remarks to doc comments
Clarify that legacy SSE sessions are not subject to IdleTimeout or MaxIdleSessionCount — their lifetime is tied to the GET /sse request. Add backpressure remark to SseResponseStreamTransport warning callers about the lack of HTTP-level backpressure when POST returns immediately. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 62a11b9 commit 4062b23

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

src/ModelContextProtocol.AspNetCore/HttpServerTransportOptions.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,14 @@ public class HttpServerTransportOptions
152152
/// The amount of time the server waits between any active requests before timing out an MCP session. The default is 2 hours.
153153
/// </value>
154154
/// <remarks>
155+
/// <para>
155156
/// This value is checked in the background every 5 seconds. A client trying to resume a session will receive a 404 status code
156157
/// and should restart their session. A client can keep their session open by keeping a GET request open.
158+
/// </para>
159+
/// <para>
160+
/// Legacy SSE sessions (when <see cref="EnableLegacySse"/> is enabled) are not subject to this timeout — their lifetime is
161+
/// tied to the open GET <c>/sse</c> request, and they are removed immediately when the client disconnects.
162+
/// </para>
157163
/// </remarks>
158164
public TimeSpan IdleTimeout { get; set; } = TimeSpan.FromHours(2);
159165

@@ -164,9 +170,16 @@ public class HttpServerTransportOptions
164170
/// The maximum number of idle sessions to track in memory. The default is 10,000 sessions.
165171
/// </value>
166172
/// <remarks>
173+
/// <para>
167174
/// Past this limit, the server logs a critical error and terminates the oldest idle sessions, even if they have not reached
168175
/// their <see cref="IdleTimeout"/>, until the idle session count is below this limit. Sessions with any active HTTP request
169176
/// are not considered idle and don't count towards this limit.
177+
/// </para>
178+
/// <para>
179+
/// Legacy SSE sessions (when <see cref="EnableLegacySse"/> is enabled) are never considered idle because their lifetime is
180+
/// tied to the open GET <c>/sse</c> request. They are not subject to <see cref="IdleTimeout"/> or this limit — they exist
181+
/// exactly as long as the SSE connection is open.
182+
/// </para>
170183
/// </remarks>
171184
public int MaxIdleSessionCount { get; set; } = 10_000;
172185

src/ModelContextProtocol.Core/Server/SseResponseStreamTransport.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@ namespace ModelContextProtocol.Server;
1818
/// This transport is used in scenarios where the server needs to push messages to the client in real-time,
1919
/// such as when streaming completion results or providing progress updates during long-running operations.
2020
/// </para>
21+
/// <para>
22+
/// <b>Backpressure consideration:</b> The SSE transport separates request and response channels — the client POSTs
23+
/// messages to a separate endpoint while responses flow over the SSE stream. If the HTTP handler for incoming
24+
/// messages returns immediately (e.g., <c>202 Accepted</c>) after calling <see cref="OnMessageReceivedAsync"/>,
25+
/// there is no HTTP-level backpressure on handler concurrency. The ASP.NET Core integration disables legacy SSE
26+
/// endpoints by default for this reason. If you are using this type directly, consider holding the POST response
27+
/// open until the handler completes, or applying rate-limiting at the HTTP layer.
28+
/// </para>
2129
/// </remarks>
2230
/// <param name="sseResponseStream">The response stream to write MCP JSON-RPC messages as SSE events to.</param>
2331
/// <param name="messageEndpoint">

0 commit comments

Comments
 (0)