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 non-core lean-ctx tool by name.\n\
19             arch: ctx_architecture, ctx_impact, ctx_callgraph, ctx_refactor, ctx_symbol, ctx_routes, ctx_smells\n\
20             debug: ctx_benchmark, ctx_verify, ctx_analyze, ctx_profile, ctx_review\n\
21             memory: ctx_semantic_search, ctx_artifacts\n\
22             batch: ctx_fill, ctx_execute, ctx_pack, ctx_plan, ctx_compile\n\
23             agent: ctx_agent, ctx_share, ctx_task, ctx_handoff, ctx_workflow\n\
24             util: ctx_compress, ctx_cache, ctx_metrics, ctx_dedup, ctx_cost, ctx_heatmap, ctx_preload\n\
25             Discover more: name=ctx_discover_tools, arguments={query}.",
26            json!({
27                "type": "object",
28                "properties": {
29                    "name": { "type": "string", "description": "Tool name" },
30                    "arguments": { "type": "object", "description": "Arguments for the tool" }
31                },
32                "required": ["name"]
33            }),
34        )
35    }
36
37    fn handle(
38        &self,
39        args: &Map<String, Value>,
40        _ctx: &ToolContext,
41    ) -> Result<ToolOutput, ErrorData> {
42        let name = get_str(args, "name")
43            .ok_or_else(|| ErrorData::invalid_params("'name' is required", None))?;
44
45        if name == "ctx_call" {
46            return Err(ErrorData::invalid_params(
47                "ctx_call cannot invoke itself",
48                None,
49            ));
50        }
51
52        Err(ErrorData::internal_error(
53            format!(
54                "ctx_call dispatch for '{name}' must be handled by the async dispatch layer. \
55                 If you see this error, the tool was routed to the sync handler by mistake."
56            ),
57            None,
58        ))
59    }
60}