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 "required": ["action"]
37 }),
38 )
39 }
40
41 fn handle(
42 &self,
43 args: &Map<String, Value>,
44 _ctx: &ToolContext,
45 ) -> Result<ToolOutput, ErrorData> {
46 let action = get_str(args, "action").unwrap_or_default();
47 let name = get_str(args, "name");
48
49 let result = crate::tools::ctx_plugins::handle(&action, name.as_deref());
50 Ok(ToolOutput::simple(result))
51 }
52}