-
Notifications
You must be signed in to change notification settings - Fork 434
Open
Labels
bugSomething isn't workingSomething isn't working
Description
Describe the bug
How/when the dependencies are injected is inconsistent between SSE and HttpStreaming.
Mainly, the dependencies for HTTP streaming (non-stateless) are derived from StreamableHttpHandler.ApplicationServices and this handler is registered as a singleton. So the HttpContextAccessor has an empty HttpContext.
On the other hand, the dependencies for SSE are derived from the HttpContext.RequestServices
(in SseHandler), so the HttpContextAccessor has a filled HttpContext
To Reproduce
builder.Services.AddHttpContextAccessor();
builder.Services.AddMcpServer()
.WithHttpTransport()
.WithTools<EchoTool>()
[McpServerToolType]
public sealed class EchoTool(IHttpContextAccessor accessor)
{
[McpServerTool]
public bool HasContext() => accessor.HttpContext != null;
}
- Connect with SSE: HasContext returns "true" ✅
- Connect with non-stateless HttpStreaming: HasContext returns "false" 🔴
Naive question: why can't we use HttpContext.RequestServices
in both?
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working