Skip to main content

lean_ctx/tools/registered/
ctx_call.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 CtxCallTool;
9
10impl McpTool for CtxCallTool {
11    fn name(&self) -> &'static str {
12        "ctx_call"
13    }
14
15    fn tool_def(&self) -> Tool {
16        tool_def(
17            "ctx_call",
18            "Invoke any of the 50+ lean-ctx tools by name. Use for tools not in the core set.\n\
19             CATEGORIES:\n\
20             arch: ctx_architecture, ctx_impact, ctx_callgraph, ctx_refactor, ctx_symbol, ctx_routes, ctx_smells, ctx_index\n\
21             debug: ctx_benchmark, ctx_verify, ctx_analyze, ctx_profile, ctx_proof, ctx_review\n\
22             memory: ctx_semantic_search, ctx_artifacts\n\
23             batch: ctx_fill, ctx_execute, ctx_expand, ctx_pack, ctx_plan, ctx_control, ctx_compile\n\
24             agent: ctx_agent, ctx_share, ctx_task, ctx_handoff, ctx_workflow\n\
25             util: ctx_compress, ctx_cache, ctx_retrieve, ctx_metrics, ctx_radar, ctx_dedup, ctx_cost, ctx_gain, ctx_heatmap, ctx_feedback, ctx_ledger, ctx_preload\n\
26             Example: ctx_call({\"name\":\"ctx_architecture\",\"arguments\":{\"action\":\"overview\"}})",
27            json!({
28                "type": "object",
29                "properties": {
30                    "name": {
31                        "type": "string",
32                        "description": "Tool name to invoke (e.g. 'ctx_architecture', 'ctx_benchmark')"
33                    },
34                    "arguments": {
35                        "type": "object",
36                        "description": "Arguments object to pass to the invoked tool"
37                    }
38                },
39                "required": ["name"]
40            }),
41        )
42    }
43
44    fn handle(
45        &self,
46        args: &Map<String, Value>,
47        _ctx: &ToolContext,
48    ) -> Result<ToolOutput, ErrorData> {
49        let name = get_str(args, "name")
50            .ok_or_else(|| ErrorData::invalid_params("'name' is required", None))?;
51
52        if name == "ctx_call" {
53            return Err(ErrorData::invalid_params(
54                "ctx_call cannot invoke itself",
55                None,
56            ));
57        }
58
59        Err(ErrorData::internal_error(
60            format!(
61                "ctx_call dispatch for '{name}' must be handled by the async dispatch layer. \
62                 If you see this error, the tool was routed to the sync handler by mistake."
63            ),
64            None,
65        ))
66    }
67}