Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions samples/AspNetCoreSseServer/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "http://localhost:3001",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
Expand All @@ -13,7 +12,6 @@
"https": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "https://localhost:7133;http://localhost:3001",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using ModelContextProtocol.Hosting;
using ModelContextProtocol.Protocol.Transport;
Expand Down Expand Up @@ -348,17 +349,8 @@ public static IMcpServerBuilder WithStdioServerTransport(this IMcpServerBuilder
{
Throw.IfNull(builder);

AddSingleSessionServerDependencies(builder.Services);
builder.Services.AddSingleton<ITransport, StdioServerTransport>();
builder.Services.AddHostedService<SingleSessionMcpServerHostedService>();

builder.Services.AddSingleton(services =>
{
ITransport serverTransport = services.GetRequiredService<ITransport>();
IOptions<McpServerOptions> options = services.GetRequiredService<IOptions<McpServerOptions>>();
ILoggerFactory? loggerFactory = services.GetService<ILoggerFactory>();

return McpServerFactory.Create(serverTransport, options.Value, loggerFactory, services);
});

return builder;
}
Expand All @@ -378,19 +370,22 @@ public static IMcpServerBuilder WithStreamServerTransport(
Throw.IfNull(inputStream);
Throw.IfNull(outputStream);

AddSingleSessionServerDependencies(builder.Services);
builder.Services.AddSingleton<ITransport>(new StreamServerTransport(inputStream, outputStream));
builder.Services.AddHostedService<SingleSessionMcpServerHostedService>();

builder.Services.AddSingleton(services =>
return builder;
}

private static void AddSingleSessionServerDependencies(IServiceCollection services)
{
services.AddHostedService<SingleSessionMcpServerHostedService>();
services.TryAddSingleton(services =>
{
ITransport serverTransport = services.GetRequiredService<ITransport>();
IOptions<McpServerOptions> options = services.GetRequiredService<IOptions<McpServerOptions>>();
ILoggerFactory? loggerFactory = services.GetService<ILoggerFactory>();

return McpServerFactory.Create(serverTransport, options.Value, loggerFactory, services);
});

return builder;
}
#endregion
}
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public async Task SendMessageAsync_Handles_Accepted_Json_RPC_Response()

var eventSourcePipe = new Pipe();
var eventSourceData = "event: endpoint\r\ndata: /sseendpoint\r\n\r\n"u8;
Assert.True(eventSourceData.TryCopyTo(eventSourcePipe.Writer.GetSpan()));
eventSourceData.CopyTo(eventSourcePipe.Writer.GetSpan(eventSourceData.Length));
eventSourcePipe.Writer.Advance(eventSourceData.Length);
await eventSourcePipe.Writer.FlushAsync(TestContext.Current.CancellationToken);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,10 @@ public override ValueTask DisposeAsync()
// completes the other half of these pipes.
_serverToClientPipe.Writer.Complete();
_serverToClientPipe.Reader.Complete();
// Disposing the CTS without waiting for the client would be problematic
// except we always dispose the HttpClient before Kestrel in our tests.
_connectionClosedCts.Dispose();

// Don't bother disposing the _connectionClosedCts, since this is just for testing,
// and it's annoying to synchronize with DuplexStream.

return base.DisposeAsync();
}

Expand Down
Loading