export_vm
Export a virtual machine to a .utm file for backup, sharing, or migration.
Instructions
Export a VM to a .utm file.
Args: name: VM name path: Destination file path (e.g. "/tmp/my-vm.utm")
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| name | Yes | ||
| path | Yes |
Implementation Reference
- src/mcp_utm/server.py:176-184 (handler)MCP tool handler for 'export_vm'. Decorated with @mcp.tool(), delegates to utm.export_vm().
def export_vm(name: str, path: str) -> dict: """Export a VM to a .utm file. Args: name: VM name path: Destination file path (e.g. "/tmp/my-vm.utm") """ utm.export_vm(name, path) return {"name": name, "exported_to": path} - src/mcp_utm/applescript.py:479-491 (helper)Core AppleScript implementation of export_vm. Validates name/path, builds AppleScript to export VM via UTM app, runs osascript with 600s timeout.
def export_vm(name: str, path: str) -> bool: """Export a VM to a .utm file at the given path.""" _validate_vm_name(name) _validate_path(path) script = f''' tell application "UTM" set vm to virtual machine named "{_esc(name)}" set dest to POSIX file "{_esc(path)}" export vm to dest end tell ''' _run(script, timeout=600) return True - src/mcp_utm/server.py:175-176 (registration)Registration via @mcp.tool() decorator on the export_vm function in server.py.
@mcp.tool() def export_vm(name: str, path: str) -> dict: - src/mcp_utm/applescript.py:45-50 (helper)Validation helper _validate_path used by export_vm to ensure absolute path and 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:33-35 (helper)Validation helper _validate_vm_name used by export_vm to validate VM name format.
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")