Table of Contents

Class HttpMcpServerBuilderExtensions

Namespace
Microsoft.Extensions.DependencyInjection
Assembly
ModelContextProtocol.AspNetCore.dll

Provides methods for configuring HTTP MCP servers via dependency injection.

public static class HttpMcpServerBuilderExtensions
Inheritance
HttpMcpServerBuilderExtensions
Inherited Members

Methods

AddAuthorizationFilters(IMcpServerBuilder)

Adds authorization filters to support AuthorizeAttribute on MCP server tools, prompts, and resources. This method should always be called when using ASP.NET Core integration to ensure proper authorization support.

public static IMcpServerBuilder AddAuthorizationFilters(this IMcpServerBuilder builder)

Parameters

builder IMcpServerBuilder

The builder instance.

Returns

IMcpServerBuilder

The builder provided in builder.

Remarks

This method automatically configures authorization filters for all MCP server handlers. These filters respect authorization attributes such as AuthorizeAttribute and AllowAnonymousAttribute.

Exceptions

ArgumentNullException

builder is null.

WithHttpTransport(IMcpServerBuilder, Action<HttpServerTransportOptions>?)

Adds the services necessary for McpEndpointRouteBuilderExtensions.MapMcp to handle MCP requests and sessions using the MCP Streamable HTTP transport. For more information on configuring the underlying HTTP server to control things like port binding custom TLS certificates, see the Minimal APIs quick reference.

public static IMcpServerBuilder WithHttpTransport(this IMcpServerBuilder builder, Action<HttpServerTransportOptions>? configureOptions = null)

Parameters

builder IMcpServerBuilder

The builder instance.

configureOptions Action<HttpServerTransportOptions>

Configures options for the Streamable HTTP transport. This allows configuring per-session McpServerOptions and running logic before and after a session.

Returns

IMcpServerBuilder

The builder provided in builder.

Exceptions

ArgumentNullException

builder is null.