Method InitializeAsync
InitializeAsync(CancellationToken)
Ensures the MCP session is initialized. If already initialized, returns a clone of the cached initialize
response.
If not, performs initialize
and then notifications/initialized
, caching the session id and payload.
All concurrent callers await the same initialization task.
public Task<JsonDocument> InitializeAsync(CancellationToken cancellationToken = default)
Parameters
cancellationToken
CancellationTokenCancellation token.
Returns
- Task<JsonDocument>
A clone of the JSON-RPC
initialize
response document.
Exceptions
- ObjectDisposedException
If the client has been disposed.
- HttpRequestException
On HTTP or JSON-RPC errors.