PC.ModelContextProtocol.Extensions.AspNetCore.Endpoints
1.0.0
dotnet add package PC.ModelContextProtocol.Extensions.AspNetCore.Endpoints --version 1.0.0
NuGet\Install-Package PC.ModelContextProtocol.Extensions.AspNetCore.Endpoints -Version 1.0.0
<PackageReference Include="PC.ModelContextProtocol.Extensions.AspNetCore.Endpoints" Version="1.0.0" />
<PackageVersion Include="PC.ModelContextProtocol.Extensions.AspNetCore.Endpoints" Version="1.0.0" />
<PackageReference Include="PC.ModelContextProtocol.Extensions.AspNetCore.Endpoints" />
paket add PC.ModelContextProtocol.Extensions.AspNetCore.Endpoints --version 1.0.0
#r "nuget: PC.ModelContextProtocol.Extensions.AspNetCore.Endpoints, 1.0.0"
#:package PC.ModelContextProtocol.Extensions.AspNetCore.Endpoints@1.0.0
#addin nuget:?package=PC.ModelContextProtocol.Extensions.AspNetCore.Endpoints&version=1.0.0
#tool nuget:?package=PC.ModelContextProtocol.Extensions.AspNetCore.Endpoints&version=1.0.0
McpEndpointExtensions
McpEndpointExtensions is a small ASP.NET Core extension library for hosting multiple Model Context Protocol (MCP) Streamable HTTP endpoints from one application while exposing a different tool set from each endpoint.
Use it when a single MCP server needs route-level tool isolation, for example:
/domain1/mcplists and invokes only domain 1 tools./domain2/mcplists and invokes only domain 2 tools.- A tool registered on one endpoint is rejected when it is called through another endpoint.
Project Status
This repository contains the library source, a runnable ASP.NET Core sample application, and MSTest coverage for the endpoint registration and per-route tool filtering behavior. The library targets net8.0, net9.0, and net10.0, and depends on ModelContextProtocol.AspNetCore 1.4.0.
How It Works
The library adds two extension methods:
WithMcpEndpoint(pattern, tools)registers the MCP tools that should be available under a route pattern.MapMcpEndpoint()maps every registered route pattern with the MCP ASP.NET Core transport.
At runtime, the library reads the current HttpContext.Request.Path and uses that path to decide which tools are available for MCP tools/list and tools/call requests.
Installation
Install from NuGet:
dotnet add package PC.ModelContextProtocol.Extensions.AspNetCore.Endpoints
Or reference the library project directly from an ASP.NET Core MCP server project:
<ProjectReference Include="..\..\src\McpEndpointExtensions.csproj" />
The application must also use the MCP ASP.NET Core server package through this library dependency.
Usage
Register the MCP server, configure the HTTP transport, and call WithMcpEndpoint once for each route-specific tool set:
using ModelContextProtocol.Server;
var builder = WebApplication.CreateBuilder(args);
builder.Services
.AddMcpServer()
.WithHttpTransport(options =>
{
options.Stateless = true;
})
.WithMcpEndpoint(
"/domain1/mcp",
McpServerTool.Create(Domain1Tools.A1),
McpServerTool.Create(Domain1Tools.A2))
.WithMcpEndpoint(
"/domain2/mcp",
McpServerTool.Create(Domain2Tools.B1));
var app = builder.Build();
app.MapMcpEndpoint();
app.Run();
Define tools with the normal ModelContextProtocol.Server APIs:
using ModelContextProtocol.Server;
using System.ComponentModel;
[McpServerToolType]
public sealed class Domain1Tools
{
[McpServerTool, Description("Echoes A1 calling.")]
public static string A1(string input) => $"A1: {input}";
[McpServerTool, Description("Echoes A2 calling.")]
public static string A2(string input) => $"A2: {input}";
}
Behavior
- Each call to
WithMcpEndpointassociates one route pattern with a specific set ofMcpServerToolinstances. MapMcpEndpoint()maps all configured MCP endpoint patterns. It throws anInvalidOperationExceptionif no endpoints were registered.tools/listreturns only the tools associated with the current endpoint path.tools/callinvokes only tools associated with the current endpoint path.- Calling a tool that is not available on the current endpoint returns an MCP
InvalidParamsprotocol error. WithMcpEndpointregistersIHttpContextAccessor; the application does not need to register it separately for this library.
Repository Layout
src/- theMcpEndpointExtensionslibrary.samples/McpEndpointServer/- a runnable ASP.NET Core sample that demonstrates multiple MCP endpoints.tests/- MSTest test coverage for endpoint options, route mapping, service registration, and MCP tool handler behavior.
Build
Use the .NET SDK to build the solution:
dotnet build ModelContextProtocol.slnx
The solution was validated with .NET SDK 10.0.300.
NuGet publish workflow
This repository publishes the package through GitHub Actions.
- CI workflow (
.github/workflows/ci.yml) runs on push/PR and performs restore, build, test, and pack checks. - Publish workflow (
.github/workflows/publish-nuget.yml) runs when a version tag is pushed (for examplev1.2.3) or via manual dispatch. - The publish job uses
dotnet nuget pushagainsthttps://api.nuget.org/v3/index.json.
Required GitHub configuration
Add the following secret before publishing:
NUGET_API_KEY: NuGet API key with package push permission.
Recommended setup path:
- Create a GitHub environment named
nuget-publish. - Add
NUGET_API_KEYas an environment secret. - Protect the environment with reviewers and/or branch-tag rules.
License
This project is licensed under the MIT License. See LICENSE for details.
| 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 is compatible. 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. |
-
net10.0
- ModelContextProtocol.AspNetCore (>= 1.4.0)
-
net8.0
- ModelContextProtocol.AspNetCore (>= 1.4.0)
-
net9.0
- ModelContextProtocol.AspNetCore (>= 1.4.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.