Expand description
§MCP Rust SDK (2025-06-18)
A comprehensive Rust SDK for the Model Context Protocol (MCP) version 2025-06-18, providing both server and client implementations with MCP specification compliance including audio content, annotations, and improved capabilities.
§Features
- ⚡ High Performance: Built with Rust’s zero-cost abstractions and async/await
- 🛡️ Type Safety: Leverages Rust’s type system to prevent runtime errors
- 🔌 Multiple Transports: Support for STDIO, HTTP/SSE, and WebSocket transports
- ✅ MCP 2025-06-18 Compliance: Comprehensive implementation of the latest MCP specification
- 🚀 Rich Ecosystem: Tools, resources, prompts, and sampling support
- 🎵 Audio Support: NEW in 2025-06-18 - Audio content support for multimodal interactions
- 🏷️ Annotations: NEW in 2025-06-18 - Tool and content annotations for improved metadata
- 💡 Autocompletion: NEW in 2025-06-18 - Argument autocompletion capabilities
- 📁 Roots Support: NEW in 2025-06-18 - File system roots for improved resource access
§Quick Start
The easiest way to get started is with the prelude module:
use prism_mcp_rs::prelude::*;
This imports all the commonly used types and traits.
§Server Example
ⓘ
use prism_mcp_rs::prelude::*;
use std::collections::HashMap;
use serde_json::{json, Value};
use async_trait::async_trait;
struct EchoHandler;
#[async_trait]
impl ToolHandler for EchoHandler {
async fn call(&self, arguments: HashMap<String, Value>) -> McpResult<ToolResult> {
let message = arguments.get("message")
.and_then(|v| v.as_str())
.unwrap_or("Hello, World!");
Ok(ToolResult {
content: vec![ContentBlock::text(message)],
is_error: Some(false),
structured_content: None,
meta: None,
})
}
}
#[tokio::main]
async fn main() -> McpResult<()> {
let mut server = McpServer::new("echo-server".to_string(), "1.0.0".to_string());
server.add_tool(
"echo".to_string(),
Some("Echo a message".to_string()),
json!({
"type": "object",
"properties": {
"message": { "type": "string" }
}
}),
EchoHandler,
).await?;
#[cfg(feature = "stdio")]
server.run_with_stdio().await?;
Ok(())
}
§Client Example
ⓘ
use prism_mcp_rs::prelude::*;
use std::collections::HashMap;
use serde_json::{json, Value};
#[tokio::main]
async fn main() -> McpResult<()> {
// Create a client
let mut client = McpClient::new("my-client".to_string(), "1.0.0".to_string());
// Set up transport (stdio feature required)
#[cfg(feature = "stdio")]
{
use prism_mcp_rs::transport::StdioClientTransport;
let transport = StdioClientTransport::new("server-command", vec!["arg1"]).await?;
client.connect(transport).await?;
}
// List available tools
let tools = client.list_tools(None).await?;
println!("Available tools: {:?}", tools);
// Call a tool
let mut args = HashMap::new();
args.insert("message".to_string(), json!("Hello from client!"));
let result = client.call_tool(
"echo".to_string(),
Some(args)
).await?;
println!("Tool result: {:?}", result);
Ok(())
}
§Module Organization
core
: Core abstractions for resources, tools, prompts, and errorsplugin
: Plugin system for dynamic tool loadingprotocol
: MCP protocol types and message definitions (2025-06-18)transport
: Transport layer implementations (STDIO, HTTP, WebSocket)server
: MCP server implementation and lifecycle managementclient
: MCP client implementation and session managementutils
: Utility functions and helpers
Re-exports§
pub use core::error::McpError;
pub use core::error::McpResult;
pub use protocol::ErrorObject;
pub use protocol::JsonRpcError;
pub use protocol::JsonRpcMessage;
pub use protocol::JsonRpcRequest;
pub use protocol::JsonRpcResponse;
pub use protocol::ServerCapabilities;
pub use protocol::types::*;
Modules§
- auth
- client
- MCP client implementation
- core
- Core abstractions and types for the MCP SDK
- plugin
- Plugin System for Dynamic Tool Loading
- prelude
- Prelude module for convenient imports (2025-06-18)
- protocol
- MCP protocol implementation (2025-06-18)
- server
- MCP server implementation
- transport
- Transport layer implementations
- utils
- Utility functions and helpers for the MCP Rust SDK
Macros§
- export_
plugin - FIXED Macro to simplify plugin exports with correct ABI
- log_
mcp_ error - Helper macro for logging errors with automatic context
- log_
mcp_ retry - Helper macro for logging retry attempts
- log_
mcp_ retry_ success - Helper macro for logging successful retries
- param_
schema - Macro for creating parameter validation schemas
- record_
connection_ metric - Helper macro for recording connection attempts with metrics
- record_
error_ metric - Helper macro for recording errors with metrics
- record_
request_ metric - Helper macro for recording requests with metrics
- record_
retry_ metric - Helper macro for recording retry attempts with metrics
- tool
- Helper macro for creating tools with schema validation
- validated_
tool - Create a validated tool with typed parameters