Blog Post

Apps on Azure Blog
1 MIN READ

Re: Smart AI Integration with the Model Context Protocol (MCP) ... part 5

Hi Mark Harrison (UK)​ Thanks for the reply. Yes I saw this, the OnTokenValidated (an JwtBearerEvent), we will have the context which has the token and user claims.

Also, if I write a custom middleware like this, then also context is being accessible within the middleware. 


Now, I was expecting the same in the Tool class as well. Even though we are registering using builder.Services.AddHttpContextAccessor(); If I tried injecting IHttpContextAccessor in my Tool class and try to access the HttpContext via it, it is always null.

I would need the user claims in the token to be passed on from my tool class to my business logic.

I tried IHttpContextAccessor, tried writing a middleware which will set the user claims to a class which is scoped. But that too didnt work, because by registering .WithTools<ToolClass>, we are registering our tool class as a singleton, so underlying scoping didnt work as well.

Any workaround that you could help with would be of much help.

Published Jul 29, 2025
Version 1.0

3 Comments