Skip to main content

lean_ctx/tools/registered/
ctx_expand.rs

1use rmcp::model::Tool;
2use rmcp::ErrorData;
3use serde_json::{json, Map, Value};
4
5use crate::server::tool_trait::{McpTool, ToolContext, ToolOutput};
6use crate::tool_defs::tool_def;
7
8pub struct CtxExpandTool;
9
10impl McpTool for CtxExpandTool {
11    fn name(&self) -> &'static str {
12        "ctx_expand"
13    }
14
15    fn tool_def(&self) -> Tool {
16        tool_def(
17            "ctx_expand",
18            "Retrieve archived tool output (zero-loss). Large outputs are auto-archived; use this to retrieve full details. Actions: retrieve (default), list.",
19            json!({
20                "type": "object",
21                "properties": {
22                    "id": { "type": "string", "description": "Archive ID from the [Archived: ...] hint" },
23                    "action": { "type": "string", "description": "retrieve (default) or list" },
24                    "start_line": { "type": "integer", "description": "Start line for range retrieval" },
25                    "end_line": { "type": "integer", "description": "End line for range retrieval" },
26                    "search": { "type": "string", "description": "Search pattern to filter archived output" },
27                    "session_id": { "type": "string", "description": "Filter list by session ID" }
28                }
29            }),
30        )
31    }
32
33    fn handle(
34        &self,
35        args: &Map<String, Value>,
36        _ctx: &ToolContext,
37    ) -> Result<ToolOutput, ErrorData> {
38        let args_val = Value::Object(args.clone());
39        let result = crate::tools::ctx_expand::handle(&args_val);
40        Ok(ToolOutput::simple(result))
41    }
42}