lean_ctx/tools/registered/
ctx_call.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 CtxCallTool;
9
10impl McpTool for CtxCallTool {
11 fn name(&self) -> &'static str {
12 "ctx_call"
13 }
14
15 fn tool_def(&self) -> Tool {
16 tool_def(
17 "ctx_call",
18 "Invoke any non-core lean-ctx tool by name — for tools not exposed as standalone MCP tools.\n\
19 Categories: arch, debug, memory, batch, agent, util. Find exact names with\n\
20 ctx_discover_tools (query=keyword; empty query lists all). Cannot invoke itself.",
21 json!({
22 "type": "object",
23 "properties": {
24 "name": { "type": "string", "description": "Tool name" },
25 "arguments": { "type": "object", "description": "Tool arguments" }
26 },
27 "required": ["name"]
28 }),
29 )
30 }
31
32 fn handle(
33 &self,
34 args: &Map<String, Value>,
35 _ctx: &ToolContext,
36 ) -> Result<ToolOutput, ErrorData> {
37 let name = get_str(args, "name")
38 .ok_or_else(|| ErrorData::invalid_params("'name' is required", None))?;
39
40 if name == "ctx_call" {
41 return Err(ErrorData::invalid_params(
42 "ctx_call cannot invoke itself",
43 None,
44 ));
45 }
46
47 Err(ErrorData::internal_error(
48 format!(
49 "ctx_call dispatch for '{name}' must be handled by the async dispatch layer. \
50 If you see this error, the tool was routed to the sync handler by mistake."
51 ),
52 None,
53 ))
54 }
55}