lean_ctx/tools/registered/
ctx_gain.rs1use rmcp::model::Tool;
2use rmcp::ErrorData;
3use serde_json::{json, Map, Value};
4
5use crate::server::tool_trait::{get_int, get_str, McpTool, ToolContext, ToolOutput};
6use crate::tool_defs::tool_def;
7
8pub struct CtxGainTool;
9
10impl McpTool for CtxGainTool {
11 fn name(&self) -> &'static str {
12 "ctx_gain"
13 }
14
15 fn tool_def(&self) -> Tool {
16 tool_def(
17 "ctx_gain",
18 "Gain report (includes Wrapped via action=wrapped).",
19 json!({
20 "type": "object",
21 "properties": {
22 "action": {
23 "type": "string",
24 "enum": ["status", "report", "score", "cost", "tasks", "heatmap", "wrapped", "agents", "json"]
25 },
26 "period": {
27 "type": "string",
28 "enum": ["week", "month", "all"]
29 },
30 "model": {
31 "type": "string"
32 },
33 "limit": {
34 "type": "integer"
35 }
36 }
37 }),
38 )
39 }
40
41 fn handle(
42 &self,
43 args: &Map<String, Value>,
44 _ctx: &ToolContext,
45 ) -> Result<ToolOutput, ErrorData> {
46 let action = get_str(args, "action").unwrap_or_else(|| "status".to_string());
47 let period = get_str(args, "period");
48 let model = get_str(args, "model");
49 let limit = get_int(args, "limit").map(|n| n as usize);
50
51 let result =
52 crate::tools::ctx_gain::handle(&action, period.as_deref(), model.as_deref(), limit);
53
54 Ok(ToolOutput {
55 text: result,
56 original_tokens: 0,
57 saved_tokens: 0,
58 mode: Some(action),
59 path: None,
60 })
61 }
62}