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/firewalled tool output (zero-loss). Use the ID from an [Archived:/Firewalled: ...] hint.",
19            json!({
20                "type": "object",
21                "properties": {
22                    "id": { "type": "string", "description": "Archive ID or handle ref (@F1)" },
23                    "action": { "type": "string", "description": "retrieve (default)|list|search_all" },
24                    "start_line": { "type": "integer" },
25                    "end_line": { "type": "integer" },
26                    "head": { "type": "integer", "description": "First N lines" },
27                    "tail": { "type": "integer", "description": "Last N lines" },
28                    "search": { "type": "string", "description": "Only lines matching substring" },
29                    "json_keys": { "type": "boolean", "description": "Describe JSON structure" },
30                    "json_path": { "type": "string", "description": "JSON path, e.g. data.items.0" },
31                    "query": { "type": "string", "description": "search_all query" },
32                    "session_id": { "type": "string" }
33                }
34            }),
35        )
36    }
37
38    fn handle(
39        &self,
40        args: &Map<String, Value>,
41        _ctx: &ToolContext,
42    ) -> Result<ToolOutput, ErrorData> {
43        let args_val = Value::Object(args.clone());
44        let result = crate::tools::ctx_expand::handle(&args_val);
45        Ok(ToolOutput::simple(result))
46    }
47}