Expand description
MCP wire types for building servers and clients; selects one versioned protocol crate.
Most users want turul-mcp-server, which
re-exports what it needs from here. Depend on this crate directly only to parse
or produce MCP messages without the server framework.
By default it re-exports turul-mcp-protocol-2026-07-28 (MCP 2026-07-28). The
2025-11-25 spec is an opt-in lane selected by a Cargo feature; the two are
mutually exclusive and exactly one must be active.
§Examples
[dependencies]
turul-mcp-protocol = "0.4"use turul_mcp_protocol::prelude::*;
let tool = Tool::new("calculator", ToolSchema::object());
let resource = Resource::new("file://data.json", "data");
let prompt = Prompt::new("code_review");§Types
- Tools:
Tool,CallToolRequest,CallToolResult - Resources:
Resource,ReadResourceRequest,ResourceContent - Prompts:
Prompt,GetPromptRequest,PromptMessage - Notifications:
ProgressNotification - Negotiation and errors:
McpVersion,ServerCapabilities,McpError
§Features
| Feature | MCP spec | Crate re-exported |
|---|---|---|
protocol-2026-07-28 (default) | 2026-07-28 | turul-mcp-protocol-2026-07-28 |
protocol-2025-11-25 | 2025-11-25 | turul-mcp-protocol-2025-11-25 |
Select the opt-in lane with --no-default-features --features protocol-2025-11-25.
§Where next
turul-mcp-server: build a serverturul-mcp-client: build a clientturul-mcp-protocol-2026-07-28: full type reference
Modules§
- caching
- Cache-control hints for results (SEP-2549).
- completion
- MCP Completion Protocol Types
- content
- Content block types for MCP 2026-07-28.
- discover
server/discovertypes for MCP 2026-07-28.- elicitation
- MCP Elicitation Protocol Types
- headers
- HTTP header name constants for MCP Streamable HTTP transport (SEP-2243).
- icons
- MCP Icon Types
- initialize
- Shared capability and implementation identity types for MCP 2026-07-28.
- input_
required - Multi-round-trip input requests for MCP 2026-07-28 (SEP-2322).
- json_
rpc - MCP-specific
paramsandresultshapes that layer on top of generic JSON-RPC 2.0 wire envelopes fromturul-rpc. - logging
- Logging level types for the deprecated MCP Logging surface.
- meta
_metafield support for MCP 2026-07-28.- notifications
- Notification payload types for MCP 2026-07-28.
- param_
extraction - Parameter extraction utilities for MCP protocol.
- ping
EmptyResultandEmptyParams— utility shapes for empty payloads.- prelude
- Common imports for the selected spec lane:
use turul_mcp_protocol::prelude::*;. - prompts
- MCP Prompts Protocol Types
- resources
- MCP Resources Protocol Types
- result_
type - Result discrimination for MCP 2026-07-28.
- roots
- MCP Roots Protocol Types
- sampling
- MCP Sampling Protocol Types
- schema
- JSON Schema Support for MCP
- serde_
maps - Serialize
HashMapwire fields in sorted key order. - subscriptions
- Unified subscription stream for MCP 2026-07-28.
- tools
- MCP Tools Protocol Types
- traits
- Traits for JSON-RPC types as per MCP specification (2026-07-28).
- version
- MCP Protocol Version Support
Macros§
- impl_
serde_ extractor - Implements
SerdeParamExtractorfor aParamstype that implementsDeserialize.
Structs§
- Annotations
- Annotations for resources, prompts, and tools —
audience,priority,last_modified. - Blob
Resource Contents - Binary resource contents (matches TypeScript BlobResourceContents exactly)
- Cacheable
Result - Defines the cacheable-result mixin from the schema. Embed via
#[serde(flatten)]: - Call
Tool Request - Inner content of a tools/call request (method name and parameters).
- Call
Tool Result - Result for tools/call — extends
Result. - Cancelled
Notification - Notification for
notifications/cancelled. - Client
Capabilities - Capabilities that a client may support.
- Discover
Request - Client → server
server/discoverrequest. - Discover
Result - Server → client
server/discoverresult. - Discover
Result Response - Envelope
JSONRPCResultResponsespecialized to carry aDiscoverResult. - Elicit
Request - The
elicitation/createrequest. - Elicit
Request Form Params - Form-mode elicitation params.
- Elicit
Result - The client’s response to an elicitation request.
- Elicitation
Builder - Constructors for common single-field form-mode elicitation requests.
- Elicitation
Schema - Restricted schema for elicitation: an object whose properties are primitive schemas, with no nesting.
- Empty
Params - Empty params for requests whose params carry no fields.
- Empty
Result - Result shape with no fields beyond
resultTypeand_meta. - GetPrompt
Request - Complete
prompts/getrequest. - GetPrompt
Result - Result for
prompts/get— extendsResult. - Icon
- Icon for tools, resources, prompts, and implementations.
- Implementation
- Describes the name and version of an MCP implementation.
- Input
Required Result - A
Resultdiscriminated as"input_required"— server signals that additional input must be gathered and the original request re-issued. - Input
Response Request Params - Mixin shape that may appear on the
paramsof any client-initiated request, allowing the client to attach prior input responses + echoed request state. - Json
RpcError - JSON-RPC 2.0 error types and standard error codes. JSON-RPC Error response
- Json
RpcError Object - JSON-RPC Error object
- Json
RpcNotification - JSON-RPC notification message structure for fire-and-forget communications. A JSON-RPC notification (request without an id)
- Json
RpcRequest - JSON-RPC request structure with method and parameters. A JSON-RPC request
- Json
RpcSuccess Response - JSON-RPC response types: the §5 Response object union (
JsonRpcResponse) and the success-only struct (JsonRpcSuccessResponse). A successful JSON-RPC response object (JSON-RPC 2.0 §5, success case):{jsonrpc, id, result}. - List
Prompts Request - Complete
prompts/listrequest —ListPromptsRequest extends PaginatedRequest { method: "prompts/list" }. - List
Prompts Result - Result for
prompts/list. - List
Resources Request - Complete resources/list request —
ListResourcesRequest extends PaginatedRequest { method: "resources/list" }. - List
Resources Result - Result for resources/list — extends
PaginatedResultandCacheableResult. - List
Tools Request - Complete tools/list request —
ListToolsRequest extends PaginatedRequest { method: "tools/list" }. - List
Tools Result - Result for tools/list — extends
PaginatedResultandCacheableResult. - Logging
Message Notification Deprecated - Notification for
notifications/message. - Logging
Message Notification Params Deprecated - Deprecated per SEP-2577 — see
LoggingMessageNotification. - Meta
Cursor - Opaque pagination cursor.
- Notification
- Base notification structure: a
methodand optionalparams. - Notification
Params - Base notification parameters that can include
_meta. - Paginated
Request Params paramsshape for any request that extendsPaginatedRequest—PaginatedRequestParams extends RequestParams { cursor?: Cursor }.- Progress
Notification - Notification for
notifications/progress. - Progress
Notification Params - Parameters of a
notifications/progressnotification. - Prompt
- A prompt or prompt template that the server offers (
Promptin the schema). - Prompt
Argument - Argument definition for prompts (extends
BaseMetadatain the schema). - Prompt
List Changed Notification - MCP notification payload for “notifications/prompts/list_changed”.
- Prompt
Message - A message returned by a prompt: a role and a content block.
- Read
Resource Request - Complete resources/read request (matches TypeScript ReadResourceRequest interface)
- Read
Resource Result - Result for
resources/read—ReadResourceResult extends CacheableResult. Caller may also returnInputRequiredResultvia theReadResourceResultResponse.resultunion. - Request
Meta Object - Strictly-typed request
_metacarrying the per-request capability negotiation. See alsoMetaObjectfor key naming rules and reserved prefixes, and General fields: _meta for the full spec section. - Request
Params - JSON-RPC
paramsobject for any request —_metais required per 2026-07-28 stateless core (carriesprotocolVersion,clientInfo,clientCapabilitiesfor per-request negotiation). - Resource
- A resource descriptor (matches TypeScript Resource interface) Resource extends BaseMetadata, so it includes name and title fields
- Resource
List Changed Notification - MCP notification payload for “notifications/resources/list_changed”.
- Resource
Updated Notification - Notification for
notifications/resources/updated. - Resource
Updated Notification Params - Parameters of a
notifications/resources/updatednotification. - Server
Capabilities - Capabilities that a server may support.
- Subscription
Filter - Opt-in filter for which notification types the client wants on this stream.
- Subscriptions
Acknowledged Notification notifications/subscriptions/acknowledged— sent by the server as the first message on asubscriptions/listenstream.- Subscriptions
Acknowledged Notification Params - Params for the acknowledgement notification.
- Subscriptions
Listen Request subscriptions/listenrequest.- Subscriptions
Listen Request Params - Params for
subscriptions/listen—SubscriptionsListenRequestParams extends RequestParams, so_metais the typedcrate::meta::RequestMetaObjectcarrying the per-request capability negotiation (protocol version, client info, client capabilities). Required by schema. - Subscriptions
Listen Result - The response to a
subscriptions/listenrequest, signalling that the subscription ended gracefully (e.g. server shutdown). The listen stream is long-lived, so this result is sent only when the server tears the subscription down deliberately — an abrupt transport close carries no response. The result body is otherwise empty;_meta.subscriptionIdis the only substantive field. - Subscriptions
Listen Result Meta Object _metaforSubscriptionsListenResult. Schema:SubscriptionsListenResultMetaObject extends ResultMetaObjectwith a REQUIREDio.modelcontextprotocol/subscriptionId: RequestId— the id of thesubscriptions/listenrequest this result closes (equals the result’s ownidin the JSON-RPC envelope). Extendingcrate::meta::ResultMetaObjectmeans it also carries the optionalio.modelcontextprotocol/serverInfo.- Subscriptions
Listen Result Response - JSON-RPC envelope carrying a
SubscriptionsListenResult, sent when the server tears the subscription down gracefully. - Text
Resource Contents - Text resource contents (matches TypeScript TextResourceContents exactly)
- Tool
- Tool definition
- Tool
List Changed Notification - MCP notification payload for “notifications/tools/list_changed”.
- Tool
Output Schema - JSON Schema for
Tool.outputSchemaper 2026-07-28: - Tool
Schema - JSON Schema for
Tool.inputSchemaper 2026-07-28:
Enums§
- Cache
Scope - Cache-sharing scope, analogous to HTTP
Cache-Control: public/private. - Content
Block - Content block union —
text | image | audio | resource_link | resource | tool_use | tool_result. - Elicit
Action - User action in response to elicitation.
- Icon
Theme - Theme preference for an icon (light or dark mode).
- Input
Request - Server → client request emitted as part of an
InputRequiredResult. - Input
Response - Client → server response for an
InputRequest, keyed by the server-assigned identifier from the correspondingInputRequestsentry. - Json
RpcError Code - JSON-RPC 2.0 error types and standard error codes. JSON-RPC error codes
- Json
RpcMessage - Incoming message union (request | notification) produced by the parser.
Enum representing the inbound JSON-RPC messages a server parses:
a request or a notification. Responses are produced, not parsed here,
and live in
turul_rpc_core::response::JsonRpcResponse. - Json
RpcParams - JSON-RPC request structure with method and parameters. Parameters for a JSON-RPC request
- Json
RpcResponse - JSON-RPC response types: the §5 Response object union (
JsonRpcResponse) and the success-only struct (JsonRpcSuccessResponse). A JSON-RPC Response object (JSON-RPC 2.0 §5): success XOR error. - Json
RpcVersion - Core JSON-RPC types for version and request identification. JSON-RPC version
- Json
RpcWire Message - Bidirectional wire-message union (request | notification | response) — the
schema’s
JSONRPCMessage. Superset ofJsonRpcMessage; for clients and peers that read responses. Parse withparse_json_rpc_wire_message. Any single JSON-RPC 2.0 message read off the wire, in either direction. - Json
Schema - A JSON Schema definition
- McpError
- MCP-specific errors.
- McpVersion
- Supported MCP protocol versions
- Primitive
Schema Definition - Restricted schema definitions that only allow primitive types without nested objects or arrays.
- Progress
Token - Progress token for tracking long-running operations.
- Progress
Token Value - Progress token for tracking long-running operations.
- Request
Id - Core JSON-RPC types for version and request identification. A uniquely identifying ID for a JSON-RPC request: a String, a Number, or Null.
- Resource
Content - Union type for resource contents (matches TypeScript union)
- Resource
Contents - Resource contents union type (matches TypeScript TextResourceContents | BlobResourceContents)
- Response
Result - JSON-RPC response types: the §5 Response object union (
JsonRpcResponse) and the success-only struct (JsonRpcSuccessResponse). Result data for a JSON-RPC response - Result
Type - Discriminator for
Result-shaped responses. - String
Format - String format constraints.
Constants§
- CURRENT_
VERSION - The MCP protocol version string of the active spec lane.
- ERROR_
CODE_ HEADER_ MISMATCH - JSON-RPC error code for header-validation failures.
- HTTP_
HEADER_ METHOD Mcp-Method— REQUIRED per SEP-2243 on all requests and notifications.- HTTP_
HEADER_ NAME Mcp-Name— REQUIRED per SEP-2243 fortools/call(params.name),resources/read(params.uri), andprompts/get(params.name).- HTTP_
HEADER_ PARAM_ PREFIX Mcp-Param-{name}— header name prefix for custom headers mirrored from tool parameters (SEP-2243 §Custom Headers from Tool Parameters).- HTTP_
HEADER_ PROTOCOL_ VERSION MCP-Protocol-Version— REQUIRED on every Streamable HTTP POST.- JSONRPC_
VERSION - JSON-RPC version constant. Mirrors
turul_rpc::JSONRPC_VERSIONfor sites that need a&strliteral rather than the typed enum. - MCP_
PARAM_ BASE64_ PREFIX - Sentinel prefix marking a Base64-encoded
Mcp-Param-*value (=?base64?{Base64EncodedValue}?=, case-sensitive, lowercase). - MCP_
PARAM_ BASE64_ SUFFIX - Sentinel suffix closing a Base64-encoded
Mcp-Param-*value. - MCP_
VERSION - The MCP protocol version string this crate currently targets, exactly as it appears
on the wire in
LATEST_PROTOCOL_VERSIONof the upstreamschema.ts. - META_
KEY_ BAGGAGE _metakey carrying the W3C Trace Contextbaggageheader value per SEP-414. Conventional, not schema-declared.- META_
KEY_ CLIENT_ CAPABILITIES - Schema-declared
_metakey for the request client capabilities. - META_
KEY_ CLIENT_ INFO - Schema-declared
_metakey for the request client info. - META_
KEY_ LOG_ LEVEL Deprecated - Schema-declared
_metakey for the per-request log level opt-in. Declared as the named fieldio.modelcontextprotocol/logLevelonRequestMetaObject. The constant is provided for use when callers index into a genericMetaObjectand want the spelling pinned. - META_
KEY_ PROTOCOL_ VERSION - Schema-declared
_metakey for the request protocol version. - META_
KEY_ SUBSCRIPTION_ ID _metakey carrying the subscription id used by the server to tag notifications delivered on asubscriptions/listenstream. Schema-declared:NotificationMetaObject.io.modelcontextprotocol/subscriptionId(optional; value = theRequestIdof thesubscriptions/listenrequest that opened the stream) andSubscriptionsListenResultMetaObject.io.modelcontextprotocol/subscriptionId(required, on the result that closes the stream).- META_
KEY_ TRACEPARENT _metakey carrying the W3C Trace Contexttraceparentheader value per SEP-414. Conventional, not schema-declared.- META_
KEY_ TRACESTATE _metakey carrying the W3C Trace Contexttracestateheader value per SEP-414. Conventional, not schema-declared.- SERVER_
DISCOVER_ METHOD - Wire method string for the discover RPC.
- SUBSCRIPTIONS_
ACKNOWLEDGED_ METHOD - Wire method string for the acknowledgement notification.
- SUBSCRIPTIONS_
LISTEN_ METHOD - Wire method string for the subscription RPC.
- X_
MCP_ HEADER_ SCHEMA_ KEY x-mcp-header— the JSON Schema extension property (inside a tool’sinputSchema) that designates a parameter for header mirroring. This is a schema annotation key, NOT a wire header name — the wire header it produces isHTTP_HEADER_PARAM_PREFIX{name}.
Traits§
- HasData
- Escape hatch — flatten a typed result into a JSON-object map. Not part of
the
RpcResultsupertrait bound; consumers that need this should preferserde_json::to_value. Retained for the rare framework site that needs an untyped view. - HasData
Param - Exposes a free-form
datamap carried in a params object. - HasError
Object - Exposes the
errorfield on aJSONRPCErrorResponse. The schema’sErrorinterface maps toturul_rpc::error::JsonRpcErrorObject({ code, message, data? }). - HasMeta
- Exposes
Result._meta?: ResultMetaObject— the result-side carrier, which addsio.modelcontextprotocol/serverInfoon top ofMetaObject. Borrowed, typed — no JSON round-trip. - HasMeta
Param - Exposes the optional
_metamap carried in a params object. - HasNotification
Meta - Exposes
Notification.params._meta?. Separate fromHasMetabecause the schema gives the two sides different carriers: results extendMetaObjectwithserverInfo, notifications withsubscriptionId. One trait returning one type cannot model both. - HasOptional
Request Id - Optional request id — used by
JSONRPCErrorResponsewhere the server may omitidif it couldn’t parse the original request’s id. - HasProgress
Token Param - Exposes the optional
progressTokena requester attached to ask for progress notifications. - HasRequest
Id - Required request id — present on requests and successful responses.
Schema:
RequestId = string | number; we expose as borrowedValuefor permissive accept (the typed narrowing is a separate follow-up). - HasResult
Type - Exposes the
resultTypediscriminator per the schema’sResult.resultType: ResultTypefield. Every spec-compliant result MUST carry this; per the schema doc-comment, absent values default toCompletefor backward compatibility with pre-2026-07-28 servers. - Json
RpcError Response Trait JSONRPCErrorResponseper schema — error response with optionalid.- Json
RpcNotification Trait - A complete JSON-RPC notification: version, method and params.
- Json
RpcRequest Trait - A complete JSON-RPC request: version, request id, method and params.
- Json
RpcResult Response Trait JSONRPCResultResponseper schema — successful response carryingresult.- Params
- Marker for a typed
paramsobject of a request or notification. - RpcResult
- Schema’s
Resultinterface:{ _meta?: ResultMetaObject, resultType: ResultType, [key: string]: unknown }. Bound toHasMeta+HasResultType— arbitrary[key: string]: unknownextra keys are domain-specific and expressed on the concrete struct itself.
Functions§
- parse_
json_ rpc_ wire_ message - Bidirectional wire-message union (request | notification | response) — the
schema’s
JSONRPCMessage. Superset ofJsonRpcMessage; for clients and peers that read responses. Parse withparse_json_rpc_wire_message. Parse a JSON string into aJsonRpcWireMessage.
Type Aliases§
- Input
Requests - Map of server-assigned identifiers → server-initiated requests.
- Input
Responses - Map of identifiers → client responses, keyed identically to the originating
InputRequests. - McpResult
- Common result type for MCP operations.
- Meta
Object - Loose
_metacarrier —Record<string, unknown>in the schema. - Resource
Reference - A resource link’s resource: the schema’s
ResourceLinkextendsResource, so this namescrate::resources::Resourcerather than defining a second struct. - Tool
Result - Alias for
crate::content::ContentBlockkept for callers that reference the type by its older name.