machine-bridge-mcp 1.2.1 → 1.2.5

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.
@@ -5,8 +5,8 @@ const SENSITIVE_FIELD = /(?:authorization|cookie|credential|password|secret|toke
5
5
  export class WorkerObservability {
6
6
  private readonly startedAt = performance.now();
7
7
  private readonly requests = { total: 0, successful: 0, client_error: 0, server_error: 0 };
8
- private readonly calls = { started: 0, completed: 0, failed: 0, cancelled: 0, timed_out: 0 };
9
- private readonly sockets = { candidates: 0, authenticated: 0, disconnected: 0, protocol_errors: 0 };
8
+ private readonly calls = { started: 0, completed: 0, failed: 0, cancelled: 0, timed_out: 0, unmatched_results: 0 };
9
+ private readonly sockets = { candidates: 0, authenticated: 0, ready: 0, disconnected: 0, protocol_errors: 0 };
10
10
  private readonly errors = new Map<string, number>();
11
11
  private readonly tools = new Map<string, { started: number; completed: number; failed: number; active: number }>();
12
12
 
@@ -39,8 +39,11 @@ export class WorkerObservability {
39
39
  this.incrementError(code);
40
40
  }
41
41
 
42
+ unmatchedResult(): void { this.calls.unmatched_results += 1; }
43
+
42
44
  socketCandidate(): void { this.sockets.candidates += 1; }
43
45
  socketAuthenticated(): void { this.sockets.authenticated += 1; }
46
+ socketReady(): void { this.sockets.ready += 1; }
44
47
  socketDisconnected(): void { this.sockets.disconnected += 1; }
45
48
  socketProtocolError(code: string): void {
46
49
  this.sockets.protocol_errors += 1;
@@ -19,6 +19,8 @@ export interface PendingCallRecord {
19
19
  timeout: ReturnType<typeof setTimeout>;
20
20
  resolve: (value: unknown) => void;
21
21
  reject: (error: Error) => void;
22
+ signal?: AbortSignal;
23
+ abortHandler?: () => void;
22
24
  }
23
25
 
24
26
  interface RegisterPendingCall {
@@ -28,6 +30,8 @@ interface RegisterPendingCall {
28
30
  tool: string;
29
31
  timeoutMs: number;
30
32
  onTimeout: (record: PendingCallRecord) => Error;
33
+ signal?: AbortSignal;
34
+ onAbort?: (record: PendingCallRecord) => Error;
31
35
  }
32
36
 
33
37
  export class PendingCallRegistry {
@@ -63,6 +67,14 @@ export class PendingCallRegistry {
63
67
  catch { error = new Error("pending daemon call timed out"); }
64
68
  reject(error instanceof Error ? error : new Error("pending daemon call timed out"));
65
69
  }, input.timeoutMs);
70
+ const abortHandler = () => {
71
+ const record = this.take(input.id);
72
+ if (!record) return;
73
+ let error: unknown;
74
+ try { error = input.onAbort?.(record); }
75
+ catch { error = new Error("pending daemon call was cancelled"); }
76
+ reject(error instanceof Error ? error : new Error("pending daemon call was cancelled"));
77
+ };
66
78
  const record: PendingCallRecord = {
67
79
  id: input.id,
68
80
  socket: input.socket,
@@ -72,9 +84,13 @@ export class PendingCallRegistry {
72
84
  timeout,
73
85
  resolve,
74
86
  reject,
87
+ signal: input.signal,
88
+ abortHandler: input.signal ? abortHandler : undefined,
75
89
  };
76
90
  this.byId.set(input.id, record);
77
91
  if (input.clientRequestKey) this.byRequestKey.set(input.clientRequestKey, input.id);
92
+ if (input.signal?.aborted) abortHandler();
93
+ else input.signal?.addEventListener("abort", abortHandler, { once: true });
78
94
  });
79
95
  }
80
96
 
@@ -131,6 +147,7 @@ export class PendingCallRegistry {
131
147
  const record = this.byId.get(id);
132
148
  if (!record) return undefined;
133
149
  clearTimeout(record.timeout);
150
+ if (record.signal && record.abortHandler) record.signal.removeEventListener("abort", record.abortHandler);
134
151
  this.byId.delete(id);
135
152
  if (record.clientRequestKey && this.byRequestKey.get(record.clientRequestKey) === id) {
136
153
  this.byRequestKey.delete(record.clientRequestKey);
package/wrangler.jsonc CHANGED
@@ -3,7 +3,7 @@
3
3
  "name": "machine-bridge-mcp",
4
4
  "main": "src/worker/index.ts",
5
5
  "compatibility_date": "2026-07-11",
6
- "compatibility_flags": ["nodejs_compat"],
6
+ "compatibility_flags": ["nodejs_compat", "enable_request_signal", "request_signal_passthrough"],
7
7
  "workers_dev": true,
8
8
  "durable_objects": {
9
9
  "bindings": [