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, Session};
20//! use mcp_sdk_rs::transport::websocket::WebSocketTransport;
21//!
22//! #[tokio::main]
23//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
24//!     // Create WebSocket transport
25//!     let transport = WebSocketTransport::new("ws://127.0.0.1:8780").await?;
26//!
27//!     // Create client communication channel
28//!     let (request_tx, response_rx) = tokio::sync::mpsc::unbounded_channel();
29//!     let (response_tx, request_rx) = tokio::sync::mpsc::unbounded_channel();
30//!
31//!     // Create a session and start listening for requests and notifications
32//!     let session = Session::new(Arc::new(transport), response_tx, request_rx, None);
33//!     session.start().await?;
34//!
35//!     // Create MCP client
36//!     let client = Client::new(request_tx, response_rx);
37//!
38//!     // Use the client...
39//!
40//!     Ok(())
41//! }
42//! ```
43
44/// Client module provides the MCP client implementation
45pub mod client;
46/// Error types and handling for the SDK
47pub mod error;
48/// Process management for local MCP servers
49pub mod process;
50/// Protocol-specific types and implementations
51pub mod protocol;
52/// Server module provides the MCP server implementation
53pub mod server;
54pub mod session;
55/// Transport layer implementations (WebSocket, stdio)
56pub mod transport;
57/// Common types used throughout the SDK
58pub mod types;
59
60// Re-export commonly used types for convenience
61pub use error::Error;
62pub use protocol::{
63    Notification, Request, Response, JSONRPC_VERSION, LATEST_PROTOCOL_VERSION,
64    SUPPORTED_PROTOCOL_VERSIONS,
65};
66pub use types::*;