@wezzard/mcp-relay 0.17.0 → 0.18.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/.claude-plugin/plugin.json +1 -1
- package/README.md +8 -6
- package/dist/build-info.json +5 -4
- package/dist/doctor.mjs +55 -17
- package/dist/integrity.json +2 -2
- package/dist/server.mjs +799 -613
- package/package.json +1 -1
- package/pi-mcp.json +1 -1
package/README.md
CHANGED
|
@@ -308,10 +308,11 @@ a real Mac that machine-service exposes, such as `Build-Mac-1`. Every other
|
|
|
308
308
|
tool works on it as on a VM ([docs/durable-machines.md](docs/durable-machines.md)).
|
|
309
309
|
|
|
310
310
|
- The relay finds the instance that owns the machine as `machctl list` does:
|
|
311
|
-
the loopback instance, then every
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
311
|
+
the loopback instance, then every instance that advertises
|
|
312
|
+
`_machine-service._tcp` with Bonjour on the network, so a Mac needs nothing
|
|
313
|
+
else installed. With `MACHINE_SERVICE_DISCOVERY=consul` it asks the Consul
|
|
314
|
+
agent at `CONSUL_HTTP_ADDR` (default `http://127.0.0.1:8500`) instead. Each
|
|
315
|
+
instance found is used only once its `/health` confirms its ID.
|
|
315
316
|
- Every call carries the lease's `lease_id`, files go as bytes, and the relay
|
|
316
317
|
stages under the lease's workspace, which machine-service removes at release.
|
|
317
318
|
- Runs take snapshots only while the Mac's cua-driver daemon (`CuaDriver.app`,
|
|
@@ -371,8 +372,9 @@ keeps the VM for a retry after space is freed.
|
|
|
371
372
|
|
|
372
373
|
- `MCP_RELAY_PROJECT`: the project directory (the plugin passes Claude Code's). Evidence lands under `relay-evidence/<task>/` there. Every host file the relay reads, `relay_stage`'s `workspace` and `files[].local` and `relay_script`'s `localPath`, lies in this folder: a relative path resolves against it, an absolute path must already lie in it, and a path through a symlink is refused.
|
|
373
374
|
- `MCP_RELAY_SESSION`: an explicit session identity. By default each server process takes a fresh random one; a stable identity lets a restarted server reconcile and reattach the guests of the same identity.
|
|
374
|
-
- `MCP_RELAY_URL`: the loopback machine-service origin, default `http://localhost:6240`. Non-loopback servers and redirects are refused; a durable machine's instance on another Mac is reached only when
|
|
375
|
-
- `
|
|
375
|
+
- `MCP_RELAY_URL`: the loopback machine-service origin, default `http://localhost:6240`. Non-loopback servers and redirects are refused; a durable machine's instance on another Mac is reached only when discovery finds it.
|
|
376
|
+
- `MACHINE_SERVICE_DISCOVERY`: how durable machines' instances are found, `bonjour` (the default) or `consul`, as for machine-service and machctl.
|
|
377
|
+
- `CONSUL_HTTP_ADDR`: the Consul agent that lists machine-service instances, in Consul mode; default `http://127.0.0.1:8500`.
|
|
376
378
|
- `MCP_RELAY_GUEST_NETWORK`: the network every guest is acquired on, `nat` (the default) or `internet`. With `internet`, machine-service gives a guest that reaches the internet and reaches neither this host nor any private network; an application that hosts agents sets it. The agent cannot choose it: `relay_acquire` takes no network. Any other value stops the server at startup and refuses every acquisition, and a machine-service that cannot give `internet` refuses the acquisition with its own reason, never falling back to `nat`.
|
|
377
379
|
- `MCP_RELAY_ON_EXIT`: what the end of a session does to its guests, `pause` (the default: renewal pauses and the VMs are kept for an explicit finish or release) or `release` (every guest is released, then the server exits). An application that owns its tasks' machines, such as The Desk, sets `release`. Any other value stops the server at startup.
|
|
378
380
|
- `MCP_RELAY_CAPACITY_WAIT`: how many seconds `relay_acquire` waits when the host is at capacity, such as at machine-service's limit of two running macOS VMs, asking again every 15 s; default 1800, and 0 for not at all. Any other value stops the server at startup.
|
package/dist/build-info.json
CHANGED
|
@@ -958,7 +958,7 @@
|
|
|
958
958
|
"src/config.ts": "3fbc475596ec0a1b6122ea963bf2769420a8a2a0e62fda55e66018fb3a6d53b3",
|
|
959
959
|
"src/console.ts": "d8258173a24449c2a394289b14983b9575c5ce753ab267d4e13213f3abfcb72d",
|
|
960
960
|
"src/core.ts": "dd889fda6af982ab47b40b346e7fbc41a213b6d258d3d5fe56cd8c5373221159",
|
|
961
|
-
"src/discovery.ts": "
|
|
961
|
+
"src/discovery.ts": "cd66b470615f7e2bf1d5d2cdf8065b6e0ec601a0929f7be063bc18bfcfbc342d",
|
|
962
962
|
"src/doctor.ts": "8249e9fa78b679e9ef7fd30f617bf07848961346101d3b64c42f779cfb042671",
|
|
963
963
|
"src/downloads.ts": "4f37b5bb4fac96f9260a3a87c83bacf715b9add5ae9926d3fe0994000c70a8dd",
|
|
964
964
|
"src/environment.ts": "5770e966e49d78ae069614078c667f94e70074b150f83111049529ff613aa215",
|
|
@@ -966,9 +966,10 @@
|
|
|
966
966
|
"src/guest/image-evidence.ts": "9c5daaed5b33b9912021a91fd79a2e6d5be42c75d37761772a3bd2645d20a55e",
|
|
967
967
|
"src/guest/receiver.ts": "92fc8d3bfe95ed56d43cfe5b46eb196034ade5e4e9f58ed202465531458f697d",
|
|
968
968
|
"src/image-presentation.ts": "64ca29a3444a04606cb783c81ac2d0f3136f9a9ac730ae9074156f0a63256c76",
|
|
969
|
-
"src/images.ts": "
|
|
970
|
-
"src/machine-service.ts": "
|
|
971
|
-
"src/manager.ts": "
|
|
969
|
+
"src/images.ts": "415bfb37966a60ef3e407236295b9aeeb314f7fb33de55a6ada512cff6661908",
|
|
970
|
+
"src/machine-service.ts": "1f7c63d295b2551728f975451bd1ab29a57cf4cab9f16510b7e3fcd1a6160205",
|
|
971
|
+
"src/manager.ts": "7bbff05dd7d3c3c98f2d71e72834e1e08b0c96a963fb76876895537d75436749",
|
|
972
|
+
"src/mdns.ts": "b85df92dfe3cd0807725a3115ecfdd21d1530a98528b6a55454370d6e4baf98c",
|
|
972
973
|
"src/owner-lock.ts": "a99cbaba67b4aff0e646dc5d5967db4497ba6dbda83fb1838c55f0bf0f6e0367",
|
|
973
974
|
"src/package.ts": "a52ed791813922e3ace9144706ddde8313a67d8580a3acd54a0799de3ebe44d2",
|
|
974
975
|
"src/probe.ts": "40a123f725aad7c22fe63707dd2de99646cb1f307d7d660927e8ca2b973e9ce0",
|
package/dist/doctor.mjs
CHANGED
|
@@ -48,6 +48,7 @@ async function command(argv, options = {}) {
|
|
|
48
48
|
// src/machine-service.ts
|
|
49
49
|
import { isIP } from "node:net";
|
|
50
50
|
import { createHash as createHash2 } from "node:crypto";
|
|
51
|
+
import { open, rm } from "node:fs/promises";
|
|
51
52
|
var MachineServiceError = class extends Error {
|
|
52
53
|
constructor(message, status, responseBody, options) {
|
|
53
54
|
super(message, options);
|
|
@@ -77,6 +78,7 @@ function expectMachineService(health, origin) {
|
|
|
77
78
|
if (health.service === SERVICE_NAME) return;
|
|
78
79
|
throw new Error(`The service at ${origin} answers as ${JSON.stringify(health.service ?? null)}, not ${SERVICE_NAME}. This relay speaks only machine-service's /machines API: install machine-service, which replaced vm-service.`);
|
|
79
80
|
}
|
|
81
|
+
var PULL_IDLE_MS = 12e4;
|
|
80
82
|
var AcquireIndeterminateError = class extends MachineServiceError {
|
|
81
83
|
constructor(purpose, cause) {
|
|
82
84
|
super(`Acquisition outcome unknown for purpose '${purpose}'; reconcile GET /machines before retrying or ending the enclosure`, void 0, void 0, { cause });
|
|
@@ -118,7 +120,7 @@ var MachineService = class {
|
|
|
118
120
|
const host = url.hostname.replace(/^\[|\]$/g, "");
|
|
119
121
|
const loopback = host === "localhost" || host === "::1" || isIP(host) === 4 && host.startsWith("127.");
|
|
120
122
|
if (!loopback && !options.listed || !["http:", "https:"].includes(url.protocol) || url.username || url.password || url.search || url.hash || url.pathname !== "/") {
|
|
121
|
-
throw new TypeError("machine-service baseUrl must be a loopback HTTP(S) origin, or one
|
|
123
|
+
throw new TypeError("machine-service baseUrl must be a loopback HTTP(S) origin, or one discovery found, without credentials, path, query or fragment");
|
|
122
124
|
}
|
|
123
125
|
this.baseUrl = url.origin;
|
|
124
126
|
this.timeoutMs = positive(options.timeoutMs ?? 66e4, "timeoutMs");
|
|
@@ -205,18 +207,39 @@ var MachineService = class {
|
|
|
205
207
|
*/
|
|
206
208
|
async pushBytes(vm, body, options = {}) {
|
|
207
209
|
const sha256 = createHash2("sha256").update(body.bytes).digest("hex");
|
|
208
|
-
const response = await this.fetchBounded(this.filesPath(vm, body.remote_path, body.lease_id), { method: "PUT", headers: { "Content-Type": "application/octet-stream", "X-Content-SHA256": sha256 }, body: new Uint8Array(body.bytes) }, options, this.maxResponseBytes);
|
|
210
|
+
const response = await this.fetchBounded(this.filesPath(vm, body.remote_path, body.lease_id), { method: "PUT", headers: { "Content-Type": "application/octet-stream", "X-Content-SHA256": sha256 }, body: new Uint8Array(body.bytes.buffer, body.bytes.byteOffset, body.bytes.byteLength) }, options, this.maxResponseBytes);
|
|
209
211
|
const answer = this.json(response.path, response.text);
|
|
210
212
|
if (answer.sha256 !== sha256 || answer.bytes !== body.bytes.length) throw new MachineServiceError(`machine-service ${response.path}: the instance stored ${answer.bytes} bytes with SHA-256 ${answer.sha256}, not what was sent`);
|
|
211
213
|
return answer;
|
|
212
214
|
}
|
|
213
|
-
/**
|
|
215
|
+
/**
|
|
216
|
+
* Pull one file as bytes, `GET /machines/<name>/files`, into `to`, which
|
|
217
|
+
* must not exist. The bytes stream to disk as they are hashed, so a file of
|
|
218
|
+
* any size needs no memory of its size, and the pull is abandoned only when
|
|
219
|
+
* no byte arrives for its timeout. The file is removed unless the bytes
|
|
220
|
+
* match the digest the instance states (DC-31).
|
|
221
|
+
*/
|
|
214
222
|
async pullBytes(vm, body, options = {}) {
|
|
215
|
-
const
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
223
|
+
const hash2 = createHash2("sha256"), file = await open(body.to, "wx", 384);
|
|
224
|
+
let bytes = 0;
|
|
225
|
+
try {
|
|
226
|
+
const response = await this.fetchBounded(this.filesPath(vm, body.remote_path, body.lease_id), { method: "GET" }, { ...options, timeoutMs: options.timeoutMs ?? PULL_IDLE_MS }, Number.MAX_SAFE_INTEGER, { idle: true, sink: async (chunk) => {
|
|
227
|
+
hash2.update(chunk);
|
|
228
|
+
bytes += chunk.byteLength;
|
|
229
|
+
await file.write(chunk);
|
|
230
|
+
} });
|
|
231
|
+
if (response.contentType !== "application/octet-stream") throw new MachineServiceError(`machine-service ${response.path}: expected one file, got ${response.contentType ?? "no content type"}`);
|
|
232
|
+
const digest = hash2.digest("hex");
|
|
233
|
+
if (!response.sha256 || digest !== response.sha256.toLowerCase()) throw new MachineServiceError(`machine-service ${response.path}: the bytes' SHA-256 ${digest} differs from the stated ${response.sha256 ?? "none"}`);
|
|
234
|
+
await file.sync();
|
|
235
|
+
await file.close();
|
|
236
|
+
return { sha256: digest, bytes };
|
|
237
|
+
} catch (error) {
|
|
238
|
+
await file.close().catch(() => {
|
|
239
|
+
});
|
|
240
|
+
await rm(body.to, { force: true });
|
|
241
|
+
throw error;
|
|
242
|
+
}
|
|
220
243
|
}
|
|
221
244
|
filesPath(vm, remote, lease_id) {
|
|
222
245
|
const query = new URLSearchParams({ ...lease_id ? { lease_id } : {}, path: remote });
|
|
@@ -241,14 +264,20 @@ var MachineService = class {
|
|
|
241
264
|
throw new MachineServiceError(`machine-service ${path}: invalid JSON response`, void 0, void 0, { cause });
|
|
242
265
|
}
|
|
243
266
|
}
|
|
244
|
-
/**
|
|
245
|
-
|
|
267
|
+
/**
|
|
268
|
+
* One request whose answer is read up to `maxBytes`; an error answer is read
|
|
269
|
+
* up to 4 KiB and thrown with its status. With `sink`, a successful answer is
|
|
270
|
+
* handed over chunk by chunk instead of kept; with `idle`, the timeout counts
|
|
271
|
+
* from the last chunk rather than from the start.
|
|
272
|
+
*/
|
|
273
|
+
async fetchBounded(path, init, options, maxBytes, stream = {}) {
|
|
246
274
|
options.signal?.throwIfAborted();
|
|
247
275
|
const timeoutMs = positive(options.timeoutMs ?? this.timeoutMs, "timeoutMs");
|
|
248
276
|
const controller = new AbortController();
|
|
249
277
|
const abort = () => controller.abort(options.signal?.reason);
|
|
250
278
|
options.signal?.addEventListener("abort", abort, { once: true });
|
|
251
|
-
const
|
|
279
|
+
const expire = () => controller.abort(new MachineServiceError(`machine-service ${path} timed out after ${timeoutMs}ms${stream.idle ? " without a byte" : ""}`));
|
|
280
|
+
let timer = setTimeout(expire, timeoutMs);
|
|
252
281
|
try {
|
|
253
282
|
const response = await fetch(`${this.baseUrl}${path}`, {
|
|
254
283
|
method: init.method,
|
|
@@ -268,6 +297,15 @@ var MachineService = class {
|
|
|
268
297
|
for (; ; ) {
|
|
269
298
|
const { value, done } = await reader.read();
|
|
270
299
|
if (done) break;
|
|
300
|
+
if (stream.idle) {
|
|
301
|
+
clearTimeout(timer);
|
|
302
|
+
timer = setTimeout(expire, timeoutMs);
|
|
303
|
+
}
|
|
304
|
+
if (response.ok && stream.sink) {
|
|
305
|
+
size += value.byteLength;
|
|
306
|
+
await stream.sink(value);
|
|
307
|
+
continue;
|
|
308
|
+
}
|
|
271
309
|
const remaining = bound - size;
|
|
272
310
|
chunks.push(value.subarray(0, remaining));
|
|
273
311
|
size += Math.min(value.byteLength, remaining);
|
|
@@ -288,7 +326,7 @@ var MachineService = class {
|
|
|
288
326
|
} catch (cause) {
|
|
289
327
|
if (controller.signal.aborted) throw controller.signal.reason;
|
|
290
328
|
if (cause instanceof MachineServiceError) throw cause;
|
|
291
|
-
throw new MachineServiceError(`machine-service ${path}: request failed`, void 0, void 0, { cause });
|
|
329
|
+
throw new MachineServiceError(`machine-service ${path}: request failed${cause instanceof Error ? `: ${cause.message}` : ""}`, void 0, void 0, { cause });
|
|
292
330
|
} finally {
|
|
293
331
|
clearTimeout(timer);
|
|
294
332
|
options.signal?.removeEventListener("abort", abort);
|
|
@@ -298,7 +336,7 @@ var MachineService = class {
|
|
|
298
336
|
|
|
299
337
|
// src/registry.ts
|
|
300
338
|
import { randomUUID as randomUUID2 } from "node:crypto";
|
|
301
|
-
import { link, lstat, mkdir, open, readFile, realpath, rename, unlink } from "node:fs/promises";
|
|
339
|
+
import { link, lstat, mkdir, open as open2, readFile, realpath, rename, unlink } from "node:fs/promises";
|
|
302
340
|
import { readFileSync as readFileSync2, statSync as statSync2 } from "node:fs";
|
|
303
341
|
import { homedir as homedir3 } from "node:os";
|
|
304
342
|
|
|
@@ -648,7 +686,7 @@ var Registry = class {
|
|
|
648
686
|
const updated = transform(original);
|
|
649
687
|
if (original === updated) return false;
|
|
650
688
|
temporary = join3(dirname2(target), `.${target.split("/").at(-1)}.${token}.tmp`);
|
|
651
|
-
const handle = await
|
|
689
|
+
const handle = await open2(temporary, "wx", before.mode & 511);
|
|
652
690
|
try {
|
|
653
691
|
await handle.chmod(before.mode & 511);
|
|
654
692
|
await handle.writeFile(updated, "utf8");
|
|
@@ -664,7 +702,7 @@ var Registry = class {
|
|
|
664
702
|
lock.check();
|
|
665
703
|
await rename(temporary, target);
|
|
666
704
|
temporary = void 0;
|
|
667
|
-
const dir = await
|
|
705
|
+
const dir = await open2(dirname2(target), "r");
|
|
668
706
|
try {
|
|
669
707
|
await dir.sync();
|
|
670
708
|
} finally {
|
|
@@ -691,7 +729,7 @@ var Registry = class {
|
|
|
691
729
|
if (!errno(error, "ENOENT")) throw error;
|
|
692
730
|
}
|
|
693
731
|
const temporary = join3(dirname2(target), `.registry.${randomUUID2()}.tmp`);
|
|
694
|
-
const handle = await
|
|
732
|
+
const handle = await open2(temporary, "wx", 384);
|
|
695
733
|
try {
|
|
696
734
|
try {
|
|
697
735
|
await handle.chmod(384);
|
|
@@ -706,7 +744,7 @@ var Registry = class {
|
|
|
706
744
|
} catch (error) {
|
|
707
745
|
if (!errno(error, "EEXIST")) throw error;
|
|
708
746
|
}
|
|
709
|
-
const dir = await
|
|
747
|
+
const dir = await open2(dirname2(target), "r");
|
|
710
748
|
try {
|
|
711
749
|
await dir.sync();
|
|
712
750
|
} finally {
|
package/dist/integrity.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
|
-
"server.mjs": "
|
|
2
|
+
"server.mjs": "2b04c5cf78833f392f9fe8570a0099a1f276c2c24ad036dc8107f9c24371c95a",
|
|
3
3
|
"receiver.mjs": "8b5b6fdd6cb789cdc4060e367a155cb42e7cf34187044c899789bf76b7bb0e14",
|
|
4
|
-
"doctor.mjs": "
|
|
4
|
+
"doctor.mjs": "4e3d5a58ead4be3afe461691b6bff6f1f933bbde70b19fd67677f158975b6e3f",
|
|
5
5
|
"review-data.mjs": "da7b6b35d060e09cfc445df4febda02a1a0c0f23d9b854866aed8d604cbb3993"
|
|
6
6
|
}
|