@50arms/platform-mcp 0.1.577 → 0.1.578
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/dist/http-client.js +40 -4
- package/dist/index.js +3 -2
- package/dist/listener-reminder.js +13 -0
- package/dist/machine-toolkit.js +1 -1
- package/dist/reply-reminders-header.js +25 -0
- package/package.json +1 -1
package/dist/http-client.js
CHANGED
|
@@ -58,6 +58,8 @@
|
|
|
58
58
|
*/
|
|
59
59
|
import { appVersionOf } from "./app-version.js";
|
|
60
60
|
import { BEHAVIOR_SIGNOFFS_HEADER } from "./behavior-signoffs.js";
|
|
61
|
+
import { mergeReminders } from "./listener-reminder.js";
|
|
62
|
+
import { replyRemindersOf } from "./reply-reminders-header.js";
|
|
61
63
|
import { boardStampOf, isReadRoute, takesBoardInBody, } from "./route-board-scope.js";
|
|
62
64
|
import { assertVersionFloorSatisfied, clientVersionHeaders, MCP_MIN_VERSION_HEADER, } from "./version-floor.js";
|
|
63
65
|
import { PLUGIN_BACKGROUND_HEADER } from "./session-options.js";
|
|
@@ -105,6 +107,21 @@ function describeFailure(err) {
|
|
|
105
107
|
const cause = err.cause instanceof Error ? `: ${err.cause.message}` : "";
|
|
106
108
|
return `${err.message}${cause}`;
|
|
107
109
|
}
|
|
110
|
+
/**
|
|
111
|
+
* DX-8178 - whether an answer has no JSON body, decided by its status and its Content-Type, never by what headers the dashboard added: any 3xx (handed over with its `location`), a body-less
|
|
112
|
+
* 204, and a Content-Type that is present and is not JSON (`application/json` or `+json`).
|
|
113
|
+
*/
|
|
114
|
+
function isNonJsonAnswer(status, headers) {
|
|
115
|
+
if ((status >= 300 && status < 400) || status === 204)
|
|
116
|
+
return true;
|
|
117
|
+
const type = (headers.get("content-type") ?? "")
|
|
118
|
+
.split(";")[0]
|
|
119
|
+
.trim()
|
|
120
|
+
.toLowerCase();
|
|
121
|
+
return !(type === "" ||
|
|
122
|
+
type === "application/json" ||
|
|
123
|
+
type.endsWith("+json"));
|
|
124
|
+
}
|
|
108
125
|
/** Whether an attempt got the dashboard's own answer, was told to come back (it is up, and busy), or got none. */
|
|
109
126
|
function verdictOf(attempt) {
|
|
110
127
|
if (attempt.kind === "failed")
|
|
@@ -272,6 +289,8 @@ export class DashboardHttpClient {
|
|
|
272
289
|
headers: init.headers,
|
|
273
290
|
body: init.body,
|
|
274
291
|
signal: bound.signal,
|
|
292
|
+
// DX-8178: a 3xx is the route's answer (an attachment's signed URL), handed to the agent with its `location`, never followed.
|
|
293
|
+
redirect: "manual",
|
|
275
294
|
});
|
|
276
295
|
return {
|
|
277
296
|
kind: "response",
|
|
@@ -340,8 +359,15 @@ export class DashboardHttpClient {
|
|
|
340
359
|
if (res.status >= 500) {
|
|
341
360
|
throw new DashboardServerError(`[platform-mcp] server error ${res.status} on ${method} ${url}: ${text.slice(0, 500)}`, { status: res.status, write, text: text.slice(0, 500) });
|
|
342
361
|
}
|
|
362
|
+
// DX-8178: the reply policy of every answer rides the header `X-Danx-Reply-Reminders`; a JSON answer also has its body's `reminders[]`, a non-JSON one has only this.
|
|
363
|
+
const headerReminders = replyRemindersOf(res.headers);
|
|
364
|
+
const redirected = res.status >= 300 && res.status < 400;
|
|
365
|
+
const jsonBody = !isNonJsonAnswer(res.status, res.headers);
|
|
366
|
+
// A non-JSON refusal (a 4xx that is not JSON) is a server-side fault as before: fail loud with its text. The envelope below is for a 3xx, a 204 or a download.
|
|
367
|
+
if (!jsonBody && res.status >= 400)
|
|
368
|
+
throw new Error(`[platform-mcp] non-JSON response (status ${res.status}) from ${method} ${url}: ${text.slice(0, 200)}`);
|
|
343
369
|
let parsed = null;
|
|
344
|
-
if (text !== "") {
|
|
370
|
+
if (jsonBody && text !== "") {
|
|
345
371
|
try {
|
|
346
372
|
parsed = JSON.parse(text);
|
|
347
373
|
}
|
|
@@ -354,10 +380,20 @@ export class DashboardHttpClient {
|
|
|
354
380
|
// DX-7767: the plugin sees no HTTP headers, so the app version rides the envelope.
|
|
355
381
|
const appVersion = appVersionOf(res.headers);
|
|
356
382
|
const version = appVersion === undefined ? {} : { app_version: appVersion };
|
|
357
|
-
|
|
358
|
-
|
|
383
|
+
const ok = res.status >= 200 && res.status < 400;
|
|
384
|
+
if (!jsonBody) {
|
|
385
|
+
const location = res.headers.get("location");
|
|
386
|
+
return {
|
|
387
|
+
ok,
|
|
388
|
+
status: res.status,
|
|
389
|
+
...version,
|
|
390
|
+
body: null,
|
|
391
|
+
reminders: headerReminders,
|
|
392
|
+
...(redirected && location !== null ? { location } : {}),
|
|
393
|
+
};
|
|
359
394
|
}
|
|
360
|
-
|
|
395
|
+
const answer = { ok, status: res.status, ...version, body: parsed };
|
|
396
|
+
return mergeReminders(answer, headerReminders);
|
|
361
397
|
}
|
|
362
398
|
/**
|
|
363
399
|
* DX-7110 - one `GET /health` attempt, for the reachability ping: whether 50 Arms answered healthy. The probe is public (no bearer) and
|
package/dist/index.js
CHANGED
|
@@ -648,12 +648,13 @@ const boardField = {
|
|
|
648
648
|
renamedTool("50arms_api",
|
|
649
649
|
// DX-3997 — `reminders[]` also relays the dashboard's own listener reminder
|
|
650
650
|
// to a plan-connected session; the reminder's text explains itself.
|
|
651
|
-
|
|
651
|
+
// DX-8178: a route that answers other than JSON (a redirect, a file, an image, a text download) has `body: null` and `reminders` at the top level; a redirect is never followed.
|
|
652
|
+
"Call any dashboard API route your credential may reach. The answer is the route's JSON body (non-JSON: `body: null`): act on its " +
|
|
652
653
|
"`reminders[]` when present. " +
|
|
653
654
|
// DX-4015 / DX-4525 — narrows SERVER_INSTRUCTIONS' general spec-first rule: a write shown below is
|
|
654
655
|
// copied from its example (3 of 3 canary sessions did, with zero 4xx), so only a write NOT shown, and
|
|
655
656
|
// always the retro, needs a spec call first.
|
|
656
|
-
"Before
|
|
657
|
+
"Before a write to a route not shown below, and always before `PUT /api/issues/:id/retro`, " +
|
|
657
658
|
"call `50arms_api_spec`. " +
|
|
658
659
|
// DX-3923 — the shapes agents guessed wrong most often, shown before the
|
|
659
660
|
// first call instead of learned from a 4xx.
|
|
@@ -27,8 +27,21 @@ function readReminders(result) {
|
|
|
27
27
|
/**
|
|
28
28
|
* DX-7110 - `result` with `extra` appended to its body's `reminders[]` (a key the body already carries is not repeated). A body that is not a
|
|
29
29
|
* JSON object, or whose own `reminders` is not an array, is returned as it is: a reminder never alters an answer it cannot sit beside.
|
|
30
|
+
* DX-8178: an answer with no JSON body (it carries its own top-level `reminders`, `NonJsonAnswer`) takes them there, by the same key rule.
|
|
30
31
|
*/
|
|
31
32
|
export function mergeReminders(result, extra) {
|
|
33
|
+
if (Array.isArray(result.reminders)) {
|
|
34
|
+
const present = new Set(result.reminders.map((r) => r.key));
|
|
35
|
+
const fresh = extra.filter((r) => {
|
|
36
|
+
if (present.has(r.key))
|
|
37
|
+
return false;
|
|
38
|
+
present.add(r.key);
|
|
39
|
+
return true;
|
|
40
|
+
});
|
|
41
|
+
return fresh.length === 0
|
|
42
|
+
? result
|
|
43
|
+
: { ...result, reminders: [...result.reminders, ...fresh] };
|
|
44
|
+
}
|
|
32
45
|
const body = result.body;
|
|
33
46
|
if (typeof body !== "object" || body === null || Array.isArray(body))
|
|
34
47
|
return result;
|
package/dist/machine-toolkit.js
CHANGED
|
@@ -630,7 +630,7 @@ var readOwnManifest = () => JSON.parse(
|
|
|
630
630
|
readFileSync(new URL("../../package.json", import.meta.url), "utf8")
|
|
631
631
|
).version;
|
|
632
632
|
var TOOLKIT_VERSION = resolveToolkitVersion(
|
|
633
|
-
false ? void 0 : "0.1.
|
|
633
|
+
false ? void 0 : "0.1.578",
|
|
634
634
|
readOwnManifest
|
|
635
635
|
);
|
|
636
636
|
function envelope(now) {
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/** Must match the dashboard's own header name verbatim. */
|
|
2
|
+
export const REPLY_REMINDERS_HEADER = "X-Danx-Reply-Reminders";
|
|
3
|
+
/**
|
|
4
|
+
* The reminders the response header carries, in its order; an answer with no header carries none. A header that is not base64url of a JSON list of `{key, text}` strings throws:
|
|
5
|
+
* a reply policy the agent cannot read must not pass as an answer with none.
|
|
6
|
+
*/
|
|
7
|
+
export function replyRemindersOf(headers) {
|
|
8
|
+
const value = headers.get(REPLY_REMINDERS_HEADER);
|
|
9
|
+
if (value === null || value === "")
|
|
10
|
+
return [];
|
|
11
|
+
let parsed;
|
|
12
|
+
try {
|
|
13
|
+
parsed = JSON.parse(Buffer.from(value, "base64url").toString("utf8"));
|
|
14
|
+
}
|
|
15
|
+
catch {
|
|
16
|
+
throw new Error(`[platform-mcp] the ${REPLY_REMINDERS_HEADER} header is not base64url of a JSON list`);
|
|
17
|
+
}
|
|
18
|
+
if (!Array.isArray(parsed) ||
|
|
19
|
+
!parsed.every((r) => typeof r === "object" &&
|
|
20
|
+
r !== null &&
|
|
21
|
+
typeof r.key === "string" &&
|
|
22
|
+
typeof r.text === "string"))
|
|
23
|
+
throw new Error(`[platform-mcp] the ${REPLY_REMINDERS_HEADER} header is not a list of {key, text} strings`);
|
|
24
|
+
return parsed.map(({ key, text }) => ({ key, text }));
|
|
25
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@50arms/platform-mcp",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.578",
|
|
4
4
|
"description": "Stdio MCP server fronting the 50 Arms dashboard API for agents (operator sessions and dispatched workers alike): the generic 50arms_api/50arms_api_list/50arms_api_spec tools reach any route the caller's credential may call, plus dedicated agent-specific tools (session_connect, request_permission, attach_file, and 50arms_slack_reply) (DX-3465, PLN-11 R-25).",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|