mcp_sdk_rs/
lib.rs

1//! # Model Context Protocol (MCP) Rust SDK
2//!
3//! This SDK provides a Rust implementation of the Model Context Protocol (MCP), a protocol designed
4//! for communication between AI models and their runtime environments. The SDK supports both client
5//! and server implementations with multiple transport layers.
6//!
7//! ## Features
8//!
9//! - Full implementation of MCP protocol specification
10//! - Multiple transport layers (WebSocket, stdio)
11//! - Async/await support using Tokio
12//! - Type-safe message handling
13//! - Comprehensive error handling
14//!
15//! ## Example
16//!
17//! ```no_run
18//! use std::sync::Arc;
19//! use mcp_sdk_rs::client::Client;
20//! use mcp_sdk_rs::session::Session;
21//! use mcp_sdk_rs::transport::websocket::WebSocketTransport;
22//! use tokio::sync::Mutex;
23//!
24//! #[tokio::main]
25//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
26//!     // Create WebSocket transport
27//!     let transport = WebSocketTransport::new("ws://127.0.0.1:8780").await?;
28//!
29//!     // Create client communication channel
30//!     let (sender, receiver) = tokio::sync::mpsc::unbounded_channel();
31//!
32//!     // Create a session and start listening for requests and notifications
33//!     let session = Session::Remote {
34//!         handler: None,
35//!         transport: Arc::new(transport) as Arc<dyn mcp_sdk_rs::transport::Transport>,
36//!         receiver: Arc::new(Mutex::new(receiver)),
37//!         sender: Arc::new(sender),
38//!     };
39//!     session.start().await?;
40//!
41//!     Ok(())
42//! }
43//! ```
44
45/// Client module provides the MCP client implementation
46pub mod client;
47/// Error types and handling for the SDK
48pub mod error;
49/// Process management for local MCP servers
50pub mod process;
51/// Protocol-specific types and implementations
52pub mod protocol;
53/// Server module provides the MCP server implementation
54pub mod server;
55pub mod session;
56/// Transport layer implementations (WebSocket, stdio)
57pub mod transport;
58/// Common types used throughout the SDK
59pub mod types;
60
61// Re-export commonly used types for convenience
62pub use error::Error;
63pub use protocol::{
64    Notification, Request, Response, JSONRPC_VERSION, LATEST_PROTOCOL_VERSION,
65    SUPPORTED_PROTOCOL_VERSIONS,
66};
67pub use types::*;