Crate mcpkit

Crate mcpkit 

Source
Expand description

§MCP - Model Context Protocol SDK for Rust

A Rust SDK for the Model Context Protocol that simplifies server development through a unified #[mcp_server] macro.

§Features

  • Reduced boilerplate via unified #[mcp_server] macro
  • Type-safe state machines via typestate pattern for connection lifecycle
  • Rich error handling with context chains and miette diagnostics
  • Full MCP 2025-11-25 protocol coverage including Tasks
  • Runtime-agnostic async support

§Quick Start

use mcpkit::prelude::*;
use mcpkit::transport::stdio::StdioTransport;

struct Calculator;

#[mcp_server(name = "calculator", version = "1.0.0")]
impl Calculator {
    #[tool(description = "Add two numbers")]
    async fn add(&self, a: f64, b: f64) -> ToolOutput {
        ToolOutput::text((a + b).to_string())
    }

    #[tool(description = "Multiply two numbers")]
    async fn multiply(&self, a: f64, b: f64) -> ToolOutput {
        ToolOutput::text((a * b).to_string())
    }
}

#[tokio::main]
async fn main() -> Result<(), McpError> {
    let transport = StdioTransport::new();
    let server = ServerBuilder::new(Calculator)
        .with_tools(Calculator)
        .build();
    server.serve(transport).await
}

§Comparison with rmcp

AspectrmcpThis SDK
Macros4 interdependent1 unified #[mcp_server]
BoilerplateManual router wiringZero initialization
ParametersParameters<T> wrapperDirect from signature
Error types3 nested layers1 unified McpError
TasksNot implementedFull support

§Crate Organization

Modules§

auth
OAuth 2.1 Authorization for MCP.
capability
Capability negotiation types.
client
Client module re-exports.
debug
Debug and tracing utilities for MCP protocol development.
error
Error types and handling.
extension
Protocol extension infrastructure.
prelude
Prelude module for convenient imports.
protocol
JSON-RPC 2.0 protocol types for the Model Context Protocol.
protocol_version
Protocol version types and negotiation.
schema
JSON Schema utilities for MCP type validation.
server
Server module re-exports.
state
Typestate pattern for connection lifecycle management.
transport
Transport module re-exports.
types
MCP type definitions.

Structs§

CancellationToken
A cancellation token for tracking request cancellation.
CancelledFuture
A future that completes when cancellation is requested.
ClientCapabilities
Client capabilities advertised during initialization.
ClientInfo
Client information provided during initialization.
Closing
Marker type for closing state (shutdown in progress).
Connected
Marker type for connected state (transport established).
Connection
A connection in a specific state.
Context
Request context passed to handler methods.
ContextData
Owned data for creating contexts.
Disconnected
Marker type for disconnected state.
InitializeRequest
Initialize request parameters.
InitializeResult
Initialize response.
Initializing
Marker type for initializing state (handshake in progress).
JsonRpcError
A JSON-RPC error response object.
NoOpPeer
A no-op peer implementation for testing.
Notification
A JSON-RPC 2.0 notification message.
Ready
Marker type for ready state (fully operational).
Request
A JSON-RPC 2.0 request message.
Response
A JSON-RPC 2.0 response message.
Server
A configured MCP server ready to serve requests.
ServerBuilder
Builder for constructing MCP servers with specific capabilities.
ServerCapabilities
Server capabilities advertised during initialization.
ServerInfo
Server information provided during initialization.
TransportMetadata
Metadata about a transport connection.

Enums§

LogLevel
Log levels for MCP logging.
McpError
The primary error type for the MCP SDK.
Message
A JSON-RPC 2.0 message (request, response, or notification).
ProgressToken
A progress token for tracking long-running operations.
ProtocolVersion
MCP protocol versions in chronological order.
RequestId
A JSON-RPC request ID.
VersionNegotiationResult
Protocol version negotiation result.

Constants§

PROTOCOL_VERSION
The latest protocol version supported by this implementation.
SUPPORTED_PROTOCOL_VERSIONS
All protocol versions supported by this implementation.

Traits§

CompletionHandler
Handler for completion suggestions.
ElicitationHandler
Handler for elicitation requests (structured user input).
LoggingHandler
Handler for logging operations.
McpResultExt
Extension trait for adding context to Result types.
Peer
Trait for sending messages to the peer (client or server).
PromptHandler
Handler for prompt-related operations.
ResourceHandler
Handler for resource-related operations.
SamplingHandler
Handler for sampling requests (server-initiated LLM calls).
ServerHandler
Core server handler trait - required for all MCP servers.
TaskHandler
Handler for task-related operations.
ToolHandler
Handler for tool-related operations.
Transport
Core transport trait for MCP communication.
TransportListener
Listener trait for server-side transports.

Functions§

is_version_supported
Check if a protocol version is supported by this implementation.
negotiate_version
Negotiate a protocol version between client and server.
negotiate_version_detailed
Perform version negotiation and return detailed result.

Attribute Macros§

elicitation
Mark a method as an elicitation handler.
mcp_client
The unified MCP client macro.
mcp_server
The unified MCP server macro.
on_connected
Mark a method as the connection established handler.
on_disconnected
Mark a method as the disconnection handler.
on_prompts_list_changed
Mark a method as a prompts list change notification handler.
on_resource_updated
Mark a method as a resource update notification handler.
on_resources_list_changed
Mark a method as a resources list change notification handler.
on_task_progress
Mark a method as a task progress notification handler.
on_tools_list_changed
Mark a method as a tools list change notification handler.
prompt
Mark a method as an MCP prompt handler.
resource
Mark a method as an MCP resource handler.
roots
Mark a method as a roots handler.
sampling
Mark a method as a sampling handler.
tool
Mark a method as an MCP tool.

Derive Macros§

ToolInput
Derive macro for tool input types.