@50arms/platform-mcp 0.1.449 → 0.1.451

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/README.md CHANGED
@@ -10,7 +10,6 @@ Stdio MCP server fronting the 50 Arms dashboard HTTP API. Since DX-3465 it expos
10
10
  |---|---|
11
11
  | `DANXBOT_DASHBOARD_URL` | Dashboard base, e.g. `http://danxbot-dashboard:5555` (inside compose) or `http://localhost:5555` (host). An operator session gets it from the 50arms plugin: its `dashboard_url` option (default the hosted dashboard), chosen per session folder: see the repo's `.claude/rules/dashboard-api-access.md`, the one owner of that rule |
12
12
  | `DANX_DASHBOARD_CREDENTIAL` | A DISPATCH's credential: the bearer verbatim, substituted into the materialized `.mcp.json` from its overlay (DX-2862, `src/credential.ts`). Authoritative when set; it never signs out. An operator session sets nothing: with no credential the server boots SIGNED OUT, every tool except `session_connect` returns one "not signed in" halt, and `session_connect` requests access (below). `restart_notice` uses the same resolver, so a session's tools and its predecessor lookups can never sign in as two different identities; the relay in this server (`plan_events_wait`) signs in with the server's own credential |
13
- | `DANXBOT_TEAM` | OPTIONAL, non-secret (DX-4446): the team slug (or id) whose approvers see this session's access request in their danxbot site. Set it in your shell or a repo's committed `.claude/settings.json` `env` block. Unset, the request is answered by link only. A value that is not a team slug fails at boot; a team the dashboard does not know makes `session_connect` answer `unknown_team` (fix `DANXBOT_TEAM`), never a silent link fallback |
14
13
  | `DANXBOT_BOARD_ID` | OPTIONAL (DX-4555, DX-5512): the dispatch's board, the board's ref, the positive integer that numbers it within its team (never its database id; the dispatch injects it). Anything else exits at boot. Unset (the 50arms plugin's own server) the server has no default board: a call that needs a board must carry its `board` argument or the dashboard answers 400 (plan and plan-session routes take their boards from the plan and need none) |
15
14
 
16
15
  BOARD-ONLY (DX-1171): board is the first-level concept; repo is DERIVED from board server-side, never passed. At boot the package reads the dispatch's board ref from `DANXBOT_BOARD_ID` and appends it as `?board=<ref>` (and `body.board` on create) to every `/api/issues/*` request, except `GET /api/issues` (the list), whose board is OPTIONAL (DX-4542): there it sends a board only when the caller names one, because no board is the team's whole list across every board. Each tool exposes an optional `board` arg - a board ref, the number (or its decimal text) - that overrides it per-call for cross-board reads/writes (unknown board -> 404). The dashboard owns board->repo resolution; this package never sends `repo`.
@@ -1,14 +1,4 @@
1
1
  import { assertVersionFloorSatisfied, MCP_MIN_VERSION_HEADER } from "./version-floor.js";
2
- // DX-4446: mirrors TEAM_SLUG_PATTERN in src/lib/auth-rules.ts (this package cannot import the main src/); a team ref is a slug,
3
- // and a team id's digits are a slug too. Keep the two in step.
4
- const TEAM_REF_PATTERN = /^[a-z0-9]+(-[a-z0-9]+)*$/;
5
- /** DX-4446: the `DANXBOT_TEAM` value, or a loud error naming the variable. */
6
- export function assertMcpTeamRef(value) {
7
- if (!TEAM_REF_PATTERN.test(value)) {
8
- throw new Error(`[platform-mcp] DANXBOT_TEAM "${value}" is not a team slug or id: lowercase letters and digits, joined by single hyphens`);
9
- }
10
- return value;
11
- }
12
2
  function baseOf(dashboardUrl) {
13
3
  return dashboardUrl.replace(/\/+$/, "");
14
4
  }
@@ -60,9 +50,8 @@ function isCreated(value) {
60
50
  export async function createAccessRequest(fetchImpl, dashboardUrl, input) {
61
51
  const url = `${baseOf(dashboardUrl)}/api/access-requests`;
62
52
  const { status, headers, json } = await postPublic(fetchImpl, url, input);
63
- if (status === 400 && input.team !== undefined && json?.error === "unknown_team") {
64
- return { kind: "unknown_team", team: input.team };
65
- }
53
+ if (status === 403 && json?.error === "machine_registration_mismatch")
54
+ return { kind: "machine_registration_mismatch" };
66
55
  if (status === 201) {
67
56
  if (!isCreated(json)) {
68
57
  throw new Error(`[platform-mcp] POST ${url} answered 201 without the access request fields: ${JSON.stringify(json)}`);
@@ -87,7 +87,9 @@ function render(example) {
87
87
  /** The description sentence `50arms_api` carries. */
88
88
  export function danxbotApiExamplesText() {
89
89
  const e = DANXBOT_API_EXAMPLES;
90
- return (`Correct first calls: card read ${render(e.cardRead)} (\`fields\` is an object, never a comma string); ` +
90
+ return (
91
+ // DX-7003: a card read answers each comment's shorter version; the tool's description says how to reach the originals.
92
+ `Correct first calls: card read ${render(e.cardRead)} (\`fields\` is an object, never a comma string; \`comments\` answers each comment's shorter version when it has one: \`comments: {"expanded": true}\` reads the originals, the ones a decision's provenance quote is copied from, and \`comments: {"q": "<words>"}\` searches them); ` +
91
93
  `card create ${render(e.cardCreate)} (\`plan\` required: "mine" or null; \`summary\` required, on every phase_children[] item too); ` +
92
94
  `card edit ${render(e.cardEdit)} (only the keys you change; \`ac\` replaces the list); ` +
93
95
  `AC tick ${render(e.acTick)}; ` +
package/dist/index.js CHANGED
@@ -61,12 +61,6 @@
61
61
  * otherwise this session's approved key (`session-key.ts`), else none: the
62
62
  * server boots SIGNED OUT, every tool but `session_connect`
63
63
  * halts, and `session_connect` requests access (`session-access.ts`)
64
- * DANXBOT_TEAM OPTIONAL (DX-4446), non-secret: the team slug (or id) whose
65
- * approvers see this session's access request in their danxbot
66
- * site. Set it in your shell or a repo's committed `.claude/settings.json` `env` block.
67
- * Unset: the request is answered by link only. Set but not a
68
- * valid ref, or unknown to the dashboard: fails loud, never a
69
- * silent fall back to the link flow.
70
64
  * DANXBOT_BOARD_ID OPTIONAL (DX-4555): the dispatch's board, the board's ref number the worker injects;
71
65
  * a positive integer (anything else exits loudly), appended as ?board=<ref>.
72
66
  * Each tool's optional `board` arg (a board ref)
@@ -91,7 +85,6 @@ import { makeSessionStop, stopWhenSessionEnds } from "./shutdown.js";
91
85
  import { SUBAGENTS_LIVE_SUBCOMMAND, runSubagentsLiveCommand } from "./subagents-live.js";
92
86
  import { resolveBootCredential } from "./credential.js";
93
87
  import { SessionKeyUnusableError, deleteSessionKey } from "./session-key.js";
94
- import { assertMcpTeamRef } from "./access-request.js";
95
88
  import { SessionAccess } from "./session-access.js";
96
89
  import { PermissionRequests } from "./permission-request.js";
97
90
  import { makeGuardedCalls } from "./guarded-calls.js";
@@ -154,19 +147,6 @@ function readBoardId() {
154
147
  }
155
148
  return id;
156
149
  }
157
- /** DX-4446: optional `DANXBOT_TEAM`; set, it must be a valid team ref or boot fails loud (no fallback to the link flow). */
158
- function readTeamRef() {
159
- const team = readEnvOptional("DANXBOT_TEAM");
160
- if (team === undefined)
161
- return undefined;
162
- try {
163
- return assertMcpTeamRef(team);
164
- }
165
- catch (err) {
166
- console.error(err.message);
167
- process.exit(1);
168
- }
169
- }
170
150
  // The dispatch config + HTTP client are LATE-BOUND (assigned by `boot()` at
171
151
  // entrypoint, below). Tool registration happens at module import and the
172
152
  // callbacks close over these `let` bindings, reading them at CALL time — so the
@@ -219,7 +199,6 @@ function boot() {
219
199
  dashboardUrl,
220
200
  sessionId: session?.id,
221
201
  clientVersion: readOwnVersion(),
222
- team: readTeamRef(),
223
202
  readRepo: () => readCheckoutRepo(process.cwd()),
224
203
  setToken: (token) => dashboardClient.setToken(token),
225
204
  initial: resolveInitialCredential(dashboardUrl, session?.id),
@@ -908,6 +887,13 @@ strictTool("session_connect",
908
887
  'The `naming` block\'s exact `{Name}: PLAN-NNN {short title}` or `{Name}: {CARD-ID} {card title}`, after renaming this thread. Omit on the first connect.'),
909
888
  assignment_id: z.number().int().positive().optional().describe("The assignment this connect answers, when a person's assignment message names one. Refused `assignment_ended` once it is over: then do nothing more about it."),
910
889
  disconnect: z.boolean().optional().describe("true = leave `target` (the plan or card you hold); no `title`."),
890
+ role: z
891
+ .string()
892
+ .regex(/^[a-z0-9]+(-[a-z0-9]+)*$/)
893
+ .optional()
894
+ .describe(
895
+ // DX-6939: read only by a call that makes a sign-in claim; a signed-in session's call ignores it.
896
+ "The key of the team role this session's key is minted with when this call signs it in: default `agent`, the system agent role every team has. It must be an agent role within what the person this machine is registered to holds, or the sign-in is refused. Omit it unless a person named another role."),
911
897
  launch_token: z
912
898
  .string()
913
899
  .min(1)
@@ -940,7 +926,7 @@ async (args) => {
940
926
  return haltResult("session_connect: `disconnect: true` needs `target`, the plan or card this session currently holds");
941
927
  }
942
928
  // DX-4390 — no key yet: ask for one (or wait for the approval already asked for).
943
- const ready = await access.ensureAccess(args.title, args.launch_token);
929
+ const ready = await access.ensureAccess(args.title, args.launch_token, args.role);
944
930
  if (!ready.signedIn)
945
931
  return accessReply(ready);
946
932
  if (args.target === undefined) {
@@ -969,7 +955,7 @@ async (args) => {
969
955
  return haltResult(revokedHalt);
970
956
  // DX-4390 — the dashboard no longer accepts the stored key: drop it and ask again in the same call.
971
957
  if (result.status === 401 && access.dropKey(result)) {
972
- return accessReply(await access.ensureAccess(args.title), "the dashboard no longer accepted this session's key");
958
+ return accessReply(await access.ensureAccess(args.title, undefined, args.role), "the dashboard no longer accepted this session's key");
973
959
  }
974
960
  return finishConnect("session_connect", result, args.disconnect === true);
975
961
  });
@@ -4,7 +4,7 @@
4
4
  * `~/.config/danxbot/machine-registrations/<sha12(dashboard url)>.json` (mode 0600): who the machine is registered to, for all future sign-ins. Its presence is what lets a session skip the registration step; a file of
5
5
  * another shape is a loud error, never a guess (CLAUDE.md Core Principle 1). Every session on the machine writes the same content, so an atomic rename is enough.
6
6
  */
7
- import { readFileSync } from "node:fs";
7
+ import { readFileSync, rmSync } from "node:fs";
8
8
  import { homedir } from "node:os";
9
9
  import { join } from "node:path";
10
10
  import { postPublic, retryAfterSeconds } from "./access-request.js";
@@ -68,6 +68,13 @@ export function writeMachineRegistration(dashboardUrl, accepted, options) {
68
68
  };
69
69
  writeFileDurable(machineRegistrationPath(dashboardUrl, options.home), JSON.stringify(record), { mode: 0o600 });
70
70
  }
71
+ /**
72
+ * DX-6939 (DEC-655) - forget this machine's registration with `dashboardUrl`: the dashboard refused a sign-in as not matching it (released, or its person left the team), so the
73
+ * machine registers again. Absent already is fine: another session on the machine may have cleared it first.
74
+ */
75
+ export function deleteMachineRegistration(dashboardUrl, home) {
76
+ rmSync(machineRegistrationPath(dashboardUrl, home), { force: true });
77
+ }
71
78
  function asPending(json, url) {
72
79
  if (typeof json.claimCode !== "string" || typeof json.registrationUrl !== "string" || typeof json.pollMs !== "number") {
73
80
  throw new Error(`[platform-mcp] POST ${url} answered pending without its fields: ${JSON.stringify(json)}`);
@@ -250,7 +250,7 @@ function resolveToolkitVersion(stamped, readManifest) {
250
250
  return stamped ?? readManifest();
251
251
  }
252
252
  var readOwnManifest = () => JSON.parse(readFileSync2(new URL("../../package.json", import.meta.url), "utf8")).version;
253
- var TOOLKIT_VERSION = resolveToolkitVersion(false ? void 0 : "0.1.449", readOwnManifest);
253
+ var TOOLKIT_VERSION = resolveToolkitVersion(false ? void 0 : "0.1.451", readOwnManifest);
254
254
  function envelope(now) {
255
255
  return { contract_version: CONTRACT_VERSION, toolkit_version: TOOLKIT_VERSION, profile: PROFILE, measured_at: now.toISOString() };
256
256
  }
@@ -29,7 +29,7 @@ import { hostname } from "node:os";
29
29
  import { claimAccessRequest, createAccessRequest } from "./access-request.js";
30
30
  import { credentialFingerprint } from "./credential.js";
31
31
  import { keyRevocationOf, keyRevokedHalt } from "./key-revoked-halt.js";
32
- import { callMachineRegistration, readMachineRegistration, writeMachineRegistration } from "./machine-registration.js";
32
+ import { callMachineRegistration, deleteMachineRegistration, readMachineRegistration, writeMachineRegistration, } from "./machine-registration.js";
33
33
  import { machineSecretFor } from "./machine-secret.js";
34
34
  import { deleteSessionKey, writeSessionKey } from "./session-key.js";
35
35
  import { McpOutdatedError } from "./version-floor.js";
@@ -62,7 +62,29 @@ const DENIED_INSTRUCTION = "The user denied the request. Do not retry unless the
62
62
  const DASHBOARD_OUTDATED_ERROR = "this dashboard does not support request-and-approve yet (POST /api/access-requests answered 404): " +
63
63
  "it must be updated before this session can sign in";
64
64
  const RATE_LIMITED_ERROR = "too many access requests from this address; wait, then call session_connect again";
65
- const unknownTeamError = (team) => `the dashboard has no team "${team}" (DANXBOT_TEAM); fix DANXBOT_TEAM in this server's env (your shell, or a repo's committed .claude/settings.json env block) and restart the session`;
65
+ /**
66
+ * DX-6939 - the role a session's sign-in claim asks for unless `session_connect` names another: the system agent role every team holds and cannot delete
67
+ * (`src/auth/permissions.ts`), what the app calls the default agent role.
68
+ */
69
+ export const DEFAULT_SESSION_ROLE = "agent";
70
+ /** DX-6939 - why the dashboard refused a sign-in claim, in words the agent can act on; null for a refusal it does not name. */
71
+ function claimRefusalError(body, role) {
72
+ const error = body?.error;
73
+ switch (error) {
74
+ case "unknown_role":
75
+ return `the team has no role "${role}"; call session_connect again without \`role\` (the default agent role) or with a role key the team has`;
76
+ case "role_exceeds_owner":
77
+ return `the role "${role}" holds permissions the person this machine is registered to lacks, so the dashboard refused the sign-in; ask them which role to use, or have a team admin widen their own role`;
78
+ case "session_role_must_be_agent":
79
+ return `the role "${role}" is a person's role, not an agent role; call session_connect again with an agent role, or without \`role\``;
80
+ case "claim_target_required":
81
+ return "the dashboard refused the sign-in for naming no team, person or role; update the 50 Arms plugin";
82
+ default:
83
+ return null;
84
+ }
85
+ }
86
+ /** DX-6939 - the dashboard kept refusing the claim as not matching this machine's registration even after the machine registered again. */
87
+ const REGISTRATION_STILL_MISMATCHED_ERROR = "the dashboard refused this sign-in as not matching this machine's registration even after the machine registered again; call session_connect again";
66
88
  const NO_SESSION_ID_ERROR = "this server has no CLAUDE_CODE_SESSION_ID, so it cannot request a session key";
67
89
  const CLAIMED_LOST_ERROR = "the dashboard says this request was already claimed, but this process never received the key; " +
68
90
  "start a new request";
@@ -250,12 +272,12 @@ export class SessionAccess {
250
272
  * (once per process) through the public claim route, with no person approving. Any answer but `approved` spends the token and
251
273
  * falls through to the person's request, the answer carrying a `note` that says why the token was not used.
252
274
  */
253
- ensureAccess(title, launchToken) {
254
- const run = this.ensureQueue.then(() => this.ensureAccessNow(title, launchToken));
275
+ ensureAccess(title, launchToken, role) {
276
+ const run = this.ensureQueue.then(() => this.ensureAccessNow(title, launchToken, role));
255
277
  this.ensureQueue = run.catch(() => undefined);
256
278
  return run;
257
279
  }
258
- async ensureAccessNow(title, launchToken) {
280
+ async ensureAccessNow(title, launchToken, role) {
259
281
  // DX-4418: a person revoked this session's access; it asks again only after `personSignIn` (DX-6894).
260
282
  const revokedHalt = this.revokedHalt();
261
283
  if (revokedHalt !== null)
@@ -292,7 +314,7 @@ export class SessionAccess {
292
314
  return settled;
293
315
  note = EXPIRED_NOTE;
294
316
  }
295
- const created = await this.createRequest(sessionId, title, note);
317
+ const created = await this.createRequest(sessionId, title, note, role ?? DEFAULT_SESSION_ROLE);
296
318
  // DX-6801: a refused or failed request carries the launch note too, so the reason is never lost.
297
319
  if (note !== undefined && !created.signedIn && !("note" in created.answer)) {
298
320
  return { ...created, answer: { ...created.answer, note } };
@@ -431,7 +453,15 @@ export class SessionAccess {
431
453
  return "expired";
432
454
  }
433
455
  }
434
- async createRequest(sessionId, title, note) {
456
+ /**
457
+ * DX-6939 (DEC-613) - the sign-in claim: for the team and person this machine is registered to (its registration file, the MCP's one source of both) and `role`.
458
+ * A `machine_registration_mismatch` deletes the file and goes back through registration (DEC-655: the one place the file is cleared), then claims again once.
459
+ */
460
+ async createRequest(sessionId, title, note, role, reRegistered = false) {
461
+ const registration = readMachineRegistration(this.deps.dashboardUrl, this.deps.home);
462
+ // Only reached once `machineRegistrationAnswer` found the file, so a missing one is a bug, loud.
463
+ if (registration === null)
464
+ throw new Error("[platform-mcp] createRequest ran with no machine registration file");
435
465
  const repo = await this.deps.readRepo();
436
466
  const created = await createAccessRequest(this.fetchImpl, this.deps.dashboardUrl, {
437
467
  kind: "session",
@@ -440,18 +470,30 @@ export class SessionAccess {
440
470
  machine: this.deps.machine ?? hostname(),
441
471
  clientVersion: this.deps.clientVersion,
442
472
  ...(repo === null ? {} : { repo }),
443
- ...(this.deps.team === undefined ? {} : { team: this.deps.team }),
473
+ team: String(registration.teamId),
474
+ person: registration.userId,
475
+ role,
444
476
  machineSecret: machineSecretFor(this.deps.dashboardUrl, { home: this.deps.home, now: this.now() }),
445
477
  });
446
478
  switch (created.kind) {
447
479
  case "dashboard_outdated":
448
480
  return notReady({ state: "dashboard_outdated", error: DASHBOARD_OUTDATED_ERROR }, true);
449
- case "unknown_team":
450
- return notReady({ state: "unknown_team", team: created.team, error: unknownTeamError(created.team) }, true);
481
+ case "machine_registration_mismatch": {
482
+ if (reRegistered)
483
+ return notReady({ state: "request_failed", error: REGISTRATION_STILL_MISMATCHED_ERROR }, true);
484
+ deleteMachineRegistration(this.deps.dashboardUrl, this.deps.home);
485
+ this.registration = null;
486
+ const unregistered = await this.machineRegistrationAnswer(note);
487
+ if (unregistered !== null)
488
+ return unregistered;
489
+ return this.createRequest(sessionId, title, note, role, true);
490
+ }
451
491
  case "rate_limited":
452
492
  return notReady({ state: "rate_limited", retryAfterSeconds: created.retryAfterSeconds, error: RATE_LIMITED_ERROR }, true);
453
- case "refused":
454
- return notReady({ state: "request_refused", status: created.status, body: created.body }, true);
493
+ case "refused": {
494
+ const error = claimRefusalError(created.body, role);
495
+ return notReady({ state: "request_refused", status: created.status, body: created.body, ...(error === null ? {} : { error }) }, true);
496
+ }
455
497
  case "created":
456
498
  this.pending = { request: created.request, settled: this.pollUntilSettled(created.request) };
457
499
  // DX-6764: a machine grant approved it: no person decides, so the key is a claim away. Wait for it as a second call would,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@50arms/platform-mcp",
3
- "version": "0.1.449",
3
+ "version": "0.1.451",
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",