lean_ctx/tools/registered/
ctx_index.rs1use std::path::Path;
2
3use rmcp::model::Tool;
4use rmcp::ErrorData;
5use serde_json::{json, Map, Value};
6
7use crate::server::tool_trait::{get_str, McpTool, ToolContext, ToolOutput};
8use crate::tool_defs::tool_def;
9
10pub struct CtxIndexTool;
11
12impl McpTool for CtxIndexTool {
13 fn name(&self) -> &'static str {
14 "ctx_index"
15 }
16
17 fn tool_def(&self) -> Tool {
18 tool_def(
19 "ctx_index",
20 "Index orchestration. Actions: status|build|build-full.",
21 json!({
22 "type": "object",
23 "properties": {
24 "action": {
25 "type": "string",
26 "enum": ["status", "build", "build-full"],
27 "description": "Index action"
28 },
29 "project_root": {
30 "type": "string",
31 "description": "Project root (default: session project root)"
32 }
33 },
34 "required": ["action"]
35 }),
36 )
37 }
38
39 fn handle(
40 &self,
41 args: &Map<String, Value>,
42 ctx: &ToolContext,
43 ) -> Result<ToolOutput, ErrorData> {
44 let action = get_str(args, "action")
45 .ok_or_else(|| ErrorData::invalid_params("action is required", None))?;
46 let root = ctx
47 .resolved_path("project_root")
48 .or(ctx.resolved_path("root"))
49 .unwrap_or(&ctx.project_root);
50
51 let result = crate::tools::ctx_index::handle(&action, Path::new(root));
52
53 Ok(ToolOutput::simple(result))
54 }
55}