lean_ctx/tools/registered/
ctx_symbol.rs1use rmcp::ErrorData;
2use rmcp::model::Tool;
3use serde_json::{Map, Value, json};
4
5use crate::server::tool_trait::{McpTool, ToolContext, ToolOutput, get_str};
6use crate::tool_defs::tool_def;
7
8pub struct CtxSymbolTool;
9
10impl McpTool for CtxSymbolTool {
11 fn name(&self) -> &'static str {
12 "ctx_symbol"
13 }
14
15 fn tool_def(&self) -> Tool {
16 tool_def(
17 "ctx_symbol",
18 "[Deprecated → ctx_search action=\"symbol\"] Get one symbol's body by name (AST-precise);\n\
19 optional file/kind narrow. Hidden from tools/list but still callable for one release —\n\
20 prefer ctx_search.",
21 json!({
22 "type": "object",
23 "properties": {
24 "name": { "type": "string", "description": "fn|struct|class|method name" },
25 "file": { "type": "string", "description": "Narrow search to file" },
26 "kind": { "type": "string", "description": "fn|struct|class|trait|enum" }
27 },
28 "required": ["name"]
29 }),
30 )
31 }
32
33 fn handle(
34 &self,
35 args: &Map<String, Value>,
36 ctx: &ToolContext,
37 ) -> Result<ToolOutput, ErrorData> {
38 let sym_name = get_str(args, "name")
39 .ok_or_else(|| ErrorData::invalid_params("name is required", None))?;
40 let file = get_str(args, "file");
41 let kind = get_str(args, "kind");
42
43 let (result, original) = crate::tools::ctx_symbol::handle(
44 &sym_name,
45 file.as_deref(),
46 kind.as_deref(),
47 &ctx.project_root,
48 );
49 let sent = crate::core::tokens::count_tokens(&result);
50 let saved = original.saturating_sub(sent);
51
52 Ok(ToolOutput {
53 text: result,
54 original_tokens: original,
55 saved_tokens: saved,
56 mode: kind,
57 path: file,
58 changed: false,
59 shell_outcome: None,
60 })
61 }
62}