get_vm
Retrieve the status and configuration of a named virtual machine managed by UTM.
Instructions
Get status and configuration of a VM by name.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| name | Yes |
Implementation Reference
- src/mcp_utm/server.py:23-28 (handler)The MCP tool handler for 'get_vm'. It calls utm.get_vm_status() and utm.get_vm_config() from the applescript module and returns combined status and configuration as a dict.
@mcp.tool() def get_vm(name: str) -> dict: """Get status and configuration of a VM by name.""" status = utm.get_vm_status(name) config = utm.get_vm_config(name) return {"status": status, **config.to_dict()} - src/mcp_utm/server.py:24-28 (schema)The function signature defines the input schema: a 'name: str' parameter. The return type is 'dict' with keys 'status' and all VMConfig fields.
def get_vm(name: str) -> dict: """Get status and configuration of a VM by name.""" status = utm.get_vm_status(name) config = utm.get_vm_config(name) return {"status": status, **config.to_dict()} - src/mcp_utm/server.py:23-23 (registration)Registered as an MCP tool via the @mcp.tool() decorator on line 22.
@mcp.tool() - src/mcp_utm/applescript.py:166-175 (helper)Helper function utm.get_vm_status(): queries UTM via AppleScript for the VM's status (stopped/started/paused).
def get_vm_status(name: str) -> str: """Get the status of a VM by name.""" _validate_vm_name(name) script = f''' tell application "UTM" set vm to virtual machine named "{_esc(name)}" return status of vm as text end tell ''' return _run(script) - src/mcp_utm/applescript.py:178-208 (helper)Helper function utm.get_vm_config(): queries UTM via AppleScript for the VM's configuration (name, memory, cpu_cores, mac_address, network_mode) and returns a VMConfig dataclass.
def get_vm_config(name: str) -> VMConfig: """Read configuration of a VM.""" _validate_vm_name(name) script = f''' tell application "UTM" set vm to virtual machine named "{_esc(name)}" set conf to configuration of vm set vmName to name of conf set vmMem to memory of conf set vmCores to cpu cores of conf set nics to network interfaces of conf if (count of nics) > 0 then set nic to item 1 of nics set macAddr to address of nic set netMode to mode of nic as text else set macAddr to "" set netMode to "" end if return vmName & "||" & vmMem & "||" & vmCores & "||" & macAddr & "||" & netMode end tell ''' raw = _run(script) parts = raw.split("||") return VMConfig( name=parts[0] if len(parts) > 0 else "", memory=_parse_int(parts[1]) if len(parts) > 1 else 0, cpu_cores=_parse_int(parts[2]) if len(parts) > 2 else 0, mac_address=parts[3] if len(parts) > 3 else "", network_mode=parts[4] if len(parts) > 4 else "", )