lean_ctx/tools/registered/
ctx_tools.rs1use rmcp::ErrorData;
2use rmcp::model::Tool;
3use serde_json::{Map, Value, json};
4
5use crate::server::tool_trait::{McpTool, ToolContext, ToolOutput};
6use crate::tool_defs::tool_def;
7
8pub struct CtxToolsTool;
12
13impl McpTool for CtxToolsTool {
14 fn name(&self) -> &'static str {
15 "ctx_tools"
16 }
17
18 fn tool_def(&self) -> Tool {
19 tool_def(
20 "ctx_tools",
21 "Gateway to downstream MCP servers — unlimited external tools at ~constant context cost.\n\
22 actions: find (query → top-N relevant tools) | call (proxy a server::tool) |\n\
23 list (servers+counts) | refresh.\n\
24 WORKFLOW: find to discover, then call the chosen server::tool.\n\
25 ANTIPATTERN: not for built-in tools — use those directly.",
26 json!({
27 "type": "object",
28 "properties": {
29 "action": {
30 "type": "string",
31 "enum": ["find", "call", "list", "refresh"],
32 "description": "find|call|list|refresh"
33 },
34 "query": { "type": "string", "description": "What you want to do (for find)" },
35 "tool": { "type": "string", "description": "`server::tool` handle (for call)" },
36 "arguments": { "type": "object", "description": "Arguments for downstream tool (call)" }
37 }
38 }),
39 )
40 }
41
42 fn handle(
43 &self,
44 args: &Map<String, Value>,
45 _ctx: &ToolContext,
46 ) -> Result<ToolOutput, ErrorData> {
47 match crate::tools::ctx_tools::run(args) {
48 Ok(text) => Ok(ToolOutput::simple(text)),
49 Err(e) => Err(ErrorData::invalid_params(e, None)),
50 }
51 }
52}