set_vm_resources
Update memory and CPU cores of a stopped virtual machine. Requires the VM name; optionally set memory in MiB or CPU core count.
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/server.py:106-120 (registration)The @mcp.tool() decorator registers 'set_vm_resources' as an MCP tool. The function delegates to applescript.set_vm_resources and returns the config as dict.
@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() - src/mcp_utm/applescript.py:445-472 (handler)Core implementation: validates name, validates memory (64–1048576 MiB) and cpu_cores (1–256), builds AppleScript to update the VM configuration via UTM's scripting API, and returns a VMConfig dataclass.
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:107-123 (schema)VMConfig dataclass defines the output shape (name, memory, cpu_cores, mac_address, network_mode) returned by set_vm_resources.
@dataclass class VMConfig: name: str memory: int # MiB cpu_cores: int mac_address: str network_mode: str def to_dict(self) -> dict: return { "name": self.name, "memory": self.memory, "cpu_cores": self.cpu_cores, "mac_address": self.mac_address, "network_mode": self.network_mode, } - src/mcp_utm/applescript.py:24-25 (helper)Validation constants used by set_vm_resources: _MAX_MEMORY_MIB (1048576) and _MAX_CPU_CORES (256).
_MAX_MEMORY_MIB = 1048576 # 1 TiB _MAX_CPU_CORES = 256 - src/mcp_utm/applescript.py:33-36 (helper)Name validation helper called at the start of set_vm_resources.
def _validate_vm_name(name: str) -> str: if not name or not _VM_NAME_RE.match(name): raise ValueError(f"Invalid VM name: {name!r} — only word characters, spaces, hyphens, and dots allowed") return name