mcp.client.client

Undocumented in source.

Members

Classes

McpClient
class McpClient

A Model Context Protocol client, transport-agnostic.

Functions

byName
Nullable!Tool byName(Tool[] tools, string name)

Find a Tool by its name in a drained tools/list slice (typically client.listTools().tools). Returns the first match wrapped in a Nullable!Tool, or a null Nullable when no tool carries that name, so callers can branch on presence without hand-rolling the scan. Usable via UFCS as tools.byName("calc").

byName
Nullable!Prompt byName(Prompt[] prompts, string name)

Find a Prompt by its name in a drained prompts/list slice (typically client.listPrompts().prompts). Returns the first match wrapped in a Nullable!Prompt, or a null Nullable when absent. Usable via UFCS as prompts.byName("greet").

resolveNegotiatedVersion
ProtocolVersion resolveNegotiatedVersion(string serverVersion)

Validate the protocol version the server returned in its initialize response and return the version to operate under. Per the Lifecycle / Version Negotiation requirement ("If the client does not support the version in the server's response, it SHOULD disconnect"), throws an UnsupportedProtocolVersionError McpException when the server's version is unparseable, not in supportedVersions, or is the modern revision (>= 2026-07-28). Conformant modern servers use server/discover rather than initialize, so a modern version in an initialize response is invalid; the client rejects it to avoid operating with useModern unset.

selectMutualVersion
bool selectMutualVersion(string[] serverVersions, ProtocolVersion chosen)

Pick the newest protocol version both this SDK and the server support, given the server's advertised wire-string list (from server/discover or the supported field of an UnsupportedProtocolVersionError). Returns false when there is no overlap. Used by McpClient.connect for modern-vs-legacy server detection per the transport backward-compatibility rules.

withProgressToken
Json withProgressToken(Json params, ProgressToken token)

Merge progressToken into a request's params._meta.progressToken, per basic/utilities/progress ("a party ... includes a progressToken in the request metadata", at params._meta.progressToken). Returns params unchanged when the token is unset. Any existing _meta keys are preserved. Exposed so callers can attach a progress token to a hand-built params object (e.g. for request methods without a dedicated progress-token overload).

withRequestLogLevel
Json withRequestLogLevel(Json params, string level)

Merge a per-request log level into a request's params._meta["io.modelcontextprotocol/logLevel"] (MetaKey.logLevel), per the draft (2026-07-28) server/utilities/logging rule that "Clients control logging verbosity per-request via _meta" (SEP-2575/2577, which removed the logging/setLevel RPC). A conformant draft server MUST NOT emit notifications/message for a request that omits this field, so attaching it is the only way a draft client can opt in to log messages for the request. An empty level leaves params unchanged. Any existing _meta keys are preserved. Exposed so callers can attach a log level to a hand-built params object; only meaningful on a draft-negotiated session.

Structs

ProgressToken
struct ProgressToken

A progress token attached to an outgoing request so the server may emit notifications/progress for it. Per basic/utilities/progress, "Progress tokens MUST be a string or integer value" and "MUST be unique across all active requests". Construct one from either a string or a long; an unset token is omitted from the request.

RequestOptions
struct RequestOptions

Per-request options shared by every McpClient request verb (callTool, readResource, getPrompt, complete). All fields are independently combinable and default to "unset":