remove_vm_share
Remove a shared directory from a stopped virtual machine by specifying the VM name and host directory path.
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/server.py:248-257 (handler)MCP tool handler for remove_vm_share. Registered as an @mcp.tool(), it delegates to utm.remove_vm_share() and returns the 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:635-642 (helper)Core implementation of remove_vm_share. Lists current shares, normalizes the path by stripping trailing slash, filters out the matching path, and calls set_vm_shares to update. Returns the unchanged list if the path was not found.
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/applescript.py:598-620 (helper)Helper set_vm_shares called by remove_vm_share. Validates paths, constructs AppleScript to update the VM's registry with the new share list via osascript, and returns the refreshed 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:580-595 (helper)Helper list_vm_shares called by remove_vm_share to fetch the current list of shared directories from the VM's registry via AppleScript.
def list_vm_shares(name: str) -> list[str]: """List shared directories registered for a VM. Returns POSIX paths.""" _validate_vm_name(name) script = f''' tell application "UTM" set vm to virtual machine named "{_esc(name)}" set shares to registry of vm set output to "" repeat with s in shares set output to output & (POSIX path of s) & linefeed end repeat return output end tell ''' raw = _run(script) return [p.strip() for p in raw.strip().split("\n") if p.strip()] - src/mcp_utm/server.py:248-249 (registration)Registration of remove_vm_share as an MCP tool via the @mcp.tool() decorator on line 248.
@mcp.tool() def remove_vm_share(name: str, path: str) -> dict: