|
| 1 | +from typing import Dict, Any |
| 2 | + |
| 3 | +from mcp_tools.interfaces import ToolInterface |
| 4 | +from mcp_tools.plugin import register_tool, discover_and_register_tools, registry |
| 5 | +from mcp_tools.plugin_config import config |
| 6 | + |
| 7 | + |
| 8 | +@register_tool(os_type="all") |
| 9 | +class McpAdminTool(ToolInterface): |
| 10 | + """Tool for administering the running MCP instance.""" |
| 11 | + |
| 12 | + @property |
| 13 | + def name(self) -> str: |
| 14 | + return "mcp_admin" |
| 15 | + |
| 16 | + @property |
| 17 | + def description(self) -> str: |
| 18 | + return "Inspect and manage MCP plugins at runtime." |
| 19 | + |
| 20 | + @property |
| 21 | + def input_schema(self) -> Dict[str, Any]: |
| 22 | + return { |
| 23 | + "type": "object", |
| 24 | + "properties": { |
| 25 | + "operation": { |
| 26 | + "type": "string", |
| 27 | + "enum": [ |
| 28 | + "enable_plugin", |
| 29 | + "disable_plugin", |
| 30 | + ], |
| 31 | + "description": "Action to perform", |
| 32 | + }, |
| 33 | + "plugin": { |
| 34 | + "type": "string", |
| 35 | + "description": "Target plugin name", |
| 36 | + }, |
| 37 | + }, |
| 38 | + "required": ["operation", "plugin"], |
| 39 | + } |
| 40 | + |
| 41 | + async def execute_tool(self, arguments: Dict[str, Any]) -> Dict[str, Any]: |
| 42 | + operation = arguments.get("operation") |
| 43 | + plugin = arguments.get("plugin") |
| 44 | + |
| 45 | + if operation == "enable_plugin": |
| 46 | + config.enable_plugin(plugin) |
| 47 | + if plugin not in registry.tools: |
| 48 | + discover_and_register_tools() |
| 49 | + return {"success": True, "plugin": plugin, "enabled": True} |
| 50 | + elif operation == "disable_plugin": |
| 51 | + config.disable_plugin(plugin) |
| 52 | + registry.tools.pop(plugin, None) |
| 53 | + registry.instances.pop(plugin, None) |
| 54 | + return {"success": True, "plugin": plugin, "enabled": False} |
| 55 | + |
| 56 | + return {"success": False, "error": f"Unknown operation: {operation}"} |
0 commit comments