Skip to main content

lean_ctx/tools/registered/
ctx_graph_diagram.rs

1use rmcp::model::Tool;
2use rmcp::ErrorData;
3use serde_json::{json, Map, Value};
4
5use crate::server::tool_trait::{get_int, get_str, McpTool, ToolContext, ToolOutput};
6use crate::tool_defs::tool_def;
7
8pub struct CtxGraphDiagramTool;
9
10impl McpTool for CtxGraphDiagramTool {
11    fn name(&self) -> &'static str {
12        "ctx_graph_diagram"
13    }
14
15    fn tool_def(&self) -> Tool {
16        tool_def(
17            "ctx_graph_diagram",
18            "Generate a Mermaid diagram of the dependency or call graph. Deprecated alias for ctx_graph action=diagram.",
19            json!({
20                "type": "object",
21                "properties": {
22                    "file": { "type": "string", "description": "Optional: scope to dependencies of a specific file" },
23                    "depth": { "type": "integer", "description": "Max depth (default: 2)" },
24                    "kind": { "type": "string", "description": "deps (file dependencies) or calls (symbol call graph)" }
25                }
26            }),
27        )
28    }
29
30    fn handle(
31        &self,
32        args: &Map<String, Value>,
33        ctx: &ToolContext,
34    ) -> Result<ToolOutput, ErrorData> {
35        let file = get_str(args, "file");
36        let depth = get_int(args, "depth").map(|d| d as usize);
37        let kind = get_str(args, "kind");
38
39        let graph_output = crate::tools::ctx_graph_diagram::handle(
40            file.as_deref(),
41            depth,
42            kind.as_deref(),
43            &ctx.project_root,
44        );
45
46        let result = format!(
47            "[DEPRECATED] Use ctx_graph with action='diagram' (supports same args).\n{graph_output}"
48        );
49
50        Ok(ToolOutput {
51            text: result,
52            original_tokens: 0,
53            saved_tokens: 0,
54            mode: kind,
55            path: None,
56        })
57    }
58}