pub struct ToolServer { /* private fields */ }Expand description
MCP tool server that registers DynTool implementations and serves them over stdio.
Implements rmcp’s ServerHandler to handle list_tools and call_tool MCP methods.
Implementations§
Source§impl ToolServer
impl ToolServer
Sourcepub fn new(tools: Vec<Box<dyn DynTool>>) -> Self
pub fn new(tools: Vec<Box<dyn DynTool>>) -> Self
Create a new server from a list of tools, registering each by name.
Sourcepub async fn serve_stdio(self) -> Result<(), Box<dyn Error>>
pub async fn serve_stdio(self) -> Result<(), Box<dyn Error>>
Run the MCP server over stdin/stdout until the client disconnects.
Sourcepub fn build_tool_list(&self) -> Vec<RmcpTool>
pub fn build_tool_list(&self) -> Vec<RmcpTool>
Convert all registered tools into rmcp RmcpTool descriptors for list_tools.
D-03: input_schema() returns serde_json::Value (JSON Schema has no fixed Rust type),
so the conversion to rmcp’s Map<String, Value> is inherently Value-based.
Sourcepub async fn dispatch_tool(
&self,
name: &str,
arguments: Option<Map<String, Value>>,
) -> Result<CallToolResult, McpError>
pub async fn dispatch_tool( &self, name: &str, arguments: Option<Map<String, Value>>, ) -> Result<CallToolResult, McpError>
Dispatch a tool call by name, returning an MCP CallToolResult.
Returns an MCP protocol error only for unknown tool names; execution
failures are returned as CallToolResult::error (content-level).
D-03: arguments is Map<String, Value> from rmcp’s CallToolRequestParam —
tool input shape is defined by the tool’s JSON Schema, not a static Rust type.
The conversion to Value::Object and pattern matching on Value::String in the
result both flow from the Tool trait being Value-based (D-03).