experimental-ext-interceptors/csharp/sdk/src/ModelContextProtocol.Interceptors
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Peder Holdgaard Pedersen 45f9e0ef27
C# Implementation (#2)
C# implementation of SEP-1763

---------

Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-27 23:53:44 +00:00
..
Client C# Implementation (#2) 2026-01-27 23:53:44 +00:00
Protocol C# Implementation (#2) 2026-01-27 23:53:44 +00:00
Server C# Implementation (#2) 2026-01-27 23:53:44 +00:00
McpServerInterceptorBuilderExtensions.cs C# Implementation (#2) 2026-01-27 23:53:44 +00:00
ModelContextProtocol.Interceptors.csproj C# Implementation (#2) 2026-01-27 23:53:44 +00:00
README.md C# Implementation (#2) 2026-01-27 23:53:44 +00:00

ModelContextProtocol.Interceptors

MCP Interceptors extension for the Model Context Protocol (MCP) .NET SDK.

This package provides the interceptor framework (SEP-1763) for validating, mutating, and observing MCP messages.

Features

  • Validation Interceptors: Validate messages and provide detailed feedback with suggestions
  • Attribute-based Discovery: Mark methods with [McpServerInterceptor] for automatic discovery
  • Dependency Injection Integration: Full support for DI in interceptor methods

Installation

dotnet add package ModelContextProtocol.Interceptors

Usage

using ModelContextProtocol.Interceptors;

var builder = Host.CreateApplicationBuilder(args);

builder.Services.AddMcpServer()
    .WithStdioServerTransport()
    .WithInterceptors<MyValidators>();

await builder.Build().RunAsync();

[McpServerInterceptorType]
public class MyValidators
{
    [McpServerInterceptor(
        Events = [InterceptorEvents.ToolsCall],
        Description = "Validates tool call parameters")]
    public ValidationInterceptorResult ValidateToolCall(JsonNode payload)
    {
        // Validation logic here
        return new ValidationInterceptorResult { Valid = true };
    }
}

Documentation

For more information, see the MCP documentation.