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:
parent
4e68a4e9ec
commit
84cd6917bb
5 changed files with 82 additions and 4 deletions
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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));
|
||||
|
|
|
|||
Loading…
Reference in a new issue