MCP.Extensions
1.2.0
dotnet add package MCP.Extensions --version 1.2.0
NuGet\Install-Package MCP.Extensions -Version 1.2.0
<PackageReference Include="MCP.Extensions" Version="1.2.0" />
<PackageVersion Include="MCP.Extensions" Version="1.2.0" />
<PackageReference Include="MCP.Extensions" />
paket add MCP.Extensions --version 1.2.0
#r "nuget: MCP.Extensions, 1.2.0"
#:package MCP.Extensions@1.2.0
#addin nuget:?package=MCP.Extensions&version=1.2.0
#tool nuget:?package=MCP.Extensions&version=1.2.0
MCP.Extensions
Extensions and middleware for ModelContextProtocol in ASP.NET Core.
Overview
This package provides useful middleware and extension methods for working with the ModelContextProtocol in ASP.NET Core applications. It is designed to help with request/response logging, audience filtering, and other common tasks when using ModelContextProtocol.
Key Feature: Audience-Based Segmentation - The McpAudienceAttribute and its streaming implementation allow you to efficiently segment your MCP server resources (tools, resources, prompts) by audience type. This enables a single MCP server to serve multiple client types with different permission levels, maximizing resource utilization while maintaining strict security boundaries.
📖 Read the Complete Guide for detailed information on audience segmentation, streaming implementation, benefits, and best practices.
This package is built against ModelContextProtocol SDK v0.4.0-preview.3.
Features
- Middleware for logging HTTP headers, request bodies, and response bodies
- Audience-based filtering middleware for tools, resources, and prompts with real-time streaming
- Attribute-based audience targeting via
[McpAudience]for declarative security - Service abstractions for unified audience management across all MCP resource types
- Efficient streaming implementation that filters responses in real-time without buffering
Installation
Install via NuGet Package Manager:
dotnet add package MCP.Extensions
Or via the NuGet UI in Visual Studio.
Usage
Add the desired middleware to your ASP.NET Core pipeline in Startup.cs or Program.cs:
// Recommended: Use the unified audience filtering (includes tools, resources, and prompts)
builder.Services.AddMcpAudienceFiltering(Assembly.GetExecutingAssembly());
app.UseMcpAudienceFiltering();
// Optional: Debugging and logging middleware
app.UseMiddleware<HeaderLoggingMiddleware>();
app.UseMiddleware<RequestBodyLoggingMiddleware>();
app.UseMiddleware<ResponseBodyLoggingMiddleware>();
Use the [McpAudience] attribute to restrict tools, resources, or prompts to specific audiences:
[McpServerTool("admin_tool")]
[McpAudience("ADMIN")]
public async Task<Result> AdminOnlyTool()
{
// Only accessible to clients with X-AGENT-MODE: ADMIN
}
[McpServerResource("sensitive-data", UriTemplate = "data://sensitive/{id}")]
[McpAudience("FINANCE", "ADMIN")]
public async Task<Data> GetSensitiveData(string id)
{
// Only accessible to FINANCE and ADMIN audiences
}
For comprehensive guidance, examples, and best practices, see the Complete Guide.
Requirements
- .NET 9.0 or later
- ModelContextProtocol v0.4.0-preview.3
- ModelContextProtocol.AspNetCore v0.4.0-preview.3
License
MIT
Repository
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | 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. |
-
net9.0
- ModelContextProtocol (>= 1.2.0)
- ModelContextProtocol.AspNetCore (>= 1.2.0)
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 |
|---|---|---|
| 1.2.0 | 221 | 4/12/2026 |
| 0.0.11-preview.24317781171 | 49 | 4/12/2026 |
| 0.0.11-preview.19416414142 | 264 | 11/17/2025 |
| 0.0.11-preview.19324399365 | 244 | 11/17/2025 |
| 0.0.11-preview.19324399340 | 242 | 11/17/2025 |
| 0.0.11-preview.18795004085 | 87 | 10/24/2025 |
| 0.0.11-preview.18794524719 | 69 | 10/24/2025 |
| 0.0.11-preview.18794524714 | 78 | 10/24/2025 |
| 0.0.11-preview.18279819569 | 147 | 10/6/2025 |
| 0.0.11-preview.18279758360 | 140 | 10/6/2025 |
| 0.0.11-preview.17716643785 | 198 | 9/14/2025 |
| 0.0.10 | 1,073 | 7/27/2025 |
| 0.0.10-preview.16548331303 | 115 | 7/27/2025 |
| 0.0.10-preview.16546775734 | 138 | 7/27/2025 |
| 0.0.9 | 430 | 7/25/2025 |
| 0.0.9-preview.16526103338 | 383 | 7/25/2025 |
| 0.0.9-preview.16525456268 | 390 | 7/25/2025 |
| 0.0.9-preview.16525136559 | 385 | 7/25/2025 |
| 0.0.8 | 433 | 7/25/2025 |
| 0.0.8-preview.16522042210 | 407 | 7/25/2025 |