You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Host multiple MCP servers with different HTTP endpoints in one process using keyed services #1202
Is your feature request related to a problem? Please describe.
In my "modulith" (ASP.NET Core) application I want to provide multiple MCP servers/endpoints, so that every endpoint delivers a subset of tools, so that MCP clients are not "overwhelmed" by the amount of tools.
Describe the solution you'd like
I would like to register multiple MCP server as keyed services in dependency injection and call MapMcp multiple times with different routes providing the key used for the keyed services.
builder.AddKeyedMcpServer("key",...)// etc.app.MapKeyedMcp("key","/mcp/key",...)// etc.
Describe alternatives you've considered
I haven't considered alternatives, because keyed services seems natural for me. Only viable alternative would be "going microservices" and split the application into multiple containers.
Reacted by Marco Minerva, Christian Steusloff, Ivan Murzak and Flavien Marianacci
It takes a slightly different approach than keyed services - each MCP host gets its own isolated DI container with configurable service bridging from the main application.
Thanks for sharing @relusion. Mcp.AspNetCore.MultiHost looks cool! I'm glad you built on top of the MCP SDK. It seems really useful for scenarios where you want a unique set of DI services per endpoint. Let us know if you need anything for your scenarios.
I would like to register multiple MCP server as keyed services in dependency injection and call MapMcp multiple times with different routes providing the key used for the keyed services.
If you just need a specific set of tools per endpoint which are resolved using keyed services, that shouldn't be too hard to do without an extra library.
This is pretty close to something we already demonstrate in the AspNetCoreMcpPerSessionTools sample, but instead of calling ConcurrentDictionary<string, McpServerTool[]>.TryGetValue(toolCategory, out var tools) in ConfigureSessionOptions, you'd call httpContext.RequestServices.GetKeyedServices<McpServerTool>(toolCategory).
We don't currently have helper methods to register McpServerTools as keyed services like WithTools, but you can register them manually using a combination of AddKeyedSingleton and McpServerTool.Create. If you use the Func version of AddKeyedSingleton, the McpServerToolCreateOptions has a Services property where you can pass in the IServiceProvider allowing you to inject services into your tool method/Delegate.
What's supported is what's demonstrated in the AspNetCoreMcpPerSessionTools. Higher level stuff like AddMcpMultiHost or AddKeyedMcp could definitely be built using the low level features demonstrated by AspNetCoreMcpPerSessionTools, but those have never been supported APIs in the main C# SDK.
Activity
relusion commentedon Feb 2, 2026
I've built a library that addresses this use case.
(https://github.com/relusion/Mcp.AspNetCore.MultiHost)
It takes a slightly different approach than keyed services - each MCP host gets its own isolated DI container with configurable service bridging from the main application.
Usage example:
Features:
Feedback’s welcome... Thanks.
halter73 commentedon Feb 10, 2026
Thanks for sharing @relusion. Mcp.AspNetCore.MultiHost looks cool! I'm glad you built on top of the MCP SDK. It seems really useful for scenarios where you want a unique set of DI services per endpoint. Let us know if you need anything for your scenarios.
If you just need a specific set of tools per endpoint which are resolved using keyed services, that shouldn't be too hard to do without an extra library.
This is pretty close to something we already demonstrate in the AspNetCoreMcpPerSessionTools sample, but instead of calling
ConcurrentDictionary<string, McpServerTool[]>.TryGetValue(toolCategory, out var tools)inConfigureSessionOptions, you'd callhttpContext.RequestServices.GetKeyedServices<McpServerTool>(toolCategory).csharp-sdk/samples/AspNetCoreMcpPerSessionTools/Program.cs
Lines 39 to 40 in 9c1538f
csharp-sdk/samples/AspNetCoreMcpPerSessionTools/Program.cs
Lines 17 to 23 in 9c1538f
We don't currently have helper methods to register McpServerTools as keyed services like
WithTools, but you can register them manually using a combination of AddKeyedSingleton and McpServerTool.Create. If you use theFuncversion ofAddKeyedSingleton, theMcpServerToolCreateOptionshas aServicesproperty where you can pass in theIServiceProviderallowing you to inject services into your tool method/Delegate.https://github.com/modelcontextprotocol/csharp-sdk/tree/9c1538fd98f171faa61b003e62e94582dbe4a3ed/samples/AspNetCoreMcpPerSessionTools
leanserver commentedon Mar 19, 2026
@halter73 Is this still supported? Despite the examples, I am not seeing any of the mentioned APIs on ToolCapabilities in the latest package.
Thanks!
halter73 commentedon Mar 22, 2026
What's supported is what's demonstrated in the AspNetCoreMcpPerSessionTools. Higher level stuff like AddMcpMultiHost or AddKeyedMcp could definitely be built using the low level features demonstrated by AspNetCoreMcpPerSessionTools, but those have never been supported APIs in the main C# SDK.