using Microsoft.AspNetCore.Authentication;
using ModelContextProtocol.AspNetCore.Authentication;
namespace Microsoft.Extensions.DependencyInjection;
///
/// Extension methods for adding MCP authorization support to ASP.NET Core applications.
///
public static class McpAuthenticationExtensions
{
///
/// Adds MCP authorization support to the application.
///
/// The authentication builder.
/// An action to configure MCP authentication options.
/// The authentication builder for chaining.
public static AuthenticationBuilder AddMcp(
this AuthenticationBuilder builder,
Action? configureOptions = null)
{
return AddMcp(
builder,
McpAuthenticationDefaults.AuthenticationScheme,
McpAuthenticationDefaults.DisplayName,
configureOptions);
}
///
/// Adds MCP authorization support to the application with a custom scheme name.
///
/// The authentication builder.
/// The authentication scheme name to use.
/// The display name for the authentication scheme.
/// An action to configure MCP authentication options.
/// The authentication builder for chaining.
public static AuthenticationBuilder AddMcp(
this AuthenticationBuilder builder,
string authenticationScheme,
string displayName,
Action? configureOptions = null)
{
return builder.AddScheme(
authenticationScheme,
displayName,
configureOptions);
}
}