Skip to content

Commit ff8a2b7

Browse files
committed
Fix server devx
1 parent 6e23f4a commit ff8a2b7

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

samples/ProtectedMCPServer/Program.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
})
1616
.AddScheme<AuthenticationSchemeOptions, SimpleAuthHandler>("Bearer", options => { })
1717
.AddMcp(options => {
18-
// Configure MCP authentication options with the resource metadata URI
18+
// Ensure ResourceMetadataUri matches the actual mapping in McpEndpointRouteBuilderExtensions.cs
1919
options.ResourceMetadataUri = new Uri("/.well-known/oauth-protected-resource", UriKind.Relative);
2020

2121
// Configure the resource metadata using our enhanced options
@@ -38,9 +38,6 @@
3838
// Don't forget to register the ResourceMetadataService
3939
builder.Services.AddSingleton<ResourceMetadataService>();
4040

41-
// IMPORTANT: Register the McpAuthorizationMarker to enable authorization on MCP endpoints
42-
builder.Services.AddSingleton<McpAuthorizationMarker>();
43-
4441
// Configure MCP Server
4542
builder.Services.AddMcpServer(options =>
4643
{
@@ -107,6 +104,8 @@
107104
app.UseAuthorization();
108105

109106
// Map MCP endpoints with authorization
107+
// Note: The SDK will automatically map /.well-known/oauth-protected-resource
108+
// and make it accessible without authorization
110109
app.MapMcp();
111110

112111
Console.WriteLine("Starting MCP server with authorization at http://localhost:7071");

src/ModelContextProtocol.AspNetCore/Auth/McpAuthorizationExtensions.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ public static AuthenticationBuilder AddMcp(
4141
Action<McpAuthenticationOptions>? configureOptions = null)
4242
{
4343
builder.Services.TryAddSingleton<ResourceMetadataService>();
44+
45+
// Register the marker to indicate that MCP authorization is configured
46+
// This will be used by MapMcp to apply authorization to endpoints
47+
builder.Services.TryAddSingleton<McpAuthorizationMarker>();
4448

4549
return builder.AddScheme<McpAuthenticationOptions, McpAuthenticationHandler>(
4650
authenticationScheme,

src/ModelContextProtocol.AspNetCore/Auth/McpAuthorizationMarker.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ namespace ModelContextProtocol.AspNetCore.Auth;
33
/// <summary>
44
/// Marker class to indicate that MCP authorization has been configured.
55
/// </summary>
6-
internal class McpAuthorizationMarker { }
6+
public class McpAuthorizationMarker { }

0 commit comments

Comments
 (0)