Skip to main content

lean_ctx/tools/registered/
ctx_response.rs

1use rmcp::ErrorData;
2use rmcp::model::Tool;
3use serde_json::{Map, Value, json};
4
5use crate::server::tool_trait::{McpTool, ToolContext, ToolOutput, get_str};
6use crate::tool_defs::tool_def;
7
8pub struct CtxResponseTool;
9
10impl McpTool for CtxResponseTool {
11    fn name(&self) -> &'static str {
12        "ctx_response"
13    }
14
15    fn tool_def(&self) -> Tool {
16        tool_def(
17            "ctx_response",
18            "Compress LLM response text via structural de-duplication.\n\
19             Removes repetitive patterns while preserving key information.\n\
20             WORKFLOW: use after receiving a response, before storing/forwarding.\n\
21             ANTIPATTERN: no-op when CRP mode is off — use ctx_read compression instead.",
22            json!({
23                "type": "object",
24                "properties": {
25                    "text": { "type": "string" }
26                },
27                "required": ["text"]
28            }),
29        )
30    }
31
32    fn handle(
33        &self,
34        args: &Map<String, Value>,
35        _ctx: &ToolContext,
36    ) -> Result<ToolOutput, ErrorData> {
37        let text = get_str(args, "text")
38            .ok_or_else(|| ErrorData::invalid_params("text is required", None))?;
39        let output = crate::tools::ctx_response::handle(&text, crate::tools::CrpMode::effective());
40        Ok(ToolOutput::simple(output))
41    }
42}