mcp_protocol_sdk/
lib.rs

1//! # MCP Rust SDK
2//!
3//! A comprehensive Rust SDK for the [Model Context Protocol (MCP)](https://modelcontextprotocol.io/),
4//! providing both server and client implementations with full MCP specification compliance.
5//!
6//! ## Features
7//!
8//! - 🚀 **High Performance**: Built with Rust's zero-cost abstractions and async/await
9//! - 🛡️ **Type Safety**: Leverages Rust's type system to prevent runtime errors
10//! - 🔌 **Multiple Transports**: Support for STDIO, HTTP/SSE, and WebSocket transports
11//! - 🎯 **Full MCP Compliance**: Complete implementation of the MCP specification
12//! - 📚 **Rich Ecosystem**: Tools, resources, prompts, and sampling support
13//!
14//! ## Quick Start
15//!
16//! ### Server Example
17//!
18//! ```rust,no_run
19//! use mcp_rust_sdk::{
20//!     server::McpServer,
21//!     core::{tool::ToolHandler, error::McpResult},
22//!     protocol::types::{Content, ToolResult},
23//! };
24//! use async_trait::async_trait;
25//! use std::collections::HashMap;
26//! use serde_json::Value;
27//!
28//! struct EchoHandler;
29//!
30//! #[async_trait]
31//! impl ToolHandler for EchoHandler {
32//!     async fn call(&self, arguments: HashMap<String, Value>) -> McpResult<ToolResult> {
33//!         let message = arguments.get("message")
34//!             .and_then(|v| v.as_str())
35//!             .unwrap_or("Hello, World!");
36//!         
37//!         Ok(ToolResult {
38//!             content: vec![Content::Text { text: message.to_string() }],
39//!             is_error: None,
40//!         })
41//!     }
42//! }
43//!
44//! #[tokio::main]
45//! async fn main() -> McpResult<()> {
46//!     let mut server = McpServer::new("echo-server".to_string(), "1.0.0".to_string());
47//!     
48//!     server.add_tool(
49//!         "echo".to_string(),
50//!         Some("Echo a message".to_string()),
51//!         serde_json::json!({
52//!             "type": "object",
53//!             "properties": {
54//!                 "message": { "type": "string" }
55//!             }
56//!         }),
57//!         EchoHandler,
58//!     ).await?;
59//!     
60//!     Ok(())
61//! }
62//! ```
63//!
64//! ## Module Organization
65//!
66//! - [`core`]: Core abstractions for resources, tools, prompts, and errors
67//! - [`protocol`]: MCP protocol types and message definitions  
68//! - [`transport`]: Transport layer implementations (STDIO, HTTP, WebSocket)
69//! - [`server`]: MCP server implementation and lifecycle management
70//! - [`client`]: MCP client implementation and session management
71//! - [`utils`]: Utility functions and helpers
72
73pub mod client;
74pub mod core;
75pub mod protocol;
76pub mod server;
77pub mod transport;
78pub mod utils;
79
80// Re-export commonly used types for convenience
81pub use core::error::{McpError, McpResult};
82pub use protocol::types::*;
83
84/// Prelude module for convenient imports
85pub mod prelude {
86    pub use crate::client::McpClient;
87    pub use crate::core::{
88        error::{McpError, McpResult},
89        prompt::{Prompt, PromptHandler},
90        resource::{Resource, ResourceHandler},
91        tool::{Tool, ToolHandler},
92        PromptInfo, ResourceInfo, ToolInfo,
93    };
94    pub use crate::protocol::types::*;
95    pub use crate::server::McpServer;
96    pub use async_trait::async_trait;
97    pub use serde_json::{json, Value};
98    pub use std::collections::HashMap;
99}
100
101#[cfg(test)]
102mod tests {
103    use super::*;
104
105    #[test]
106    fn test_library_exports() {
107        // Basic smoke test to ensure all modules are accessible
108        let _error = McpError::Protocol("test".to_string());
109    }
110}