set_vm_shares
Replace all shared directories on a stopped VM by specifying a list of host paths. Clears shares if list is empty. Use for bulk configuration; for incremental changes see add/remove tools.
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/server.py:260-272 (handler)MCP tool handler for set_vm_shares – registered via @mcp.tool() decorator, delegates to utm.set_vm_shares() in applescript module.
@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:598-620 (helper)Core AppleScript implementation of set_vm_shares – replaces all shared directories for a VM by updating its registry via osascript, then returns the current 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/applescript.py:45-50 (helper)Path validation helper used by set_vm_shares to ensure paths are absolute and prevent 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-36 (helper)VM name validation helper used by set_vm_shares 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 - tests/test_server.py:15-24 (registration)Test confirming set_vm_shares is registered as an MCP tool by checking the tool manager's list of tools.
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