Skip to main content

Crate turul_mcp_protocol

Crate turul_mcp_protocol 

Source
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

§Features

FeatureMCP specCrate re-exported
protocol-2026-07-28 (default)2026-07-28turul-mcp-protocol-2026-07-28
protocol-2025-11-252025-11-25turul-mcp-protocol-2025-11-25

Select the opt-in lane with --no-default-features --features protocol-2025-11-25.

§Where next

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/discover types 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 params and result shapes that layer on top of generic JSON-RPC 2.0 wire envelopes from turul-rpc.
logging
Logging level types for the deprecated MCP Logging surface.
meta
_meta field support for MCP 2026-07-28.
notifications
Notification payload types for MCP 2026-07-28.
param_extraction
Parameter extraction utilities for MCP protocol.
ping
EmptyResult and EmptyParams — 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 HashMap wire 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 SerdeParamExtractor for a Params type that implements Deserialize.

Structs§

Annotations
Annotations for resources, prompts, and tools — audience, priority, last_modified.
BlobResourceContents
Binary resource contents (matches TypeScript BlobResourceContents exactly)
CacheableResult
Defines the cacheable-result mixin from the schema. Embed via #[serde(flatten)]:
CallToolRequest
Inner content of a tools/call request (method name and parameters).
CallToolResult
Result for tools/call — extends Result.
CancelledNotification
Notification for notifications/cancelled.
ClientCapabilities
Capabilities that a client may support.
DiscoverRequest
Client → server server/discover request.
DiscoverResult
Server → client server/discover result.
DiscoverResultResponse
Envelope JSONRPCResultResponse specialized to carry a DiscoverResult.
ElicitRequest
The elicitation/create request.
ElicitRequestFormParams
Form-mode elicitation params.
ElicitResult
The client’s response to an elicitation request.
ElicitationBuilder
Constructors for common single-field form-mode elicitation requests.
ElicitationSchema
Restricted schema for elicitation: an object whose properties are primitive schemas, with no nesting.
EmptyParams
Empty params for requests whose params carry no fields.
EmptyResult
Result shape with no fields beyond resultType and _meta.
GetPromptRequest
Complete prompts/get request.
GetPromptResult
Result for prompts/get — extends Result.
Icon
Icon for tools, resources, prompts, and implementations.
Implementation
Describes the name and version of an MCP implementation.
InputRequiredResult
A Result discriminated as "input_required" — server signals that additional input must be gathered and the original request re-issued.
InputResponseRequestParams
Mixin shape that may appear on the params of any client-initiated request, allowing the client to attach prior input responses + echoed request state.
JsonRpcError
JSON-RPC 2.0 error types and standard error codes. JSON-RPC Error response
JsonRpcErrorObject
JSON-RPC Error object
JsonRpcNotification
JSON-RPC notification message structure for fire-and-forget communications. A JSON-RPC notification (request without an id)
JsonRpcRequest
JSON-RPC request structure with method and parameters. A JSON-RPC request
JsonRpcSuccessResponse
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}.
ListPromptsRequest
Complete prompts/list request — ListPromptsRequest extends PaginatedRequest { method: "prompts/list" }.
ListPromptsResult
Result for prompts/list.
ListResourcesRequest
Complete resources/list request — ListResourcesRequest extends PaginatedRequest { method: "resources/list" }.
ListResourcesResult
Result for resources/list — extends PaginatedResult and CacheableResult.
ListToolsRequest
Complete tools/list request — ListToolsRequest extends PaginatedRequest { method: "tools/list" }.
ListToolsResult
Result for tools/list — extends PaginatedResult and CacheableResult.
LoggingMessageNotificationDeprecated
Notification for notifications/message.
LoggingMessageNotificationParamsDeprecated
Deprecated per SEP-2577 — see LoggingMessageNotification.
MetaCursor
Opaque pagination cursor.
Notification
Base notification structure: a method and optional params.
NotificationParams
Base notification parameters that can include _meta.
PaginatedRequestParams
params shape for any request that extends PaginatedRequest — PaginatedRequestParams extends RequestParams { cursor?: Cursor }.
ProgressNotification
Notification for notifications/progress.
ProgressNotificationParams
Parameters of a notifications/progress notification.
Prompt
A prompt or prompt template that the server offers (Prompt in the schema).
PromptArgument
Argument definition for prompts (extends BaseMetadata in the schema).
PromptListChangedNotification
MCP notification payload for “notifications/prompts/list_changed”.
PromptMessage
A message returned by a prompt: a role and a content block.
ReadResourceRequest
Complete resources/read request (matches TypeScript ReadResourceRequest interface)
ReadResourceResult
Result for resources/read — ReadResourceResult extends CacheableResult. Caller may also return InputRequiredResult via the ReadResourceResultResponse.result union.
RequestMetaObject
Strictly-typed request _meta carrying the per-request capability negotiation. See also MetaObject for key naming rules and reserved prefixes, and General fields: _meta for the full spec section.
RequestParams
JSON-RPC params object for any request — _meta is required per 2026-07-28 stateless core (carries protocolVersion, clientInfo, clientCapabilities for per-request negotiation).
Resource
A resource descriptor (matches TypeScript Resource interface) Resource extends BaseMetadata, so it includes name and title fields
ResourceListChangedNotification
MCP notification payload for “notifications/resources/list_changed”.
ResourceUpdatedNotification
Notification for notifications/resources/updated.
ResourceUpdatedNotificationParams
Parameters of a notifications/resources/updated notification.
ServerCapabilities
Capabilities that a server may support.
SubscriptionFilter
Opt-in filter for which notification types the client wants on this stream.
SubscriptionsAcknowledgedNotification
notifications/subscriptions/acknowledged — sent by the server as the first message on a subscriptions/listen stream.
SubscriptionsAcknowledgedNotificationParams
Params for the acknowledgement notification.
SubscriptionsListenRequest
subscriptions/listen request.
SubscriptionsListenRequestParams
Params for subscriptions/listen — SubscriptionsListenRequestParams extends RequestParams, so _meta is the typed crate::meta::RequestMetaObject carrying the per-request capability negotiation (protocol version, client info, client capabilities). Required by schema.
SubscriptionsListenResult
The response to a subscriptions/listen request, 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.subscriptionId is the only substantive field.
SubscriptionsListenResultMetaObject
_meta for SubscriptionsListenResult. Schema: SubscriptionsListenResultMetaObject extends ResultMetaObject with a REQUIRED io.modelcontextprotocol/subscriptionId: RequestId — the id of the subscriptions/listen request this result closes (equals the result’s own id in the JSON-RPC envelope). Extending crate::meta::ResultMetaObject means it also carries the optional io.modelcontextprotocol/serverInfo.
SubscriptionsListenResultResponse
JSON-RPC envelope carrying a SubscriptionsListenResult, sent when the server tears the subscription down gracefully.
TextResourceContents
Text resource contents (matches TypeScript TextResourceContents exactly)
Tool
Tool definition
ToolListChangedNotification
MCP notification payload for “notifications/tools/list_changed”.
ToolOutputSchema
JSON Schema for Tool.outputSchema per 2026-07-28:
ToolSchema
JSON Schema for Tool.inputSchema per 2026-07-28:

