list_vm_drives
Lists all drives attached to a virtual machine, showing their IDs and sizes. Use this to inspect storage configuration of a specific VM.
Instructions
List drives attached to a VM with their IDs and sizes.
Args: name: VM name
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| name | Yes |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |
Implementation Reference
- src/mcp_utm/applescript.py:519-550 (handler)Core implementation of list_vm_drives: executes AppleScript to query UTM for drives attached to a VM, parses the output (id, removable, host_size_mib) into DriveInfo objects.
def list_vm_drives(name: str) -> list[DriveInfo]: """List drives attached to 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 drvs to drives of conf set output to "" repeat with d in drvs set dId to id of d set dRemovable to removable of d set dSize to host size of d set output to output & dId & "||" & dRemovable & "||" & dSize & linefeed end repeat return output end tell ''' raw = _run(script) drives = [] for line in raw.strip().split("\n"): line = line.strip() if not line: continue parts = line.split("||") if len(parts) >= 3: drives.append(DriveInfo( id=parts[0], removable=parts[1].lower() == "true", host_size_mib=_parse_int(parts[2]), )) return drives - src/mcp_utm/applescript.py:125-132 (schema)DriveInfo dataclass schema with id, removable, host_size_mib fields and to_dict() method.
@dataclass class DriveInfo: id: str removable: bool host_size_mib: int def to_dict(self) -> dict: return {"id": self.id, "removable": self.removable, "host_size_mib": self.host_size_mib} - src/mcp_utm/server.py:198-205 (registration)MCP tool registration via @mcp.tool() decorator - list_vm_drives delegates to applescript.list_vm_drives and converts results via to_dict().
@mcp.tool() def list_vm_drives(name: str) -> list[dict]: """List drives attached to a VM with their IDs and sizes. Args: name: VM name """ return [d.to_dict() for d in utm.list_vm_drives(name)] - src/mcp_utm/applescript.py:28-30 (helper)Helper _esc() used for safe string escaping in AppleScript interpolation.
def _esc(value: str) -> str: """Escape a string for safe interpolation into AppleScript double-quoted literals.""" return value.replace("\\", "\\\\").replace('"', '\\"') - src/mcp_utm/applescript.py:33-36 (helper)Helper _validate_vm_name() used to validate VM name before querying drives.
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