export_vm
Export a virtual machine to a .utm file for backup or transfer. Provide the VM name and destination path.
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/applescript.py:479-491 (handler)The actual implementation of the export_vm function. Validates inputs, builds an AppleScript to export the VM using UTM's AppleScript API, runs it with a 600s timeout, and returns True on success.
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-184 (registration)MCP tool registration for export_vm. Decorated with @mcp.tool(), delegates to utm.export_vm() (from applescript.py) and returns a dict with the result.
@mcp.tool() 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:45-50 (helper)Validation helper used by export_vm to ensure the path is absolute and doesn't contain 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:28-30 (helper)Escape helper used by export_vm to safely interpolate strings into AppleScript double-quoted literals.
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)Validation helper used by export_vm to ensure the VM name is valid.
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