stop_vm
Stop a running VM. Use force option to shut down when graceful stop fails.
Instructions
Stop a running VM.
Args: name: VM name force: Force stop if graceful shutdown fails
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| name | Yes | ||
| force | No |
Implementation Reference
- src/mcp_utm/server.py:55-56 (registration)The stop_vm tool is registered as an MCP tool via the @mcp.tool() decorator on line 55.
@mcp.tool() def stop_vm(name: str, force: bool = False) -> dict: - src/mcp_utm/server.py:55-64 (handler)The MCP tool handler function for stop_vm that accepts name and force parameters and delegates to the AppleScript helper.
@mcp.tool() def stop_vm(name: str, force: bool = False) -> dict: """Stop a running VM. Args: name: VM name force: Force stop if graceful shutdown fails """ status = utm.stop_vm(name, force=force) return {"name": name, "status": status} - src/mcp_utm/applescript.py:262-273 (helper)The core AppleScript helper function that executes the 'stop vm' command via osascript, with optional force flag.
def stop_vm(name: str, force: bool = False) -> str: """Stop a VM. Returns status after stop command.""" _validate_vm_name(name) method = "by force" if force else "" script = f''' tell application "UTM" set vm to virtual machine named "{_esc(name)}" stop vm {method} return status of vm as text end tell ''' return _run(script, timeout=60) - src/mcp_utm/applescript.py:33-36 (helper)Input validation helper (_validate_vm_name) called by stop_vm to ensure the VM name is safe for AppleScript interpolation.
def _validate_vm_name(name: str) -> str: if not name or not _VM_NAME_RE.match(name): raise ValueError(f"Invalid VM name: {name!r} — only word characters, spaces, hyphens, and dots allowed") return name - tests/test_server.py:18-18 (registration)Test registration verification that confirms 'stop_vm' is one of the 22 registered tools.
"list_vms", "get_vm", "clone_vm", "start_vm", "stop_vm", "delete_vm",