Expand description
§Model Context Protocol (MCP) - Current Version
The official Rust implementation of the Model Context Protocol specification.
This crate provides a stable API that aliases the current version of the MCP specification, ensuring your code stays up-to-date with the latest protocol version while maintaining compatibility. Currently implements MCP 2025-06-18 specification.
§Installation
[dependencies]
turul-mcp-protocol = "0.2"
§Quick Start
use turul_mcp_protocol::prelude::*;
// Create tools, resources, prompts
let tool = Tool::new("calculator", ToolSchema::object());
let resource = Resource::new("file://data.json", "data");
let prompt = Prompt::new("code_review");
// Handle requests and responses
let request = InitializeRequest::new(
McpVersion::CURRENT,
ClientCapabilities::default(),
Implementation::new("my-client", "1.0.0")
);
§Protocol Types
This crate provides all core MCP types:
- Tools:
Tool
,CallToolRequest
,CallToolResult
- Resources:
Resource
,ReadResourceRequest
,ResourceContent
- Prompts:
Prompt
,GetPromptRequest
,PromptMessage
- Notifications:
ProgressNotification
,LoggingMessage
- Protocol:
InitializeRequest
,McpVersion
,ServerCapabilities
- Errors:
McpError
,JsonRpcError
, error codes
§Use Cases
- MCP Server Development: Use with
turul-mcp-server
- MCP Client Development: Use with
turul-mcp-client
- Protocol Parsing: Direct protocol message handling
- Type Definitions: Reference implementation for MCP types
§Related Crates
turul-mcp-server
- High-level server frameworkturul-mcp-client
- Client libraryturul-mcp-derive
- Procedural macros
§Version Mapping
This Crate | MCP Spec | Implementation Crate |
---|---|---|
0.2.x | 2025-06-18 | turul-mcp-protocol-2025-06-18 |
Currently aliases: turul-mcp-protocol-2025-06-18
Modules§
- completion
- MCP Completion Protocol Types
- content
- Content types for MCP 2025-06-18 specification
- elicitation
- MCP Elicitation Protocol Types
- initialize
- MCP Initialize Protocol Types
- json_
rpc - JSON-RPC 2.0 Implementation for MCP 2025-06-18
- logging
- MCP Logging Protocol Types
- meta
- _meta Field Support for MCP 2025-06-18
- notifications
- MCP Notifications Protocol Types
- param_
extraction - Parameter extraction utilities for MCP protocol
- ping
- MCP Ping Protocol Types
- prelude
- prompts
- MCP Prompts Protocol Types
- resources
- MCP Resources Protocol Types
- roots
- MCP Roots Protocol Types
- sampling
- MCP Sampling Protocol Types
- schema
- JSON Schema Support for MCP
- tools
- MCP Tools Protocol Types
- traits
- Traits for JSON-RPC types as per MCP specification (2025-06-18)
- version
- MCP Protocol Version Support
Macros§
- impl_
serde_ extractor - Macro to implement SerdeParamExtractor for any Params type that implements Deserialize
Structs§
- Annotations
- Generic annotations structure (matches TypeScript Annotations) Used across all MCP types that support client annotations
- Blob
Resource Contents - Binary resource contents (matches TypeScript BlobResourceContents exactly)
- Call
Tool Request - Complete tools/call request (matches TypeScript CallToolRequest interface)
- Call
Tool Result - Result for tools/call (per MCP spec)
- Cancelled
Notification - Method: “notifications/cancelled”
- Client
Capabilities - Capabilities that a client may support
- Elicit
Create Params - Parameters for elicitation/create request (per MCP spec)
- Elicit
Create Request - Complete elicitation/create request (matches TypeScript ElicitRequest interface)
- Elicit
Result - The client’s response to an elicitation request (per MCP spec)
- Elicitation
Builder - Builder for creating common elicitation patterns
- Elicitation
Schema - Restricted schema for elicitation (only primitive types, no nesting) - per MCP spec
- Empty
Params - Empty
Result - Empty result for successful operations (per MCP spec)
- GetPrompt
Request - Complete prompts/get request (matches TypeScript GetPromptRequest interface)
- GetPrompt
Result - Result for prompts/get (per MCP spec)
- Implementation
- Describes the name and version of an MCP implementation
- Initialize
Request - Parameters for initialize request
- Initialize
Result - Result payload for initialize (per MCP spec)
- Initialized
Notification - Method: “notifications/initialized”
- Json
RpcError - JSON-RPC 2.0 error object
- Json
RpcNotification - A JSON-RPC 2.0 notification (no response expected)
- Json
RpcRequest - A standard JSON-RPC 2.0 request
- Json
RpcResponse - A standard JSON-RPC 2.0 response
- List
Prompts Request - Complete prompts/list request (matches TypeScript ListPromptsRequest interface)
- List
Prompts Result - Result for prompts/list (per MCP spec)
- List
Resources Request - Complete resources/list request (matches TypeScript ListResourcesRequest interface)
- List
Resources Result - Result for resources/list (per MCP spec)
- List
Tools Request - Complete tools/list request (matches TypeScript ListToolsRequest interface)
- List
Tools Result - Result for tools/list (per MCP spec) - extends PaginatedResult
- Logging
Message Notification - Method: “notifications/message”
- Logging
Message Notification Params - Meta
- Structured _meta field for MCP 2025-06-18
- Meta
Cursor - Cursor for pagination support
- Notification
- Base notification structure following MCP TypeScript specification
- Notification
Params - Base notification parameters that can include _meta
- Paginated
Response - Helper for pagination responses
- Ping
Request - Request for ping (per MCP spec)
- Progress
Notification - Method: “notifications/progress”
- Progress
Notification Params - Progress
Response - Helper for progress responses
- Progress
Token - Progress token for tracking long-running operations
- Prompt
- A prompt descriptor (matches TypeScript Prompt interface exactly)
- Prompt
Argument - Argument definition for prompts (extends BaseMetadata per MCP spec)
- Prompt
List Changed Notification - Method: “notifications/prompts/listChanged” (per MCP spec)
- Prompt
Message - Message content for prompts (matches MCP PromptMessage interface exactly)
- Read
Resource Request - Complete resources/read request (matches TypeScript ReadResourceRequest interface)
- Read
Resource Result - Result for resources/read (per MCP spec)
- Request
Params - JSON-RPC
params
object with optional_meta
and method-specific arguments - Resource
- A resource descriptor (matches TypeScript Resource interface) Resource extends BaseMetadata, so it includes name and title fields
- Resource
List Changed Notification - Method: “notifications/resources/listChanged” (per MCP spec)
- Resource
Reference - Resource reference for resource links (matches TypeScript Resource interface)
- Resource
Subscription - Resource subscription parameters
- Resource
Updated Notification - Method: “notifications/resources/updated”
- Resource
Updated Notification Params - Result
With Meta - A generic result wrapper that combines data with optional _meta information
- Roots
List Changed Notification - Method: “notifications/roots/listChanged” (per MCP spec)
- Server
Capabilities - Capabilities that a server may support
- Subscribe
Request - Complete resources/subscribe request (per MCP spec)
- Text
Resource Contents - Text resource contents (matches TypeScript TextResourceContents exactly)
- Tool
- Tool definition
- Tool
List Changed Notification - Method: “notifications/tools/listChanged” (per MCP spec)
- Tool
Schema - JSON Schema definition for tool input/output (matches TypeScript spec exactly) Must be an object with type: “object”, properties, and required fields
- Unsubscribe
Request - Complete resources/unsubscribe request (per MCP spec)
Enums§
- Content
Block - Content block union type matching MCP 2025-06-18 specification exactly
- Elicit
Action - User action in response to elicitation
- Json
RpcMessage - Unified JSON-RPC message type
- Json
Schema - A JSON Schema definition
- Legacy
Request Params - Parameters for a JSON-RPC request
- 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 (per MCP spec).
- Request
Id - A uniquely identifying ID for a JSON-RPC request. Can be a string or a number, but never null.
- Resource
Content - Union type for resource contents (matches TypeScript union)
- Resource
Contents - Resource contents union type (matches TypeScript TextResourceContents | BlobResourceContents)
- Response
Result - Result data for a JSON-RPC response
- String
Format - String format constraints
Constants§
- CURRENT_
VERSION - The current MCP protocol version implemented by this crate
- MCP_
VERSION - The MCP protocol version implemented by this crate
Traits§
- HasData
- HasData
Param - HasMeta
- HasMeta
Param - HasProgress
Token Param - Json
RpcNotification Trait - Json
RpcRequest Trait - Json
RpcResponse Trait - Params
- RpcResult
- With
Meta - Trait for types that can include _meta fields
Type Aliases§
- McpResult
- Common result type for MCP operations
- Tool
Result - Tool result type - an alias for ContentBlock to maintain backward compatibility while ensuring MCP 2025-06-18 specification compliance