Expand description
MCP wire types — the Model Context Protocol message surface. RFC 0004 (client), RFC 0005 (server).
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 (RFC 0004 §wire).
Structs§
- Call
Tool Params - Call
Tool Result - Result of
tools/call.is_error: trueis a tool-domain failure (fed to the model as an observation), distinct from a JSON-RPC transport error (RFC 0004 §isError). - Client
Capabilities - Capabilities a client declares. agentd declares none in v1 (no roots / sampling / elicitation / tasks) — RFC 0004 §declare-no-client-caps.
- Complete
Params completion/completeparams: what to complete (arefto a prompt or resource template) and the argument being typed. Kept asValue— therefshape varies by target and revision (forward-compat).- Complete
Result - Completion
- Discover
Result - Result of
server/discover(modern era): the server’s supported protocol versions, capabilities, and identity in a single call — the stateless replacement for the legacyinitializecapability exchange.resultTypeand the caching fields (ttlMs/cacheScope) are carried for forward-compat. - GetPrompt
Params prompts/getparams — the template name + its argument fills (all strings).- GetPrompt
Result prompts/getresult — the rendered messages.messages[]is kept asVec<Value>(each{role, content}) for forward-compat with content types.- Implementation
- Initialize
Params - Initialize
Result - List
Prompts Result - List
Resource Templates Result - List
Resources Result - List
Tools Result - Prompt
- A prompt template a server offers (RFC 0004 §prompts).
argumentsdescribe the template’s fill-ins. - Prompt
Argument - Read
Resource Params - Read
Resource Result - Resource
- Resource
Template - A resource template (a parameterized
uriTemplate, RFC 6570) a server offers viaresources/templates/list— distinct from a concreteResource. - Resource
Updated Params - Payload of
notifications/resources/updated— URI only (no diff). The reactive core re-reads on wake: notify-then-read (RFC 0004 §1.3, RFC 0008). - Resources
Capability - Server
Capabilities - What a server says it can do. We gate every call on these (RFC 0004
§capability-gating): no
tools/callunlesstoolsis present; noresources/subscribeunlessresources.subscribe == Some(true). - Subscribe
Params resources/subscribe/resources/unsubscribeparams (per-URI only — templates are NOT subscribable, RFC 0004 §item-vs-list).- 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 pollsmethod::TASKS_GETuntil a terminalstatus. - Tool
- Tools
Capability - Unsupported
Protocol Version - The payload of an
UNSUPPORTED_PROTOCOL_VERSION_CODEerror’sdata— the modern era’s version-negotiation signal (versioning §protocol-version-negotiation).
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-Versionheader (transports §protocol-version-header). - 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
initializehandshake advertises. - LATEST_
MODERN_ VERSION - The latest modern revision (advertised where the peer is known to be modern).
- META_NS
- The
_metakey namespace carrying per-request protocol metadata in the modern era (io.modelcontextprotocol/{protocolVersion,clientInfo,clientCapabilities}). - PROTOCOL_
VERSION - The version advertised in a legacy
initializehandshake. Kept as the latest legacy revision: the handshake path speaks legacy until the modern (stateless) dialect is wired into the client (a later phase). A modern client declares its 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.extensionsto 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
supportedversions (from a-32022error), 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
Eraa protocol version belongs to. A well-formed date>=FIRST_MODERN_VERSION(including unknown future dates) isEra::Modern; anything else isEra::Legacy(the safe default — legacy is the older, wider-deployed behavior). - is_
date_ version - Does
shave the MCPYYYY-MM-DDversion shape? (Cheap structural check, not a calendar validation — enough to tell a date revision from a bogus string.) - is_
modern_ error_ code - Is
codea JSON-RPC error code only a modern server emits? Used for era detection (versioning §backward-compatibility): 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 toinitialize. Generic codes (e.g.-32601method-not- found) are ambiguous across eras and are NOT modern-defining. - is_
supported_ version - Is
va revision this library explicitly understands? - negotiate_
version - Negotiate the session version from a legacy server’s
initializeresponse (lifecycle §version-negotiation). The server echoes our advertised version if it supports it, else returns another it supports.