Open
Description
Describe the bug
Refer to #185, there's an example fetching request info from IHttpContextAccessor.
It worked in 0.1.0-preview.9 but not working in preview 10 and 11.
To Reproduce
Steps to reproduce the behavior:
-
Add service:
builder.Services.AddHttpContextAccessor();
-
Inject and use:
[McpServerToolType] public class EchoTool(IHttpContextAccessor contextAccessor) { private readonly IHttpContextAccessor _contextAccessor = contextAccessor ?? throw new ArgumentNullException(nameof(contextAccessor)); [McpServerTool, Description("Echoes the message back to the client.")] public string Echo(string message) { return $"hello {message}, {_contextAccessor.HttpContext?.Request.Path ?? "(no HttpContext)"}"; } }
Expected behavior
The _contextAccessor.HttpContext
is not null, and provides current httpContext
.
It is in preview 10 and preview 11. (Same code works in preview.9).
Logs
Having IHttpAccessor allows checking authorization header until the official authorization middleware is in place.
Looking forward to #349 .
Additional context