Skip to content

Commit a4f2495

Browse files
committed
Proper authorization configuration
1 parent 03438d2 commit a4f2495

File tree

2 files changed

+1
-7
lines changed

2 files changed

+1
-7
lines changed

samples/ProtectedMCPServer/Program.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,7 @@
9898
app.UseAuthentication();
9999
app.UseAuthorization();
100100

101-
// Map MCP endpoints with authorization
102-
// Note: The SDK will automatically map /.well-known/oauth-protected-resource
103-
// and make it accessible without authorization
104-
app.MapMcp();
101+
app.MapMcp().RequireAuthorization(McpAuthenticationDefaults.AuthenticationScheme);
105102

106103
Console.WriteLine("Starting MCP server with authorization at http://localhost:7071");
107104
Console.WriteLine("PRM Document URL: http://localhost:7071/.well-known/oauth-protected-resource");

src/ModelContextProtocol.AspNetCore/McpEndpointRouteBuilderExtensions.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,6 @@ public static IEndpointConventionBuilder MapMcp(this IEndpointRouteBuilder endpo
6565
.WithMetadata(new ProducesResponseTypeMetadata(StatusCodes.Status200OK, contentTypes: ["application/json"]))
6666
.AllowAnonymous()
6767
.WithDisplayName("MCP Resource Metadata");
68-
69-
// Apply authorization to MCP endpoints
70-
mcpGroup.RequireAuthorization(McpAuthenticationDefaults.AuthenticationScheme);
7168
}
7269

7370
return mcpGroup;

0 commit comments

Comments
 (0)