Skip to main content

lean_ctx/tools/registered/
ctx_callers.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 CtxCallersTool;
9
10impl McpTool for CtxCallersTool {
11    fn name(&self) -> &'static str {
12        "ctx_callers"
13    }
14
15    fn tool_def(&self) -> Tool {
16        tool_def(
17            "ctx_callers",
18            "Find all symbols that call a given function/method. Deprecated alias for ctx_callgraph direction=callers.",
19            json!({
20                "type": "object",
21                "properties": {
22                    "symbol": { "type": "string", "description": "Symbol name to find callers of" },
23                    "file": { "type": "string", "description": "Optional: scope to a specific file" }
24                },
25                "required": ["symbol"]
26            }),
27        )
28    }
29
30    fn handle(
31        &self,
32        args: &Map<String, Value>,
33        ctx: &ToolContext,
34    ) -> Result<ToolOutput, ErrorData> {
35        let symbol = get_str(args, "symbol")
36            .ok_or_else(|| ErrorData::invalid_params("symbol is required", None))?;
37        let file = get_str(args, "file");
38
39        let result = crate::tools::ctx_callers::handle(&symbol, file.as_deref(), &ctx.project_root);
40
41        Ok(ToolOutput::simple(result))
42    }
43}