Move the SseResponseStreamTransport out of sample (#47)
This commit is contained in:
parent
e1a5828036
commit
1b1c7fa8ca
1 changed files with 103 additions and 125 deletions
|
|
@ -2,6 +2,7 @@
|
|||
using ModelContextProtocol.Server;
|
||||
using ModelContextProtocol.Utils.Json;
|
||||
using Microsoft.Extensions.Options;
|
||||
using ModelContextProtocol.Protocol.Transport;
|
||||
|
||||
namespace AspNetCoreSseServer;
|
||||
|
||||
|
|
@ -10,7 +11,7 @@ public static class McpEndpointRouteBuilderExtensions
|
|||
public static IEndpointConventionBuilder MapMcpSse(this IEndpointRouteBuilder endpoints)
|
||||
{
|
||||
IMcpServer? server = null;
|
||||
SseServerStreamTransport? transport = null;
|
||||
SseResponseStreamTransport? transport = null;
|
||||
var loggerFactory = endpoints.ServiceProvider.GetRequiredService<ILoggerFactory>();
|
||||
var mcpServerOptions = endpoints.ServiceProvider.GetRequiredService<IOptions<McpServerOptions>>();
|
||||
|
||||
|
|
@ -18,7 +19,7 @@ public static class McpEndpointRouteBuilderExtensions
|
|||
|
||||
routeGroup.MapGet("/sse", async (HttpResponse response, CancellationToken requestAborted) =>
|
||||
{
|
||||
await using var localTransport = transport = new SseServerStreamTransport(response.Body);
|
||||
await using var localTransport = transport = new SseResponseStreamTransport(response.Body);
|
||||
await using var localServer = server = McpServerFactory.Create(transport, mcpServerOptions.Value, loggerFactory, endpoints.ServiceProvider);
|
||||
|
||||
await localServer.StartAsync(requestAborted);
|
||||
|
|
@ -37,7 +38,7 @@ public static class McpEndpointRouteBuilderExtensions
|
|||
}
|
||||
});
|
||||
|
||||
routeGroup.MapPost("/message", async (HttpContext context) =>
|
||||
routeGroup.MapPost("/message", async context =>
|
||||
{
|
||||
if (transport is null)
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue