Skip to main content

Crate prism_mcp_rs

Crate prism_mcp_rs 

Source
Expand description

§Prism MCP Rust SDK

Async client and server primitives for the Model Context Protocol 2026-07-28 with interoperable 2025-11-25 support. The crate includes protocol types, tools, resources, prompts, sampling, completion, roots, replaceable transports, and opt-in production controls.

STDIO is enabled by default. HTTP, WebSocket, SSE, authentication helpers, TLS/mTLS, OpenTelemetry, compression, and trusted native plugins are feature-gated. Security controls are not enabled automatically: a host must authenticate callers and install its request policy.

§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;

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_default();

        Ok(ToolResult {
            content: vec![ContentBlock::text(message)],
            is_error: Some(false),
            structured_content: None,
            meta: None,
        })
    }
}

#[tokio::main]
async fn main() -> McpResult<()> {
    let server = McpServer::create("echo-server", "1.0.0");

    server.add_tool(
        "echo",
        Some("Echo a message"),
        json!({
            "type": "object",
            "properties": {
                "message": { "type": "string" }
            }
        }),
        EchoHandler,
    ).await?;

    server.run_with_transport(StdioServerTransport::new()).await
}

§Module Organization

  • core: Core abstractions for resources, tools, prompts, and errors
  • plugin: trusted native dynamic tool loading (feature-gated)
  • protocol: MCP 2026/2025 types, negotiation, and message definitions
  • transport: Transport layer implementations (STDIO, HTTP, WebSocket)
  • server: MCP server implementation and lifecycle management
  • client: MCP client implementation and session management
  • security: request identity, authorization, and rate limiting
  • 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
OAuth 2.1 Authorization Support for MCP Protocol
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
protocol
Dual-era MCP protocol implementation.
security
Request identity, authorization, and rate-limiting primitives.
server
MCP server implementation
telemetry
OpenTelemetry setup for exporting the request spans emitted by the SDK.
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