Mcp.AspNetCore.MultiHost
0.2.0-preview
dotnet add package Mcp.AspNetCore.MultiHost --version 0.2.0-preview
NuGet\Install-Package Mcp.AspNetCore.MultiHost -Version 0.2.0-preview
<PackageReference Include="Mcp.AspNetCore.MultiHost" Version="0.2.0-preview" />
<PackageVersion Include="Mcp.AspNetCore.MultiHost" Version="0.2.0-preview" />
<PackageReference Include="Mcp.AspNetCore.MultiHost" />
paket add Mcp.AspNetCore.MultiHost --version 0.2.0-preview
#r "nuget: Mcp.AspNetCore.MultiHost, 0.2.0-preview"
#:package Mcp.AspNetCore.MultiHost@0.2.0-preview
#addin nuget:?package=Mcp.AspNetCore.MultiHost&version=0.2.0-preview&prerelease
#tool nuget:?package=Mcp.AspNetCore.MultiHost&version=0.2.0-preview&prerelease
Mcp.AspNetCore.MultiHost
Host multiple MCP (Model Context Protocol) servers with distinct tool sets and configurations in a single ASP.NET Core application.
Features
- Multiple MCP Hosts: Run multiple isolated MCP servers in a single application
- Per-Host DI Containers: Each host has its own isolated dependency injection container
- Service Bridging: Share services from the main application with MCP hosts
- Flexible Configuration: Configure each host independently with different tools, prompts, and resources
- Discovery Endpoint: Optional endpoint to list all available MCP hosts
- Security Helpers: Origin validation for cross-origin protection
Installation
dotnet add package Mcp.AspNetCore.MultiHost
Quick Start
var builder = WebApplication.CreateBuilder(args);
// Register MCP hosts
builder.Services.AddMcpMultiHost(options =>
{
options.AddHost("admin", host =>
{
host.WithRoutePrefix("/mcp/admin")
.ConfigureMcpServer(mcp => mcp
.WithHttpTransport()
.WithTools<AdminTools>());
});
options.AddHost("user", host =>
{
host.WithRoutePrefix("/mcp/user")
.ConfigureMcpServer(mcp => mcp
.WithHttpTransport()
.WithTools<UserTools>());
});
});
var app = builder.Build();
// Map all MCP hosts
app.MapMcpMultiHost();
app.Run();
Configuration
Host Configuration
Each host is configured using the fluent builder API:
options.AddHost("myhost", host =>
{
// Required: Set the route prefix
host.WithRoutePrefix("/mcp/myhost");
// Required: Configure MCP server
host.ConfigureMcpServer(mcp => mcp
.WithHttpTransport()
.WithTools<MyTools>()
.WithPrompts<MyPrompts>());
// Optional: Add host-specific services
host.ConfigureHostServices(services =>
{
services.AddSingleton<MyHostService>();
});
// Optional: Configure endpoint conventions
host.ConfigureEndpoints(endpoints =>
{
endpoints.RequireAuthorization("AdminPolicy");
});
// Optional: Custom service bridging
host.BridgeServices(bridge =>
{
bridge.ForwardAspNetCoreDefaults();
bridge.ForwardSingleton<IMySharedService>();
});
});
Discovery Endpoint
Enable a discovery endpoint to list all available MCP hosts:
app.MapMcpMultiHost(options =>
{
options.MapDiscoveryEndpoint = true;
options.DiscoveryEndpointPath = "/mcp/_hosts"; // default
});
Response format:
{
"hosts": [
{ "name": "admin", "routePrefix": "/mcp/admin" },
{ "name": "user", "routePrefix": "/mcp/user" }
]
}
Service Bridging
By default, the following ASP.NET Core services are automatically bridged to each host:
ILoggerFactory(withILogger<T>support)IConfigurationIHostEnvironmentIHostApplicationLifetimeIHttpContextAccessor(if registered)
Custom Bridging
Override the default bridging behavior:
host.BridgeServices(bridge =>
{
// Include ASP.NET Core defaults
bridge.ForwardAspNetCoreDefaults();
// Forward additional singletons
bridge.ForwardSingleton<IMyService>();
// Forward with factory
bridge.Forward<IMyService>(sp => sp.GetRequiredService<IMyService>());
});
Security
Origin Validation
Protect MCP endpoints from unauthorized cross-origin requests:
host.ConfigureEndpoints(endpoints =>
{
endpoints.RequireSameOriginOrAllowed("https://trusted.example.com");
});
This filter:
- Allows requests without Origin header (non-browser clients)
- Allows same-origin requests
- Allows explicitly listed origins
- Blocks all other cross-origin requests with 403 Forbidden
Authorization
Apply ASP.NET Core authorization to MCP endpoints:
host.ConfigureEndpoints(endpoints =>
{
endpoints.RequireAuthorization("MyPolicy");
});
Accessing the Registry
Inject IMcpHostRegistry to access registered hosts at runtime:
app.MapGet("/admin/hosts", (IMcpHostRegistry registry) =>
{
return registry.Hosts.Select(h => new { h.Name, h.RoutePrefix });
});
Requirements
- .NET 8.0 or later
- ModelContextProtocol.AspNetCore 0.8.0-preview.1 or later
Architecture
Each MCP host runs in isolation with its own:
- DI container
- Service registrations
- Tool definitions
- Prompt templates
Services can be shared from the main application through bridging, but each host maintains its own instances of host-specific services.
Main Application
|
+--------------+--------------+
| | |
[Host A] [Host B] [Host C]
/mcp/a /mcp/b /mcp/c
| | |
Tools A Tools B Tools C
License
MIT
Contributing
Contributions are welcome! Please open an issue or submit a pull request.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net8.0
- ModelContextProtocol.AspNetCore (>= 0.8.0-preview.1)
-
net9.0
- ModelContextProtocol.AspNetCore (>= 0.8.0-preview.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 0.2.0-preview | 2,556 | 2/9/2026 |
| 0.1.0-preview | 85 | 2/4/2026 |