Skip to main content
Glama
washyu
by washyu

control_vm

Manage virtual machine states in homelab environments by starting, stopping, or restarting VMs and containers across Docker and LXD platforms.

Instructions

Control VM state (start, stop, restart)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
device_idYesDatabase ID of the target device
platformYesVM platform
vm_nameYesName of the VM/container
actionYesAction to perform

Implementation Reference

  • Core implementation function control_vm_state that executes the VM control logic - retrieves device connection info, establishes SSH connection, calls provider.control_vm(), and returns formatted JSON response
    async def control_vm_state(device_id: int, platform: str, vm_name: str, action: str) -> str:
        """Control VM state (start, stop, restart)."""
        try:
            manager = VMManager()
            connection_info = await manager.get_device_connection_info(device_id)
    
            if not connection_info:
                return json.dumps(
                    {
                        "status": "error",
                        "message": f"Device with ID {device_id} not found in sitemap",
                    }
                )
    
            provider = get_vm_provider(platform)
    
            async with asyncssh.connect(
                connection_info["hostname"],
                username=connection_info["username"],
                known_hosts=None,
            ) as conn:
                result = await provider.control_vm(conn, vm_name, action)
                result["device_id"] = device_id
                result["platform"] = platform
    
                return json.dumps(result, indent=2)
    
        except ValueError as e:
            return json.dumps({"status": "error", "message": str(e)})
        except Exception as e:
            return json.dumps({"status": "error", "message": f"VM control failed: {str(e)}"})
  • Schema definition for control_vm tool - defines input parameters (device_id, platform, vm_name, action) with types, enums, and descriptions
    "control_vm": {
        "description": "Control VM state (start, stop, restart)",
        "inputSchema": {
            "type": "object",
            "properties": {
                "device_id": {
                    "type": "integer",
                    "description": "Database ID of the target device",
                },
                "platform": {
                    "type": "string",
                    "enum": ["docker", "lxd"],
                    "description": "VM platform",
                },
                "vm_name": {
                    "type": "string",
                    "description": "Name of the VM/container",
                },
                "action": {
                    "type": "string",
                    "enum": ["start", "stop", "restart"],
                    "description": "Action to perform",
                },
            },
            "required": ["device_id", "platform", "vm_name", "action"],
        },
    },
  • Handler wrapper function handle_control_vm that extracts arguments from the tool request and calls control_vm_state with proper parameters
    async def handle_control_vm(arguments: dict[str, Any]) -> dict[str, Any]:
        """Handle control_vm tool."""
        result = await control_vm_state(
            device_id=arguments["device_id"],
            platform=arguments["platform"],
            vm_name=arguments["vm_name"],
            action=arguments["action"],
        )
        return {"content": [{"type": "text", "text": result}]}
  • Tool registration in TOOL_HANDLERS dictionary mapping 'control_vm' tool name to handle_control_vm handler function
    "control_vm": handle_control_vm,
  • Provider interface control_vm method that dispatches to appropriate platform-specific methods (start_vm, stop_vm, restart_vm) based on the action parameter
    async def control_vm(self, conn: Any, vm_name: str, action: str) -> dict[str, Any]:
        """Control VM state with the specified action."""
        action_lower = action.lower()
    
        if action_lower == "start":
            return await self.start_vm(conn, vm_name)
        elif action_lower == "stop":
            return await self.stop_vm(conn, vm_name)
        elif action_lower == "restart":
            return await self.restart_vm(conn, vm_name)
        else:
            return {
                "status": "error",
                "message": f"Unknown action: {action}. Supported actions: start, stop, restart",
            }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It states the tool performs state changes (start, stop, restart), implying it's a mutation tool, but doesn't cover critical aspects like required permissions, idempotency, side effects, error handling, or what happens if the VM is already in the target state. This is inadequate for a mutation tool with zero annotation coverage.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is extremely concise—a single parenthetical phrase that efficiently conveys the core functionality without any wasted words. It's front-loaded with the main purpose and immediately specifies the actions.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a mutation tool with no annotations and no output schema, the description is insufficient. It lacks details on behavioral traits (e.g., permissions, idempotency), expected outcomes, error conditions, and doesn't compensate for the absence of structured safety or output information, leaving significant gaps for agent understanding.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema fully documents all four parameters (device_id, platform, vm_name, action) with descriptions and enums. The description adds no additional parameter semantics beyond implying the action parameter's purpose, meeting the baseline for high schema coverage.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose with a specific verb ('control') and resource ('VM state'), and lists the three possible actions (start, stop, restart). It doesn't explicitly differentiate from sibling tools like 'manage_proxmox_vm' or 'get_vm_status', but the action-oriented nature is clear.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention prerequisites, dependencies, or compare it to similar tools like 'manage_proxmox_vm', 'deploy_vm', or 'get_vm_status', leaving the agent to infer usage context.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/washyu/mcp_python_server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server