import_vm
Import a virtual machine from a .utm file into UTM on macOS. Provide the file path to restore or add a VM.
Instructions
Import a VM from a .utm file.
Args: path: Path to the .utm file to import
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| path | Yes |
Implementation Reference
- src/mcp_utm/server.py:187-195 (handler)MCP tool handler for import_vm. Accepts path string, delegates to utm.import_vm(path), and returns the result as a dict.
@mcp.tool() def import_vm(path: str) -> dict: """Import a VM from a .utm file. Args: path: Path to the .utm file to import """ vm = utm.import_vm(path) return vm.to_dict() - src/mcp_utm/applescript.py:494-512 (schema)Core implementation of import_vm. Validates path, runs AppleScript to import a .utm file via UTM's scripting API, parses the result into a VMInfo dataclass.
def import_vm(path: str) -> VMInfo: """Import a VM from a .utm file. Returns the imported VM info.""" _validate_path(path) script = f''' tell application "UTM" set src to POSIX file "{_esc(path)}" set vm to import new virtual machine from src set vmId to id of vm set vmName to name of vm set vmStatus to status of vm as text set vmBackend to backend of vm as text return vmId & "||" & vmName & "||" & vmStatus & "||" & vmBackend end tell ''' raw = _run(script, timeout=600) parts = raw.split("||") if len(parts) < 4: raise RuntimeError(f"Unexpected import result: {raw!r}") return VMInfo(id=parts[0], name=parts[1], status=parts[2], backend=parts[3]) - src/mcp_utm/server.py:187-195 (registration)The @mcp.tool() decorator on the import_vm function registers it as an MCP tool named 'import_vm'.
@mcp.tool() def import_vm(path: str) -> dict: """Import a VM from a .utm file. Args: path: Path to the .utm file to import """ vm = utm.import_vm(path) return vm.to_dict() - src/mcp_utm/applescript.py:45-50 (helper)Helper function _validate_path used by import_vm to ensure the path is absolute and has no path traversal.
def _validate_path(path: str) -> str: if not path.startswith("/"): raise ValueError(f"Path must be absolute: {path!r}") if ".." in path.split("/"): raise ValueError(f"Path traversal not allowed: {path!r}") return path - src/mcp_utm/applescript.py:96-104 (helper)VMInfo dataclass returned by import_vm, with a to_dict() method used by the server handler.
@dataclass class VMInfo: id: str name: str status: str backend: str def to_dict(self) -> dict: return {"id": self.id, "name": self.name, "status": self.status, "backend": self.backend}