Skip to main content

lean_ctx_server/tools/registered/
ctx_compress_memory.rs

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