Enums§

CacheScope
Cache-sharing scope, analogous to HTTP Cache-Control: public / private.
ContentBlock
Content block union — text | image | audio | resource_link | resource | tool_use | tool_result.
ElicitAction
User action in response to elicitation.
IconTheme
Theme preference for an icon (light or dark mode).
InputRequest
Server → client request emitted as part of an InputRequiredResult.
InputResponse
Client → server response for an InputRequest, keyed by the server-assigned identifier from the corresponding InputRequests entry.
JsonRpcErrorCode
JSON-RPC 2.0 error types and standard error codes. JSON-RPC error codes
JsonRpcMessage
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.
JsonRpcParams
JSON-RPC request structure with method and parameters. Parameters for a JSON-RPC request
JsonRpcResponse
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.
JsonRpcVersion
Core JSON-RPC types for version and request identification. JSON-RPC version
JsonRpcWireMessage
Bidirectional wire-message union (request | notification | response) — the schema’s JSONRPCMessage. Superset of JsonRpcMessage; for clients and peers that read responses. Parse with parse_json_rpc_wire_message. Any single JSON-RPC 2.0 message read off the wire, in either direction.
JsonSchema
A JSON Schema definition
McpError
MCP-specific errors.
McpVersion
Supported MCP protocol versions
PrimitiveSchemaDefinition
Restricted schema definitions that only allow primitive types without nested objects or arrays.
ProgressToken
Progress token for tracking long-running operations.
ProgressTokenValue
Progress token for tracking long-running operations.
RequestId
Core JSON-RPC types for version and request identification. A uniquely identifying ID for a JSON-RPC request: a String, a Number, or Null.
ResourceContent
Union type for resource contents (matches TypeScript union)
ResourceContents
Resource contents union type (matches TypeScript TextResourceContents | BlobResourceContents)
ResponseResult
JSON-RPC response types: the §5 Response object union (JsonRpcResponse) and the success-only struct (JsonRpcSuccessResponse). Result data for a JSON-RPC response
ResultType
Discriminator for Result-shaped responses.
StringFormat
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 for tools/call (params.name), resources/read (params.uri), and prompts/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_VERSION for sites that need a &str literal 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_VERSION of the upstream schema.ts.
META_KEY_BAGGAGE
_meta key carrying the W3C Trace Context baggage header value per SEP-414. Conventional, not schema-declared.
META_KEY_CLIENT_CAPABILITIES
Schema-declared _meta key for the request client capabilities.
META_KEY_CLIENT_INFO
Schema-declared _meta key for the request client info.
META_KEY_LOG_LEVELDeprecated
Schema-declared _meta key for the per-request log level opt-in. Declared as the named field io.modelcontextprotocol/logLevel on RequestMetaObject. The constant is provided for use when callers index into a generic MetaObject and want the spelling pinned.
META_KEY_PROTOCOL_VERSION
Schema-declared _meta key for the request protocol version.
META_KEY_SUBSCRIPTION_ID
_meta key carrying the subscription id used by the server to tag notifications delivered on a subscriptions/listen stream. Schema-declared: NotificationMetaObject.io.modelcontextprotocol/subscriptionId (optional; value = the RequestId of the subscriptions/listen request that opened the stream) and SubscriptionsListenResultMetaObject.io.modelcontextprotocol/subscriptionId (required, on the result that closes the stream).
META_KEY_TRACEPARENT
_meta key carrying the W3C Trace Context traceparent header value per SEP-414. Conventional, not schema-declared.
META_KEY_TRACESTATE
_meta key carrying the W3C Trace Context tracestate header 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’s inputSchema) that designates a parameter for header mirroring. This is a schema annotation key, NOT a wire header name — the wire header it produces is HTTP_HEADER_PARAM_PREFIX{name}.

