Flow ExecutionContext with JsonRpcMessage (#616)
The primary goal of this change is to support IHttpContextAccessor in tool calls when the Streamable HTTP is in its default non-Stateless mode.
This commit is contained in:
parent
5f1c74f1ff
commit
a88ef0deb7
2 changed files with 61 additions and 14 deletions
|
|
@ -52,12 +52,6 @@ public abstract class MapMcpTests(ITestOutputHelper testOutputHelper) : KestrelI
|
|||
[Fact]
|
||||
public async Task Can_UseIHttpContextAccessor_InTool()
|
||||
{
|
||||
Assert.SkipWhen(UseStreamableHttp && !Stateless,
|
||||
"""
|
||||
IHttpContextAccessor is not currently supported with non-stateless Streamable HTTP.
|
||||
TODO: Support it in stateless mode by manually capturing and flowing execution context.
|
||||
""");
|
||||
|
||||
Builder.Services.AddMcpServer().WithHttpTransport(ConfigureStateless).WithTools<EchoHttpContextUserTools>();
|
||||
|
||||
Builder.Services.AddHttpContextAccessor();
|
||||
|
|
|
|||
|
|
@ -387,7 +387,7 @@ public class StreamableHttpServerConformanceTests(ITestOutputHelper outputHelper
|
|||
}
|
||||
|
||||
[Fact]
|
||||
public async Task AsyncLocalSetInRunSessionHandlerCallback_Flows_ToAllToolCalls()
|
||||
public async Task AsyncLocalSetInRunSessionHandlerCallback_Flows_ToAllToolCalls_IfPerSessionExecutionContextEnabled()
|
||||
{
|
||||
var asyncLocal = new AsyncLocal<string>();
|
||||
var totalSessionCount = 0;
|
||||
|
|
@ -395,6 +395,7 @@ public class StreamableHttpServerConformanceTests(ITestOutputHelper outputHelper
|
|||
Builder.Services.AddMcpServer()
|
||||
.WithHttpTransport(options =>
|
||||
{
|
||||
options.PerSessionExecutionContext = true;
|
||||
options.RunSessionHandler = async (httpContext, mcpServer, cancellationToken) =>
|
||||
{
|
||||
asyncLocal.Value = $"RunSessionHandler ({totalSessionCount++})";
|
||||
|
|
|
|||
Loading…
Reference in a new issue