lean_ctx/tools/registered/
ctx_compress.rs1use rmcp::model::Tool;
2use rmcp::ErrorData;
3use serde_json::{json, Map, Value};
4
5use crate::server::tool_trait::{get_bool, McpTool, ToolContext, ToolOutput};
6use crate::tool_defs::tool_def;
7
8pub struct CtxCompressTool;
9
10impl McpTool for CtxCompressTool {
11 fn name(&self) -> &'static str {
12 "ctx_compress"
13 }
14
15 fn tool_def(&self) -> Tool {
16 tool_def(
17 "ctx_compress",
18 "Context checkpoint for long conversations.",
19 json!({
20 "type": "object",
21 "properties": {
22 "include_signatures": { "type": "boolean", "description": "Include signatures (default: true)" }
23 }
24 }),
25 )
26 }
27
28 fn handle(
29 &self,
30 args: &Map<String, Value>,
31 ctx: &ToolContext,
32 ) -> Result<ToolOutput, ErrorData> {
33 let include_sigs = get_bool(args, "include_signatures").unwrap_or(true);
34 let cache = ctx.cache.as_ref().unwrap();
35 let Some(guard) = crate::server::bounded_lock::read(cache, "ctx_compress") else {
36 return Ok(ToolOutput::simple(
37 "[cache temporarily unavailable — retry in a moment]".to_string(),
38 ));
39 };
40 let result = crate::tools::ctx_compress::handle(&guard, include_sigs, ctx.crp_mode);
41 Ok(ToolOutput::simple(result))
42 }
43}