Table of Contents

Class McpAuthenticationHandler

Namespace
ModelContextProtocol.AspNetCore.Authentication
Assembly
ModelContextProtocol.AspNetCore.dll

Authentication handler for MCP protocol that adds resource metadata to challenge responses and handles resource metadata endpoint requests.

public class McpAuthenticationHandler : AuthenticationHandler<McpAuthenticationOptions>, IAuthenticationRequestHandler, IAuthenticationHandler
Inheritance
McpAuthenticationHandler
Implements
Inherited Members

Constructors

McpAuthenticationHandler(IOptionsMonitor<McpAuthenticationOptions>, ILoggerFactory, UrlEncoder)

Initializes a new instance of the McpAuthenticationHandler class.

public McpAuthenticationHandler(IOptionsMonitor<McpAuthenticationOptions> options, ILoggerFactory logger, UrlEncoder encoder)

Parameters

options IOptionsMonitor<McpAuthenticationOptions>
logger ILoggerFactory
encoder UrlEncoder

Methods

HandleAuthenticateAsync()

Allows derived types to handle authentication.

protected override Task<AuthenticateResult> HandleAuthenticateAsync()

Returns

Task<AuthenticateResult>

The AuthenticateResult.

HandleChallengeAsync(AuthenticationProperties)

Override this method to deal with 401 challenge concerns, if an authentication scheme in question deals an authentication interaction as part of it's request flow. (like adding a response header, or changing the 401 result to 302 of a login page or external sign-in location.)

protected override Task HandleChallengeAsync(AuthenticationProperties properties)

Parameters

properties AuthenticationProperties

Returns

Task

A Task.

HandleRequestAsync()

Gets a value that determines if the request should stop being processed.

This feature is supported by the Authentication middleware which does not invoke any subsequent IAuthenticationHandler or middleware configured in the request pipeline if the handler returns true.

public Task<bool> HandleRequestAsync()

Returns

Task<bool>

true if request processing should stop.