Skip to main content

Rust MCP SDK

A high-performance, asynchronous Rust toolkit for building MCP servers and clients. Focus on your application logic - we handle the protocol, transports, and the rest.

crates.iodocs.rsCI

Build an MCP server in 3 steps

use async_trait::async_trait;
use rust_mcp_sdk::*;
use std::sync::Arc;

// Step 1 - Define a tool
#[macros::mcp_tool(name = "say_hello", description = "Returns a friendly greeting")]
#[derive(Debug, serde::Deserialize, serde::Serialize, macros::JsonSchema)]
pub struct SayHelloTool { pub name: String }

// Step 2 - Implement the handler
#[async_trait]
impl ServerHandler for MyServer {
async fn handle_list_tools_request(
&self, _: Option<PaginatedRequestParams>, _: Arc<dyn McpServer>,
) -> Result<ListToolsResult, RpcError> {
Ok(ListToolsResult { tools: vec![SayHelloTool::tool()], ..Default::default() })
}

async fn handle_call_tool_request(
&self, params: CallToolRequestParams, _: Arc<dyn McpServer>,
) -> Result<CallToolResult, CallToolError> {
let input: SayHelloTool = params.arguments.parse()?;
Ok(CallToolResult::text_content(vec![format!("Hello, {}!", input.name)]))
}
}

// Step 3 - Start the server
#[tokio::main]
async fn main() -> SdkResult<()> {
let server = server_runtime::create_server(McpServerOptions {
transport: StdioTransport::new(TransportOptions::default()?)?,
handler: MyServer.to_mcp_server_handler(),
..Default::default()
});
server.start().await
}
Try the Quickstart โ†’