Add stateless doc, prefer stateless mode and disable legacy SSE by default (#1468)
This commit is contained in:
parent
49bf17077d
commit
8eb4023c20
1 changed files with 1440 additions and 73 deletions
|
|
@ -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) =>
|
||||
|
|
|
|||
Loading…
Reference in a new issue