CognitiveForge.McpCategoryRouting 0.2.0

dotnet add package CognitiveForge.McpCategoryRouting --version 0.2.0
                    
NuGet\Install-Package CognitiveForge.McpCategoryRouting -Version 0.2.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="CognitiveForge.McpCategoryRouting" Version="0.2.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="CognitiveForge.McpCategoryRouting" Version="0.2.0" />
                    
Directory.Packages.props
<PackageReference Include="CognitiveForge.McpCategoryRouting" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add CognitiveForge.McpCategoryRouting --version 0.2.0
                    
#r "nuget: CognitiveForge.McpCategoryRouting, 0.2.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package [email protected]
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=CognitiveForge.McpCategoryRouting&version=0.2.0
                    
Install as a Cake Addin
#tool nuget:?package=CognitiveForge.McpCategoryRouting&version=0.2.0
                    
Install as a Cake Tool

CognitiveForge.McpCategoryRouting

Category-based routing for .NET MCP servers. Expose different subsets of tools, prompts, and resources on different URL paths from a single MCP server.

NuGet version codecov License: MIT CodeRabbit Pull Request Reviews

Overview

This library hooks into the Model Context Protocol (MCP) SDK for .NET and filters MCP primitives per HTTP session based on a route parameter. For example, app.MapMcp("/{category}") lets requests to /analytics see only analytics tools while /ops sees only operations tools.

Filtering happens at session connection time via IPostConfigureOptions<HttpServerTransportOptions>, so there is no per-message overhead.

Prerequisites

Installation

dotnet add package CognitiveForge.McpCategoryRouting

Quick Start

using CognitiveForge.McpCategoryRouting;
using ModelContextProtocol.Server;
using System.ComponentModel;

var builder = WebApplication.CreateBuilder(args);

builder.Services
    .AddMcpServer()
    .WithHttpTransport()
    .WithToolsFromAssembly(typeof(Program).Assembly)
    .AddCategoryFilters(); // enable category filtering

var app = builder.Build();
app.MapMcp("/{category}"); // standard MapMcp with a route parameter
app.Run();

// Tools categorized as "analytics" — visible at /analytics
[McpServerToolType]
[McpCategory("analytics")]
public static class AnalyticsTools
{
    [McpServerTool, Description("Returns a tiny analytics summary.")]
    public static string GetSummary() => "Users: 42, ConversionRate: 3.1%";
}

// Tools categorized as "ops" — visible at /ops
[McpServerToolType]
[McpCategory("ops")]
public static class OperationsTools
{
    [McpServerTool, Description("Returns a simple health status.")]
    public static string GetHealth() => "OK";
}

See the samples/Basic project for a complete working example.

Configuration

Pass an options delegate to AddCategoryFilters():

.AddCategoryFilters(options =>
{
    options.RouteValueName = "category";
    options.CaseInsensitive = true;
    options.UncategorizedBehavior = UncategorizedBehavior.ExcludeAlways;
});
Property Default Description
RouteValueName "category" ASP.NET Core route parameter name to read
CaseInsensitive true Case-insensitive category matching
DisableFilteringWhenCategoryMissing true Skip filtering when the route has no category segment (expose all primitives)
UncategorizedBehavior ExcludeAlways How to handle primitives with no category (see below)
FallbackCategory "mcp" Route value that activates uncategorized primitives when using FallbackRoute behavior

Category Assignment

Apply [McpCategory] to a class (affects all tools in the class) or to individual methods:

[McpCategory("analytics")]
[McpCategory("reporting")] // multiple categories allowed
public static class MultiCategoryTools { ... }

[System.ComponentModel.Category] is also supported as a fallback when [McpCategory] is not present.

Uncategorized Primitives

The UncategorizedBehavior enum controls visibility of primitives that have no category:

Value Behavior
IncludeAlways Always visible on every route
ExcludeAlways Never visible (default)
FallbackRoute Visible only when the route matches FallbackCategory

Building

dotnet build CognitiveForge.McpCategoryRouting.slnx

Testing

# Run all tests
dotnet test CognitiveForge.McpCategoryRouting.slnx

# Run unit tests only
dotnet test src/CognitiveForge.McpCategoryRouting.Tests

# Run integration tests only
dotnet test src/CognitiveForge.McpCategoryRouting.IntegrationTests

# Run a single test
dotnet test src/CognitiveForge.McpCategoryRouting.Tests --filter "FullyQualifiedName~GetCategories_should_return_empty"

Contributing

Contributions are welcome! Please open an issue or submit a pull request.

License

This project is licensed under the MIT License.

Product Compatible and additional computed target framework versions.
.NET 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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 356 2/25/2026
0.2.0-pre.f63d35d 75 2/24/2026
0.1.0-pre.39894a5 208 2/23/2026