start_vm
Resume a stopped or suspended virtual machine, powering it on to restore its operational state.
Instructions
Start a stopped or suspended VM.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| name | Yes |
Implementation Reference
- src/mcp_utm/server.py:48-52 (handler)MCP tool handler for start_vm. Decorated with @mcp.tool(). Calls utm.start_vm(name) and returns the resulting status.
@mcp.tool() def start_vm(name: str) -> dict: """Start a stopped or suspended VM.""" status = utm.start_vm(name) return {"name": name, "status": status} - src/mcp_utm/applescript.py:249-259 (handler)Core implementation of start_vm. Validates the VM name, then runs an AppleScript via osascript that tells UTM to start the VM and returns its status.
def start_vm(name: str) -> str: """Start a VM. Returns status after start command.""" _validate_vm_name(name) script = f''' tell application "UTM" set vm to virtual machine named "{_esc(name)}" start vm return status of vm as text end tell ''' return _run(script, timeout=60) - src/mcp_utm/server.py:48-48 (registration)Registration: the @mcp.tool() decorator registers start_vm as a tool on the FastMCP server.
@mcp.tool() - src/mcp_utm/applescript.py:33-36 (helper)Validation helper _validate_vm_name ensures VM name contains only allowed characters before starting.
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 - src/mcp_utm/applescript.py:61-74 (helper)The _run helper executes AppleScript via subprocess (osascript), used by start_vm to issue the 'start vm' command.
def _run(script: str, timeout: int = 30) -> str: """Execute an AppleScript snippet and return stdout.""" result = subprocess.run( ["osascript", "-e", script], capture_output=True, text=True, timeout=timeout, ) if result.returncode != 0: err = result.stderr.strip() if "Application can" in err and "found" in err: raise RuntimeError("UTM is not running. Launch UTM and try again.") raise RuntimeError(err or f"osascript failed (rc={result.returncode})") return result.stdout.strip()