Table of Contents

Class McpServerRequestHandler

Namespace
ModelContextProtocol.Server
Assembly
ModelContextProtocol.Core.dll

Represents a custom request handler that can be registered with the MCP server to handle arbitrary JSON-RPC methods.

[Experimental("MCPEXP002", UrlFormat = "https://github.com/modelcontextprotocol/csharp-sdk/blob/main/docs/list-of-diagnostics.md#mcpexp002")]
public sealed class McpServerRequestHandler
Inheritance
McpServerRequestHandler
Inherited Members

Remarks

Custom request handlers are registered via RequestHandlers and are invoked when a JSON-RPC request with the matching Method is received. The handler receives the raw JsonRpcRequest and returns a serialized JsonNode response, giving extensions full control over request/response serialization.

Properties

Handler

Gets the handler function that processes incoming requests for the specified method.

public required Func<JsonRpcRequest, CancellationToken, ValueTask<JsonNode?>> Handler { get; init; }

Property Value

Func<JsonRpcRequest, CancellationToken, ValueTask<JsonNode>>

Remarks

The handler receives the full JsonRpcRequest and a CancellationToken, and returns a serialized JsonNode response (or null for void methods).

Method

Gets the JSON-RPC method name this handler responds to.

public required string Method { get; init; }

Property Value

string

RoutingNameParameter

Gets the name of the top-level request parameter whose value is mirrored in the Mcp-Name HTTP routing header.

[Experimental("MCPEXP002", UrlFormat = "https://github.com/modelcontextprotocol/csharp-sdk/blob/main/docs/list-of-diagnostics.md#mcpexp002")]
public string? RoutingNameParameter { get; init; }

Property Value

string

Remarks

When set, Streamable HTTP servers require the request to include an Mcp-Name header whose decoded value matches the string value of this parameter.