use rmcp::{ServerHandler, model::*};
use async_trait::async_trait;
struct MyMCPServer;
#[async_trait]
impl ServerHandler for MyMCPServer {
async fn list_tools(
&self,
_params: ListToolsRequestParams,
) -> rmcp::Result<ListToolsResult> {
Ok(ListToolsResult {
tools: vec![
Tool {
name: "example_tool".into(),
description: Some("Example tool".to_string()),
input_schema: serde_json::json!({
"type": "object",
"properties": {
"input": {"type": "string"}
},
"required": ["input"]
}),
}
],
})
}
async fn call_tool(
&self,
params: CallToolRequestParams,
) -> rmcp::Result<CallToolResult> {
match params.name.as_str() {
"example_tool" => {
// Extract arguments
let input = params.arguments
.get("input")
.and_then(|v| v.as_str())
.ok_or_else(|| rmcp::Error::invalid_params(
"Missing input parameter"
))?;
// Perform operation
let result = process(input);
// Return result
Ok(CallToolResult {
content: vec![ToolResponseContent::text(result)],
is_error: Some(false),
})
}
_ => Err(rmcp::Error::method_not_found(
format!("Unknown tool: {}", params.name)
)),
}
}
}