Method SendRequestAsync
SendRequestAsync(long, string, object, CancellationToken)
Sends a JSON-RPC request and waits for the corresponding response.
public Task<JsonDocument> SendRequestAsync(long id, string method, object parameters, CancellationToken cancellationToken = default)
Parameters
idlongThe unique request identifier for response correlation.
methodstringThe JSON-RPC method name (e.g., "initialize", "tools/list").
parametersobjectThe method parameters, or
nullif none.cancellationTokenCancellationTokenA token to cancel the request.
Returns
- Task<JsonDocument>
A task that completes with the JSON-RPC response document. The caller is responsible for disposing the returned JsonDocument.
Exceptions
- McpTransportException
Thrown on transport-level failures.
- TimeoutException
Thrown when the request times out waiting for a response.
- OperationCanceledException
Thrown when the operation is canceled.
- InvalidOperationException
Thrown when the transport is not connected.