Add stateless doc, prefer stateless mode and disable legacy SSE by default (#1468)

This commit is contained in:
Stephen Halter 2026-03-27 13:56:16 -07:00 • committed by GitHub
commit 8eb4023c20
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -15,6 +15,13 @@ using System.Collections.Concurrent;
var builder = WebApplication.CreateBuilder(args);
// Note: This sample requires stateful (session-based) mode because it uses:
// - SampleLlmTool: server-to-client sampling via SampleAsync
// - Resource subscriptions: unsolicited notifications via SendNotificationAsync
// - Per-session state: subscription tracking keyed by SessionId
// See https://csharp.sdk.modelcontextprotocol.io/concepts/sessions for details
// on when to prefer stateless mode instead.
// Dictionary of session IDs to a set of resource URIs they are subscribed to
// The value is a ConcurrentDictionary used as a thread-safe HashSet
// because .NET does not have a built-in concurrent HashSet
@ -50,6 +57,10 @@ builder.Services
})
.WithHttpTransport(options =>
{
// This sample uses subscriptions, SampleLlmTool (sampling), and RunSessionHandler.
// Set Stateless = false explicitly for forward compatibility in case the default changes.
options.Stateless = false;
// Add a RunSessionHandler to remove all subscriptions for the session when it ends
#pragma warning disable MCPEXP002 // RunSessionHandler is experimental
options.RunSessionHandler = async (httpContext, mcpServer, token) =>