lean_ctx/tools/registered/
ctx_compress_memory.rs1use rmcp::ErrorData;
2use rmcp::model::Tool;
3use serde_json::{Map, Value, json};
4
5use crate::server::tool_trait::{McpTool, ToolContext, ToolOutput, require_resolved_path};
6use crate::tool_defs::tool_def;
7
8pub struct CtxCompressMemoryTool;
9
10impl McpTool for CtxCompressMemoryTool {
11 fn name(&self) -> &'static str {
12 "ctx_compress_memory"
13 }
14
15 fn tool_def(&self) -> Tool {
16 tool_def(
17 "ctx_compress_memory",
18 "Compress memory/config file (CLAUDE.md, .cursorrules) preserving code, URLs, and paths. Creates .original.md backup.\n\
19 WORKFLOW: check token overhead with ctx_context, then compress to reduce persistent instruction cost.",
20 json!({
21 "type": "object",
22 "properties": {
23 "path": { "type": "string", "description": "Path to memory/config file (e.g., CLAUDE.md, .cursorrules). Creates .original.md backup." }
24 },
25 "required": ["path"]
26 }),
27 )
28 }
29
30 fn handle(
31 &self,
32 args: &Map<String, Value>,
33 ctx: &ToolContext,
34 ) -> Result<ToolOutput, ErrorData> {
35 let path = require_resolved_path(ctx, args, "path")?;
36
37 let result = crate::tools::ctx_compress_memory::handle(&path);
38 Ok(ToolOutput::simple(result))
39 }
40}