Skip to main content

Module mcp

Module mcp 

Source
Expand description

MCP wire types — the Model Context Protocol message surface, shared by the client and the served-MCP side.

Method/notification names are constants (typos become compile errors). Result/param structs use camelCase to match the spec. content[] and resource contents[] are kept as Vec<Value> with text-extraction helpers rather than a brittle tagged enum, so an unknown content type from a newer server is preserved, not a parse error (forward-compat).

The protocol version + era model lives in crate::version; it is re-exported here so mcp::wire::{PROTOCOL_VERSION, negotiate_version, …} resolves.

Modules§

method
Method + notification names. Constants, so a typo is a compile error rather than a -32601 at runtime.

Structs§

CallToolParams
CallToolResult
Result of tools/call. is_error: true is a tool-domain failure (fed to the model as an observation so it can adapt), distinct from a JSON-RPC transport error, which fails the call outright.
ClientCapabilities
Capabilities a client declares. Only declare what the client can actually service: a server is entitled to call anything advertised here, and a declared-but-unanswerable capability strands it waiting on a reply.
CompleteParams
completion/complete params: what to complete (a ref to a prompt or resource template) and the argument being typed. Kept as Value — the ref shape varies by target and revision (forward-compat).
CompleteResult
Completion
DiscoverResult
Result of server/discover (modern era): the server’s supported protocol versions, capabilities, and identity in a single call — the stateless replacement for the legacy initialize capability exchange. resultType and the caching fields (ttlMs/cacheScope) are carried for forward-compat.
GetPromptParams
prompts/get params — the template name + its argument fills (all strings).
GetPromptResult
prompts/get result — the rendered messages. messages[] is kept as Vec<Value> (each {role, content}) for forward-compat with content types.
Implementation
InitializeParams
InitializeResult
ListPromptsResult
ListResourceTemplatesResult
ListResourcesResult
ListToolsResult
Prompt
A prompt template a server offers via prompts/list. arguments describe the template’s fill-ins.
PromptArgument
ReadResourceParams
ReadResourceResult
Resource
ResourceTemplate
A resource template (a parameterized uriTemplate, RFC 6570) a server offers via resources/templates/list — distinct from a concrete Resource.
ResourceUpdatedParams
Payload of notifications/resources/updatedURI only, never a diff. The notification is a wake-up, not the data: the reader re-reads the URI on wake, so a burst of updates collapses into one read of the current state and a missed notification costs freshness, not correctness.
ResourcesCapability
ServerCapabilities
What a server says it can do. Every call is gated on these, and the gate is fail-closed — an absent capability is a refusal, not a maybe: no tools/call unless tools is present; no resources/subscribe unless resources.subscribe == Some(true).
SubscribeParams
resources/subscribe / resources/unsubscribe params. Per-URI only: a subscription names one concrete resource, never a ResourceTemplate, since a template matches an open-ended set with no item to watch.
Task
A durable async-task handle (the tasks extension). A supported request (e.g. tools/call) may return one (resultType: "task") instead of blocking; the client polls method::TASKS_GET until a terminal status.
Tool
ToolsCapability
UnsupportedProtocolVersion
The payload of an UNSUPPORTED_PROTOCOL_VERSION_CODE error’s data — the modern era’s whole version-negotiation signal, since there is no handshake in which to agree a version up front.

Enums§

Era
A protocol era: how version/identity/capabilities are conveyed and whether the connection is session-based.

Constants§

DEFAULT_NEGOTIATED_VERSION
The version a legacy Streamable HTTP server assumes when a request carries no MCP-Protocol-Version header. A header-less request is therefore not an error — it is a request for this revision.
FIRST_MODERN_VERSION
The first modern (stateless) revision — the era boundary. Any well-formed date >= this is Modern; anything earlier is Legacy.
HEADER_MISMATCH_CODE
The MCP-reserved JSON-RPC error code for a Streamable-HTTP header/body mismatch or a missing/malformed required routing header (-32020).
LATEST_LEGACY_VERSION
The latest legacy revision — what the initialize handshake advertises.
LATEST_MODERN_VERSION
The latest modern revision (advertised where the peer is known to be modern).
META_NS
The _meta key namespace carrying per-request protocol metadata in the modern era (io.modelcontextprotocol/{protocolVersion,clientInfo,clientCapabilities}).
PROTOCOL_VERSION
The version advertised in a legacy initialize handshake — necessarily a legacy revision, since a modern server has no handshake to advertise into. A modern peer is told the version per request instead (LATEST_MODERN_VERSION).
SUPPORTED_PROTOCOL_VERSIONS
Every MCP revision this library understands, newest first (dates sort chronologically). To support a newly-released revision, add its date at the front. The head is the latest overall; era-specific latests are LATEST_MODERN_VERSION / LATEST_LEGACY_VERSION.
TASKS_EXTENSION
The tasks extension identifier — advertised in capabilities.extensions to opt into task-augmented (async long-running) requests.
UNSUPPORTED_PROTOCOL_VERSION_CODE
The MCP-reserved JSON-RPC error code for an unsupported protocol version (-32022, modern negotiation).

Functions§

as_task_result
If a result value is a task handle (resultType: "task"), parse it — the polymorphic shape a task-augmented request returns instead of its normal result.
best_mutual_version
Given a modern server’s advertised supported versions (from a -32022 error), pick the best mutually-supported one to retry with — our newest that the server also supports. None ⇒ no common version (surface to the user).
era_of
The Era a protocol version belongs to. A well-formed date >= FIRST_MODERN_VERSION (including unknown future dates) is Era::Modern; anything else is Era::Legacy (the safe default — legacy is the older, wider-deployed behavior).
is_date_version
Does s have the MCP YYYY-MM-DD version shape? (Cheap structural check, not a calendar validation — enough to tell a date revision from a bogus string.)
is_modern_error_code
Is code a JSON-RPC error code only a modern server emits? Used for era detection: a -32022 (UnsupportedProtocolVersion) or -32020 (HeaderMismatch) in the body of a failed modern probe identifies a modern server, so the client retries rather than falling back to initialize. Generic codes (e.g. -32601 method-not- found) are ambiguous across eras and are NOT modern-defining.
is_supported_version
Is v a revision this library explicitly understands?
negotiate_version
Negotiate the session version from a legacy server’s initialize response. The server echoes our advertised version if it supports it, else returns another it supports; this decides whether that answer is usable.