list_vm_drives
List drives attached to a virtual machine with their IDs and sizes for quick disk inventory and management.
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/server.py:198-205 (handler)MCP tool handler that lists drives attached to a VM. Decorated with @mcp.tool() and delegates to applescript.list_vm_drives.
@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:519-550 (helper)Core implementation that executes AppleScript via osascript to query UTM for the VM's drive list, parsing the results 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)Data class representing a drive's information returned by list_vm_drives, with id, removable flag, and host size in MiB.
@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)Registration via @mcp.tool() decorator on the FastMCP instance. The function name becomes the tool name.
@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:33-36 (helper)Validation helper called by list_vm_drives to sanitize VM name input before constructing AppleScript.
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