lean_ctx/tools/registered/
ctx_outline.rs1use rmcp::ErrorData;
2use rmcp::model::Tool;
3use serde_json::{Map, Value, json};
4
5use crate::server::tool_trait::{McpTool, ToolContext, ToolOutput, get_str, require_resolved_path};
6use crate::tool_defs::tool_def;
7
8pub struct CtxOutlineTool;
9
10impl McpTool for CtxOutlineTool {
11 fn name(&self) -> &'static str {
12 "ctx_outline"
13 }
14
15 fn tool_def(&self) -> Tool {
16 tool_def(
17 "ctx_outline",
18 "WORKFLOW: call BEFORE ctx_read to preview API surface.\n\
19 ANTIPATTERN: NOT for file content (use ctx_read) or deep understanding (use ctx_compose).\n\
20 Returns fn/struct/class/trait signatures + line numbers via tree-sitter.\n\
21 kind=fn|struct|class|all filters. Saves tokens: only the API surface.",
22 json!({
23 "type": "object",
24 "properties": {
25 "path": { "type": "string", "description": "Path" },
26 "kind": { "type": "string", "description": "fn|struct|class|all filter" }
27 },
28 "required": ["path"]
29 }),
30 )
31 }
32
33 fn handle(
34 &self,
35 args: &Map<String, Value>,
36 ctx: &ToolContext,
37 ) -> Result<ToolOutput, ErrorData> {
38 let path = require_resolved_path(ctx, args, "path")?;
39 let kind = get_str(args, "kind");
40
41 let (result, original) = crate::tools::ctx_outline::handle(&path, kind.as_deref());
42 let sent = crate::core::tokens::count_tokens(&result);
43 let saved = original.saturating_sub(sent);
44
45 Ok(ToolOutput {
46 text: result,
47 original_tokens: original,
48 saved_tokens: saved,
49 mode: kind,
50 path: Some(path),
51 changed: false,
52 shell_outcome: None,
53 })
54 }
55}