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