use serde_json::json;
use solidmcp::{McpServer, McpTools};
use tracing::{error, info, warn};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
tracing_subscriber::fmt().with_env_filter("debug").init();
info!("๐ ๏ธ Starting SolidMCP Custom Tools Server Example");
let mut server = McpServer::new().await?;
let port = 3033;
info!("๐ Server will be available at:");
info!(" WebSocket: ws://localhost:{}/mcp", port);
info!(" HTTP: http://localhost:{}/mcp", port);
info!("๐ Built-in tools: echo, read_file");
info!("๐ ๏ธ Custom tools: You can extend McpTools to add more!");
info!("๐ก To add custom tools, you would:");
info!(" 1. Extend the McpTools struct");
info!(" 2. Add new tool definitions to get_tools_list()");
info!(" 3. Add new cases to execute_tool()");
info!(" 4. Implement your custom tool logic");
demo_custom_tool_usage().await;
info!("Press Ctrl+C to stop the server");
if let Err(e) = server.start(port).await {
error!("โ Server error: {}", e);
return Err(e.into());
}
Ok(())
}
async fn demo_custom_tool_usage() {
info!("๐งช Demonstrating custom tool concepts...");
let tools_list = McpTools::get_tools_list();
let tools = tools_list["tools"].as_array().unwrap();
info!("๐ Current tools count: {}", tools.len());
for tool in tools {
let name = tool["name"].as_str().unwrap();
let description = tool["description"].as_str().unwrap();
info!(" โข {}: {}", name, description);
}
match McpTools::execute_tool(
"echo",
json!({"message": "Hello from custom tools example!"}),
)
.await
{
Ok(result) => {
info!("โ
Echo tool result: {}", result);
}
Err(e) => {
warn!("โ ๏ธ Echo tool error: {}", e);
}
}
info!("๐ญ To add a custom tool like 'calculate', you would:");
info!(" 1. Add to tools list in get_tools_list():");
info!(" {{\"name\": \"calculate\", \"description\": \"Perform math calculations\", ...}}");
info!(" 2. Add to execute_tool() match:");
info!(" \"calculate\" => handle_calculate(arguments).await,");
info!(" 3. Implement handle_calculate() function");
info!(" 4. Return results in the expected MCP format");
}