set_vm_shares
Replace all shared directories on a stopped VM. Provide a list of host paths to share; an empty list clears all shares.
Instructions
Replace all shared directories on a VM.
Overwrites the entire share list. Use add_vm_share/remove_vm_share for incremental changes.
Args: name: VM name (must be stopped) paths: List of host directory paths to share (empty list clears all)
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| name | Yes | ||
| paths | Yes |
Implementation Reference
- src/mcp_utm/applescript.py:598-620 (handler)Core handler that replaces all shared directories for a VM via AppleScript. Validates inputs, constructs AppleScript to update the registry, and returns the updated share list.
def set_vm_shares(name: str, paths: list[str]) -> list[str]: """Replace all shared directories for a VM.""" _validate_vm_name(name) for p in paths: _validate_path(p) if not paths: script = f''' tell application "UTM" set vm to virtual machine named "{_esc(name)}" update registry of vm with {{}} end tell ''' else: share_items = ", ".join(f'POSIX file "{_esc(p)}"' for p in paths) script = f''' tell application "UTM" set vm to virtual machine named "{_esc(name)}" update registry of vm with {{{share_items}}} end tell ''' _run(script) return list_vm_shares(name) - src/mcp_utm/server.py:260-272 (registration)MCP tool registration (via @mcp.tool() decorator) for set_vm_shares. Delegates to utm.set_vm_shares (applescript module) and returns structured dict result.
@mcp.tool() def set_vm_shares(name: str, paths: list[str]) -> dict: """Replace all shared directories on a VM. Overwrites the entire share list. Use add_vm_share/remove_vm_share for incremental changes. Args: name: VM name (must be stopped) paths: List of host directory paths to share (empty list clears all) """ shares = utm.set_vm_shares(name, paths) return {"name": name, "shares": shares} - src/mcp_utm/applescript.py:45-50 (helper)Path validation helper called by set_vm_shares to ensure each path is absolute and contains 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 - tests/test_server.py:15-24 (schema)Test confirming set_vm_shares is registered as an MCP tool with the expected name.
def test_expected_tools(self): names = {t.name for t in mcp._tool_manager.list_tools()} expected = { "list_vms", "get_vm", "clone_vm", "start_vm", "stop_vm", "delete_vm", "suspend_vm", "wait_for_vm", "get_vm_ip", "set_vm_network", "set_vm_resources", "rename_vm", "set_vm_display", "list_vm_shares", "add_vm_share", "remove_vm_share", "set_vm_shares", "list_vm_drives", "attach_drive", "export_vm", "import_vm", "get_serial_port", } assert expected == names