lean_ctx_server/tools/registered/
ctx_discover_tools.rs1use rmcp::ErrorData;
3use rmcp::model::Tool;
4use serde_json::{Map, Value, json};
5
6use crate::server::tool_trait::{McpTool, ToolContext, ToolOutput, get_str};
7use lean_ctx::tool_defs::tool_def;
8
9pub struct CtxDiscoverToolsTool;
10
11impl McpTool for CtxDiscoverToolsTool {
12 fn name(&self) -> &'static str {
13 "ctx_discover_tools"
14 }
15
16 fn tool_def(&self) -> Tool {
17 tool_def(
18 "ctx_discover_tools",
19 "WORKFLOW: call FIRST when unsure which tool fits your task — lists all tools on empty query.\n\
20 Then use ctx_call to invoke discovered tools (for static-tool-list clients).\n\
21 ANTIPATTERN: not for runtime invocation — use ctx_call(name=..., arguments=...) directly.",
22 json!({
23 "type": "object",
24 "properties": {
25 "query": { "type": "string", "description": "Search keyword (empty returns all)" }
26 }
27 }),
28 )
29 }
30
31 fn handle(
32 &self,
33 args: &Map<String, Value>,
34 _ctx: &ToolContext,
35 ) -> Result<ToolOutput, ErrorData> {
36 let query = get_str(args, "query").unwrap_or_default();
37 let result = lean_ctx::tool_defs::discover_tools(&query);
38 Ok(ToolOutput::simple(result))
39 }
40}