lean_ctx/tools/registered/
ctx_analyze.rs1use rmcp::model::Tool;
2use rmcp::ErrorData;
3use serde_json::{json, Map, Value};
4
5use crate::server::tool_trait::{McpTool, ToolContext, ToolOutput};
6use crate::tool_defs::tool_def;
7
8pub struct CtxAnalyzeTool;
9
10impl McpTool for CtxAnalyzeTool {
11 fn name(&self) -> &'static str {
12 "ctx_analyze"
13 }
14
15 fn tool_def(&self) -> Tool {
16 tool_def(
17 "ctx_analyze",
18 "Entropy analysis — recommends optimal compression mode for a file.",
19 json!({
20 "type": "object",
21 "properties": {
22 "path": { "type": "string" }
23 },
24 "required": ["path"]
25 }),
26 )
27 }
28
29 fn handle(
30 &self,
31 _args: &Map<String, Value>,
32 ctx: &ToolContext,
33 ) -> Result<ToolOutput, ErrorData> {
34 let path = ctx
35 .resolved_path("path")
36 .ok_or_else(|| ErrorData::invalid_params("path is required", None))?
37 .to_string();
38
39 let result = crate::tools::ctx_analyze::handle(&path, crate::tools::CrpMode::effective());
40
41 Ok(ToolOutput {
42 text: result,
43 original_tokens: 0,
44 saved_tokens: 0,
45 mode: None,
46 path: Some(path),
47 })
48 }
49}