lean-ctx 3.8.16

Context Runtime for AI Agents with CCP. 71 MCP tools, 10 read modes, 95+ compression patterns, cross-session memory (CCP), persistent AI knowledge with temporal facts + contradiction detection, multi-agent context sharing, LITM-aware positioning, AAAK compact format, adaptive compression with Thompson Sampling bandits. Supports 24+ AI tools. Reduces LLM token consumption by up to 99%.
Documentation
use rmcp::ErrorData;
use rmcp::model::Tool;
use serde_json::{Map, Value, json};

use crate::server::tool_trait::{McpTool, ToolContext, ToolOutput, get_str};
use crate::tool_defs::tool_def;

pub struct CtxDiscoverToolsTool;

impl McpTool for CtxDiscoverToolsTool {
    fn name(&self) -> &'static str {
        "ctx_discover_tools"
    }

    fn tool_def(&self) -> Tool {
        tool_def(
            "ctx_discover_tools",
            "WORKFLOW: call FIRST when unsure which tool fits your task — lists all tools on empty query.\n\
             Then use ctx_call to invoke discovered tools (for static-tool-list clients).\n\
             ANTIPATTERN: not for runtime invocation — use ctx_call(name=..., arguments=...) directly.",
            json!({
                "type": "object",
                "properties": {
                    "query": { "type": "string", "description": "Search keyword (empty returns all)" }
                }
            }),
        )
    }

    fn handle(
        &self,
        args: &Map<String, Value>,
        _ctx: &ToolContext,
    ) -> Result<ToolOutput, ErrorData> {
        let query = get_str(args, "query").unwrap_or_default();
        let result = crate::tool_defs::discover_tools(&query);
        Ok(ToolOutput::simple(result))
    }
}