set_vm_resources
Update memory and CPU cores of a stopped virtual machine. Specify new values or keep current settings.
Instructions
Update memory and CPU cores of a stopped VM.
Args: name: VM name (must be stopped) memory: Memory in MiB, or None to keep current cpu_cores: Number of CPU cores, or None to keep current
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| name | Yes | ||
| memory | No | ||
| cpu_cores | No |
Implementation Reference
- src/mcp_utm/applescript.py:445-472 (handler)Core handler function that updates memory and/or CPU cores of a stopped UTM VM via AppleScript. Validates inputs, builds AppleScript commands, runs them, and returns updated config.
def set_vm_resources(name: str, memory: int | None = None, cpu_cores: int | None = None) -> VMConfig: """Update memory and/or CPU cores of a stopped VM.""" _validate_vm_name(name) parts = [] if memory is not None: memory = int(memory) if memory < 64 or memory > _MAX_MEMORY_MIB: raise ValueError(f"Memory must be 64–{_MAX_MEMORY_MIB} MiB, got {memory}") parts.append(f"set memory of conf to {memory}") if cpu_cores is not None: cpu_cores = int(cpu_cores) if cpu_cores < 1 or cpu_cores > _MAX_CPU_CORES: raise ValueError(f"CPU cores must be 1–{_MAX_CPU_CORES}, got {cpu_cores}") parts.append(f"set cpu cores of conf to {cpu_cores}") if not parts: return get_vm_config(name) updates = "\n ".join(parts) script = f''' tell application "UTM" set vm to virtual machine named "{_esc(name)}" set conf to configuration of vm {updates} update configuration of vm with conf end tell ''' _run(script) return get_vm_config(name) - src/mcp_utm/applescript.py:23-24 (schema)Constants used for validation in set_vm_resources: max memory (1 TiB) and max CPU cores (256).
_MAX_TIMEOUT = 600 # seconds _MAX_MEMORY_MIB = 1048576 # 1 TiB - src/mcp_utm/server.py:106-120 (registration)MCP tool registration decorating set_vm_resources as a FastMCP tool, delegating to applescript.set_vm_resources.
@mcp.tool() def set_vm_resources( name: str, memory: int | None = None, cpu_cores: int | None = None, ) -> dict: """Update memory and CPU cores of a stopped VM. Args: name: VM name (must be stopped) memory: Memory in MiB, or None to keep current cpu_cores: Number of CPU cores, or None to keep current """ config = utm.set_vm_resources(name, memory=memory, cpu_cores=cpu_cores) return config.to_dict()