lean_ctx/tools/registered/
ctx_outline.rs1use rmcp::model::Tool;
2use rmcp::ErrorData;
3use serde_json::{json, Map, Value};
4
5use crate::server::tool_trait::{get_str, require_resolved_path, McpTool, ToolContext, ToolOutput};
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 "List all symbols in a file (functions, structs, classes, methods) with signatures. \
19Much fewer tokens than reading the full file.",
20 json!({
21 "type": "object",
22 "properties": {
23 "path": { "type": "string", "description": "File path" },
24 "kind": { "type": "string", "description": "Optional filter: fn|struct|class|all" }
25 },
26 "required": ["path"]
27 }),
28 )
29 }
30
31 fn handle(
32 &self,
33 args: &Map<String, Value>,
34 ctx: &ToolContext,
35 ) -> Result<ToolOutput, ErrorData> {
36 let path = require_resolved_path(ctx, args, "path")?;
37 let kind = get_str(args, "kind");
38
39 let (result, original) = crate::tools::ctx_outline::handle(&path, kind.as_deref());
40 let sent = crate::core::tokens::count_tokens(&result);
41 let saved = original.saturating_sub(sent);
42
43 Ok(ToolOutput {
44 text: result,
45 original_tokens: original,
46 saved_tokens: saved,
47 mode: kind,
48 path: Some(path),
49 changed: false,
50 })
51 }
52}