Class McpClientBase

Assembly: redb.Route.Llm.Mcp.dll

Shared client logic: per-id registry,
monotonic id generator, response demux, notifications/cancelled emission on
CT trip. Subclasses provide the byte-level transport ( +
the read pump that calls ).

public abstract class McpClientBase : IMcpClient, IAsyncDisposable

Inheritance

Object→McpClientBase

Implements

Derived

Properties

Initialize

Server identification reported during initialize; null until handshake completes.

public InitializeResult? Initialize { get; }

Logger

Logger used by the client and its read pump.

protected ILogger Logger { get; }

ServerName

Logical server name as registered with .

public string ServerName { get; }

Status

Current health state of the client.

public McpClientStatus Status { get; protected set; }

Methods

CallToolAsync(string, JsonNode?, CancellationToken)

Invokes a tool via tools/call. On cancellationToken trip the client

public Task<CallToolResult> CallToolAsync(string toolName, JsonNode? arguments, CancellationToken cancellationToken = default)

DisposeAsync()

Performs application-defined tasks associated with freeing, releasing, or

public virtual ValueTask DisposeAsync()

InitializeAsync(CancellationToken)

Performs the initialize handshake. Must be called before any other method.

public Task InitializeAsync(CancellationToken cancellationToken = default)

ListToolsAsync(CancellationToken)

Returns the current tool catalogue via tools/list.

public Task<IReadOnlyList<ToolDefinition>> ListToolsAsync(CancellationToken cancellationToken = default)

OnFrameReceived(string)

Called by the transport's read pump for every received frame (response or notification).

protected void OnFrameReceived(string frameJson)

OnTransportFailed(string?)

Convenience: invoked by transports when the connection drops outside our control.

protected void OnTransportFailed(string? reason)

SendFrameAsync(string, CancellationToken)

Writes a single JSON frame to the server. Implementations must serialize concurrent writes.

protected abstract Task SendFrameAsync(string frameJson, CancellationToken cancellationToken)

StartTransportAsync(CancellationToken)

Brings up the byte-level transport (e.g. spawn process, open HTTP/SSE channels).

protected abstract Task StartTransportAsync(CancellationToken cancellationToken)

StopTransportAsync()

Tears the transport down. Should not throw on already-stopped state.

protected abstract Task StopTransportAsync()

Constructors

McpClientBase(string, ILogger)

Initializes the base client with the given server name and logger.