Mark RunSessionHandler experimental (MCPEXP002) (#1383)

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: halter73 <54385+halter73@users.noreply.github.com>
Co-authored-by: jeffhandley <1031940+jeffhandley@users.noreply.github.com>
This commit is contained in:
Copilot 2026-02-24 15:02:34 -08:00 • committed by GitHub
commit 84cd6917bb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 82 additions and 4 deletions

View file

@ -213,12 +213,14 @@ public class MapMcpStreamableHttpTests(ITestOutputHelper outputHelper) : MapMcpT
}).WithHttpTransport(opts =>
{
ConfigureStateless(opts);
#pragma warning disable MCPEXP002 // RunSessionHandler is experimental
opts.RunSessionHandler = async (context, server, cancellationToken) =>
{
Interlocked.Increment(ref runSessionCount);
serverTcs.TrySetResult(server);
await server.RunAsync(cancellationToken);
};
#pragma warning restore MCPEXP002
}).WithTools<EchoHttpContextUserTools>();
await using var app = Builder.Build();
@ -481,11 +483,13 @@ public class MapMcpStreamableHttpTests(ITestOutputHelper outputHelper) : MapMcpT
Builder.Services.AddMcpServer().WithHttpTransport(opts =>
{
ConfigureStateless(opts);
#pragma warning disable MCPEXP002 // RunSessionHandler is experimental
opts.RunSessionHandler = async (context, server, cancellationToken) =>
{
serverTcs.TrySetResult(server);
await server.RunAsync(cancellationToken);
};
#pragma warning restore MCPEXP002
}).WithTools<ClaimsPrincipalTools>();
await using var app = Builder.Build();

View file

@ -253,11 +253,13 @@ public abstract class ResumabilityIntegrationTestsBase(ITestOutputHelper testOut
await using var app = await CreateServerAsync(configureTransport: options =>
{
#pragma warning disable MCPEXP002 // RunSessionHandler is experimental
options.RunSessionHandler = (httpContext, mcpServer, cancellationToken) =>
{
serverTcs.TrySetResult(mcpServer);
return mcpServer.RunAsync(cancellationToken);
};
#pragma warning restore MCPEXP002
});
await using var client = await ConnectClientAsync();

View file

@ -83,6 +83,7 @@ public partial class SseIntegrationTests(ITestOutputHelper outputHelper) : Kestr
Builder.Services.AddMcpServer()
.WithHttpTransport(httpTransportOptions =>
{
#pragma warning disable MCPEXP002 // RunSessionHandler is experimental
httpTransportOptions.RunSessionHandler = (httpContext, mcpServer, cancellationToken) =>
{
// We could also use ServerCapabilities.NotificationHandlers, but it's good to have some test coverage of RunSessionHandler.
@ -93,6 +94,7 @@ public partial class SseIntegrationTests(ITestOutputHelper outputHelper) : Kestr
});
return mcpServer.RunAsync(cancellationToken);
};
#pragma warning restore MCPEXP002
});
await using var app = Builder.Build();

View file

@ -158,6 +158,7 @@ public class StatelessServerTests(ITestOutputHelper outputHelper) : KestrelInMem
Builder.Services.AddMcpServer()
.WithHttpTransport(options =>
{
#pragma warning disable MCPEXP002 // RunSessionHandler is experimental
options.RunSessionHandler = async (context, server, cancellationToken) =>
{
unsolicitedNotificationException = await Assert.ThrowsAsync<InvalidOperationException>(
@ -165,6 +166,7 @@ public class StatelessServerTests(ITestOutputHelper outputHelper) : KestrelInMem
await server.RunAsync(cancellationToken);
};
#pragma warning restore MCPEXP002
});
await StartAsync();

View file

@ -325,11 +325,13 @@ public class StreamableHttpServerConformanceTests(ITestOutputHelper outputHelper
Builder.Services.AddMcpServer()
.WithHttpTransport(options =>
{
#pragma warning disable MCPEXP002 // RunSessionHandler is experimental
options.RunSessionHandler = (httpContext, mcpServer, cancellationToken) =>
{
server = mcpServer;
return mcpServer.RunAsync(cancellationToken);
};
#pragma warning restore MCPEXP002
});
await StartAsync();
@ -365,11 +367,13 @@ public class StreamableHttpServerConformanceTests(ITestOutputHelper outputHelper
Builder.Services.AddMcpServer()
.WithHttpTransport(options =>
{
#pragma warning disable MCPEXP002 // RunSessionHandler is experimental
options.RunSessionHandler = (httpContext, mcpServer, cancellationToken) =>
{
server = mcpServer;
return mcpServer.RunAsync(cancellationToken);
};
#pragma warning restore MCPEXP002
});
await StartAsync();
@ -502,11 +506,13 @@ public class StreamableHttpServerConformanceTests(ITestOutputHelper outputHelper
.WithHttpTransport(options =>
{
options.PerSessionExecutionContext = true;
#pragma warning disable MCPEXP002 // RunSessionHandler is experimental
options.RunSessionHandler = async (httpContext, mcpServer, cancellationToken) =>
{
asyncLocal.Value = $"RunSessionHandler ({totalSessionCount++})";
await mcpServer.RunAsync(cancellationToken);
};
#pragma warning restore MCPEXP002
});
Builder.Services.AddSingleton(McpServerTool.Create([McpServerTool(Name = "async-local-session")] () => asyncLocal.Value));