lean-ctx 3.5.4

Context Runtime for AI Agents with CCP. 57 MCP tools, 10 read modes, 95+ compression patterns, cross-session memory (CCP), persistent AI knowledge with temporal facts + contradiction detection, multi-agent context sharing + diaries, 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 std::path::Path;

use rmcp::model::Tool;
use rmcp::ErrorData;
use serde_json::{json, Map, Value};

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

pub struct CtxIndexTool;

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

    fn tool_def(&self) -> Tool {
        tool_def(
            "ctx_index",
            "Index orchestration. Actions: status|build|build-full.",
            json!({
                "type": "object",
                "properties": {
                    "action": {
                        "type": "string",
                        "enum": ["status", "build", "build-full"],
                        "description": "Index action"
                    },
                    "project_root": {
                        "type": "string",
                        "description": "Project root (default: session project root)"
                    }
                },
                "required": ["action"]
            }),
        )
    }

    fn handle(
        &self,
        args: &Map<String, Value>,
        ctx: &ToolContext,
    ) -> Result<ToolOutput, ErrorData> {
        let action = get_str(args, "action")
            .ok_or_else(|| ErrorData::invalid_params("action is required", None))?;
        let root = ctx
            .resolved_path("project_root")
            .or(ctx.resolved_path("root"))
            .unwrap_or(&ctx.project_root);

        let result = crate::tools::ctx_index::handle(&action, Path::new(root));

        Ok(ToolOutput::simple(result))
    }
}