loopctl-mcp-server 3.46.0 → 3.46.1

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/lib/api-keys.js CHANGED
@@ -15,7 +15,7 @@
15
15
  import { isAbsolute } from "node:path";
16
16
 
17
17
  import { uuid } from "./delivery-loop.js";
18
- import { createSecretFile } from "./secret-file.js";
18
+ import { createSecretFile, secretOutcomeUnknown, unknownOutcomeDetail } from "./secret-file.js";
19
19
 
20
20
  export const API_KEY_ROLES = ["user", "orchestrator", "agent"];
21
21
 
@@ -78,7 +78,7 @@ export async function apiKeyCreate(
78
78
 
79
79
  if (!created || typeof created.raw_key !== "string") {
80
80
  sink.discardSecret();
81
- return transportUnknown(result) ? mayHaveMinted(result, name) : stripRaw(result);
81
+ return secretOutcomeUnknown(result) ? mayHaveMinted(result, name) : stripRaw(result);
82
82
  }
83
83
 
84
84
  const { raw_key, ...rest } = created;
@@ -215,7 +215,7 @@ export async function apiKeyRotate(
215
215
 
216
216
  if (!minted || typeof minted.raw_key !== "string") {
217
217
  sink.discardSecret();
218
- return transportUnknown(result) ? mayHaveRotated(result, api_key_id) : result;
218
+ return secretOutcomeUnknown(result) ? mayHaveRotated(result, api_key_id) : result;
219
219
  }
220
220
 
221
221
  const { raw_key, ...rest } = minted;
@@ -240,9 +240,10 @@ export async function apiKeyRotate(
240
240
 
241
241
  function mayHaveRotated(result, keyId) {
242
242
  return {
243
- ...result,
243
+ error: true,
244
+ status: result && Number.isInteger(result.status) ? result.status : 0,
244
245
  body:
245
- `${typeof result.body === "string" ? result.body : JSON.stringify(result.body)}. ` +
246
+ `Rotation outcome unknown (${unknownOutcomeDetail(result)}). ` +
246
247
  `The request may have rotated ${keyId}, minting a replacement whose raw value is lost, ` +
247
248
  `and if it did, ${keyId} now expires when its grace period ends. Before then, list the ` +
248
249
  "tenant's keys (api_key_list) and, if a second key by that name appeared, revoke it and " +
@@ -251,17 +252,12 @@ function mayHaveRotated(result, keyId) {
251
252
  };
252
253
  }
253
254
 
254
- // status 0 is apiCall's transport failure (a timeout, a dropped connection): the server may
255
- // have committed the mint before the answer was lost.
256
- function transportUnknown(result) {
257
- return Boolean(result && result.error && result.status === 0);
258
- }
259
-
260
255
  function mayHaveMinted(result, name) {
261
256
  return {
262
- ...result,
257
+ error: true,
258
+ status: result && Number.isInteger(result.status) ? result.status : 0,
263
259
  body:
264
- `${typeof result.body === "string" ? result.body : JSON.stringify(result.body)}. ` +
260
+ `Mint outcome unknown (${unknownOutcomeDetail(result)}). ` +
265
261
  `The request may have minted a key named "${name}" whose raw value is lost: list the ` +
266
262
  "tenant's keys (GET /api/v1/api_keys) and revoke any by that name before retrying.",
267
263
  };
@@ -12,6 +12,33 @@
12
12
 
13
13
  import { closeSync, openSync, unlinkSync, writeSync } from "node:fs";
14
14
 
15
+ /**
16
+ * Whether a request that should have produced a secret, and did not hand one over, may still
17
+ * have created the record that holds it. Only two answers are certain that nothing was created:
18
+ * a 4xx refusal from loopctl, and a status-0 refusal marked `not_sent` (index.js `sendRequest`,
19
+ * no key configured), which sent nothing. Every other answer may follow a committed create: a
20
+ * transport failure (status 0), a proxy's 502/503/504, a 500 raised after the insert, and a 2xx
21
+ * whose body failed to parse or lacked the secret. Same rule as `lib/runners.js`
22
+ * (`ambiguousEnrollment`): only a 4xx is an unambiguous refusal.
23
+ */
24
+ export function secretOutcomeUnknown(result) {
25
+ if (result && result.error === true && result.not_sent === true) return false;
26
+ const status = result && Number.isInteger(result.status) ? result.status : undefined;
27
+ return !(result && result.error === true && status >= 400 && status < 500);
28
+ }
29
+
30
+ /**
31
+ * What to say about an unknown outcome without echoing the answer: any body other than a
32
+ * transport error's message may be the created record itself, secret included (a truncated
33
+ * 2xx arrives as `{error: true, status: 201, body: "<raw text>"}`).
34
+ */
35
+ export function unknownOutcomeDetail(result) {
36
+ const status = result && Number.isInteger(result.status) ? result.status : undefined;
37
+ return status === 0 && typeof result.body === "string"
38
+ ? result.body
39
+ : `HTTP ${status ?? "?"}; response body withheld: it may contain the secret`;
40
+ }
41
+
15
42
  export function createSecretFile(path) {
16
43
  const fd = openSync(path, "wx", 0o600);
17
44
  let open = true;
package/lib/webhooks.js CHANGED
@@ -31,8 +31,7 @@
31
31
  import { isAbsolute } from "node:path";
32
32
 
33
33
  import { uuid } from "./delivery-loop.js";
34
- import { GATEWAY_STATUSES } from "./holder-journal.js";
35
- import { createSecretFile } from "./secret-file.js";
34
+ import { createSecretFile, secretOutcomeUnknown, unknownOutcomeDetail } from "./secret-file.js";
36
35
 
37
36
  export const WEBHOOK_MAX_PAGE_SIZE = 100;
38
37
 
@@ -160,7 +159,7 @@ export async function webhookCreate(
160
159
 
161
160
  if (!created || typeof created.signing_secret !== "string") {
162
161
  sink.discardSecret();
163
- return transportUnknown(result) ? mayHaveCreated(result, url) : stripSecret(result);
162
+ return secretOutcomeUnknown(result) ? mayHaveCreated(result, url) : stripSecret(result);
164
163
  }
165
164
 
166
165
  const { signing_secret, ...rest } = created;
@@ -251,21 +250,12 @@ export async function webhookDeliveries({ webhook_id, page, page_size } = {}, {
251
250
  return apiCall("GET", webhookDeliveriesPath(webhook_id, query), null);
252
251
  }
253
252
 
254
- // The outcome is unknown when the answer did not come from loopctl: status 0 is apiCall's
255
- // transport failure (a timeout, a dropped connection), and a 502/503/504 is the proxy's. Either
256
- // can follow a committed create. A status-0 refusal marked `not_sent` (no key configured) sent
257
- // nothing, so it is an ordinary failure.
258
- function transportUnknown(result) {
259
- if (!result || !result.error) return false;
260
- if (result.status === 0) return result.not_sent !== true;
261
- return GATEWAY_STATUSES.includes(result.status);
262
- }
263
-
264
253
  function mayHaveCreated(result, url) {
265
254
  return {
266
- ...result,
255
+ error: true,
256
+ status: result && Number.isInteger(result.status) ? result.status : 0,
267
257
  body:
268
- `${typeof result.body === "string" ? result.body : JSON.stringify(result.body)}. ` +
258
+ `Create outcome unknown (${unknownOutcomeDetail(result)}). ` +
269
259
  `The request may have created a webhook for ${url} whose signing secret is lost: list ` +
270
260
  "the tenant's webhooks (webhook_list) and delete any for that URL before retrying.",
271
261
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "loopctl-mcp-server",
3
- "version": "3.46.0",
3
+ "version": "3.46.1",
4
4
  "description": "MCP server for loopctl — structural trust for AI development loops",
5
5
  "type": "module",
6
6
  "main": "index.js",