mcp_protocol_sdk/lib.rs
1// Copyright (c) 2025 MCP Rust Contributors
2// SPDX-License-Identifier: MIT
3
4//! # MCP Rust SDK (2025-06-18)
5//!
6//! A comprehensive Rust SDK for the [Model Context Protocol (MCP)](https://modelcontextprotocol.io/)
7//! version 2025-06-18, 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-06-18 Compliance**: Complete implementation of the latest MCP specification
16//! - 📚 **Rich Ecosystem**: Tools, resources, prompts, and sampling support
17//! - 🎵 **Audio Support**: NEW in 2025-06-18 - Audio content support for multimodal interactions
18//! - 🏷️ **Annotations**: NEW in 2025-06-18 - Tool and content annotations for enhanced metadata
19//! - 🔧 **Autocompletion**: NEW in 2025-06-18 - Argument autocompletion capabilities
20//! - 📁 **Roots Support**: NEW in 2025-06-18 - 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//! structured_content: None,
49//! meta: None,
50//! })
51//! }
52//! }
53//!
54//! #[tokio::main]
55//! async fn main() -> McpResult<()> {
56//! let mut server = McpServer::new("echo-server".to_string(), "1.0.0".to_string());
57//!
58//! server.add_tool(
59//! "echo".to_string(),
60//! Some("Echo a message".to_string()),
61//! serde_json::json!({
62//! "type": "object",
63//! "properties": {
64//! "message": { "type": "string" }
65//! }
66//! }),
67//! EchoHandler,
68//! ).await?;
69//!
70//! Ok(())
71//! }
72//! ```
73//!
74//! ## Module Organization
75//!
76//! - [`core`]: Core abstractions for resources, tools, prompts, and errors
77//! - [`protocol`]: MCP protocol types and message definitions (2025-06-18)
78//! - [`transport`]: Transport layer implementations (STDIO, HTTP, WebSocket)
79//! - [`server`]: MCP server implementation and lifecycle management
80//! - [`client`]: MCP client implementation and session management
81//! - [`utils`]: Utility functions and helpers
82
83pub mod client;
84pub mod core;
85pub mod protocol;
86pub mod server;
87pub mod transport;
88pub mod utils;
89
90// Re-export commonly used types for convenience
91pub use core::error::{McpError, McpResult};
92pub use protocol::types::*;
93
94/// Prelude module for convenient imports (2025-06-18)
95pub mod prelude {
96 pub use crate::client::McpClient;
97 pub use crate::core::{
98 error::{McpError, McpResult},
99 prompt::{Prompt, PromptHandler},
100 resource::{Resource, ResourceHandler},
101 tool::{Tool, ToolHandler},
102 };
103 pub use crate::protocol::types::*;
104 pub use crate::server::McpServer;
105 pub use async_trait::async_trait;
106 pub use serde_json::{Value, json};
107 pub use std::collections::HashMap;
108}
109
110#[cfg(test)]
111mod tests {
112 use super::*;
113
114 #[test]
115 fn test_library_exports() {
116 // Basic smoke test to ensure all modules are accessible
117 let _error = McpError::Protocol("test".to_string());
118 }
119}