suspend_vm
Suspend a running virtual machine to memory, optionally saving its state to disk for later resume.
Instructions
Suspend a running VM to memory.
Args: name: VM name (must be running) save: Save VM state to disk for later resume (default: True)
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| name | Yes | ||
| save | No |
Implementation Reference
- src/mcp_utm/server.py:124-132 (handler)MCP tool handler for suspend_vm - decorated with @mcp.tool(), calls utm.suspend_vm() and returns the result.
def suspend_vm(name: str, save: bool = True) -> dict: """Suspend a running VM to memory. Args: name: VM name (must be running) save: Save VM state to disk for later resume (default: True) """ status = utm.suspend_vm(name, save=save) return {"name": name, "status": status} - src/mcp_utm/applescript.py:292-303 (helper)Core AppleScript implementation of suspend_vm - executes osascript to suspend a UTM VM (with or without saving state).
def suspend_vm(name: str, save: bool = True) -> str: """Suspend a running VM to memory. Optionally save state to disk.""" _validate_vm_name(name) saving = "with saving" if save else "without saving" script = f''' tell application "UTM" set vm to virtual machine named "{_esc(name)}" suspend vm {saving} return status of vm as text end tell ''' return _run(script, timeout=60) - src/mcp_utm/server.py:124-124 (registration)Registration as MCP tool via @mcp.tool() decorator on line 123 in server.py.
def suspend_vm(name: str, save: bool = True) -> dict: - src/mcp_utm/applescript.py:61-74 (helper)The _run() helper that executes AppleScript via osascript subprocess.
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()