Skip to main content

lean_ctx/tools/registered/
ctx_context.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 CtxContextTool;
9
10impl McpTool for CtxContextTool {
11    fn name(&self) -> &'static str {
12        "ctx_context"
13    }
14
15    fn tool_def(&self) -> Tool {
16        tool_def(
17            "ctx_context",
18            "Session context overview — cached files, seen files, session state.",
19            json!({
20                "type": "object",
21                "properties": {}
22            }),
23        )
24    }
25
26    fn handle(
27        &self,
28        _args: &Map<String, Value>,
29        ctx: &ToolContext,
30    ) -> Result<ToolOutput, ErrorData> {
31        let cache = ctx.cache.as_ref().unwrap();
32        let guard = tokio::task::block_in_place(|| cache.blocking_read());
33        let turn = ctx
34            .call_count
35            .as_ref()
36            .map_or(0, |c| c.load(std::sync::atomic::Ordering::Relaxed));
37        let result = crate::tools::ctx_context::handle_status(&guard, turn, ctx.crp_mode);
38        Ok(ToolOutput::simple(result))
39    }
40}