Traits§

HasData
Escape hatch — flatten a typed result into a JSON-object map. Not part of the RpcResult supertrait bound; consumers that need this should prefer serde_json::to_value. Retained for the rare framework site that needs an untyped view.
HasDataParam
Exposes a free-form data map carried in a params object.
HasErrorObject
Exposes the error field on a JSONRPCErrorResponse. The schema’s Error interface maps to turul_rpc::error::JsonRpcErrorObject ({ code, message, data? }).
HasMeta
Exposes Result._meta?: ResultMetaObject — the result-side carrier, which adds io.modelcontextprotocol/serverInfo on top of MetaObject. Borrowed, typed — no JSON round-trip.
HasMetaParam
Exposes the optional _meta map carried in a params object.
HasNotificationMeta
Exposes Notification.params._meta?. Separate from HasMeta because the schema gives the two sides different carriers: results extend MetaObject with serverInfo, notifications with subscriptionId. One trait returning one type cannot model both.
HasOptionalRequestId
Optional request id — used by JSONRPCErrorResponse where the server may omit id if it couldn’t parse the original request’s id.
HasProgressTokenParam
Exposes the optional progressToken a requester attached to ask for progress notifications.
HasRequestId
Required request id — present on requests and successful responses. Schema: RequestId = string | number; we expose as borrowed Value for permissive accept (the typed narrowing is a separate follow-up).
HasResultType
Exposes the resultType discriminator per the schema’s Result.resultType: ResultType field. Every spec-compliant result MUST carry this; per the schema doc-comment, absent values default to Complete for backward compatibility with pre-2026-07-28 servers.
JsonRpcErrorResponseTrait
JSONRPCErrorResponse per schema — error response with optional id.
JsonRpcNotificationTrait
A complete JSON-RPC notification: version, method and params.
JsonRpcRequestTrait
A complete JSON-RPC request: version, request id, method and params.
JsonRpcResultResponseTrait
JSONRPCResultResponse per schema — successful response carrying result.
Params
Marker for a typed params object of a request or notification.
RpcResult
Schema’s Result interface: { _meta?: ResultMetaObject, resultType: ResultType, [key: string]: unknown }. Bound to HasMeta + HasResultType — arbitrary [key: string]: unknown extra 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 of JsonRpcMessage; for clients and peers that read responses. Parse with parse_json_rpc_wire_message. Parse a JSON string into a JsonRpcWireMessage.

Type Aliases§

InputRequests
Map of server-assigned identifiers → server-initiated requests.
InputResponses
Map of identifiers → client responses, keyed identically to the originating InputRequests.
McpResult
Common result type for MCP operations.
MetaObject
Loose _meta carrier — Record<string, unknown> in the schema.
ResourceReference
A resource link’s resource: the schema’s ResourceLink extends Resource, so this names crate::resources::Resource rather than defining a second struct.
ToolResult
Alias for crate::content::ContentBlock kept for callers that reference the type by its older name.