Add server-side Streamable HTTP transport support (#330)
- Changes IJsonRpcMessage to an abstract base class so RelatedTransport will always be available - Streamable HTTP supports multiple concurrent HTTP request with their own indpendent SSE response streams - RelatedTransport indicates the source or destination of the JsonRpcMessage - Changes the default RequestId to a JSON number for better compatibility with MCP servers in the wild
This commit is contained in:
parent
7d77be68cf
commit
7dcba357d4
1 changed files with 1637 additions and 395 deletions
|
|
@ -11,11 +11,11 @@ public static class HttpMcpServerBuilderExtensions
|
|||
{
|
||||
/// <summary>
|
||||
/// Adds the services necessary for <see cref="M:McpEndpointRouteBuilderExtensions.MapMcp"/>
|
||||
/// to handle MCP requests and sessions using the MCP HTTP Streaming transport. For more information on configuring the underlying HTTP server
|
||||
/// to handle MCP requests and sessions using the MCP Streamable HTTP transport. For more information on configuring the underlying HTTP server
|
||||
/// to control things like port binding custom TLS certificates, see the <see href="https://learn.microsoft.com/aspnet/core/fundamentals/minimal-apis">Minimal APIs quick reference</see>.
|
||||
/// </summary>
|
||||
/// <param name="builder">The builder instance.</param>
|
||||
/// <param name="configureOptions">Configures options for the HTTP Streaming transport. This allows configuring per-session
|
||||
/// <param name="configureOptions">Configures options for the Streamable HTTP transport. This allows configuring per-session
|
||||
/// <see cref="McpServerOptions"/> and running logic before and after a session.</param>
|
||||
/// <returns>The builder provided in <paramref name="builder"/>.</returns>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="builder"/> is <see langword="null"/>.</exception>
|
||||
|
|
@ -23,6 +23,8 @@ public static class HttpMcpServerBuilderExtensions
|
|||
{
|
||||
ArgumentNullException.ThrowIfNull(builder);
|
||||
builder.Services.TryAddSingleton<StreamableHttpHandler>();
|
||||
builder.Services.TryAddSingleton<SseHandler>();
|
||||
builder.Services.AddHostedService<IdleTrackingBackgroundService>();
|
||||
|
||||
if (configureOptions is not null)
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue