lean_ctx/tools/registered/
ctx_callgraph.rs1use 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 CtxCallgraphTool;
9
10impl McpTool for CtxCallgraphTool {
11 fn name(&self) -> &'static str {
12 "ctx_callgraph"
13 }
14
15 fn tool_def(&self) -> Tool {
16 tool_def(
17 "ctx_callgraph",
18 "Unified call graph query. direction=callers|callees for a symbol. Returns file/symbol/line edges.",
19 json!({
20 "type": "object",
21 "properties": {
22 "symbol": { "type": "string", "description": "Symbol name to inspect" },
23 "direction": { "type": "string", "description": "callers|callees (default: callers)" },
24 "file": { "type": "string", "description": "Optional: scope to a specific file" }
25 },
26 "required": ["symbol"]
27 }),
28 )
29 }
30
31 fn handle(
32 &self,
33 args: &Map<String, Value>,
34 ctx: &ToolContext,
35 ) -> Result<ToolOutput, ErrorData> {
36 let symbol = get_str(args, "symbol")
37 .ok_or_else(|| ErrorData::invalid_params("symbol is required", None))?;
38 let direction = get_str(args, "direction").unwrap_or_else(|| "callers".to_string());
39 let file = get_str(args, "file");
40
41 let result = crate::tools::ctx_callgraph::handle(
42 &symbol,
43 file.as_deref(),
44 &ctx.project_root,
45 &direction,
46 );
47
48 Ok(ToolOutput {
49 text: result,
50 original_tokens: 0,
51 saved_tokens: 0,
52 mode: Some(direction),
53 path: None,
54 })
55 }
56}