suspend_vm
Suspend a running virtual machine to memory and optionally save 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:123-132 (handler)MCP tool handler that exposes suspend_vm as a @mcp.tool() — calls utm.suspend_vm (the AppleScript helper) and returns the VM name and status.
@mcp.tool() 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)AppleScript helper function that validates the VM name, constructs and runs an AppleScript to suspend a VM in UTM (with or without saving state), and returns the VM status.
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:12-14 (registration)MCP server creation and registration — the @mcp.tool() decorator on suspend_vm registers it as an MCP tool named 'suspend_vm'.
from . import applescript as utm mcp = FastMCP("utm") - tests/test_server.py:15-24 (registration)Test confirming 'suspend_vm' is in the set of expected MCP tool names registered on the server.
def test_expected_tools(self): names = {t.name for t in mcp._tool_manager.list_tools()} expected = { "list_vms", "get_vm", "clone_vm", "start_vm", "stop_vm", "delete_vm", "suspend_vm", "wait_for_vm", "get_vm_ip", "set_vm_network", "set_vm_resources", "rename_vm", "set_vm_display", "list_vm_shares", "add_vm_share", "remove_vm_share", "set_vm_shares", "list_vm_drives", "attach_drive", "export_vm", "import_vm", "get_serial_port", } assert expected == names - tests/test_applescript.py:202-212 (helper)Unit tests for suspend_vm in applescript.py, verifying 'with saving' and 'without saving' are correctly passed in the AppleScript.
@patch("mcp_utm.applescript._run") def test_suspend_with_save(self, mock_run): mock_run.return_value = "paused" suspend_vm("my-vm", save=True) assert "with saving" in mock_run.call_args[0][0] @patch("mcp_utm.applescript._run") def test_suspend_without_save(self, mock_run): mock_run.return_value = "paused" suspend_vm("my-vm", save=False) assert "without saving" in mock_run.call_args[0][0]