list_vm_shares
List all VirtioFS shared directories registered for a specific UTM virtual machine by providing its name.
Instructions
List shared directories (VirtioFS) registered for a VM.
Args: name: VM name
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| name | Yes |
Implementation Reference
- src/mcp_utm/server.py:221-229 (handler)MCP tool handler for list_vm_shares. Decorated with @mcp.tool(), it accepts a VM name and delegates to utm.list_vm_shares(name) (the applescript module), returning a dict with name and shares list.
@mcp.tool() def list_vm_shares(name: str) -> dict: """List shared directories (VirtioFS) registered for a VM. Args: name: VM name """ shares = utm.list_vm_shares(name) return {"name": name, "shares": shares} - src/mcp_utm/applescript.py:580-595 (helper)Core implementation of list_vm_shares. Validates the VM name, builds and executes an AppleScript that iterates over the VM's registry entries (shared directories), and returns a list of POSIX path strings.
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:12-12 (registration)Import binding: the server module imports applescript as 'utm', and the @mcp.tool() decorator registers list_vm_shares as an MCP tool on line 221.
from . import applescript as utm - tests/test_server.py:20-20 (registration)Test confirms 'list_vm_shares' is listed among the expected registered MCP tool names.
"set_vm_resources", "rename_vm", "set_vm_display", "list_vm_shares", - tests/test_applescript.py:431-469 (helper)Tests for list_vm_shares and related share management functions, verifying AppleScript output parsing and empty-list handling.
class TestShares: @patch("mcp_utm.applescript._run") def test_list_shares(self, mock_run): mock_run.return_value = "/Users/dev/.ssh/\n/tmp\n" shares = list_vm_shares("my-vm") assert shares == ["/Users/dev/.ssh/", "/tmp"] @patch("mcp_utm.applescript._run") def test_list_shares_empty(self, mock_run): mock_run.return_value = "" assert list_vm_shares("my-vm") == [] @patch("mcp_utm.applescript.list_vm_shares") @patch("mcp_utm.applescript.set_vm_shares") def test_add_share_new(self, mock_set, mock_list): mock_list.return_value = ["/existing/"] mock_set.return_value = ["/existing/", "/new/path"] result = add_vm_share("my-vm", "/new/path") assert "/new/path" in result @patch("mcp_utm.applescript.list_vm_shares") def test_add_share_dedup(self, mock_list): mock_list.return_value = ["/existing/"] result = add_vm_share("my-vm", "/existing") assert result == ["/existing/"] @patch("mcp_utm.applescript.list_vm_shares") @patch("mcp_utm.applescript.set_vm_shares") def test_remove_share(self, mock_set, mock_list): mock_list.return_value = ["/Users/dev/.ssh/", "/tmp/"] mock_set.return_value = ["/Users/dev/.ssh/"] result = remove_vm_share("my-vm", "/tmp") mock_set.assert_called_once() @patch("mcp_utm.applescript.list_vm_shares") def test_remove_nonexistent(self, mock_list): mock_list.return_value = ["/existing/"] result = remove_vm_share("my-vm", "/not-there") assert result == ["/existing/"]