Skip to main content

lean_ctx/tools/registered/
ctx_architecture.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 CtxArchitectureTool;
9
10impl McpTool for CtxArchitectureTool {
11    fn name(&self) -> &'static str {
12        "ctx_architecture"
13    }
14
15    fn tool_def(&self) -> Tool {
16        tool_def(
17            "ctx_architecture",
18            "Graph-based architecture analysis. Actions: overview|clusters|communities|layers|cycles|entrypoints|hotspots|health|module.",
19            json!({
20                "type": "object",
21                "properties": {
22                    "action": {
23                        "type": "string",
24                        "enum": ["overview", "clusters", "communities", "layers", "cycles", "entrypoints", "hotspots", "health", "module"],
25                        "description": "Architecture operation (default: overview)"
26                    },
27                    "path": {
28                        "type": "string",
29                        "description": "Used for action=module (module/file path)"
30                    },
31                    "root": {
32                        "type": "string",
33                        "description": "Project root (default: .)"
34                    },
35                    "format": {
36                        "type": "string",
37                        "description": "Output format"
38                    }
39                }
40            }),
41        )
42    }
43
44    fn handle(
45        &self,
46        args: &Map<String, Value>,
47        ctx: &ToolContext,
48    ) -> Result<ToolOutput, ErrorData> {
49        let action = get_str(args, "action").unwrap_or_else(|| "overview".to_string());
50        let path = get_str(args, "path");
51        let format = get_str(args, "format");
52        let root = ctx
53            .resolved_path("root")
54            .or(ctx.resolved_path("project_root"))
55            .unwrap_or(&ctx.project_root);
56
57        let result = crate::tools::ctx_architecture::handle(
58            &action,
59            path.as_deref(),
60            root,
61            format.as_deref(),
62        );
63
64        Ok(ToolOutput::simple(result))
65    }
66}