lean_ctx/tools/registered/
ctx_heatmap.rs1use rmcp::ErrorData;
2use rmcp::model::Tool;
3use serde_json::{Map, Value, json};
4
5use crate::server::tool_trait::{McpTool, ToolContext, ToolOutput, get_str};
6use crate::tool_defs::tool_def;
7
8pub struct CtxHeatmapTool;
9
10impl McpTool for CtxHeatmapTool {
11 fn name(&self) -> &'static str {
12 "ctx_heatmap"
13 }
14
15 fn tool_def(&self) -> Tool {
16 tool_def(
17 "ctx_heatmap",
18 "File access heatmap — shows most frequently accessed files per session.\n\
19 action=status (default) for summary, action=detail for per-file access counts.\n\
20 Identify hot files to optimize context usage.",
21 json!({
22 "type": "object",
23 "properties": {
24 "action": { "type": "string", "description": "status|detail" },
25 "path": { "type": "string" }
26 }
27 }),
28 )
29 }
30
31 fn handle(
32 &self,
33 args: &Map<String, Value>,
34 _ctx: &ToolContext,
35 ) -> Result<ToolOutput, ErrorData> {
36 let action = get_str(args, "action").unwrap_or_else(|| "status".to_string());
37 let path = get_str(args, "path");
38 let result = crate::tools::ctx_heatmap::handle(&action, path.as_deref());
39 Ok(ToolOutput {
40 text: result,
41 original_tokens: 0,
42 saved_tokens: 0,
43 mode: Some(action),
44 path: None,
45 changed: false,
46 shell_outcome: None,
47 })
48 }
49}