Delegate McpMessageHandler
- Namespace
- ModelContextProtocol.Server
- Assembly
- ModelContextProtocol.Core.dll
Delegate type for handling incoming JSON-RPC messages.
public delegate Task McpMessageHandler(MessageContext context, CancellationToken cancellationToken)
Parameters
contextMessageContextThe message context containing the JSON-RPC message and other metadata.
cancellationTokenCancellationTokenA cancellation token to cancel the operation.
Returns
- Task
A task representing the asynchronous operation.
Remarks
This delegate can handle any type of JSON-RPC message, including requests, notifications, responses, and errors. Use this for implementing cross-cutting concerns that need to intercept all message types, such as logging, authentication, rate limiting, or request tracing.
For request-specific handling, use McpRequestHandler<TParams, TResult> instead.