Skip to main content

lean_ctx/tools/registered/
ctx_impact.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 CtxImpactTool;
9
10impl McpTool for CtxImpactTool {
11    fn name(&self) -> &'static str {
12        "ctx_impact"
13    }
14
15    fn tool_def(&self) -> Tool {
16        tool_def(
17            "ctx_impact",
18            "Graph-based impact analysis. Actions: analyze|chain|build|status.",
19            json!({
20                "type": "object",
21                "properties": {
22                    "action": {
23                        "type": "string",
24                        "enum": ["analyze", "chain", "build", "status"],
25                        "description": "Impact operation (default: analyze)"
26                    },
27                    "path": {
28                        "type": "string",
29                        "description": "Target file path (required for analyze). For chain: from->to spec."
30                    },
31                    "root": {
32                        "type": "string",
33                        "description": "Project root (default: .)"
34                    },
35                    "depth": {
36                        "type": "integer",
37                        "description": "Max traversal depth (default: 5)"
38                    },
39                    "format": {
40                        "type": "string",
41                        "description": "Output format"
42                    }
43                }
44            }),
45        )
46    }
47
48    fn handle(
49        &self,
50        args: &Map<String, Value>,
51        ctx: &ToolContext,
52    ) -> Result<ToolOutput, ErrorData> {
53        let action = get_str(args, "action").unwrap_or_else(|| "analyze".to_string());
54        let path = get_str(args, "path");
55        let depth = get_int(args, "depth").map(|d| d as usize);
56        let format = get_str(args, "format");
57        let root = ctx
58            .resolved_path("root")
59            .or(ctx.resolved_path("project_root"))
60            .unwrap_or(&ctx.project_root);
61
62        let result = crate::tools::ctx_impact::handle(
63            &action,
64            path.as_deref(),
65            root,
66            depth,
67            format.as_deref(),
68        );
69
70        Ok(ToolOutput::simple(result))
71    }
72}