Expand description
§mcp-utils
Abstractions that extend rust-mcp-sdk
for simplified MCP tool definition and server setup.
For more information, see the repository’s documentation.
This crate provides higher-level traits and abstractions that simplify tool definition and server setup beyond the base SDK. It offers ergonomic wrappers around the core MCP functionality with automatic serialization and flexible output handling.
§Tool Traits
The crate provides several tool trait options you can implement:
tool::TextTool
– Returns plain text responses (synchronous)tool::AsyncTextTool
– Returns plain text responses (asynchronous)tool::StructuredTool
– Returns structured JSON data (synchronous)tool::AsyncStructuredTool
– Returns structured JSON data (asynchronous)
All traits provide flexible output handling. Return Result
objects, plain strings, or anything that implements Serialize
.
§Quick Start
§1. Define a Tool
use mcp_utils::tool_prelude::*;
#[mcp_tool(
name = "example_tool",
description = "An example tool for demonstration",
title = "Example Tool",
idempotent_hint = true,
read_only_hint = true,
destructive_hint = false,
open_world_hint = false,
)]
#[derive(Debug, JsonSchema, Serialize, Deserialize)]
pub struct ExampleTool {
/// A message to process
pub message: String,
}
impl TextTool for ExampleTool {
type Output = String;
fn call(&self) -> Self::Output {
format!("Processed: {}", self.message)
}
}
§2. Aggregate Tools
After defining your tools, use the setup_tools!
macro to create a tool collection:
use mcp_utils::tool_prelude::*;
setup_tools!(pub MyTools, [
text(ExampleTool),
]);
§Prelude Modules
This crate provides two prelude modules for convenient imports:
tool_prelude
- Everything needed for defining toolsserver_prelude
- Everything needed for server setup and tool aggregation
Modules§
- server_
prelude - Everything needed for server setup and tool aggregation.
- tool_
prelude - Everything needed for defining MCP tools.