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 errorsplugin: trusted native dynamic tool loading (feature-gated)protocol: MCP 2026/2025 types, negotiation, and message definitionstransport: Transport layer implementations (STDIO, HTTP, WebSocket)server: MCP server implementation and lifecycle managementclient: MCP client implementation and session managementsecurity: request identity, authorization, and rate limitingutils: 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