lean_ctx/tools/registered/
ctx_overview.rs1use rmcp::model::Tool;
2use rmcp::ErrorData;
3use serde_json::{json, Map, Value};
4
5use crate::server::tool_trait::{get_str, McpTool, ToolContext, ToolOutput};
6use crate::tool_defs::tool_def;
7
8pub struct CtxOverviewTool;
9
10impl McpTool for CtxOverviewTool {
11 fn name(&self) -> &'static str {
12 "ctx_overview"
13 }
14
15 fn tool_def(&self) -> Tool {
16 tool_def(
17 "ctx_overview",
18 "Task-relevant project map — use at session start.",
19 json!({
20 "type": "object",
21 "properties": {
22 "task": {
23 "type": "string",
24 "description": "Task description for relevance scoring"
25 },
26 "path": {
27 "type": "string",
28 "description": "Project root directory (default: .)"
29 }
30 }
31 }),
32 )
33 }
34
35 fn handle(
36 &self,
37 args: &Map<String, Value>,
38 ctx: &ToolContext,
39 ) -> Result<ToolOutput, ErrorData> {
40 let task = get_str(args, "task");
41
42 let resolved_path = if get_str(args, "path").is_some() {
43 ctx.resolved_path("path").map(String::from)
44 } else if let Some(ref session) = ctx.session {
45 let guard = tokio::task::block_in_place(|| session.blocking_read());
46 guard.project_root.clone()
47 } else {
48 None
49 };
50
51 let cache = ctx.cache.as_ref().unwrap();
52 let guard = tokio::task::block_in_place(|| cache.blocking_read());
53 let result = crate::tools::ctx_overview::handle(
54 &guard,
55 task.as_deref(),
56 resolved_path.as_deref(),
57 ctx.crp_mode,
58 );
59
60 Ok(ToolOutput {
61 text: result,
62 original_tokens: 0,
63 saved_tokens: 0,
64 mode: Some("overview".to_string()),
65 path: None,
66 changed: false,
67 })
68 }
69}