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.

WithDistributedCacheEventStreamStore(IMcpServerBuilder, Action<DistributedCacheEventStreamStoreOptions>?)

Registers a DistributedCacheEventStreamStore as the ISseEventStreamStore for SSE resumability.

public static IMcpServerBuilder WithDistributedCacheEventStreamStore(this IMcpServerBuilder builder, Action<DistributedCacheEventStreamStoreOptions>? configureOptions = null)

Parameters

builder IMcpServerBuilder

The builder instance.

configureOptions Action<DistributedCacheEventStreamStoreOptions>

An optional action to configure DistributedCacheEventStreamStoreOptions.

Returns

IMcpServerBuilder

The builder provided in builder.

Remarks

An IDistributedCache implementation must be registered in the service collection before calling this method. The registered cache is automatically assigned to Cache.

To use a specific IDistributedCache instance instead of the one registered in DI, set the Cache property in the configureOptions callback.

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.

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.

Remarks

For more information on configuring the underlying HTTP server to control things like port binding and custom TLS certificates, see the Minimal APIs quick reference.

Exceptions

ArgumentNullException

builder is null.