lean_ctx/tools/registered/
ctx_plugins.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 CtxPluginsTool;
9
10impl McpTool for CtxPluginsTool {
11 fn name(&self) -> &'static str {
12 "ctx_plugins"
13 }
14
15 fn tool_def(&self) -> Tool {
16 tool_def(
17 "ctx_plugins",
18 "WORKFLOW: list -> info/name -> enable/disable.\n\
19 ANTIPATTERN: NOT for tool listing (use ctx_discover_tools).\n\
20 Plugin management — list, enable, disable, info, hooks.\n\
21 name required for enable/disable/info. Extends tool functionality.\n\
22 Saves tokens: loads only needed plugins.",
23 json!({
24 "type": "object",
25 "properties": {
26 "action": {
27 "type": "string",
28 "enum": ["list", "enable", "disable", "info", "hooks"],
29 "description": "Plugin action to perform"
30 },
31 "name": {
32 "type": "string",
33 "description": "Plugin name (required for enable, disable, info)"
34 }
35 },
36 "allOf": [
37 {
38 "if": { "properties": { "action": { "const": "enable" } }, "required": ["action"] },
39 "then": { "required": ["action", "name"] }
40 },
41 {
42 "if": { "properties": { "action": { "const": "disable" } }, "required": ["action"] },
43 "then": { "required": ["action", "name"] }
44 },
45 {
46 "if": { "properties": { "action": { "const": "info" } }, "required": ["action"] },
47 "then": { "required": ["action", "name"] }
48 }
49 ],
50 "required": ["action"]
51 }),
52 )
53 }
54
55 fn handle(
56 &self,
57 args: &Map<String, Value>,
58 _ctx: &ToolContext,
59 ) -> Result<ToolOutput, ErrorData> {
60 let action = get_str(args, "action").unwrap_or_default();
61 let name = get_str(args, "name");
62
63 let result = crate::tools::ctx_plugins::handle(&action, name.as_deref());
64 Ok(ToolOutput::simple(result))
65 }
66}