lean_ctx/tools/registered/
ctx_discover.rs1use rmcp::model::Tool;
2use rmcp::ErrorData;
3use serde_json::{json, Map, Value};
4
5use crate::server::tool_trait::{get_int, McpTool, ToolContext, ToolOutput};
6use crate::tool_defs::tool_def;
7
8pub struct CtxDiscoverTool;
9
10impl McpTool for CtxDiscoverTool {
11 fn name(&self) -> &'static str {
12 "ctx_discover"
13 }
14
15 fn tool_def(&self) -> Tool {
16 tool_def(
17 "ctx_discover",
18 "Find missed compression opportunities in shell history.",
19 json!({
20 "type": "object",
21 "properties": {
22 "limit": { "type": "integer" }
23 }
24 }),
25 )
26 }
27
28 fn handle(
29 &self,
30 args: &Map<String, Value>,
31 _ctx: &ToolContext,
32 ) -> Result<ToolOutput, ErrorData> {
33 let limit = get_int(args, "limit").unwrap_or(15) as usize;
34 let history = crate::cli::load_shell_history_pub();
35 let result = crate::tools::ctx_discover::discover_from_history(&history, limit);
36
37 Ok(ToolOutput::simple(result))
38 }
39}