set_vm_display
Toggle dynamic resolution on a stopped VM's display to enable or disable adaptive screen scaling.
Instructions
Toggle dynamic resolution on the VM display.
Args: name: VM name (must be stopped) dynamic_resolution: Enable or disable dynamic resolution
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| name | Yes | ||
| dynamic_resolution | Yes |
Implementation Reference
- src/mcp_utm/server.py:275-284 (handler)MCP tool handler function decorated with @mcp.tool() that exposes 'set_vm_display' to clients. It accepts a VM name and a boolean for dynamic resolution, delegates to the AppleScript layer, and returns the result dict.
@mcp.tool() def set_vm_display(name: str, dynamic_resolution: bool) -> dict: """Toggle dynamic resolution on the VM display. Args: name: VM name (must be stopped) dynamic_resolution: Enable or disable dynamic resolution """ utm.set_vm_display(name, dynamic_resolution) return {"name": name, "dynamic_resolution": dynamic_resolution} - src/mcp_utm/applescript.py:649-665 (helper)Core AppleScript logic that toggles dynamic resolution on the first display of a stopped UTM VM. Validates the VM name, constructs an AppleScript snippet, and executes it via osascript.
def set_vm_display(name: str, dynamic_resolution: bool) -> bool: """Toggle dynamic resolution on the first display of a stopped VM.""" _validate_vm_name(name) val = "true" if dynamic_resolution else "false" script = f''' tell application "UTM" set vm to virtual machine named "{_esc(name)}" set conf to configuration of vm set disps to displays of conf if (count of disps) > 0 then set dynamic resolution of item 1 of disps to {val} update configuration of vm with conf end if end tell ''' _run(script) return True - src/mcp_utm/server.py:275-275 (registration)The @mcp.tool() decorator on line 275 registers 'set_vm_display' as an MCP tool. The function name (set_vm_display) becomes the tool name exposed by the MCP server.
@mcp.tool() - src/mcp_utm/server.py:276-276 (schema)Type signatures for the tool: name (str) and dynamic_resolution (bool). The return type is dict (inferred from -> dict annotation).
def set_vm_display(name: str, dynamic_resolution: bool) -> dict: - tests/test_applescript.py:480-489 (helper)Unit tests for set_vm_display: verifies that passing True/False injects the correct 'true'/'false' value into the generated AppleScript.
class TestDisplay: @patch("mcp_utm.applescript._run") def test_enable_dynamic(self, mock_run): set_vm_display("my-vm", True) assert "true" in mock_run.call_args[0][0] @patch("mcp_utm.applescript._run") def test_disable_dynamic(self, mock_run): set_vm_display("my-vm", False) assert "false" in mock_run.call_args[0][0]