Method HandleMessageAsync
HandleMessageAsync(string, McpRequestContext, CancellationToken)
Handles one incoming JSON-RPC message and produces the reply.
public Task<string> HandleMessageAsync(string requestJson, McpRequestContext context, CancellationToken cancellationToken = default)
Parameters
requestJsonstringThe raw JSON-RPC message.
contextMcpRequestContextSession and caller identity for this message. The server fills in the progress token when the caller supplied one.
cancellationTokenCancellationTokenA token to observe while handling.
Returns
- Task<string>
The serialized reply, or
nullwhen the message was a notification and therefore takes no response.
Remarks
This method does not throw for malformed input or failing tools. Protocol faults come back
as JSON-RPC errors and tool faults as results carrying isError, because a transport
exception would leave the caller with nothing to act on.