Respect HandleResponse() and SkipHandler() calls in OnResourceMetadataRequest (#607)

This commit is contained in:
Stephen Halter 2025-07-17 17:39:05 -07:00 • committed by GitHub
commit f53e0d2132
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -43,8 +43,7 @@ public class McpAuthenticationHandler : AuthenticationHandler<McpAuthenticationO
return false;
}
await HandleResourceMetadataRequestAsync();
return true;
return await HandleResourceMetadataRequestAsync();
}
/// <summary>
@ -78,10 +77,7 @@ public class McpAuthenticationHandler : AuthenticationHandler<McpAuthenticationO
return absoluteUri.ToString();
}
/// <summary>
/// Handles the resource metadata request.
/// </summary>
private async Task HandleResourceMetadataRequestAsync()
private async Task<bool> HandleResourceMetadataRequestAsync()
{
var resourceMetadata = Options.ResourceMetadata;
@ -93,6 +89,23 @@ public class McpAuthenticationHandler : AuthenticationHandler<McpAuthenticationO
};
await Options.Events.OnResourceMetadataRequest(context);
if (context.Result is not null)
{
if (context.Result.Handled)
{
return true;
}
else if (context.Result.Skipped)
{
return false;
}
else if (context.Result.Failure is not null)
{
throw new AuthenticationFailureException("An error occurred from the OnResourceMetadataRequest event.", context.Result.Failure);
}
}
resourceMetadata = context.ResourceMetadata;
}
@ -104,6 +117,7 @@ public class McpAuthenticationHandler : AuthenticationHandler<McpAuthenticationO
}
await Results.Json(resourceMetadata, McpJsonUtilities.DefaultOptions.GetTypeInfo(typeof(ProtectedResourceMetadata))).ExecuteAsync(Context);
return true;
}
/// <inheritdoc />