lean_ctx/tools/registered/
ctx_discover.rs1use rmcp::ErrorData;
2use rmcp::model::Tool;
3use serde_json::{Map, Value, json};
4
5use crate::server::tool_trait::{McpTool, ToolContext, ToolOutput, get_usize};
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 shell commands not yet using lean-ctx compression — use when context feels bloated.\n\
19 Shows which commands would save tokens via lean-ctx patterns. limit=N caps results.\n\
20 ANTIPATTERN: not for finding compression bugs — reports missed opportunities only.\n\
21 Run 'lean-ctx init --global' to auto-compress all commands.",
22 json!({
23 "type": "object",
24 "properties": {
25 "limit": { "type": "integer", "description": "Max results (default 15)" }
26 }
27 }),
28 )
29 }
30
31 fn handle(
32 &self,
33 args: &Map<String, Value>,
34 _ctx: &ToolContext,
35 ) -> Result<ToolOutput, ErrorData> {
36 let limit = get_usize(args, "limit").unwrap_or(15).min(100_000);
37 let history = crate::cli::load_shell_history_pub();
38 let result = crate::tools::ctx_discover::discover_from_history(&history, limit);
39
40 Ok(ToolOutput::simple(result))
41 }
42}