Skip to main content

lean_ctx/tools/registered/
ctx_smells.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 CtxSmellsTool;
9
10impl McpTool for CtxSmellsTool {
11    fn name(&self) -> &'static str {
12        "ctx_smells"
13    }
14
15    fn tool_def(&self) -> Tool {
16        tool_def(
17            "ctx_smells",
18            "Code smell detection. Actions: scan|summary|rules|file.",
19            json!({
20                "type": "object",
21                "properties": {
22                    "action": {
23                        "type": "string",
24                        "enum": ["scan", "summary", "rules", "file"],
25                        "description": "Smell operation (default: summary)"
26                    },
27                    "rule": {
28                        "type": "string",
29                        "description": "Filter by rule name (for scan)"
30                    },
31                    "path": {
32                        "type": "string",
33                        "description": "Filter by file path"
34                    },
35                    "root": {
36                        "type": "string",
37                        "description": "Project root (default: .)"
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(|| "summary".to_string());
54        let rule = get_str(args, "rule");
55        let path = get_str(args, "path");
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_smells::handle(
63            &action,
64            rule.as_deref(),
65            path.as_deref(),
66            root,
67            format.as_deref(),
68        );
69
70        Ok(ToolOutput::simple(result))
71    }
72}