Expand description
§Model Context Protocol (MCP) Rust SDK
This SDK provides a Rust implementation of the Model Context Protocol (MCP), a protocol designed for communication between AI models and their runtime environments. The SDK supports both client and server implementations with multiple transport layers.
§Features
- Full implementation of MCP protocol specification
- Multiple transport layers (WebSocket, stdio)
- Async/await support using Tokio
- Type-safe message handling
- Comprehensive error handling
§Example
use std::sync::Arc;
use mcp_sdk_rs::client::{Client, Session};
use mcp_sdk_rs::transport::websocket::WebSocketTransport;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Create WebSocket transport
let transport = WebSocketTransport::new("ws://127.0.0.1:8780").await?;
// Create client communication channel
let (request_tx, response_rx) = tokio::sync::mpsc::unbounded_channel();
let (response_tx, request_rx) = tokio::sync::mpsc::unbounded_channel();
// Create a session and start listening for requests and notifications
let session = Session::new(Arc::new(transport), response_tx, request_rx, None);
session.start().await?;
// Create MCP client
let client = Client::new(request_tx, response_rx);
// Use the client...
Ok(())
}
Re-exports§
pub use error::Error;
pub use protocol::Notification;
pub use protocol::Request;
pub use protocol::Response;
pub use protocol::JSONRPC_VERSION;
pub use protocol::LATEST_PROTOCOL_VERSION;
pub use protocol::SUPPORTED_PROTOCOL_VERSIONS;
pub use types::*;
Modules§
- client
- Client module provides the MCP client implementation
- error
- Error types and handling for the SDK Error types for the MCP protocol.
- protocol
- Protocol-specific types and implementations
- server
- Server module provides the MCP server implementation
- transport
- Transport layer implementations (WebSocket, stdio)
- types
- Common types used throughout the SDK