remove_vm_share
Remove a shared directory from a stopped VM by specifying the host directory path. Use this to clean up shared folders.
Instructions
Remove a shared directory from a VM.
Args: name: VM name (must be stopped) path: Host directory path to remove
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| name | Yes | ||
| path | Yes |
Implementation Reference
- src/mcp_utm/applescript.py:635-642 (handler)Core handler: removes a shared directory from a VM by listing current shares, filtering out the matching path (normalized by stripping trailing slash), and calling set_vm_shares. If the path is not found, returns the current list unchanged.
def remove_vm_share(name: str, path: str) -> list[str]: """Remove a shared directory from a VM.""" current = list_vm_shares(name) normalized = path.rstrip("/") updated = [p for p in current if p.rstrip("/") != normalized] if len(updated) == len(current): return current return set_vm_shares(name, updated) - src/mcp_utm/server.py:248-257 (registration)MCP tool registration via @mcp.tool() decorator. The server function delegates to applescript.remove_vm_share and returns the VM name and updated share list.
@mcp.tool() def remove_vm_share(name: str, path: str) -> dict: """Remove a shared directory from a VM. Args: name: VM name (must be stopped) path: Host directory path to remove """ shares = utm.remove_vm_share(name, path) return {"name": name, "shares": shares} - src/mcp_utm/applescript.py:598-620 (helper)Helper function set_vm_shares - used by remove_vm_share to apply the updated share list via AppleScript. It validates paths and calls UTM's 'update registry' AppleScript API.
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)