Crate prism_mcp_rs

Crate prism_mcp_rs 

Source
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 errors
  • plugin: Plugin system for dynamic tool loading
  • protocol: MCP protocol types and message definitions (2025-06-18)
  • transport: Transport layer implementations (STDIO, HTTP, WebSocket)
  • server: MCP server implementation and lifecycle management
  • client: MCP client implementation and session management
  • utils: 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