Skip to main content

lean_ctx/tools/registered/
ctx_discover_tools.rs

1use rmcp::ErrorData;
2use rmcp::model::Tool;
3use serde_json::{Map, Value, json};
4
5use crate::server::tool_trait::{McpTool, ToolContext, ToolOutput, get_str};
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            "WORKFLOW: call FIRST when unsure which tool fits your task — lists all tools on empty query.\n\
19             Then use ctx_call to invoke discovered tools (for static-tool-list clients).\n\
20             ANTIPATTERN: not for runtime invocation — use ctx_call(name=..., arguments=...) directly.",
21            json!({
22                "type": "object",
23                "properties": {
24                    "query": { "type": "string", "description": "Search keyword (empty returns all)" }
25                }
26            }),
27        )
28    }
29
30    fn handle(
31        &self,
32        args: &Map<String, Value>,
33        _ctx: &ToolContext,
34    ) -> Result<ToolOutput, ErrorData> {
35        let query = get_str(args, "query").unwrap_or_default();
36        let result = crate::tool_defs::discover_tools(&query);
37        Ok(ToolOutput::simple(result))
38    }
39}