-
Notifications
You must be signed in to change notification settings - Fork 401
Authorization Support (Using ASP.NET Core Native AuthN/AuthZ Integration) #377
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
src/ModelContextProtocol.AspNetCore/Auth/McpAuthorizationExtensions.cs
Outdated
Show resolved
Hide resolved
src/ModelContextProtocol.AspNetCore/Auth/McpAuthorizationExtensions.cs
Outdated
Show resolved
Hide resolved
src/ModelContextProtocol.AspNetCore/Auth/McpAuthorizationExtensions.cs
Outdated
Show resolved
Hide resolved
src/ModelContextProtocol.AspNetCore/Auth/McpAuthorizationExtensions.cs
Outdated
Show resolved
Hide resolved
src/ModelContextProtocol.AspNetCore/Auth/McpAuthenticationResponseMiddlewareExtensions.cs
Outdated
Show resolved
Hide resolved
Co-authored-by: Stephen Halter <[email protected]>
Co-authored-by: Stephen Halter <[email protected]>
…sions.cs Co-authored-by: Stephen Halter <[email protected]>
src/ModelContextProtocol.AspNetCore/Auth/McpAuthorizationExtensions.cs
Outdated
Show resolved
Hide resolved
# Conflicts: # src/ModelContextProtocol.Core/Client/StreamableHttpClientSessionTransport.cs
- Use Streamable HTTP transport in samples
Hey, don't know if you're looking for feedback on this at this stage, but I've been using this branch for a couple of weeks. It would be super super helpful to have a sample showing how to get the user ID/claims within a tool. I've managed to bodge something together which works (putting it in the known client info and enabling stateless mode) but it was extremely painful as httpcontext is often null which I didn't realise depending on the transport. also feels to me I'm doing this wrong entirely and it should be abstracted somehow? so some docs around this would be super helpful |
Hello! I see typescript sdk has already supported, when will you plan to merge? |
…-inmemory-oauth-3 # Conflicts: # tests/ModelContextProtocol.AspNetCore.Tests/Utils/KestrelInMemoryTest.cs
# Conflicts: # tests/ModelContextProtocol.AspNetCore.Tests/HttpServerIntegrationTests.cs
…zation more reliable
Hi! I tried by passing ProtocolVersion in Below is the sc to show how mcp-remote handles it - and I think as first party SDK this should also consider old specs Thanks, |
# Conflicts: # src/ModelContextProtocol.Core/Client/StreamableHttpClientSessionTransport.cs
Aiming for a merge in the next couple of days. Need to run a few extra tests. |
@localden I was trying to integrate with Auth0, and having some issue. I am using Client Id / Secrect so Dynamic Client Registration is off. As per the documentation authorization-code-flow-with-pkce we should pass audience however from As of now, my soln is like below, which works - ClientOAuthOptions.cs BuildAuthorizationUrl in ClientOAuthProvider.cs
ExchangeCodeForTokenAsync in ClientOAuthProvider.cs
essentially add the above block whereever required. and finally from Client
potentially, Another question in slightly different note, How do I get AccessToken and RefreshToken which we received from auth server for that McpTool. My scenario is - User will authenticate MCPtool in client but tool will be invoked from SignalR hub using SK, I would like to pass the same accesstoken in header which i received from client |
Implements the authorization flow for clients and servers, per specification. Instead of re-implementing everything from scratch, this follows the suggestions from #349 and uses the native ASP.NET Core constructs to handle post-discovery steps server-side.
Developer experience
Server
HTTP context in tools
.AddHttpContextAccessor
is used to ensure that tools can access the HTTP context (such as the authorization header contents).Tools that want to use the HTTP context will need to amend their signatures to include a reference to
IHttpContextAccessor
, like this:Client