utm-mcp 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,3 +1,113 @@
1
- # Temporary Holding Version
1
+ # utm-mcp
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ An MCP server that lets an AI coding agent set up and manage [UTM](https://getutm.app) virtual
4
+ machines on macOS, and a skill that teaches the agent to use it. No GUI and no desktop control.
5
+
6
+ As a plugin, which your harness keeps up to date:
7
+
8
+ - **Claude Code:** `/plugin marketplace add krishchow/utm-mcp`, then `/plugin install utm@utm`.
9
+ - **Codex:** it reads `.codex-plugin/plugin.json` and `.agents/plugins/marketplace.json` from this
10
+ repository.
11
+
12
+ Or into any harness agentdist supports (Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI and
13
+ others), for you or for one repository:
14
+
15
+ ```bash
16
+ npx utm-mcp install # pick harnesses, and user or repository scope
17
+ ```
18
+
19
+ Both set up the same server and skill, from `agentdist.json`; the plugin manifests are generated
20
+ from it with `npm run gen:plugins`. Either way the server runs from npm with `npx`, and the settings
21
+ below are read from your environment.
22
+
23
+ ## A broker, not a shell
24
+
25
+ The server sits between the agent and UTM. Each tool is one fixed operation: a specific `utmctl`
26
+ command, or one of a fixed set of AppleScripts in `src/applescript.mjs` with the values passed as
27
+ arguments. There is no tool that runs an arbitrary command or script on the host, and nothing is
28
+ passed through a shell.
29
+
30
+ What it enforces is decided by whoever configures it, through the server's environment:
31
+
32
+ | Rule | Default | Setting |
33
+ |---|---|---|
34
+ | Which VMs it may change | Only VMs it created, marked in their UTM notes. All others are visible and read-only. | `UTM_MCP_ALLOW_VMS`: comma-separated names or UUIDs to add |
35
+ | Which host paths the agent may name, for images, ISOs, shared folders and file transfer | Only its exchange directory, `~/.utm-mcp/files`. Symlinks are resolved before the check. | `UTM_MCP_HOST_DIRS`: colon-separated directories to add |
36
+ | Where it keeps generated install media, the exchange directory and the audit log | `~/.utm-mcp` | `UTM_MCP_HOME` |
37
+
38
+ Every tool call is appended to `~/.utm-mcp/audit.log` with its arguments (passwords and stdin left
39
+ out) and whether it succeeded.
40
+
41
+ What it does not restrict: `guest_exec` runs any program inside a VM the server manages, as root or
42
+ SYSTEM. The VM is the sandbox. Destructive tools carry MCP's destructive hint so a harness can ask
43
+ first, but the server itself does not prompt.
44
+
45
+ This is a policy layer, not a security boundary against a hostile agent that also has a shell on
46
+ the host: such an agent can call `utmctl` directly. It keeps a cooperative agent inside the lines
47
+ and leaves a record.
48
+
49
+ ## Tools
50
+
51
+ | | |
52
+ |---|---|
53
+ | Look | `get_policy`, `list_vms`, `get_vm` |
54
+ | Create | `create_linux_vm` (cloud image and cloud-init), `create_windows_vm` (unattended install from an ISO), `clone_vm` |
55
+ | Run | `start_vm`, `stop_vm`, `suspend_vm`, `delete_vm` |
56
+ | Configure | `configure_vm`, `set_shared_folder`, `detach_media` |
57
+ | Guest | `wait_for_guest`, `guest_exec`, `guest_push_file`, `guest_pull_file` |
58
+ | Snapshots | `snapshot_list`, `snapshot_create`, `snapshot_restore`, `snapshot_delete` |
59
+ | Display | `capture_screen`, `send_keys`, `click` |
60
+ | Feedback | `submit_feedback`, only when feedback is turned on (below) |
61
+
62
+ The guest tools are the same for Linux and Windows; they go through the QEMU guest agent.
63
+
64
+ ## Feedback
65
+
66
+ Off unless you turn it on. Set `UTM_MCP_FEEDBACK_ENDPOINT` to the URL of an
67
+ [mcp-feedback](https://github.com/krishchow/feedback) ingest hub, and the server offers agents a
68
+ `submit_feedback` tool for reporting what went wrong (or right) with its tools. Without it there is
69
+ no such tool and nothing is sent anywhere.
70
+
71
+ - The agent shows you each report and sends it only after you say yes. The tool's description names
72
+ the host it goes to.
73
+ - A report holds what the agent wrote, plus the server's version, the macOS (Darwin), Node and UTM
74
+ versions, the Mac's architecture, and, for the VM it names, that VM's status, backend and whether
75
+ the server manages it. No VM names, host paths or guest content are added.
76
+ - When the hub cannot be reached, the report waits in `~/.utm-mcp/feedback/queue` and is sent the next
77
+ time the server starts. Deleting the file cancels it. The installation's token is kept beside it.
78
+ - Each submission is written to the audit log by id, kind and title.
79
+ - `MCP_FEEDBACK_DISABLED=1` turns it off even when the endpoint is set.
80
+
81
+ Reports are anonymous: each installation is a random `install:…` id.
82
+
83
+ ## Layout
84
+
85
+ - `src/server.mjs`: the tools.
86
+ - `src/policy.mjs`: the rules above and the audit log.
87
+ - `src/exec.mjs`, `src/applescript.mjs`: every local command the server can run.
88
+ - `src/media.mjs`: the cloud-init seed and the Windows answer file.
89
+ - `src/feedback.mjs`: `submit_feedback`, when `UTM_MCP_FEEDBACK_ENDPOINT` is set.
90
+ - `skills/utm/`: the skill, with references for Linux guests, Windows guests, and doing the same
91
+ things by hand.
92
+ - `dev/call.mjs`: call one tool over stdio, for development: `node dev/call.mjs list_vms`.
93
+ - `scripts/release.mjs`: cuts a release (below).
94
+
95
+ ## Releasing
96
+
97
+ From a clean, up-to-date `main`:
98
+
99
+ ```bash
100
+ npm run release -- --otp=<code> # publish the version in package.json
101
+ npm run release -- patch --otp=<code> # or minor, major, x.y.z: bump first
102
+ ```
103
+
104
+ It bumps the version, regenerates the plugin manifests for it, validates and publishes to npm, then
105
+ commits the bump, tags `v<version>` and pushes. Nothing is committed, tagged or pushed unless npm
106
+ accepted the package. `--dry-run` goes as far as `npm publish --dry-run` and puts everything back.
107
+
108
+ ## Requirements
109
+
110
+ macOS with UTM 5 in `/Applications`, Node 22.13 or later (`engines` in `package.json`; the server
111
+ says so and exits on anything older, and `.nvmrc` picks Node 22 for work on this repository). The
112
+ first use raises a macOS prompt asking to let the calling app control UTM. Windows installs need
113
+ UTM's Windows guest tools to have been downloaded once.
package/agentdist.json ADDED
@@ -0,0 +1,55 @@
1
+ {
2
+ "$schema": "./node_modules/agentdist/schema/agentdist.schema.json",
3
+ "engine": "v1",
4
+ "name": "utm",
5
+ "description": "An MCP server that creates and operates UTM virtual machines on macOS through a fixed set of operations, with a skill for using it. Linux and Windows guests, no GUI.",
6
+ "skills": "./skills",
7
+ "listing": {
8
+ "displayName": "utm",
9
+ "shortDescription": "Create and operate UTM virtual machines on macOS",
10
+ "longDescription": "An MCP server that sits between your agent and UTM: each tool is one fixed operation (create a Linux VM from a cloud image, install Windows unattended, clone, start, snapshot, run a command or move a file inside the guest), limited to VMs it created and host directories you allow, with every call in an audit log. The skill teaches the agent the order of operations and what to do when something fails.",
11
+ "category": "Developer Tools",
12
+ "keywords": ["mcp", "utm", "virtual-machines", "macos", "qemu"],
13
+ "defaultPrompts": [
14
+ "Make me a throwaway Debian VM",
15
+ "Set up a Windows 11 VM from this ISO",
16
+ "Snapshot this VM, then run the installer inside it"
17
+ ],
18
+ "author": { "name": "krishchow" },
19
+ "homepage": "https://github.com/krishchow/utm-mcp",
20
+ "repository": "https://github.com/krishchow/utm-mcp",
21
+ "license": "MIT"
22
+ },
23
+ "pack": {
24
+ "claude-plugin": {
25
+ "marketplace": { "description": "Create and operate UTM virtual machines on macOS through a fixed set of operations, with a skill for using them." }
26
+ },
27
+ "codex-plugin": {
28
+ "capabilities": ["Read", "Write"],
29
+ "marketplace": { "pluginDisplayName": "utm — UTM virtual machines on macOS", "policy": { "installation": "AVAILABLE" } }
30
+ }
31
+ },
32
+ "mcpServers": {
33
+ "utm": {
34
+ "command": "npx",
35
+ "args": ["-y", "utm-mcp@{{version}}"],
36
+ "envPassthrough": ["UTM_MCP_HOST_DIRS", "UTM_MCP_ALLOW_VMS", "UTM_MCP_HOME", "UTM_MCP_FEEDBACK_ENDPOINT"],
37
+ "startupTimeoutSec": 60,
38
+ "toolTimeoutSec": 900
39
+ }
40
+ },
41
+ "environment": {
42
+ "UTM_MCP_HOST_DIRS": {
43
+ "description": "Colon-separated host directories the server may read images and ISOs from, share with guests, and transfer files to and from. Its own exchange directory is always allowed."
44
+ },
45
+ "UTM_MCP_ALLOW_VMS": {
46
+ "description": "Comma-separated names or UUIDs of existing VMs the server may operate. Without this it changes only VMs it created."
47
+ },
48
+ "UTM_MCP_HOME": {
49
+ "description": "Where the server keeps generated install media, its exchange directory and its audit log. Defaults to ~/.utm-mcp."
50
+ },
51
+ "UTM_MCP_FEEDBACK_ENDPOINT": {
52
+ "description": "URL of an mcp-feedback ingest hub. When set, agents can send feedback about this server there, each report confirmed by the user first. Unset, feedback is off."
53
+ }
54
+ }
55
+ }
@@ -0,0 +1,30 @@
1
+ #!/usr/bin/env node
2
+ import { fileURLToPath } from "node:url";
3
+
4
+ // npx only warns about package.json's engines, so say it plainly instead of failing later on a
5
+ // missing API. Kept in step with "engines".
6
+ const [major, minor] = process.versions.node.split(".").map(Number);
7
+ if (major < 22 || (major === 22 && minor < 13)) {
8
+ process.stderr.write(`utm-mcp needs Node 22.13 or later; this is Node ${process.versions.node}.\n`);
9
+ process.exit(1);
10
+ }
11
+
12
+ const INSTALLER_COMMANDS = new Set(["install", "uninstall", "status", "harnesses"]);
13
+ const argv = process.argv.slice(2);
14
+
15
+ if (INSTALLER_COMMANDS.has(argv[0])) {
16
+ // The installer is the agentdist engine reading agentdist.json one level above this file;
17
+ // nothing about any harness lives here. Loaded on demand so the server does not pay for it.
18
+ const { runCli } = await import("agentdist");
19
+ const packageRoot = fileURLToPath(new URL("..", import.meta.url));
20
+ process.exit(await runCli({ packageRoot, argv, bin: "npx utm-mcp" }));
21
+ } else if (argv.includes("--help") || argv.includes("-h")) {
22
+ process.stdout.write(
23
+ "utm-mcp run the MCP server on stdio\n" +
24
+ "utm-mcp install install the server and skill into your AI coding harnesses\n" +
25
+ "utm-mcp uninstall remove what install wrote\n" +
26
+ "utm-mcp status show where it is installed\n",
27
+ );
28
+ } else {
29
+ await import("../src/server.mjs");
30
+ }
package/package.json CHANGED
@@ -1,6 +1,45 @@
1
1
  {
2
2
  "name": "utm-mcp",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "description": "MCP server and skill that let an AI coding agent create, run, snapshot and operate UTM virtual machines on macOS through a fixed set of operations.",
5
+ "type": "module",
6
+ "license": "MIT",
7
+ "homepage": "https://github.com/krishchow/utm-mcp",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/krishchow/utm-mcp.git"
11
+ },
12
+ "bugs": "https://github.com/krishchow/utm-mcp/issues",
13
+ "bin": {
14
+ "utm-mcp": "bin/utm-mcp.mjs"
15
+ },
16
+ "files": [
17
+ "bin",
18
+ "src",
19
+ "skills",
20
+ "agentdist.json",
21
+ "README.md"
22
+ ],
23
+ "os": [
24
+ "darwin"
25
+ ],
26
+ "engines": {
27
+ "node": ">=22.13"
28
+ },
29
+ "scripts": {
30
+ "validate": "agentdist validate . && agentdist pack . --check",
31
+ "gen:plugins": "agentdist pack .",
32
+ "prepublishOnly": "npm run validate",
33
+ "release": "node scripts/release.mjs",
34
+ "start": "node bin/utm-mcp.mjs"
35
+ },
36
+ "dependencies": {
37
+ "@modelcontextprotocol/sdk": "^1.32.2",
38
+ "agentdist": "^0.1.0",
39
+ "mcp-feedback": "^0.8.0",
40
+ "zod": "^4.6.7"
41
+ },
42
+ "publishConfig": {
43
+ "access": "public"
44
+ }
45
+ }
@@ -0,0 +1,119 @@
1
+ ---
2
+ name: utm
3
+ description: Create, run, snapshot and operate UTM virtual machines on macOS through the utm MCP server, with no GUI and no desktop control. Use when asked to set up a Linux or Windows VM in UTM, make a sandbox or throwaway VM, snapshot or roll back a VM, run a command or copy files inside a guest, share a folder with a guest, or watch an OS installation.
4
+ ---
5
+
6
+ # UTM virtual machines
7
+
8
+ The `utm` MCP server is a broker between you and UTM. Each tool is one fixed operation; there is no tool that runs an arbitrary command on the host. Use the tools rather than calling `utmctl` or `osascript` yourself: they apply the rules below, wait for the right states, and write an audit log.
9
+
10
+ Checked on UTM 5.0.9, macOS 26, Apple silicon, QEMU backend, with Debian 13 and Windows 11 guests.
11
+
12
+ ## What you may touch
13
+
14
+ - **VMs.** You can change only VMs this server created, plus any the person running it allowed. Every other VM appears in `list_vms` with `managed: false` and is read-only. Do not look for a way around that; ask the user to allow the VM.
15
+ - **Host files.** Images, ISOs, shared folders and file transfers must be inside an allowed host directory. `get_policy` lists them. The server's exchange directory is always allowed and is the place for files going in and out of guests.
16
+ - **No undo.** `delete_vm`, `snapshot_restore` and `snapshot_delete` cannot be reversed. Before a restore, say what will be lost: everything in the VM since that snapshot. Ask first unless the VM is one you made for the task at hand.
17
+
18
+ When a tool refuses, the message says which setting the user would change (`UTM_MCP_HOST_DIRS` or `UTM_MCP_ALLOW_VMS`). Relay it.
19
+
20
+ ## The shape of every task
21
+
22
+ 1. `list_vms` or `get_vm` to see what exists. Use the UUID from then on.
23
+ 2. Create, clone or start.
24
+ 3. **`wait_for_guest`.** A VM that is `started` is powered on, not ready. Guest commands, file transfer and the IP address work only once the guest agent answers. If it returns `ready: false`, call it again; it does not mean failure.
25
+ 4. Work inside with `guest_exec`, `guest_push_file`, `guest_pull_file`.
26
+ 5. Stop with `stop_vm` (mode `request` shuts a Linux guest down cleanly; Windows ignores it, so run `shutdown /s /t 0` with `guest_exec` first).
27
+
28
+ ## Getting a VM
29
+
30
+ **Linux, from nothing, in about a minute.** `create_linux_vm` takes a distribution's cloud image and configures it with cloud-init: no installer.
31
+
32
+ - Download an image for the host's architecture into an allowed directory, e.g. `https://cloud.debian.org/images/cloud/trixie/latest/debian-13-genericcloud-arm64.qcow2`, and check it against the published checksum.
33
+ - The result has a passwordless-sudo user (`agent` by default), the guest agent, and your SSH key if you passed one.
34
+ - Debian's `genericcloud` image cannot mount shared folders or read USB drives. Use the `generic` image when you need either. See [references/linux-guests.md](references/linux-guests.md).
35
+
36
+ **Windows, from an installer ISO, in about twenty minutes.** `create_windows_vm` writes an answer file and starts an unattended installation that needs no input. See [references/windows-guests.md](references/windows-guests.md) for what to expect and how to tell it is finished.
37
+
38
+ **Another copy of a VM that works.** `clone_vm` takes about a second and gives the copy its own MAC address. Build one good VM, keep it stopped as a template, and clone it for each use. A cloned cloud-init Linux guest needs one more step before it has a network; it is in the Linux reference.
39
+
40
+ **A run you will throw away.** `start_vm` with `disposable: true` writes nothing to disk. Simpler than snapshot and restore when you want none of it kept.
41
+
42
+ ## Inside the guest
43
+
44
+ `guest_exec` takes a program and its arguments as a list, not a shell line.
45
+
46
+ - For pipes, redirects, `&&` or globbing, run a shell: `["sh", "-c", "…"]` on Linux, `["powershell", "-NoProfile", "-Command", "…"]` or `["cmd", "/c", "…"]` on Windows.
47
+ - It returns `exit_code`, `stdout` and `stderr`. A non-zero exit code is a result, not a tool error.
48
+ - It runs as root on Linux and SYSTEM on Windows. That is an administrative channel: fine for setup and repair, wrong for testing how something behaves for an ordinary user. For that, SSH in as the user (below).
49
+ - If it reports `timed_out`, the program may still be running in the guest. Start long jobs in the background and poll, rather than raising the timeout.
50
+ - It works when the guest has no network, which makes it the way to repair one.
51
+
52
+ `guest_push_file` and `guest_pull_file` move one file each and are binary safe. For a directory, archive it on one side and unpack on the other.
53
+
54
+ **SSH** suits long or interactive work, and work as a normal user. With the default shared network the guest's address from `wait_for_guest` or `get_vm` is reachable from the host directly, with no port forward. Run `ssh` yourself; it is not a broker tool. The address comes from DHCP and can change between boots, so look it up each time.
55
+
56
+ ## Snapshots
57
+
58
+ - `snapshot_create` on a **running** VM captures the running state. `snapshot_restore` then returns the VM to that moment, still running, in a second or two.
59
+ - On a **stopped** VM a snapshot holds the disks only.
60
+ - **Windows VMs can only be snapshotted while stopped.** Their NVMe disk rules out saving running state, and suspending them.
61
+ - A running-state snapshot holds the guest's memory, so it is large: about 800 MB for an idle 2 GiB Linux guest.
62
+ - A name already in use gets a number appended. Use the name or id the tool returns.
63
+ - Clones inherit their source's snapshots.
64
+ - **Shared folders are not covered.** Rolling back a guest does not roll back what it wrote to a shared folder. Keep experimental data on the guest's own disk.
65
+
66
+ ## Sharing a folder
67
+
68
+ `guest_push_file` and `guest_pull_file` need no setup and are the default. Use `set_shared_folder` only when the guest must see a directory continuously. Share a small exchange directory, never a home directory or a project tree. The guest then has to mount it; the commands are in the guest references.
69
+
70
+ ## The display
71
+
72
+ `capture_screen`, `send_keys` and `click` reach what no command can: an installer, a boot menu, a login screen. They are for those moments only. Reading a guest through screenshots is slow and lossy; once the guest agent answers, use `guest_exec`.
73
+
74
+ Never send `space` or `enter` blindly. Look with `capture_screen` first: the focused control may be a Cancel button.
75
+
76
+ ## When something fails
77
+
78
+ | What you see | What it means |
79
+ |---|---|
80
+ | `…was not created by this server, so it is read-only here` | The VM is not yours to change. Ask the user to allow it. |
81
+ | `…is outside the directories this server may use` | Move the file into an allowed directory, or ask the user to allow that one. |
82
+ | `The guest agent is not answering` | The guest is still booting or installing, or has no agent. Call `wait_for_guest`. |
83
+ | `…is started. Stop it before you…` | Cloning, deleting and configuration changes need a stopped VM. |
84
+ | `wait_for_guest` is ready but `ip` is null | The agent is up and the guest has no address. Inspect with `guest_exec`. Usual after cloning a cloud-init guest. |
85
+ | A new Linux VM never becomes ready | The image may be for the wrong architecture, or may not run cloud-init. |
86
+
87
+ When a tool fails in a way this table does not explain, or you had to work around the server to finish, offer to report it (next section).
88
+
89
+ ## Reporting problems with utm-mcp
90
+
91
+ `submit_feedback` is there only when the person running the server has turned feedback on. If it is not in your tool list and the user wants to report a problem, point them at https://github.com/krishchow/utm-mcp/issues instead.
92
+
93
+ When the server's tools let the user down, tell its maintainers with `submit_feedback`. They read reports later with no access to this session or this Mac, so write for that reader.
94
+
95
+ **When to file**
96
+
97
+ - A tool errored, timed out or did something its description did not lead you to expect: `create_windows_vm` never reaching a ready guest, `wait_for_guest` still `ready: false` long after the guest booted, a snapshot that did not restore what it held.
98
+ - The user needed something the tools could not do, such as a setting `configure_vm` does not offer.
99
+ - A tool worked, but you had to guess its arguments, retry, or fall back to `send_keys` and `capture_screen` to get past something.
100
+ - Something worked notably well.
101
+
102
+ Do not file about the guest operating system itself, the user's own images or ISOs, a refusal whose message names the setting to change (`UTM_MCP_HOST_DIRS`, `UTM_MCP_ALLOW_VMS`), or a call you got wrong against a clearly documented tool.
103
+
104
+ Finish or get blocked on the user's request first. Then show the user the exact report you would file (kind, severity, title, body and context) and ask whether to submit it. File only after an explicit yes to that report; a complaint, a request for help or silence is not a yes. If they change it, show the new version and ask again. One report per distinct problem, not one per failed call.
105
+
106
+ **What to include**
107
+
108
+ - `kind` (`bug`, `tool_failure`, `feature_request`, `friction`, `praise` or `other`), `severity` (`blocker`, `major`, `minor`), a one-line `title` naming the tool and the problem, and a `body` saying what happened and why it mattered.
109
+ - `context.goal`, `context.expected`, `context.actual`, and `context.tool_calls` in order, each with a short `arguments_summary` and any `error` text.
110
+ - `context.references.vmId`: the UUID of the VM involved, if there is one. The server adds that VM's status and backend, and its own, macOS's and UTM's versions.
111
+ - `context.repro_steps`, `context.workaround` and `context.suggestion` when you have them.
112
+
113
+ **What to leave out.** The report leaves this Mac. No passwords (`create_windows_vm` returns one), keys or tokens, nothing personal about the user, no host paths or VM names that reveal who they are (say "a Debian 13 cloud image" rather than the path), and guest output only as far as it shows the problem. Do not fill in `context.server_context`.
114
+
115
+ **Afterwards.** Tell the user it was filed. If the result says `queued`, the feedback service could not be reached: the report is waiting on this Mac and goes out the next time the server starts; pass on the note, which says how to cancel it. If the tool reports a size limit, shorten that field and submit again. Otherwise submit once: if a call timed out and you cannot tell whether it went through, say so rather than sending it again.
116
+
117
+ ## Without the server
118
+
119
+ If the MCP server is not connected, the same operations exist as `utmctl` commands and AppleScript. [references/utmctl.md](references/utmctl.md), [references/configuration.md](references/configuration.md) and the guest references describe them. Nothing then enforces the rules above, so apply them yourself: touch only VMs you created or the user named.
@@ -0,0 +1,131 @@
1
+ # Creating and configuring VMs with AppleScript
2
+
3
+ The MCP server's `create_*`, `configure_vm`, `clone_vm` and `set_shared_folder` tools cover the common cases. This is what they do underneath, and how to do what they do not expose (extra drives, network modes, port forwards), for a person or for a session without the server.
4
+
5
+ `utmctl` cannot create a VM or change its hardware. AppleScript can. Run it with `osascript`, and pass values as arguments rather than pasting them into the script text, so a name or path with a quote in it cannot break or change the script:
6
+
7
+ ```bash
8
+ osascript - "my-vm" 4096 <<'EOF'
9
+ on run argv
10
+ set {vmName, memoryMib} to argv
11
+ tell application "UTM"
12
+ set vm to virtual machine named vmName
13
+ set cfg to configuration of vm
14
+ set memory of cfg to (memoryMib as integer)
15
+ update configuration of vm with cfg
16
+ end tell
17
+ end run
18
+ EOF
19
+ ```
20
+
21
+ Checked on UTM 5.0.9, QEMU backend, unless marked otherwise. The authoritative list of properties is `sdef /Applications/UTM.app`.
22
+
23
+ ## The pattern
24
+
25
+ 1. The VM must be **stopped** to change its configuration.
26
+ 2. Read the whole configuration into a variable: `set cfg to configuration of vm`.
27
+ 3. Change properties of `cfg`.
28
+ 4. Write it back: `update configuration of vm with cfg`.
29
+
30
+ Read nested values through the variable. `drives of cfg` works; `drives of configuration of vm` in one expression fails with error -1700.
31
+
32
+ ## Create
33
+
34
+ ```applescript
35
+ tell application "UTM"
36
+ set vm to make new virtual machine with properties {backend:qemu, configuration:{name:"my-vm", architecture:"aarch64", memory:2048, cpu cores:2, drives:{{guest size:16384}}}}
37
+ return id of vm
38
+ end tell
39
+ ```
40
+
41
+ - Sizes are in MiB.
42
+ - `architecture` is QEMU's name: `aarch64` on Apple silicon runs at native speed with the hypervisor. Another architecture (`x86_64`) is emulated and much slower.
43
+ - What you do not specify gets these defaults: shared network with a random MAC, one serial port on a pseudo-terminal, UEFI on, hypervisor on, **no display** and no sound. That is a headless machine, which suits a guest you reach by agent or SSH. Add an entry to `displays` if you need a screen.
44
+ - `make` returns as soon as the VM exists. It is `stopped`.
45
+
46
+ ## Drives
47
+
48
+ Each entry in `drives` is one of:
49
+
50
+ | Entry | Result |
51
+ |---|---|
52
+ | `{guest size:16384}` | A new empty disk of that size, stored in the VM. |
53
+ | `{source:(POSIX file "/path/disk.qcow2")}` | A disk made from an existing image. The image is **copied into the VM**; the original is not used again. |
54
+ | `{removable:true, source:(POSIX file "/path/install.iso")}` | A removable drive (attached as USB) with that image in it. The file is **referenced in place**, not copied, so it must stay where it is. |
55
+ | `{source:…, interface:VirtIO}` | The same with an explicit interface: `VirtIO`, `NVMe`, `SCSI`, `IDE`, `USB` and others. |
56
+
57
+ Things that are not obvious:
58
+
59
+ - **`drives` is the complete list.** When you update a configuration, any existing drive you leave out is removed and its image file is deleted. To keep a drive, include it by id: `{id:"…"}`.
60
+ - A `guest size` given together with a `source` at creation is ignored. Create first, then resize.
61
+ - A removable drive cannot use the `VirtIO` interface; the VM will refuse to start with `Device … is not removable`.
62
+
63
+ Grow a disk (the VM must be stopped; shrinking was not tried):
64
+
65
+ ```applescript
66
+ tell application "UTM"
67
+ set vm to virtual machine named "my-vm"
68
+ set cfg to configuration of vm
69
+ set ds to drives of cfg
70
+ -- keep every drive: list them all, changing only the one being resized
71
+ set drives of cfg to {{id:(id of item 1 of ds), guest size:32768}, {id:(id of item 2 of ds)}}
72
+ update configuration of vm with cfg
73
+ end tell
74
+ ```
75
+
76
+ The guest still has to grow its partition and filesystem. Cloud-init images do that on the next boot by themselves.
77
+
78
+ ## Memory and CPUs
79
+
80
+ ```applescript
81
+ set memory of cfg to 4096 -- MiB
82
+ set cpu cores of cfg to 4 -- 0 means the host's default
83
+ ```
84
+
85
+ ## Network
86
+
87
+ A new VM has one interface in `shared` mode: the guest gets a DHCP address on a private network and the host can reach it directly at that address. Nothing else is needed for SSH from the host.
88
+
89
+ Change the MAC address (needed after a clone, which copies it):
90
+
91
+ ```applescript
92
+ set nic to item 1 of network interfaces of cfg
93
+ set address of nic to "52:54:00:12:34:56"
94
+ set network interfaces of cfg to {nic}
95
+ update configuration of vm with cfg
96
+ ```
97
+
98
+ Setting the address to an empty string does not generate a new one; it leaves the old one in place. Supply a value.
99
+
100
+ The other modes are `emulated`, `host` and `bridged`. In `emulated` mode the guest is not reachable from the host by address, and you reach it through entries in the interface's `port forwards`, each `{protocol:TCP, host address:"127.0.0.1", host port:2222, guest address:"", guest port:22}`. Port forwards were not exercised here.
101
+
102
+ ## Shared folder
103
+
104
+ Two settings, both made while the VM is stopped: how the folder is presented, and which folder it is.
105
+
106
+ ```bash
107
+ osascript - "my-vm" "/Users/me/vm-exchange" <<'EOF'
108
+ on run argv
109
+ set {vmName, sharePath} to argv
110
+ tell application "UTM"
111
+ set vm to virtual machine named vmName
112
+ set cfg to configuration of vm
113
+ set directory share mode of cfg to VirtFS
114
+ update configuration of vm with cfg
115
+ update registry of vm with {{POSIX file sharePath}}
116
+ end tell
117
+ end run
118
+ EOF
119
+ ```
120
+
121
+ - `VirtFS` is for Linux guests, which mount it as a 9p filesystem with the tag `share`. `WebDAV` is the mode for Windows guests, and is what a new VM is set to; it needs the SPICE guest tools in the guest. Only `VirtFS` with Linux was exercised here.
122
+ - The directory must exist. Files the guest creates there are owned on the host by the user running UTM.
123
+ - The guest-side mount is in [linux-guests.md](linux-guests.md).
124
+
125
+ ## Other things in the dictionary
126
+
127
+ Not exercised here; check `sdef /Applications/UTM.app` before using them.
128
+
129
+ - `export vm to file` and `import new virtual machine from file` move a VM as a `.utm` package.
130
+ - `install guest tools vm` puts the Windows guest tools ISO in the VM's empty removable drive.
131
+ - The Apple backend (`backend:apple`) has its own configuration record, with `directory shares` in place of the share mode and registry, and macOS guests can be installed unattended with `install`. Guest commands and file transfer go through the QEMU guest agent, so they are a QEMU-backend feature.
@@ -0,0 +1,87 @@
1
+ # Linux guests
2
+
3
+ Checked with Debian 13 (arm64) on UTM 5.0.9, QEMU backend. Other distributions follow the same shape; their package and service names can differ.
4
+
5
+ ## From a cloud image
6
+
7
+ Distributions publish small disk images meant to boot unattended and configure themselves with cloud-init on first start. That replaces the installer entirely. `create_linux_vm` does the following, and each step can be done by hand:
8
+
9
+ 1. Writes a cloud-init seed: a `meta-data` file (instance id, hostname) and a `user-data` file that creates a sudo user, authorises an SSH key, installs `qemu-guest-agent` and starts it.
10
+ 2. Packs the two files into an ISO whose volume is labelled `cidata`, which is how cloud-init's NoCloud source recognises it:
11
+ `hdiutil makehybrid -iso -joliet -default-volume-name cidata -o seed.iso seed/`
12
+ 3. Creates the VM with two drives: the cloud image, and the seed on a fixed `VirtIO` drive.
13
+ 4. Grows the disk to the requested size. The image's own size is only a few GiB.
14
+ 5. Starts the VM and waits for the guest agent. cloud-init grows the root filesystem to fill the disk.
15
+
16
+ About a minute from start to a reachable guest, most of it the package install.
17
+
18
+ Do further setup (more packages, files, services) after the first boot with `guest_exec` or SSH.
19
+
20
+ ### Choosing an image
21
+
22
+ - Match the host: `arm64` (also written `aarch64`) on Apple silicon.
23
+ - Take the `.qcow2` (or a `.img` that is qcow2 inside). UTM copies it into the VM.
24
+ - Debian publishes two flavours. **`genericcloud`** has a cut-down kernel: it is smaller and boots fast, but it has no USB storage driver and no 9p driver, so it cannot read a removable (USB) drive and cannot mount a shared folder. **`generic`** has the full kernel. Use `genericcloud` for a plain sandbox and `generic` when you need a shared folder. A `genericcloud` guest can be converted in place: `apt-get install -y linux-image-arm64`, remove `linux-image-cloud-arm64`, reboot.
25
+ - The seed has to be on a drive the kernel can read. That is why the seed goes on a fixed VirtIO drive: a removable drive is USB, and a `genericcloud` guest would boot with cloud-init finding nothing, leaving hostname `localhost`, no user and no agent.
26
+ - Verify the download against the distribution's published checksum before booting it.
27
+
28
+ The seed drive stays attached after first boot. It is harmless: cloud-init acts once per instance id. Its contents are readable inside the guest, so do not put a secret in `user-data`.
29
+
30
+ ## Guest agent
31
+
32
+ `guest_exec`, file transfer and the guest's IP address need it. `create_linux_vm` installs it; on a guest made another way:
33
+
34
+ ```bash
35
+ apt-get install -y qemu-guest-agent && systemctl enable --now qemu-guest-agent
36
+ ```
37
+
38
+ `spice-vdagent` is a different thing (clipboard and display resizing) and does not provide these.
39
+
40
+ ## Shared folder
41
+
42
+ After `set_shared_folder` (mode `VirtFS`), mount it in the guest by its tag, `share`:
43
+
44
+ ```bash
45
+ mkdir -p /mnt/share
46
+ mount -t 9p -o trans=virtio,version=9p2000.L share /mnt/share
47
+ ```
48
+
49
+ - `unknown filesystem type '9p'` means the kernel has no 9p driver. See "Choosing an image".
50
+ - Files appear with the host user's numeric id (usually 501). Root in the guest can read and write them; an ordinary guest user gets `Permission denied` on write. Either work on the share as root, or copy in and out of it.
51
+ - For a mount that survives reboots, add to `/etc/fstab`: `share /mnt/share 9p trans=virtio,version=9p2000.L,nofail 0 0`.
52
+ - Test a write, not just that the directory lists.
53
+
54
+ ## Cloning
55
+
56
+ A clone is a byte-for-byte copy: same MAC address, hostname, machine-id, SSH host keys and cloud-init state. Two copies with the same MAC get the same address and cannot both be on the network.
57
+
58
+ `clone_vm` gives the clone a new MAC. For a cloud-init guest that alone leaves the clone with **no network**: cloud-init wrote a network configuration that matches the interface by the old MAC, so the interface stays down.
59
+
60
+ Reset cloud-init's state so it configures the machine afresh. Either on the source, as the last thing before stopping it to be cloned:
61
+
62
+ ```
63
+ guest_exec command: ["cloud-init", "clean", "--logs", "--machine-id"]
64
+ stop_vm mode: request
65
+ ```
66
+
67
+ or on a clone that has already come up without a network. The guest agent does not need the network, so this works:
68
+
69
+ ```
70
+ guest_exec command: ["sh", "-c", "cloud-init clean --logs --machine-id; systemctl reboot"]
71
+ ```
72
+
73
+ After that boot the clone has its own address, machine-id and SSH host keys. cloud-init also sets the hostname back to the one in the seed, which is the source's, so rename it:
74
+
75
+ ```
76
+ guest_exec command: ["hostnamectl", "set-hostname", "<new name>"]
77
+ ```
78
+
79
+ A source that was cleaned re-runs cloud-init on its own next boot too. That was not exercised here; expect it to behave like a first boot.
80
+
81
+ A template you clone from repeatedly is best kept stopped and cleaned, and never used directly.
82
+
83
+ ## SSH
84
+
85
+ Cloud images run an SSH server and accept only key logins. The user `create_linux_vm` creates has the key you passed and passwordless sudo. With the default shared network, connect to the address from `wait_for_guest` or `get_vm`.
86
+
87
+ Each new VM and each cleaned clone has new host keys, and DHCP reuses addresses, so a stale `known_hosts` entry is normal for throwaway VMs. Use `-o StrictHostKeyChecking=accept-new`, and remove an old entry with `ssh-keygen -R <address>` rather than turning checking off.
@@ -0,0 +1,51 @@
1
+ # utmctl, directly
2
+
3
+ What the MCP server's tools run underneath, for when the server is not connected. Checked on UTM 5.0.9; run `utmctl <subcommand> --help` before relying on a flag elsewhere.
4
+
5
+ ```bash
6
+ UTMCTL=/Applications/UTM.app/Contents/MacOS/utmctl # not on PATH
7
+ ```
8
+
9
+ - It talks to the UTM app and starts it if needed. `--hide` keeps the main window from appearing.
10
+ - It prints `Error from event: … (OSStatus error -10004.)` on stderr during successful calls. Ignore that line and trust the exit code.
11
+ - The first call from a new terminal can raise a macOS prompt asking to let it control UTM.
12
+ - A VM is named by UUID or exact name.
13
+
14
+ | Task | Command |
15
+ |---|---|
16
+ | List VMs | `$UTMCTL list` |
17
+ | Status | `$UTMCTL status <vm>` |
18
+ | Start or resume | `$UTMCTL start <vm> --hide` |
19
+ | Start without saving disk changes | `$UTMCTL start <vm> --hide --disposable` |
20
+ | Ask the guest to shut down | `$UTMCTL stop <vm> --request` |
21
+ | Power off / kill the process | `$UTMCTL stop <vm> --force` / `--kill` |
22
+ | Pause in memory | `$UTMCTL suspend <vm>` |
23
+ | Clone a stopped VM | `$UTMCTL clone <vm> --name <new>` |
24
+ | Delete, with no confirmation | `$UTMCTL delete <vm>` |
25
+
26
+ `start` and `stop --request` return before the guest has finished booting or shutting down. Poll `status`, and poll `ip-address` until it succeeds to know the guest agent is up.
27
+
28
+ ## Inside the guest
29
+
30
+ ```bash
31
+ $UTMCTL exec <vm> --cmd uname -a # exit code, stdout and stderr come back
32
+ $UTMCTL exec <vm> --cmd sh -c 'cd /srv && ls | wc -l' # --cmd takes a program and arguments
33
+ $UTMCTL exec <vm> --env NAME=value --cmd printenv NAME
34
+ echo data | $UTMCTL exec <vm> --input --cmd tee /tmp/in.txt
35
+ $UTMCTL file push <vm> /tmp/remote.bin < local.bin
36
+ $UTMCTL file pull <vm> /var/log/syslog > syslog.txt
37
+ $UTMCTL ip-address <vm>
38
+ ```
39
+
40
+ `--cmd` must come last; everything after it is the command.
41
+
42
+ ## Snapshots
43
+
44
+ ```bash
45
+ $UTMCTL snapshot create <vm> --name before-upgrade
46
+ $UTMCTL snapshot list <vm> --json
47
+ $UTMCTL snapshot restore <vm> --snapshot before-upgrade
48
+ $UTMCTL snapshot delete <vm> --snapshot before-upgrade
49
+ ```
50
+
51
+ On the Apple Virtualization backend, UTM's documentation says snapshots need macOS 27 and a stopped or suspended VM. Not checked here.