@50arms/platform-mcp 0.1.525 → 0.1.527
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/behavior-signoffs.js +81 -0
- package/dist/handlers.js +12 -1
- package/dist/http-client.js +5 -0
- package/dist/index.js +18 -2
- package/dist/machine-toolkit.js +1 -1
- package/dist/spec-read.js +15 -0
- package/package.json +1 -1
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/**
|
|
3
|
+
* DX-7947 (AC 76323; PLAN-151 section 574) - the platform MCP's side of the behavior sign-off protocol. A write an agent makes signs the behavior rules resolved for it (the server's `write-signoff-stage.ts`): the spec read shows a route's base slot,
|
|
4
|
+
* the write carries its sign-offs (`behavior_rule_signoffs`), and a write that needs more is refused `428 behavior_signoffs_required` with a request id, which `POST /api/write-requests/<id>/commit` commits with the sign-offs alone. This module is
|
|
5
|
+
* everything the client adds to a call for it; the refusal itself reaches the agent whole, as any other 4xx answer does (`http-client.ts` passes every answer under 500 through verbatim).
|
|
6
|
+
*
|
|
7
|
+
* This package cannot import the server, so the two names below and the entry shape restate the server's (`src/http/route-request.ts` `SIGNOFFS_BODY_FIELD`, `src/http/signoffs-header.ts` `BEHAVIOR_SIGNOFFS_HEADER`, `src/behavior-delivery/write-signoff-check.ts`
|
|
8
|
+
* `SIGNOFF_ENTRY_SCHEMA`); the server refuses an entry its format does not accept, naming it, so a drift fails loudly on the first call.
|
|
9
|
+
*/
|
|
10
|
+
/** The body field a write's sign-offs ride in, on every route whose body is JSON (a route that takes no body included). */
|
|
11
|
+
export const BEHAVIOR_SIGNOFFS_FIELD = "behavior_rule_signoffs";
|
|
12
|
+
/** The header a raw-body write (a file's bytes for a body, `body_file`) carries its sign-offs in: the base64 of the UTF-8 JSON list of entries. */
|
|
13
|
+
export const BEHAVIOR_SIGNOFFS_HEADER = "X-Danx-Behavior-Signoffs";
|
|
14
|
+
/**
|
|
15
|
+
* One sign-off: a statement, per rule and at the rule's version, that the agent followed it, with a confidence of 1-5. A field is sent or left out, never null. DX-7947: this schema holds only the entry's SHAPE (its keys and their types); a value
|
|
16
|
+
* check (the confidence range, the status names, a blank note) is the server's alone, which refuses a bad entry naming the rule it broke, so no second copy of the rule can drift from it.
|
|
17
|
+
*/
|
|
18
|
+
export const behaviorSignoffEntrySchema = z
|
|
19
|
+
.object({
|
|
20
|
+
rule_id: z.number().describe("The rule's id, as the policy lists it."),
|
|
21
|
+
rule_version: z
|
|
22
|
+
.string()
|
|
23
|
+
.optional()
|
|
24
|
+
.describe("The rule's version, as listed."),
|
|
25
|
+
slot: z.string().optional().describe("`write` for a write's rules."),
|
|
26
|
+
status: z
|
|
27
|
+
.string()
|
|
28
|
+
.describe("compliant, incompliant, rejected or not_applicable. A broken rule is never signed compliant."),
|
|
29
|
+
confidence: z
|
|
30
|
+
.number()
|
|
31
|
+
.optional()
|
|
32
|
+
.describe("A whole number from 1 to 5; it must reach the rule's threshold."),
|
|
33
|
+
note: z
|
|
34
|
+
.string()
|
|
35
|
+
.optional()
|
|
36
|
+
.describe("Your reasoning. Required for a rule that requires reasoning, and for rejected and not_applicable."),
|
|
37
|
+
})
|
|
38
|
+
.strict();
|
|
39
|
+
/** `50arms_api`'s `behavior_rule_signoffs` argument: one entry per rule. */
|
|
40
|
+
export const behaviorSignoffsSchema = z.array(behaviorSignoffEntrySchema);
|
|
41
|
+
/** What `50arms_api`'s `behavior_rule_signoffs` argument tells the agent (agent wording, DEC-1818). */
|
|
42
|
+
export const BEHAVIOR_SIGNOFFS_DESCRIPTION = "Your sign-offs of the behavior rules this write must sign, one entry per rule. Send them with the write when its spec shows an `x-behavior-base-slot`. " +
|
|
43
|
+
"A write that needs more is refused 428 `behavior_signoffs_required`, listing every policy to sign, why each rule is unsigned and a `request_id`: follow its `instructions`, then call `POST /api/write-requests/<request_id>/commit` " +
|
|
44
|
+
"with only this argument, never the write's body again. A request id commits once, within 30 minutes. A broken rule never commits: follow its policy's `violation_instructions` first. " +
|
|
45
|
+
`On a \`body_file\` write the list goes in the ${BEHAVIOR_SIGNOFFS_HEADER} header (the base64 of the UTF-8 JSON list); that is done for you. Never on a GET.`;
|
|
46
|
+
/** The header value for a raw-body write: the entries as JSON, UTF-8 encoded, then base64 (a note is free text and a header value is not). */
|
|
47
|
+
export function encodeSignoffsHeader(entries) {
|
|
48
|
+
return Buffer.from(JSON.stringify(entries), "utf8").toString("base64");
|
|
49
|
+
}
|
|
50
|
+
/** The commit of a held write request: `POST /api/write-requests/<request id>/commit`. */
|
|
51
|
+
const WRITE_REQUEST_COMMIT = /^\/api\/write-requests\/[^/?#]+\/commit$/;
|
|
52
|
+
/** Whether the call commits a held write request. The path may carry a query string, which is not part of the route. */
|
|
53
|
+
export function isWriteRequestCommit(method, path) {
|
|
54
|
+
return (method === "POST" && WRITE_REQUEST_COMMIT.test(path.split("?", 1)[0] ?? ""));
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Places `signoffs` on a call: in the body's `behavior_rule_signoffs`, or, on a write whose body is a file (`rawBody`), in the sign-offs header. Every refusal throws before any request is made: a read signs nothing, a body that already carries the field and an
|
|
58
|
+
* argument that also names it is ambiguous, and the commit of a held request sends only the sign-offs, never the write's body again (the server holds it).
|
|
59
|
+
*/
|
|
60
|
+
export function placeSignoffs(call) {
|
|
61
|
+
const { method, path, body, rawBody, signoffs } = call;
|
|
62
|
+
if (signoffs !== undefined && method === "GET")
|
|
63
|
+
throw new Error(`50arms_api: ${BEHAVIOR_SIGNOFFS_FIELD} signs a write; a GET writes nothing`);
|
|
64
|
+
let placed = body;
|
|
65
|
+
let signoffsHeader;
|
|
66
|
+
if (signoffs !== undefined) {
|
|
67
|
+
if (rawBody)
|
|
68
|
+
signoffsHeader = encodeSignoffsHeader(signoffs);
|
|
69
|
+
else {
|
|
70
|
+
if (body !== undefined && Object.hasOwn(body, BEHAVIOR_SIGNOFFS_FIELD))
|
|
71
|
+
throw new Error(`50arms_api: ${BEHAVIOR_SIGNOFFS_FIELD} is in the body and also an argument; send it once, as the argument`);
|
|
72
|
+
placed = { ...(body ?? {}), [BEHAVIOR_SIGNOFFS_FIELD]: signoffs };
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
if (isWriteRequestCommit(method, path)) {
|
|
76
|
+
const sent = Object.keys(placed ?? {});
|
|
77
|
+
if (rawBody || sent.some((key) => key !== BEHAVIOR_SIGNOFFS_FIELD))
|
|
78
|
+
throw new Error(`50arms_api: committing a held write request sends only its id and ${BEHAVIOR_SIGNOFFS_FIELD}, never the write's body again`);
|
|
79
|
+
}
|
|
80
|
+
return { body: placed, signoffsHeader };
|
|
81
|
+
}
|
package/dist/handlers.js
CHANGED
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
*/
|
|
24
24
|
import { posix, win32 } from "node:path";
|
|
25
25
|
import { readFile, stat } from "node:fs/promises";
|
|
26
|
+
import { placeSignoffs, } from "./behavior-signoffs.js";
|
|
26
27
|
// ---------------- session_connect (DX-2683, DX-5553, DX-6917) ----------------
|
|
27
28
|
// DX-3465 (PLN-11 R-25) — every other per-operation handler that used to
|
|
28
29
|
// live in this file (issue_*, plan_*, brief_*,
|
|
@@ -183,6 +184,13 @@ bearer) {
|
|
|
183
184
|
const rawBody = args.body_file === undefined
|
|
184
185
|
? undefined
|
|
185
186
|
: await readRawBodyFile(args.body_file, deps);
|
|
187
|
+
const signed = placeSignoffs({
|
|
188
|
+
method: args.method,
|
|
189
|
+
path: args.path,
|
|
190
|
+
body: args.body,
|
|
191
|
+
rawBody: rawBody !== undefined,
|
|
192
|
+
signoffs: args.behavior_rule_signoffs,
|
|
193
|
+
});
|
|
186
194
|
return client.request({
|
|
187
195
|
method: args.method,
|
|
188
196
|
// `basePath: ""` — `path` here is the FULL absolute path already (see
|
|
@@ -193,8 +201,11 @@ bearer) {
|
|
|
193
201
|
basePath: "",
|
|
194
202
|
path: args.path,
|
|
195
203
|
query: args.query,
|
|
196
|
-
body:
|
|
204
|
+
body: signed.body,
|
|
197
205
|
rawBody,
|
|
206
|
+
...(signed.signoffsHeader === undefined
|
|
207
|
+
? {}
|
|
208
|
+
: { behaviorSignoffs: signed.signoffsHeader }),
|
|
198
209
|
board: args.board,
|
|
199
210
|
background: args.background,
|
|
200
211
|
...(bearer === undefined ? {} : { bearer }),
|
package/dist/http-client.js
CHANGED
|
@@ -57,6 +57,7 @@
|
|
|
57
57
|
* Transforming the body here would erase that signal.
|
|
58
58
|
*/
|
|
59
59
|
import { appVersionOf } from "./app-version.js";
|
|
60
|
+
import { BEHAVIOR_SIGNOFFS_HEADER } from "./behavior-signoffs.js";
|
|
60
61
|
import { boardStampOf, isReadRoute, takesBoardInBody, } from "./route-board-scope.js";
|
|
61
62
|
import { assertVersionFloorSatisfied, clientVersionHeaders, MCP_MIN_VERSION_HEADER, } from "./version-floor.js";
|
|
62
63
|
import { PLUGIN_BACKGROUND_HEADER } from "./session-options.js";
|
|
@@ -206,10 +207,14 @@ export class DashboardHttpClient {
|
|
|
206
207
|
headers[TOOL_USE_ID_HEADER] = toolUseId;
|
|
207
208
|
}
|
|
208
209
|
let payload;
|
|
210
|
+
if (args.behaviorSignoffs !== undefined && args.rawBody === undefined)
|
|
211
|
+
throw new Error("[platform-mcp] `behaviorSignoffs` is the header of a raw-body request; a JSON body carries its sign-offs in `behavior_rule_signoffs`");
|
|
209
212
|
if (args.rawBody !== undefined) {
|
|
210
213
|
if (args.body !== undefined)
|
|
211
214
|
throw new Error("[platform-mcp] a request sends `body` or `rawBody`, never both");
|
|
212
215
|
headers["Content-Type"] = args.rawBody.contentType;
|
|
216
|
+
if (args.behaviorSignoffs !== undefined)
|
|
217
|
+
headers[BEHAVIOR_SIGNOFFS_HEADER] = args.behaviorSignoffs;
|
|
213
218
|
payload = new Blob([args.rawBody.bytes]);
|
|
214
219
|
}
|
|
215
220
|
else if (args.body !== undefined) {
|
package/dist/index.js
CHANGED
|
@@ -108,6 +108,8 @@ import { docsRead, docsSearch, docsSourceShape } from "./docs-tools.js";
|
|
|
108
108
|
import { spillRoleInstruction } from "./role-instruction-file.js";
|
|
109
109
|
import { DEFAULT_LIMIT, MAX_SEARCH_LIMIT } from "@50arms/docs/agent";
|
|
110
110
|
import { boundedResultText } from "./result-limit.js";
|
|
111
|
+
import { BEHAVIOR_SIGNOFFS_DESCRIPTION, behaviorSignoffsSchema, } from "./behavior-signoffs.js";
|
|
112
|
+
import { specReadStop } from "./spec-read.js";
|
|
111
113
|
import { withAppVersion } from "./app-version.js";
|
|
112
114
|
import { bodyValueSchema, queryValueSchema } from "./types.js";
|
|
113
115
|
import { termsAcceptanceCallHalt, termsHaltFor } from "./terms-halt.js";
|
|
@@ -678,6 +680,10 @@ renamedTool("50arms_api",
|
|
|
678
680
|
.min(1)
|
|
679
681
|
.optional()
|
|
680
682
|
.describe("Absolute path of an image file (png, jpg, webp, svg; max 1 MB) sent as the raw body instead of `body`."),
|
|
683
|
+
// DX-7947 (AC 76323): the agent's sign-offs of the behavior rules a write needs; where they go (the body, or the header of a `body_file` write) is `placeSignoffs`'s.
|
|
684
|
+
behavior_rule_signoffs: behaviorSignoffsSchema
|
|
685
|
+
.optional()
|
|
686
|
+
.describe(BEHAVIOR_SIGNOFFS_DESCRIPTION),
|
|
681
687
|
...boardField,
|
|
682
688
|
// DX-5033 - sends x-danx-plugin-background (see DanxbotApiArgs.background); an agent setting it would hide its own calls from the pause and idle logic.
|
|
683
689
|
background: z
|
|
@@ -738,14 +744,24 @@ renamedTool("50arms_api_spec",
|
|
|
738
744
|
"routes you name: request and response shape, required permission and " +
|
|
739
745
|
'every documented error. `endpoints`: `"METHOD /path/template"` strings as `50arms_api_list` reports them ' +
|
|
740
746
|
'(e.g. `"POST /api/issues/:id/transition"`), never a real path with ids. An endpoint the dashboard does ' +
|
|
741
|
-
"not serve, or your credential may not call, is refused and named."
|
|
747
|
+
"not serve, or your credential may not call, is refused and named. A write route may carry `x-behavior-base-slot`: the behavior policies every call to it must sign " +
|
|
748
|
+
"(each rule with its id, version and threshold, and the policy's violation_instructions), except the `complete` action of `POST /api/issues/:id/transition`, which signs none of them; " +
|
|
749
|
+
"sign them in `50arms_api`'s `behavior_rule_signoffs`. " +
|
|
750
|
+
"A read that fails is not an answer: stop.", {
|
|
742
751
|
endpoints: z.array(z.string().min(1)).min(1),
|
|
743
752
|
},
|
|
744
753
|
// DX-5765: with no agent held it answers for the two proposal routes only; any other endpoint keeps the no-agent answer.
|
|
745
754
|
() => async (args) => {
|
|
746
|
-
|
|
755
|
+
const guarded = await guardedCall(() => danxbotApiSpec(client, args), {
|
|
747
756
|
gateOpen: isAgentGateOpenSpec(args.endpoints),
|
|
748
757
|
});
|
|
758
|
+
if ("halt" in guarded)
|
|
759
|
+
return haltResult(guarded.halt);
|
|
760
|
+
// DX-7947 (R-21): a spec read the dashboard failed ends the call; an agent without a write's policies stops.
|
|
761
|
+
const stop = specReadStop(guarded.result);
|
|
762
|
+
if (stop !== null)
|
|
763
|
+
return haltResult(stop);
|
|
764
|
+
return boundedJsonResult(guarded.result);
|
|
749
765
|
});
|
|
750
766
|
// ---------------- attach_file (DX-3465 A4, checklist item 36140) ----------------
|
|
751
767
|
//
|
package/dist/machine-toolkit.js
CHANGED
|
@@ -612,7 +612,7 @@ var readOwnManifest = () => JSON.parse(
|
|
|
612
612
|
readFileSync(new URL("../../package.json", import.meta.url), "utf8")
|
|
613
613
|
).version;
|
|
614
614
|
var TOOLKIT_VERSION = resolveToolkitVersion(
|
|
615
|
-
false ? void 0 : "0.1.
|
|
615
|
+
false ? void 0 : "0.1.527",
|
|
616
616
|
readOwnManifest
|
|
617
617
|
);
|
|
618
618
|
function envelope(now) {
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { isUnreachableAnswer } from "./dashboard-errors.js";
|
|
2
|
+
/**
|
|
3
|
+
* DX-7947 (AC 76323, R-21) - what a failed spec read means. `50arms_api_spec` is how an agent meets the behavior policies a write must sign (each write route's base slot, `x-behavior-base-slot`): the dashboard fails a read whose slots it cannot resolve or render,
|
|
4
|
+
* and an agent without its instructions stops, so the failure ends the call (an error result) with the dashboard's own answer and the instruction to stop. A refusal the agent can correct (an unknown or disallowed endpoint, 4xx) is an ordinary answer, and
|
|
5
|
+
* so is a successful read.
|
|
6
|
+
*/
|
|
7
|
+
/** The answer text of a spec read that failed on the dashboard's side (a 5xx, or no answer at all), or `null` for a read that answered. */
|
|
8
|
+
export function specReadStop(result) {
|
|
9
|
+
if (result.ok)
|
|
10
|
+
return null;
|
|
11
|
+
if (result.status < 500 && !isUnreachableAnswer(result))
|
|
12
|
+
return null;
|
|
13
|
+
return (`50arms_api_spec failed, so you do not have these endpoints' contract or the behavior policies a write to them must sign. Stop: make no write to them until a read succeeds, and tell the person. ` +
|
|
14
|
+
`The dashboard answered: ${JSON.stringify(result.body)}`);
|
|
15
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@50arms/platform-mcp",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.527",
|
|
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",
|