Skip to main content

lean_ctx/tools/registered/
ctx_discover_tools.rs

1use rmcp::model::Tool;
2use rmcp::ErrorData;
3use serde_json::{json, Map, Value};
4
5use crate::server::tool_trait::{get_str, McpTool, ToolContext, ToolOutput};
6use crate::tool_defs::tool_def;
7
8pub struct CtxDiscoverToolsTool;
9
10impl McpTool for CtxDiscoverToolsTool {
11    fn name(&self) -> &'static str {
12        "ctx_discover_tools"
13    }
14
15    fn tool_def(&self) -> Tool {
16        tool_def(
17            "ctx_discover_tools",
18            "Search available lean-ctx tools by keyword. Returns matching tool names and descriptions.",
19            json!({
20                "type": "object",
21                "properties": {
22                    "query": { "type": "string", "description": "Search keyword to filter tools (optional, empty returns all)" }
23                }
24            }),
25        )
26    }
27
28    fn handle(
29        &self,
30        args: &Map<String, Value>,
31        _ctx: &ToolContext,
32    ) -> Result<ToolOutput, ErrorData> {
33        let query = get_str(args, "query").unwrap_or_default();
34        let result = crate::tool_defs::discover_tools(&query);
35        Ok(ToolOutput::simple(result))
36    }
37}