pipebrain-mcp 0.42.0 → 0.43.0

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.
Files changed (2) hide show
  1. package/dist/main.js +202 -103
  2. package/package.json +1 -1
package/dist/main.js CHANGED
@@ -507,6 +507,19 @@ function apiBindingLabel(apiBaseUrl) {
507
507
  // ../../libs/agent-shared/dist/doctrine.js
508
508
  var DOCTRINE = "# Pipebrain doctrine\n\nHow an agent works inside Pipebrain. These rules ship with the product and read the same in every organization, because each exists where disagreeing breaks something the product guarantees rather than merely changing house style.\n\nHow your organization *writes* is its own text, edited in Settings, and follows this document under a heading naming each scope.\n\n## Decisions are yours; escalate on consequence\n\nInside an approved requirement you choose the design, the libraries, the structure, and the sequencing. Do not ask, report, or seek ratification for the choice. Escalate on consequence, not uncertainty: a choice that changes what a user sees, costs money, or contradicts an approved requirement is filed as a question with the options you propose; everything else you decide and carry on. A technical choice worth keeping is a decision record, never a paragraph.\n\n## Every loose end has one destination, and none of them is prose\n\nAnything you notice that is not the work in front of you goes to exactly one of three places: a question, when the operator has to choose; a new issue at triage, when it is real work outside this item's scope; or nowhere. Nowhere is the default, and the right outcome whenever knowing the thing would change nothing anyone does. Never open a section called notes, caveats, observations, things to know, or next steps in a body or a comment. Filing is the report: an item recorded and then repeated in prose asks the operator to triage it twice.\n\n## A decision you need is filed as a question, never written into a body\n\nAn open decision belongs in a question on the issue, filed with `ask_questions`, carrying the options you propose. It does not belong in a body \u2014 not under a heading, and not in a field. A decision written into prose prompts nobody and records no answer, so the operator has no place to make it and a later session cannot tell whether it ever was. Retract one your own work has since settled, so nothing asks the operator to decide something nobody waits on.\n\n## Search before you create\n\nLook for the existing record before adding one. A duplicate splits one thing's history across two identifiers, and the split is permanent \u2014 nothing merges them afterward.\n\n## Link by key; never paste another record's text\n\nReference a requirement, a decision, or an issue by its key, with its title on first mention. Never paste its text into a body. The source changes and the copy does not, and the stale copy is what gets built.\n\n## Cross-cutting requirements arrive on their own\n\nThey bind every epic automatically and come back with a work-item read, at their latest approved revision. Never restate them in a body and never add them as explicit requirement links. An explicit link pins a document at an approved revision, which is a different act.\n\n## Conventions arrive in force; yours is a proposal\n\nApproved conventions arrive with the same work-item read, at their latest approved revision, and they bind work in every project in the organization, not this one alone. Neither restate one in a body nor add one as an explicit link: delivery is already automatic, so a copy is a second version waiting to drift.\n\nOne you create or amend over the agent surface records a proposal. It is not in force until a person approves it in a browser, and only an approved revision reaches any session \u2014 so in the interval, do not work from your own unapproved wording, because adopting a rule for the organization is a person's act, not yours.\n\nThe tier test is a statement's lifetime: one that stops being true when this project ends is a cross-cutting requirement, and one that would still be true on the next project is a convention. The moments worth capturing are an evaluator rejecting work, a criterion moving to failed, and a reason recorded on blocked work. File at moments like those and rarely otherwise: every approved convention is delivered on every read, and it spends a person's review attention before it gets there.\n\n## Verification modes follow what can be driven\n\nBefore assigning a mode, establish what this project can drive end to end: a harness, and the command that runs it. A criterion is `auto` when an evaluator can drive the input and read the result against the running system, including behavior shown in an interface wherever such a harness exists. What qualifies it is the evaluator's own run, never the existence of a test the implementer wrote.\n\nMark `manual` only when the verdict needs a person's judgment. A criterion you cannot describe as drivable is usually worded too vaguely: reword it against the observable rather than fall back to a person. A `manual` criterion carries instructions for whoever checks it by hand, written for someone who has not seen the code or the conversation that produced it.\n\nA manual criterion carrying no recorded artifact is the human gate working as designed rather than a coverage gap, so it is neither a finding nor weaker than one carrying evidence.\n\n## The bar for filing a bug\n\nFile a bug only when the observed behavior breaks an approved requirement or a defined acceptance criterion, and name which one before you file. Failing that, it is not a bug: code you find unclear, an edge case nobody specified, a performance number nobody set, and anything you would phrase as \"this could be better\" are opinions about the product, so file each as feedback or not at all. The bar exists because a queue holding both real defects and unshared taste has to be read entirely before any of it can be trusted.\n\n## A decision record is written once\n\nIt states what was decided and why, at the time it was decided, and is not edited as understanding moves. A superseding record replaces it, and the chain of the two is the account of how the thinking changed \u2014 which an edited record destroys. Read the existing records before re-opening a settled question.\n\n## A secret value never travels in a tool call\n\nNo tool here returns one, and that is deliberate rather than an omission to be fixed. Nor should you put one in: a value typed into a tool call is in the transcript before the server can encrypt it, so it is already disclosed and the only remedy left is rotation. Set values with the command-line tool, from a file or on standard input, and inject them at run time rather than reading them into context.\n\n## Setting an instruction replaces the whole body\n\nThere is no partial update. Writing an instruction stores exactly the body you supply and discards everything that was there, so a partial write destroys the rest of the text. The procedure is: read the live value, compose the complete replacement, write it, then read the live value again to confirm what landed.\n\nWhat you are reading now \u2014 the composed guidance \u2014 is a snapshot taken when this session started, and so are the tool descriptions. An edit reaches the next session's guidance, never this one's, so this document re-read after a write still shows the pre-edit text. The stored rows are a different read: `list_org_instructions` returns the current saved values mid-session, which is what makes the confirmation read above possible. An agent that reports its write as absent has re-read the snapshot instead of the record.\n";
509
509
 
510
+ // ../../libs/agent-shared/dist/org-reference.js
511
+ var CANONICAL_UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
512
+ async function resolveOrgReference(reference, listOrgs) {
513
+ if (CANONICAL_UUID_RE.test(reference))
514
+ return reference;
515
+ const orgs = await listOrgs();
516
+ const match = orgs.find((org) => org.slug === reference);
517
+ if (match !== void 0)
518
+ return match.id;
519
+ const available = orgs.map((org) => org.slug).sort();
520
+ throw new Error(available.length === 0 ? `no organization is named "${reference}", and this credential can see none at all.` : `no organization is named "${reference}" \u2014 you are a member of: ${available.join(", ")}.`);
521
+ }
522
+
510
523
  // ../../libs/agent-shared/dist/resolve-agent-env.js
511
524
  function pick(env, name) {
512
525
  const value = env[name];
@@ -515,7 +528,8 @@ function pick(env, name) {
515
528
  function resolveAgentEnv(env) {
516
529
  return {
517
530
  apiUrl: pick(env, "PIPEBRAIN_API_URL"),
518
- token: pick(env, "PIPEBRAIN_TOKEN")
531
+ token: pick(env, "PIPEBRAIN_TOKEN"),
532
+ org: pick(env, "PIPEBRAIN_ORG")
519
533
  };
520
534
  }
521
535
 
@@ -15820,12 +15834,14 @@ var commentSchema = external_exports.object({
15820
15834
  updatedAt: external_exports.iso.datetime({ offset: true }),
15821
15835
  deletedAt: external_exports.iso.datetime({ offset: true }).nullable()
15822
15836
  });
15837
+ var apiTokenKindSchema = external_exports.enum(["connector", "manual"]);
15823
15838
  var apiTokenSchema = external_exports.object({
15824
15839
  id: uuidSchema,
15825
15840
  orgId: uuidSchema,
15826
15841
  userId: uuidSchema,
15827
15842
  label: external_exports.string().min(1),
15828
15843
  tokenPrefix: tokenPrefixSchema,
15844
+ kind: apiTokenKindSchema,
15829
15845
  lastUsedAt: external_exports.iso.datetime({ offset: true }).nullable(),
15830
15846
  revokedAt: external_exports.iso.datetime({ offset: true }).nullable(),
15831
15847
  createdAt: external_exports.iso.datetime({ offset: true })
@@ -16589,7 +16605,14 @@ var ApiClient = class _ApiClient {
16589
16605
  * leave the header pointing at the old org (the cross-org cache-bleed and
16590
16606
  * post-leave `/login` lockout root cause). Org-INDEPENDENT calls (`me`/`listOrgs`/
16591
16607
  * `createOrg`/the invitation inbox + by-token routes) stay on the base client,
16592
- * which sends NO header; bearer callers (MCP) ignore the header entirely.
16608
+ * which sends NO header.
16609
+ *
16610
+ * A BEARER CALLER USES IT TOO, and it is honoured there (PIPE-410): this is how
16611
+ * `pipebrain-mcp` scopes a session to `PIPEBRAIN_ORG`, how it re-scopes one call that
16612
+ * names another organization, and how `ppb` scopes an invocation to `--org`. The same
16613
+ * per-call binding is what makes that safe under the MCP SDK's unqueued dispatch — two
16614
+ * tool calls naming two organizations are genuinely in flight together, and a shared
16615
+ * mutable would place one call's write through the other's client.
16593
16616
  */
16594
16617
  forOrg(orgId) {
16595
16618
  return new _ApiClient({
@@ -17133,9 +17156,13 @@ var ApiClient = class _ApiClient {
17133
17156
  * (PIPE-87): revisions awaiting approval, questions awaiting an answer, and work
17134
17157
  * in `verify` with a criterion not yet passed, longest wait first.
17135
17158
  *
17136
- * Takes NO project and NO org: a queue you point at a project is the per-project
17137
- * surface this replaces, and org scope is the client's own (`X-Org-Id` for a
17138
- * session, the token's org for a bearer caller). `mine` narrows to the gates whose
17159
+ * Takes NO project and NO org PARAMETER: a queue you point at a project is the
17160
+ * per-project surface this replaces, and the organization is a property of the CLIENT,
17161
+ * which is where every caller already binds it — `X-Org-Id` for a session and for a
17162
+ * bearer caller alike, falling back to the credential's own organization when nothing
17163
+ * stamped one (PIPE-410 withdrew the rule that a bearer call's organization came off
17164
+ * the token). The agent tool DOES take an `org`, and it is spent on `forOrg` before it
17165
+ * gets here. `mine` narrows to the gates whose
17139
17166
  * work the viewer claimed — plus the requirement gates, which have no claimant at
17140
17167
  * all and would otherwise be waited on by nobody; omitting it is the wide view.
17141
17168
  */
@@ -17417,6 +17444,7 @@ function safeJsonParse(text) {
17417
17444
  }
17418
17445
 
17419
17446
  // ../../libs/mcp-server/dist/server.js
17447
+ import { AsyncLocalStorage } from "node:async_hooks";
17420
17448
  import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
17421
17449
 
17422
17450
  // ../../libs/mcp-server/dist/instructions.js
@@ -17541,10 +17569,22 @@ async function resolveDeliverableTargetId(client2, projectKey, ref) {
17541
17569
  }
17542
17570
  return match.id;
17543
17571
  }
17544
- function createMcpServer(client2, apiBaseUrl, orgInstructions2 = /* @__PURE__ */ new Map(), opts = {}) {
17572
+ var ORG_ARGUMENT_DESCRIPTION = "The organization this call acts in \u2014 its slug or its uuid. Omit it to act in this session\u2019s default.";
17573
+ var orgArgumentSchema = external_exports.string().min(1).describe(ORG_ARGUMENT_DESCRIPTION).optional();
17574
+ function createMcpServer(baseClient, apiBaseUrl, orgInstructions2 = /* @__PURE__ */ new Map(), opts = {}) {
17545
17575
  const surface = opts.surface ?? "local";
17576
+ const scope = new AsyncLocalStorage();
17577
+ function client2() {
17578
+ return scope.getStore()?.client ?? baseClient;
17579
+ }
17546
17580
  const banner = bindingBanner(apiBaseUrl);
17547
17581
  const guidance = composeGuidance(banner, orgInstructions2);
17582
+ async function callGuidance() {
17583
+ const fetchFor = opts.orgInstructionsFor;
17584
+ if (fetchFor === void 0)
17585
+ return guidance;
17586
+ return composeGuidance(banner, await fetchFor(scope.getStore()?.orgId));
17587
+ }
17548
17588
  const server2 = new McpServer({ name: "pipebrain", version: opts.version ?? DEFAULT_VERSION }, {
17549
17589
  // A BOUNDED INDEX, not a document container (PIPE-D30). The client truncates this
17550
17590
  // field at 2KB and shares roughly 4KB across all configured servers, so what goes
@@ -17562,15 +17602,31 @@ function createMcpServer(client2, apiBaseUrl, orgInstructions2 = /* @__PURE__ */
17562
17602
  });
17563
17603
  function registerStrict(name, config3, cb) {
17564
17604
  const declared = config3.inputSchema;
17565
- const inputSchema = declared === void 0 ? external_exports.strictObject({}) : "_zod" in declared || "_def" in declared ? declared : external_exports.strictObject(declared);
17605
+ const strict = declared === void 0 ? external_exports.strictObject({}) : "_zod" in declared || "_def" in declared ? declared : external_exports.strictObject(declared);
17606
+ const inputSchema = strict.extend({ org: orgArgumentSchema });
17566
17607
  server2.registerTool(
17567
17608
  name,
17568
17609
  { ...config3, inputSchema },
17569
17610
  // The cast retells what the generic already guarantees: the SDK calls the
17570
17611
  // handler with the parse result of the schema derived from `InputArgs`, and a
17571
17612
  // strict wrap changes which calls REACH the handler, never the shape of one
17572
- // that does.
17573
- cb
17613
+ // that does. The wrapper below hands `cb` the same parse result minus `org`,
17614
+ // which no handler declared and none can see.
17615
+ (async (raw, extra) => {
17616
+ const { org, ...args } = raw;
17617
+ const handler = cb;
17618
+ if (org === void 0)
17619
+ return handler(args, extra);
17620
+ let scoped;
17621
+ let orgId;
17622
+ try {
17623
+ orgId = await resolveOrgReference(org, () => baseClient.listOrgs());
17624
+ scoped = baseClient.forOrg(orgId);
17625
+ } catch (err) {
17626
+ return toolError(err);
17627
+ }
17628
+ return scope.run({ client: scoped, orgId }, () => handler(args, extra));
17629
+ })
17574
17630
  );
17575
17631
  }
17576
17632
  registerStrict("list_projects", {
@@ -17581,24 +17637,25 @@ function createMcpServer(client2, apiBaseUrl, orgInstructions2 = /* @__PURE__ */
17581
17637
  limit: external_exports.number().int().min(1).max(500).optional(),
17582
17638
  offset: external_exports.number().int().nonnegative().optional()
17583
17639
  }
17584
- }, (args) => run(() => client2.listProjects(args), GUIDANCE_POINTER));
17640
+ }, (args) => run(() => client2().listProjects(args), GUIDANCE_POINTER));
17585
17641
  registerStrict("create_project", {
17586
17642
  description: "Create a new project \u2014 the workflow bootstrap entry point, since issues and requirements are all project-scoped and nothing can be filed until a project exists. Both `name` (its display label) and `key` are required; the key is 2\u20135 uppercase letters (A\u2013Z, e.g. `DWB`), unique per org, and becomes the prefix of every display id in the project. Returns the created project (\xA77).",
17587
17643
  // Inline shape: @pipeline/domain has no standalone create-project schema — the
17588
17644
  // same `{ name, key }` pair lives only inside createOrgInputSchema.project, so
17589
17645
  // this mirrors it exactly (key = 2–5 A–Z via projectKeySchema) and matches
17590
- // client.createProject's `{ name, key }` contract.
17646
+ // `ApiClient.createProject`'s `{ name, key }` contract.
17591
17647
  inputSchema: {
17592
17648
  name: external_exports.string().min(1),
17593
17649
  key: projectKeySchema
17594
17650
  }
17595
- }, (args) => run(() => client2.createProject(args)));
17651
+ }, (args) => run(() => client2().createProject(args)));
17596
17652
  registerStrict("list_waiting", {
17597
- description: "Every gate awaiting a PERSON across ALL projects in the token\u2019s org, longest wait first: a requirement revision awaiting approval, a question awaiting an answer, and work in `verify` holding at least one criterion not yet passed. Each entry names its project, the ref the action is taken on (`KEY-R{n}` for a revision, the ISSUE\u2019s `KEY-{n}` for a question or for work at verify), and `waitingSince` \u2014 the instant the wait began, not a duration. Nothing else is a gate: work in `triage` never appears, and neither does work in verify whose criteria have ALL passed. THIS TOOL is READ-ONLY and clears nothing; what clears each gate differs. Answering a question has no tool on this surface, by design. A requirement revision is approved with `approve_requirement`. A verify gate clears as its criteria pass \u2014 an `auto` one through `set_criterion_state`, a `manual` one only ever by a person in the web app. Use it to see what your work is blocked on before asking, rather than to act on it."
17598
- // NO arguments — not even an org. Org scope arrives from the token, exactly as
17599
- // it does for `list_projects`, and an org parameter would open a cross-org read
17600
- // path that has no precedent anywhere on this surface. The viewer narrowing the
17601
- // web queue offers is filter state on that view, not something an agent picks.
17653
+ description: "Every gate awaiting a PERSON across ALL projects in the organization this call acts in \u2014 name that organization with `org`, or omit it to read the one this session defaults to \u2014 longest wait first: a requirement revision awaiting approval, a question awaiting an answer, and work in `verify` holding at least one criterion not yet passed. Each entry names its project, the ref the action is taken on (`KEY-R{n}` for a revision, the ISSUE\u2019s `KEY-{n}` for a question or for work at verify), and `waitingSince` \u2014 the instant the wait began, not a duration. Nothing else is a gate: work in `triage` never appears, and neither does work in verify whose criteria have ALL passed. THIS TOOL is READ-ONLY and clears nothing; what clears each gate differs. Answering a question has no tool on this surface, by design. A requirement revision is approved with `approve_requirement`. A verify gate clears as its criteria pass \u2014 an `auto` one through `set_criterion_state`, a `manual` one only ever by a person in the web app. Use it to see what your work is blocked on before asking, rather than to act on it."
17654
+ // NO NARROWING ARGUMENTS. The one argument this tool does take — `org`, which every
17655
+ // tool takes — is not a narrowing: it says WHICH ORGANIZATION the call acts in, not
17656
+ // which of that organization's gates come back, and the caller's membership there is
17657
+ // checked on the way in (PIPE-410). The viewer narrowing the web queue offers is
17658
+ // filter state on that view, not something an agent picks.
17602
17659
  }, () => (
17603
17660
  // `{ items }`, mirroring the HTTP envelope rather than unwrapping to a bare array
17604
17661
  // like the sibling list tools. The reason is the envelope itself: this tool is a
@@ -17606,12 +17663,12 @@ function createMcpServer(client2, apiBaseUrl, orgInstructions2 = /* @__PURE__ */
17606
17663
  // place for that answer's shape to be decided.
17607
17664
  //
17608
17665
  // The two surfaces are NOT interchangeable, and nothing here should suggest they
17609
- // are. This tool takes no narrowing arguments and returns the org's WHOLE queue,
17610
- // while the web view narrows what it DRAWS — by project, by category, and by viewer
17611
- // scope. One endpoint decides what counts as a gate, so that definition cannot drift
17612
- // between them; what an agent reads here is everything waiting, rather than whatever
17613
- // the operator happens to be looking at.
17614
- run(async () => ({ items: await client2.listWaiting() }), GUIDANCE_POINTER)
17666
+ // are. This tool returns the WHOLE queue of the organization it acts in, while the
17667
+ // web view narrows what it DRAWS — by project, by category, and by viewer scope. One
17668
+ // endpoint decides what counts as a gate, so that definition cannot drift between
17669
+ // them; what an agent reads here is everything waiting, rather than whatever the
17670
+ // operator happens to be looking at.
17671
+ run(async () => ({ items: await client2().listWaiting() }), GUIDANCE_POINTER)
17615
17672
  ));
17616
17673
  registerStrict(
17617
17674
  "get_work_context",
@@ -17649,7 +17706,22 @@ function createMcpServer(client2, apiBaseUrl, orgInstructions2 = /* @__PURE__ */
17649
17706
  // THE COMPOSED GUIDANCE RIDES THE RESULT, as a second text block after the API's JSON.
17650
17707
  // This is the delivery PIPE-D30 chose: a tool result is not subject to the 2KB cap that
17651
17708
  // cut the previous mechanism to a tenth of the document.
17652
- (args) => run(() => client2.getWorkContext(args), guidance)
17709
+ //
17710
+ // AND IT IS COMPOSED FOR THE ORGANIZATION THE CALL ACTED IN (PIPE-410). This is the one
17711
+ // call site the composition has, so a call naming another organization would otherwise
17712
+ // return that organization's work item, requirements and conventions under THIS one's
17713
+ // writing rules, in one document, with nothing in it saying so. See
17714
+ // `opts.orgInstructionsFor`, which is what a caller supplies to close that; without it
17715
+ // the construction-time composition is returned exactly as before.
17716
+ async (args) => {
17717
+ let appended;
17718
+ try {
17719
+ appended = await callGuidance();
17720
+ } catch (err) {
17721
+ return toolError(err);
17722
+ }
17723
+ return run(() => client2().getWorkContext(args), appended);
17724
+ }
17653
17725
  );
17654
17726
  registerStrict("create_milestone", {
17655
17727
  description: "Create a milestone on a project. `token` is the short ref issues point at via their `milestone` field (e.g. `M1`) and is unique per project (a duplicate is rejected); `label` is its display name (e.g. `Feature Verification`). Optional `position` orders it (0-based, defaults to last); optional `active` marks it the current milestone \u2014 AT MOST ONE milestone per project is active, so `active: true` transactionally DEMOTES the previously active one rather than failing. Returns the created milestone (\xA77).",
@@ -17660,7 +17732,7 @@ function createMcpServer(client2, apiBaseUrl, orgInstructions2 = /* @__PURE__ */
17660
17732
  position: external_exports.number().int().nonnegative().optional(),
17661
17733
  active: external_exports.boolean().optional()
17662
17734
  }
17663
- }, ({ project, ...input }) => run(() => client2.createMilestone(project, input)));
17735
+ }, ({ project, ...input }) => run(() => client2().createMilestone(project, input)));
17664
17736
  registerStrict("update_milestone", {
17665
17737
  description: "Rename or reorder a milestone, addressed by its token (e.g. `M1`) or uuid. Supply at least one of `token`, `label`, or `position` \u2014 an empty edit is rejected. Renaming the `token` does NOT rewrite issues pointing at the old one (`issues.milestone` is a loose ref), so prefer changing `label`. Use set_active_milestone to change `active` (\xA77).",
17666
17738
  inputSchema: {
@@ -17670,14 +17742,14 @@ function createMcpServer(client2, apiBaseUrl, orgInstructions2 = /* @__PURE__ */
17670
17742
  label: external_exports.string().min(1).optional(),
17671
17743
  position: external_exports.number().int().nonnegative().optional()
17672
17744
  }
17673
- }, ({ project, milestone, ...fields }) => run(async () => client2.updateMilestone(project, await resolveMilestoneId(client2, project, milestone), fields)));
17745
+ }, ({ project, milestone, ...fields }) => run(async () => client2().updateMilestone(project, await resolveMilestoneId(client2(), project, milestone), fields)));
17674
17746
  registerStrict("set_active_milestone", {
17675
17747
  description: "Make a milestone the project\u2019s active one, addressed by its token (e.g. `M2`) or uuid. At most one milestone per project is active; this clears the previous one in the same transaction. Returns the activated milestone (\xA77).",
17676
17748
  inputSchema: {
17677
17749
  project: projectKeySchema,
17678
17750
  milestone: external_exports.string().min(1)
17679
17751
  }
17680
- }, ({ project, milestone }) => run(async () => client2.activateMilestone(project, await resolveMilestoneId(client2, project, milestone))));
17752
+ }, ({ project, milestone }) => run(async () => client2().activateMilestone(project, await resolveMilestoneId(client2(), project, milestone))));
17681
17753
  registerStrict("delete_milestone", {
17682
17754
  description: "Soft-delete a milestone, addressed by its token (e.g. `M3`) or uuid; its token frees up for reuse. Issues still naming it are NOT rewritten and keep the now-dangling token (`issues.milestone` is a loose ref) \u2014 re-point them first. Returns confirmation metadata only (\xA77).",
17683
17755
  inputSchema: {
@@ -17685,8 +17757,8 @@ function createMcpServer(client2, apiBaseUrl, orgInstructions2 = /* @__PURE__ */
17685
17757
  milestone: external_exports.string().min(1)
17686
17758
  }
17687
17759
  }, ({ project, milestone }) => run(async () => {
17688
- const id = await resolveMilestoneId(client2, project, milestone);
17689
- await client2.deleteMilestone(project, id);
17760
+ const id = await resolveMilestoneId(client2(), project, milestone);
17761
+ await client2().deleteMilestone(project, id);
17690
17762
  return { deleted: true, project, milestone, id };
17691
17763
  }));
17692
17764
  registerStrict("create_deliverable_target", {
@@ -17698,7 +17770,7 @@ function createMcpServer(client2, apiBaseUrl, orgInstructions2 = /* @__PURE__ */
17698
17770
  position: external_exports.number().int().nonnegative().optional(),
17699
17771
  active: external_exports.boolean().optional()
17700
17772
  }
17701
- }, ({ project, ...input }) => run(() => client2.createDeliverableTarget(project, input)));
17773
+ }, ({ project, ...input }) => run(() => client2().createDeliverableTarget(project, input)));
17702
17774
  registerStrict("update_deliverable_target", {
17703
17775
  description: "Update a deliverable target, addressed by its slug (e.g. `bsky`) or uuid. Supply at least one of `label`, `position`, or `active` \u2014 an empty edit is rejected. The `slug` is immutable (it is the value stored on existing deliverables). Set `active: false` to remove it from the add-deliverable menu while keeping existing deliverables working.",
17704
17776
  inputSchema: {
@@ -17708,7 +17780,7 @@ function createMcpServer(client2, apiBaseUrl, orgInstructions2 = /* @__PURE__ */
17708
17780
  position: external_exports.number().int().nonnegative().optional(),
17709
17781
  active: external_exports.boolean().optional()
17710
17782
  }
17711
- }, ({ project, target, ...fields }) => run(async () => client2.updateDeliverableTarget(project, await resolveDeliverableTargetId(client2, project, target), fields)));
17783
+ }, ({ project, target, ...fields }) => run(async () => client2().updateDeliverableTarget(project, await resolveDeliverableTargetId(client2(), project, target), fields)));
17712
17784
  registerStrict("delete_deliverable_target", {
17713
17785
  description: "Delete a deliverable target, addressed by its slug (e.g. `bsky`) or uuid. Only a target with NO deliverables can be deleted; one already in use is rejected (deactivate it with update_deliverable_target instead). Returns confirmation metadata only.",
17714
17786
  inputSchema: {
@@ -17716,8 +17788,8 @@ function createMcpServer(client2, apiBaseUrl, orgInstructions2 = /* @__PURE__ */
17716
17788
  target: external_exports.string().min(1)
17717
17789
  }
17718
17790
  }, ({ project, target }) => run(async () => {
17719
- const id = await resolveDeliverableTargetId(client2, project, target);
17720
- await client2.deleteDeliverableTarget(project, id);
17791
+ const id = await resolveDeliverableTargetId(client2(), project, target);
17792
+ await client2().deleteDeliverableTarget(project, id);
17721
17793
  return { deleted: true, project, target, id };
17722
17794
  }));
17723
17795
  registerStrict(
@@ -17736,7 +17808,7 @@ function createMcpServer(client2, apiBaseUrl, orgInstructions2 = /* @__PURE__ */
17736
17808
  // and an explicit filter, terminal values and all, is forwarded verbatim as
17737
17809
  // it always was. (The work page kept its terminal rows by naming every
17738
17810
  // status on its reads, so nothing over there leant on the defaultless API.)
17739
- (args) => run(() => client2.listIssues(args), GUIDANCE_POINTER)
17811
+ (args) => run(() => client2().listIssues(args), GUIDANCE_POINTER)
17740
17812
  );
17741
17813
  registerStrict("get_issue", {
17742
17814
  description: `Full issue detail by display id or uuid: the header \u2014 \`summary\`, \`why\`, \`affectedSurfaces\`, with \`headerDerivedAt\` and \`headerStale\`, true when nobody has written a header or the body has moved since one was written, and \`set_issue_header\` is what writes it \u2014 body, criteria (states, modes, evidence), explicit requirement links (pinned revision + staleness), the project\u2019s cross-cutting requirements at their latest approved revision, this organization\u2019s approved conventions \u2014 standing guidance that BINDS work in every project here, delivered in full at the revision a person approved \u2014 children, and comments (\xA77). Carries \`terminal\`: true when the issue is finished (\`done\`) or deliberately abandoned (\`killed\`) and is therefore NOT buildable work \u2014 check it before acting on an issue you were handed by key. Reading criterion state: \`state_evidence\` is required only when a TOKEN sets one, so a \`manual\` criterion \u2014 settable only from a web session \u2014 carries none by design, and the attribution the server already stores (who set it, and when) IS its record. What this payload tells you about ANOTHER issue goes stale. Reference that issue by key and say what you need from it; never restate its status, its criteria, or whether those criteria passed. Long records read in PARTS: \`bodyOffset\`/\`bodyLimit\` window the body (UTF-16 offsets; parts concatenate back exactly), \`commentOffset\`/\`commentLimit\` window the oldest-first comment list. Unpaged, the body is capped at ${ISSUE_BODY_CHAR_LIMIT} chars and comments at the newest ${ISSUE_COMMENT_LIMIT}; a response that left anything out says so in \`omitted\` \u2014 the true totals, the omitted comment count, and in \`next\` the exact arguments for the adjacent part (body walks forward, comments toward older) \u2014 follow \`next\` until null to retrieve everything. An issue under both caps reads whole in ONE call, no notice.`,
@@ -17759,7 +17831,7 @@ function createMcpServer(client2, apiBaseUrl, orgInstructions2 = /* @__PURE__ */
17759
17831
  // comment tail needs no offset — an omitted `commentOffset` beside a present
17760
17832
  // `commentLimit` IS the newest tail, resolved server-side, so no extra round
17761
17833
  // trip asks how many comments exist (PIPE-R15 rule 4).
17762
- client2.getIssue(issue2, {
17834
+ client2().getIssue(issue2, {
17763
17835
  bodyOffset,
17764
17836
  bodyLimit: bodyLimit ?? ISSUE_BODY_CHAR_LIMIT,
17765
17837
  commentOffset,
@@ -17769,14 +17841,14 @@ function createMcpServer(client2, apiBaseUrl, orgInstructions2 = /* @__PURE__ */
17769
17841
  registerStrict("create_issue", {
17770
17842
  description: "Create an issue (epic/task/bug/feedback). Omitted status defaults to triage (still subject to \xA76 guards); omitted environment resolves explicit \u2192 parent\u2019s environment \u2192 project default (prod). Optional parent (a parent already `done` or `killed` is rejected `parent_terminal`, unless the child is itself terminal; a new issue is a leaf, so no cycle is possible here), priority, milestone, requirement_links (pins each at its approved revision; a target with no approved revision is rejected), deliverable_links (content deliverables like DWB-C3/bsky \u2014 pins each at its current revision; the promotion path), and ordered {text, verification, howTo} criteria (\xA77). A `status` other than `triage` or `killed` REQUIRES `milestone` (PIPE-R10 rule 9): work past triage belongs to a release, and the create is refused (`milestone_required`) without one. A `manual` criterion must carry `howTo` \u2014 one or two sentences saying where to look, what to do, and what counts as passing; writing or changing one without it is refused (`how_to_required`), and so is supplying it on an `auto` criterion, which a machine checks. Work of any kind carries criteria \u2014 an epic, a task, a bug alike \u2014 with feedback the one exception, refused with `criteria_not_supported` because it is a report rather than agreed work; `promote_feedback` retypes it into work before anything is built. When a bug is filed against a defined acceptance criterion, pass that criterion\u2019s uuid as `criterionId` and the bug records which criterion it was filed against \u2014 what has already been reported arrives as `filedBugs` on every criteria read. Filing a second bug against one criterion is supported: one row can fail for two different reasons at once. Bugs only: any other type naming a criterion is refused (`criterion_requires_bug`). Writing guidance for this tool lives in the product doctrine, which `get_work_context` returns \u2014 see \u201CSearch before you create\u201D and \u201CThe bar for filing a bug\u201D.",
17771
17843
  inputSchema: createIssueInputSchema.shape
17772
- }, (args) => run(() => client2.createIssue(args)));
17844
+ }, (args) => run(() => client2().createIssue(args)));
17773
17845
  registerStrict("promote_feedback", {
17774
17846
  description: "Promote a FEEDBACK issue into a NEW epic or task (PIPE-143): creates the issue in the feedback\u2019s project (`title` + `type` required; omitted environment inherits the FEEDBACK\u2019s environment, not the project default; optional status/body/priority/milestone/requirement_links/criteria as in create_issue), records the feedback as its permanent source (`promotedFrom`/`promotedTo` on both details), closes the feedback as done, and comments the new key on it. The feedback\u2019s own title/body are never touched \u2014 write the new issue\u2019s body as real work. Rejected (409) for non-feedback, terminal, or already-promoted sources, and refused (422 `status_guard`, naming each offending child and its status) when the feedback carries a child issue that is not yet `done` or `killed` \u2014 closing the source would strand that child under a finished parent, so finish or kill the child first. Returns the created issue. A `status` other than `triage` or `killed` REQUIRES `milestone` (PIPE-R10 rule 9), exactly as in create_issue; the SOURCE feedback needs none to be closed by the promotion. A `manual` criterion must carry `howTo` \u2014 one or two sentences saying where to look, what to do, and what counts as passing; writing or changing one without it is refused (`how_to_required`), and so is supplying it on an `auto` criterion, which a machine checks. Work of any kind carries criteria \u2014 an epic, a task, a bug alike \u2014 with feedback the one exception, refused with `criteria_not_supported` because it is a report rather than agreed work; this tool is what retypes it into work before anything is built. Writing guidance for this tool lives in the product doctrine, which `get_work_context` returns \u2014 see \u201CSearch before you create\u201D and \u201CThe bar for filing a bug\u201D.",
17775
17847
  inputSchema: {
17776
17848
  issue: external_exports.string().min(1),
17777
17849
  ...promoteFeedbackInputSchema.shape
17778
17850
  }
17779
- }, ({ issue: issue2, ...fields }) => run(() => client2.promoteFeedback(issue2, fields)));
17851
+ }, ({ issue: issue2, ...fields }) => run(() => client2().promoteFeedback(issue2, fields)));
17780
17852
  registerStrict("open_review", {
17781
17853
  description: "Open the COMPLETION REVIEW \u2014 the reading of an epic\u2019s WHOLE accumulated change as one body of work, by a third fresh session that neither built it nor evaluated it. It runs at one moment: once the epic\u2019s contract is green and before anyone sets it `done`. It creates one ORDINARY `task` at `ready` carrying the review checklist as its body. The epic form (`epic`) titles it `Completion review \u2014 <KEY-n> <epic title>`, files it as a CHILD of the epic and inherits the epic\u2019s milestone; the milestone form (`project` + `milestone`) titles it `Completion review \u2014 milestone <token>`, carries that token and has no parent. Pass EXACTLY ONE of `epic` or `project` + `milestone`: both, or neither, is refused. One review at a time per scope \u2014 a second is refused (`review_already_open`) NAMING the standing one, so read, finish or kill that task instead. The scopes overlap ONE way: the epic form\u2019s review also stands for that same project and milestone, so a later milestone-form open is refused; a milestone-form review blocks no epic-form open. A review opens only on a non-terminal epic \u2014 `review_target_not_epic` otherwise, `review_target_terminal` on a `done`/`killed` epic (a re-opened epic reviews again). NO NEW GATE was added to `done`: file each finding as ordinary work \u2014 a CHILD OF THE EPIC, a sibling of this review \u2014 and the children clause already on `done` holds the epic open until every finding is done or killed. A finding filed UNDER the review gates nothing, because that gate reads one level deep. Killing the review, or any finding, is the recorded waiver: deliberately ungated, and written to the status history with who did it and through which token. Writing guidance for the checklist and for each finding lives in the product doctrine, which `get_work_context` returns.",
17782
17854
  // The WHOLE domain schema rather than its `.shape`, for `get_work_context`'s
@@ -17784,51 +17856,51 @@ function createMcpServer(client2, apiBaseUrl, orgInstructions2 = /* @__PURE__ */
17784
17856
  // shape drops it — the refusal naming the two forms would never reach the
17785
17857
  // caller, and both arguments (or neither) would be accepted here.
17786
17858
  inputSchema: openReviewInputSchema
17787
- }, (args) => run(() => client2.openReview(args)));
17859
+ }, (args) => run(() => client2().openReview(args)));
17788
17860
  registerStrict("update_issue", {
17789
17861
  description: "Update any subset of an issue\u2019s title, body, type, priority, milestone, environment, parent (self/cycle rejected, and moving an OPEN issue onto a parent already `done` or `killed` is rejected with `parent_terminal` \u2014 clearing the parent with null is always allowed), requirement_links (add/remove; adding a link to an unapproved requirement is rejected), deliverable_links (add/remove content-deliverable links, add pins at the current revision), or decision_links (add/remove decision records this work sits under \u2014 `KEY-D{n}`, from `list_decisions`). Changing type to `feedback` is rejected while the issue has criteria (\xA77), since feedback carries none; epic, task and bug interchange freely and the criteria ride along, keeping their AC-{n} numbers and their states. Clearing `milestone` (passing null) is rejected while the issue sits past `triage` \u2014 work already scheduled keeps a milestone (PIPE-R10 rule 9); swap it for a different one, or move the issue back to `triage` first. Writing guidance for this tool lives in the product doctrine, which `get_work_context` returns \u2014 see \u201CLink by key; never paste another record\u2019s text\u201D and \u201CA decision you need is filed as a question, never written into a body\u201D.",
17790
17862
  inputSchema: updateIssueInputSchema.shape
17791
- }, ({ issue: issue2, ...fields }) => run(() => client2.updateIssue(issue2, fields)));
17863
+ }, ({ issue: issue2, ...fields }) => run(() => client2().updateIssue(issue2, fields)));
17792
17864
  registerStrict("set_issue_header", {
17793
17865
  description: "Write an issue\u2019s HEADER \u2014 the three lines an operator reads before deciding anything: `summary` (the change, in one sentence), `why` (the user, business, cost or operational reason rather than the technical one; when nothing is user-visible, the cost of leaving it alone) and `affectedSurfaces` (which parts of the product this touches, and who feels it). All three are REQUIRED and the write is whole-value: the header is replaced entire and never merged, so a partial write cannot leave the stored provenance vouching for lines it did not touch. Returns the full issue detail. WRITE ALL THREE IN PLAIN WORDS: no identifiers, no file paths, no type names, no jargon. Their reader is deciding, not building, and the depth belongs in the body underneath them. A `summary` shaped like code \u2014 a repository path, a line number, a symbol written as a call or in backticks \u2014 is refused (400) naming what was found. `summary` is capped at 350 characters; over it the write is refused naming both the cap and the length received. THE HEADER CAN BE WRITTEN NO OTHER WAY: `summary`, `why` or `affectedSurfaces` passed to `create_issue`, `update_issue` or `promote_feedback` is refused (400) naming the field, rather than silently dropped \u2014 create the issue first, then write its header here. Every read of the issue carries `headerStale`, true when the body has changed since these three lines were derived from it and true when no header was ever written; writing here clears it. Writing guidance for these three lines is stated above; the organization\u2019s own writing rules, which `get_work_context` returns, govern the body beneath them.",
17794
17866
  inputSchema: setIssueHeaderInputSchema.shape
17795
- }, ({ issue: issue2, ...fields }) => run(() => client2.setIssueHeader(issue2, fields)));
17867
+ }, ({ issue: issue2, ...fields }) => run(() => client2().setIssueHeader(issue2, fields)));
17796
17868
  registerStrict("set_status", {
17797
17869
  description: "Set an issue\u2019s status; the \xA76 guards apply and a guard failure returns the specific reason, naming the rows it refused on (\xA77). The criteria gates read whatever criteria the issue carries, whatever its type: verify needs every auto criterion passed, done needs every criterion passed. ONE guard remains EPIC-ONLY, and the asymmetry is the rule rather than an oversight \u2014 an epic that has stated NO criteria is refused at both gates, because an empty list would clear them having committed to nothing, while a task or a bug carrying none moves through both untouched (most work is stated adequately by its body). `done` additionally requires every child of the issue being closed to be terminal \u2014 an epic, a task and a bug alike \u2014 read from each child\u2019s STATUS and never from its criteria. A BLOCKED issue \u2014 one carrying an explicit mark or waiting on a blocker that is not yet `done`/`killed` \u2014 cannot move to `ready` or `in_progress`, and the refusal names the reason and every unresolved blocker, so clear the mark (`clear_blocked`) or finish, kill or `unlink_blocker` each blocker first; every other target still moves while blocked. An issue with NO milestone cannot move to any status but `triage` and `killed` (PIPE-R10 rule 9) \u2014 set one with `update_issue` first; `killed` is exempt, so work nobody scheduled can still be abandoned.",
17798
17870
  inputSchema: setStatusInputSchema.shape
17799
- }, (args) => run(() => client2.setStatus(args.issue, args.status)));
17871
+ }, (args) => run(() => client2().setStatus(args.issue, args.status)));
17800
17872
  registerStrict("claim_issue", {
17801
17873
  description: "Atomically claim an issue (\xA76 rule 1): succeeds only if unclaimed; under a race exactly one wins and the loser\u2019s error names the current claimer. Claim is orthogonal to status (\xA77).",
17802
17874
  inputSchema: { issue: issueRefSchema }
17803
- }, (args) => run(() => client2.claimIssue(args.issue)));
17875
+ }, (args) => run(() => client2().claimIssue(args.issue)));
17804
17876
  registerStrict("release_issue", {
17805
17877
  description: "Release an issue\u2019s claim, clearing claimed_by (\xA77).",
17806
17878
  inputSchema: { issue: issueRefSchema }
17807
- }, (args) => run(() => client2.releaseIssue(args.issue)));
17879
+ }, (args) => run(() => client2().releaseIssue(args.issue)));
17808
17880
  registerStrict("add_comment", {
17809
17881
  description: "Add a markdown comment to an issue, attributed to the operator (and token label over MCP). A comment EXPLAINS a blockage \u2014 the full account of what you hit and why you stopped \u2014 but never records one: `set_blocked` (with a reason) and `link_blocker` (when you are waiting on another issue) are what put an issue in the blocked state (\xA77/WORKFLOW). Writing guidance for a comment lives in the product doctrine, which `get_work_context` returns \u2014 see \u201CEvery loose end has one destination, and none of them is prose\u201D.",
17810
17882
  inputSchema: commentInputSchema.shape
17811
- }, (args) => run(() => client2.addComment(args.issue, args.body)));
17883
+ }, (args) => run(() => client2().addComment(args.issue, args.body)));
17812
17884
  registerStrict("set_blocked", {
17813
17885
  description: "Record an issue as BLOCKED with a required human-readable `reason` \u2014 state on the issue, not a comment: it shows on the issue and counts on the project\u2019s Work page, and only clearing it (`clear_blocked`) ends it. Setting it again on an already-blocked issue replaces the standing reason and keeps the old one as history, attributed to whoever set it. The reason is one or two lines saying what the work is waiting on; the full account of what you tried still belongs in a comment. Returns the updated issue detail, whose `blocked` carries the reason and who set it. Writing guidance for the reason lives in the product doctrine, which `get_work_context` returns.",
17814
17886
  inputSchema: setBlockedInputSchema.shape
17815
- }, (args) => run(() => client2.setBlocked(args.issue, args.reason)));
17887
+ }, (args) => run(() => client2().setBlocked(args.issue, args.reason)));
17816
17888
  registerStrict("clear_blocked", {
17817
17889
  description: "Clear an issue\u2019s blocked mark \u2014 the blockage is over. Idempotent: clearing an issue that is not blocked is a no-op, not an error. The cleared mark is kept as history with who ended it, so a past blockage stays readable. Returns the updated issue detail (`blocked` is then null).",
17818
17890
  inputSchema: { issue: issueRefSchema }
17819
- }, (args) => run(() => client2.clearBlocked(args.issue)));
17891
+ }, (args) => run(() => client2().clearBlocked(args.issue)));
17820
17892
  registerStrict("link_blocker", {
17821
17893
  description: "Record that `issue` is WAITING ON `blocker` \u2014 the dependency between two issues, written from the waiting issue\u2019s side. One call records both directions: `get_issue` on the waiting issue lists it under `blockedBy` (with the blocker\u2019s display id, title, and whether it is already `done`/`killed`), and `get_issue` on the blocker lists it under `blocks`, so finishing work shows what it frees. Both issues must be in the SAME project. An issue cannot block itself, and an edge that would close a cycle (directly or through other issues) is refused with nothing recorded. Adding the same blocker twice records no second edge. Returns the waiting issue\u2019s updated detail.",
17822
17894
  inputSchema: linkBlockerInputSchema.shape
17823
- }, (args) => run(() => client2.addBlocker(args.issue, args.blocker)));
17895
+ }, (args) => run(() => client2().addBlocker(args.issue, args.blocker)));
17824
17896
  registerStrict("unlink_blocker", {
17825
17897
  description: "Remove the blocked-by edge between `issue` and `blocker` \u2014 the dependency is gone, and one call clears it from BOTH issues\u2019 views. Idempotent: unlinking a pair that is not linked is a no-op, not an error. Returns the waiting issue\u2019s updated detail.",
17826
17898
  inputSchema: linkBlockerInputSchema.shape
17827
- }, (args) => run(() => client2.removeBlocker(args.issue, args.blocker)));
17899
+ }, (args) => run(() => client2().removeBlocker(args.issue, args.blocker)));
17828
17900
  registerStrict("set_criteria", {
17829
17901
  description: "Define or replace the ordered acceptance criteria list ({text, verification, howTo}) on a piece of work. Matched rows keep their stable AC-{n} number; new items get fresh never-reused numbers; removed items are soft-deleted. A matched row keeps its state only when BOTH its text and verification mode are unchanged \u2014 a mode flip resets it to pending (\xA77). A `manual` criterion must carry `howTo` \u2014 one or two sentences saying where to look, what to do, and what counts as passing; writing or changing one without it is refused (`how_to_required`), and so is supplying it on an `auto` criterion, which a machine checks. Work of any kind carries criteria \u2014 an epic, a task, a bug alike \u2014 with feedback the one exception, refused with `criteria_not_supported` because it is a report rather than agreed work; `promote_feedback` retypes it into work before anything is built. Raising a criterion from `manual` to `auto` both resets its state and clears the stored `howTo`, so a criterion moved to `auto` has lost its checking instructions \u2014 moving it back to `manual` does not restore them, and is refused (`how_to_required`) until you write new ones. Writing guidance for a criterion, and for choosing its mode, lives in the product doctrine, which `get_work_context` returns \u2014 see \u201CVerification modes follow what can be driven\u201D.",
17830
17902
  inputSchema: setCriteriaInputSchema.shape
17831
- }, (args) => run(() => client2.setCriteria(args.issue, args.criteria)));
17903
+ }, (args) => run(() => client2().setCriteria(args.issue, args.criteria)));
17832
17904
  registerStrict("set_criterion_state", {
17833
17905
  description: "Set a criterion\u2019s state (pending/passed/failed) on whatever work carries it \u2014 an epic, a task and a bug alike \u2014 addressed by criterionId ALONE, or by issue + criterionNumber (the stable AC-{n}); exactly one form. Feedback never carries criteria, so neither address resolves to one. A token-authenticated call is REJECTED on a manual criterion (manual state is web-session-only, \xA74); evidence is required when a token marks passed/failed (\xA77). Writing guidance for that evidence lives in the product doctrine, which `get_work_context` returns \u2014 see \u201CVerification modes follow what can be driven\u201D.",
17834
17906
  // `issue` is OPTIONAL: the criterionId-only form needs no issue ref. The
@@ -17849,12 +17921,12 @@ function createMcpServer(client2, apiBaseUrl, orgInstructions2 = /* @__PURE__ */
17849
17921
  }, (args) => run(() => {
17850
17922
  const input = setCriterionStateInputSchema.parse(args);
17851
17923
  if (input.criterionId !== void 0) {
17852
- return client2.setCriterionStateById(input.criterionId, {
17924
+ return client2().setCriterionStateById(input.criterionId, {
17853
17925
  state: input.state,
17854
17926
  evidence: input.evidence
17855
17927
  });
17856
17928
  }
17857
- return client2.setCriterionState(input.issue, {
17929
+ return client2().setCriterionState(input.issue, {
17858
17930
  criterionNumber: input.criterionNumber,
17859
17931
  state: input.state,
17860
17932
  evidence: input.evidence
@@ -17863,23 +17935,23 @@ function createMcpServer(client2, apiBaseUrl, orgInstructions2 = /* @__PURE__ */
17863
17935
  registerStrict("ask_questions", {
17864
17936
  description: "Ask the operator a BATCH of questions on an issue \u2014 `questions` takes 1 or more {text, options?}, and a session with one open decision usually has two or three, so ask them in ONE call rather than one at a time (a half-asked set costs the operator a second pass). `options` are the choices you propose, in the order you offer them; omit it to ask in open words. Each question gets a stable per-issue `Q-{n}` number that is NEVER reused. Returns the updated issue detail, and every issue read from then on carries `questions` with their answers \u2014 so read the answer in the `get_issue` you were going to make anyway, and READ the existing questions and answers BEFORE asking again rather than re-asking a decision already taken. Answering is reserved for a person in the web UI: there is deliberately no tool for it on this surface (PIPE-R22 rule 4). A question is withdrawn with `withdraw_question`. Writing guidance for a question lives in the product doctrine, which `get_work_context` returns \u2014 see \u201CA decision you need is filed as a question, never written into a body\u201D.",
17865
17937
  inputSchema: askQuestionsInputSchema.shape
17866
- }, (args) => run(() => client2.askQuestions(args.issue, args.questions)));
17938
+ }, (args) => run(() => client2().askQuestions(args.issue, args.questions)));
17867
17939
  registerStrict("withdraw_question", {
17868
- description: "Withdraw a question by its stable `Q-{n}` number \u2014 asker only: the asker is the token\u2019s OWNING user, so another agent\u2019s question is not yours to clear. Deliberately NOT human-gated, because the point is to clear a question you no longer need \u2014 the work answered it, or it was wrong to ask \u2014 instead of leaving the operator to answer something nobody is waiting on. It is recorded, never an answer: the question is soft-deleted (kept for the audit trail), its number retires and is not reissued, and the next issue read no longer carries it in `questions`. Returns the updated issue detail.",
17940
+ description: "Withdraw a question by its stable `Q-{n}` number \u2014 asker only: the asker is the PERSON your credential belongs to, whichever organization the call names in `org`, so another agent\u2019s question is not yours to clear. Deliberately NOT human-gated, because the point is to clear a question you no longer need \u2014 the work answered it, or it was wrong to ask \u2014 instead of leaving the operator to answer something nobody is waiting on. It is recorded, never an answer: the question is soft-deleted (kept for the audit trail), its number retires and is not reissued, and the next issue read no longer carries it in `questions`. Returns the updated issue detail.",
17869
17941
  inputSchema: withdrawQuestionInputSchema.shape
17870
- }, (args) => run(() => client2.withdrawQuestion(args.issue, args.number)));
17942
+ }, (args) => run(() => client2().withdrawQuestion(args.issue, args.number)));
17871
17943
  registerStrict("list_requirements", {
17872
17944
  description: "List requirements filtered by project and text: display id, title, summary (the latest revision\u2019s one/two-line outline description), area (product-area label), cross_cutting flag, lifecycle (draft/approved/amended), latest + approved revision numbers, and linked-epic count (\xA77).",
17873
17945
  inputSchema: listRequirementsFilterSchema.shape
17874
- }, (args) => run(() => client2.listRequirements(args), GUIDANCE_POINTER));
17946
+ }, (args) => run(() => client2().listRequirements(args), GUIDANCE_POINTER));
17875
17947
  registerStrict("get_requirement", {
17876
17948
  description: "Get a requirement by display id or uuid. Defaults to the approved revision (latest if never approved) unless `revision` is given; includes lifecycle, revision list, approvals, and linked issues (\xA77).",
17877
17949
  inputSchema: { requirement: requirementRefSchema, revision: positiveIntSchema.optional() }
17878
- }, (args) => run(() => client2.getRequirement(args.requirement, args.revision), GUIDANCE_POINTER));
17950
+ }, (args) => run(() => client2().getRequirement(args.requirement, args.revision), GUIDANCE_POINTER));
17879
17951
  registerStrict("create_requirement", {
17880
17952
  description: 'Create a project-scoped requirement document with revision 1 (title, body). Optional summary is a short one/two-line outline description (versioned on the revision, like title/body); optional area is a free-text product-area label ("Backup", "Billing") used to group/filter the outline (metadata, like cross_cutting). Optional cross_cutting flags it as binding every epic in the project automatically \u2014 never link cross-cutting documents (\xA75 rule 6, \xA77). Writing guidance for this tool lives in the product doctrine, which `get_work_context` returns \u2014 see \u201CSearch before you create\u201D and \u201CLink by key; never paste another record\u2019s text\u201D.',
17881
17953
  inputSchema: createRequirementInputSchema.shape
17882
- }, (args) => run(() => client2.createRequirement(args)));
17954
+ }, (args) => run(() => client2().createRequirement(args)));
17883
17955
  registerStrict("update_requirement", {
17884
17956
  description: "Update a requirement: title, body, and/or summary APPENDS a new revision (nothing is edited in place; summary versions like title/body); optional note records why. Optional area (product-area label), cross_cutting, and decision_links (add/remove decision records this rule sits under \u2014 `KEY-D{n}`, from `list_decisions`) are metadata changes (no revision) \u2014 toggling cross_cutting ON is rejected while explicit links exist; unlink first. Supplying none of title/body/summary/area/cross_cutting/decision_links is an empty edit (400) (\xA77). Writing guidance for this tool lives in the product doctrine, which `get_work_context` returns \u2014 see \u201CLink by key; never paste another record\u2019s text\u201D.",
17885
17957
  // Inline shape (updateRequirementInputSchema is a refine, no .shape) — add
@@ -17895,23 +17967,23 @@ function createMcpServer(client2, apiBaseUrl, orgInstructions2 = /* @__PURE__ */
17895
17967
  crossCutting: external_exports.boolean().optional(),
17896
17968
  decisionLinks: decisionLinkChangesSchema.optional()
17897
17969
  }
17898
- }, ({ requirement, ...fields }) => run(() => client2.updateRequirement(requirement, fields)));
17970
+ }, ({ requirement, ...fields }) => run(() => client2().updateRequirement(requirement, fields)));
17899
17971
  registerStrict("approve_requirement", {
17900
17972
  description: "Approve (pin) a requirement\u2019s latest revision, or a specified `revision`, recording it in approvals history and advancing the approved revision that downstream links and reads build against (\xA75, \xA77).",
17901
17973
  inputSchema: approveRequirementInputSchema.shape
17902
- }, (args) => run(() => client2.approveRequirement(args.requirement, args.revision)));
17974
+ }, (args) => run(() => client2().approveRequirement(args.requirement, args.revision)));
17903
17975
  registerStrict("list_conventions", {
17904
17976
  description: "List this organization\u2019s conventions \u2014 standing guidance that binds work in EVERY project here, unlike a requirement, which binds one project. Returns display id (`CONV-{n}`), title, the standing text, lifecycle (draft/approved/amended), latest + approved revision numbers, and whether it has been superseded and by which convention. Optional `text` matches over title and body. Retired conventions are INCLUDED and marked, so you can see what the organization used to require rather than proposing it again. Only APPROVED, unretired conventions are actually delivered to agents \u2014 every `get_issue` and `get_work_context` read carries them.",
17905
17977
  inputSchema: listConventionsFilterSchema.shape
17906
- }, (args) => run(() => client2.listConventions(args), GUIDANCE_POINTER));
17978
+ }, (args) => run(() => client2().listConventions(args), GUIDANCE_POINTER));
17907
17979
  registerStrict("get_convention", {
17908
17980
  description: "Get one convention by display id (`CONV-{n}`) or uuid: the standing text at the approved revision, its full revision history with who wrote each and when, its approval history, and \u2014 when it has been retired \u2014 which convention replaced it. A convention that was never approved is readable here and is delivered to nobody.",
17909
17981
  inputSchema: { convention: conventionRefSchema }
17910
- }, (args) => run(() => client2.getConvention(args.convention), GUIDANCE_POINTER));
17982
+ }, (args) => run(() => client2().getConvention(args.convention), GUIDANCE_POINTER));
17911
17983
  registerStrict("create_convention", {
17912
17984
  description: "Write a convention: organization-wide standing guidance, with no project attached. THE GOVERNING TEST \u2014 if it stops being true when this project ends it is a cross-cutting requirement; if it would still be true on the next project it is a convention. You must assert that test by passing `outlivesAnyProject: true`; the write is refused without it. A statement naming one specific project \u2014 its key, a display id built on it, a repository path, or a database object \u2014 is also refused (422 `convention_names_project_scope`), and the message says to file it as a cross-cutting requirement on that project instead. IT BINDS NOBODY UNTIL IT IS APPROVED, and approval is NOT available on this surface: it requires a signed-in person in the browser, so there is no tool for it here and asking for one is asking for a tool that deliberately does not exist. A new convention starts as a draft; write it, then ask a person to review and approve it. Writing guidance for this tool lives in the product doctrine, which `get_work_context` returns \u2014 see \u201CSearch before you create\u201D and \u201CLink by key; never paste another record\u2019s text\u201D.",
17913
17985
  inputSchema: createConventionInputSchema.shape
17914
- }, (args) => run(() => client2.createConvention(args)));
17986
+ }, (args) => run(() => client2().createConvention(args)));
17915
17987
  registerStrict("update_convention", {
17916
17988
  description: "Amend a convention: `title` and/or `body` APPEND a new revision \u2014 nothing is ever edited in place \u2014 and optional `note` records why. Supplying neither is an empty edit (400); a note alone amends nothing. The same project-scope refusal applies as on create, over the amended text. THE AMENDMENT BINDS NOBODY UNTIL IT IS ITSELF APPROVED: until then agents keep receiving the approved revision, so amending is not a way to change what is being delivered \u2014 a signed-in person approving the new revision is. Writing guidance for this tool lives in the product doctrine, which `get_work_context` returns \u2014 see \u201CConventions arrive in force; yours is a proposal\u201D.",
17917
17989
  // Inline shape (updateConventionInputSchema is a refine, so it has no `.shape`);
@@ -17922,19 +17994,19 @@ function createMcpServer(client2, apiBaseUrl, orgInstructions2 = /* @__PURE__ */
17922
17994
  body: markdownSchema.optional(),
17923
17995
  note: external_exports.string().min(1).optional()
17924
17996
  }
17925
- }, ({ convention, ...fields }) => run(() => client2.updateConvention(convention, fields)));
17997
+ }, ({ convention, ...fields }) => run(() => client2().updateConvention(convention, fields)));
17926
17998
  registerStrict("list_prompts", {
17927
17999
  description: "List this organization\u2019s prompt library \u2014 reusable prompt text, addressed `PROMPT-{n}`. A prompt belongs to the ORGANIZATION rather than to a project, unlike a requirement or a content draft, so with no filter this returns the whole library. Returns display id, title, the current text, the latest revision number, and the attached project when it has one. `project` narrows to the prompts attached to that project \u2014 that attachment is metadata saying what a prompt is ABOUT, never its scope, so a prompt attached elsewhere is still one you may read and run. `text` matches over TITLE AND BODY, because someone looking for a prompt remembers what it says rather than what somebody called it.",
17928
18000
  inputSchema: listPromptsFilterSchema.shape
17929
- }, (args) => run(() => client2.listPrompts(args), GUIDANCE_POINTER));
18001
+ }, (args) => run(() => client2().listPrompts(args), GUIDANCE_POINTER));
17930
18002
  registerStrict("get_prompt", {
17931
18003
  description: "Get one prompt by display id (`PROMPT-{n}`) or uuid: its current text \u2014 the LATEST revision, which is simply the prompt, since nothing approves a prompt and nothing pins to an older wording \u2014 plus the full revision history with who wrote each save, through which token, when, and the note saying why. Nothing here was edited in place, so a wording that has been replaced is still readable rather than lost; read the history before rewriting a prompt that already works.",
17932
18004
  inputSchema: { prompt: promptRefSchema }
17933
- }, (args) => run(() => client2.getPrompt(args.prompt), GUIDANCE_POINTER));
18005
+ }, (args) => run(() => client2().getPrompt(args.prompt), GUIDANCE_POINTER));
17934
18006
  registerStrict("create_prompt", {
17935
18007
  description: "Write a prompt: reusable prompt text kept ORGANIZATION-WIDE (`PROMPT-{n}`) and available in every project here \u2014 unlike a requirement or a content draft, which belong to the one project they are filed under. `body` is the prompt itself and must not be empty; `title` names it; optional `note` records why it was written. Optional `project` ATTACHES the prompt to a project, which says what it is about and nothing more \u2014 the prompt is still the organization\u2019s, and a prompt about no project in particular simply omits it. There is no approval step: it is usable the moment it is written. Nothing deletes a prompt either \u2014 later wording is added as a revision, so what is here now stays readable. Writing guidance for this tool lives in the product doctrine, which `get_work_context` returns \u2014 see \u201CSearch before you create\u201D.",
17936
18008
  inputSchema: createPromptInputSchema.shape
17937
- }, (args) => run(() => client2.createPrompt(args)));
18009
+ }, (args) => run(() => client2().createPrompt(args)));
17938
18010
  registerStrict("update_prompt", {
17939
18011
  description: "Amend a prompt: `title` and/or `body` APPEND a new revision \u2014 nothing is ever edited in place \u2014 and optional `note` records why. Amending is therefore safe rather than destructive: the earlier text stays readable, the revision chain is the record of how this prompt got to where it is, and the new wording answers immediately because there is nothing to approve. `project` moves the attachment and `project: null` DETACHES it, leaving a prompt the whole organization still has; either way NO revision is written, because the revision chain is the history of the TEXT and moving the attachment changes no text. Supplying none of `title`, `body` or `project` is an empty edit (400) \u2014 a note alone amends nothing. Writing guidance for this tool lives in the product doctrine, which `get_work_context` returns.",
17940
18012
  // Inline shape (updatePromptInputSchema is a refine, so it has no `.shape`),
@@ -17949,51 +18021,51 @@ function createMcpServer(client2, apiBaseUrl, orgInstructions2 = /* @__PURE__ */
17949
18021
  note: external_exports.string().min(1).optional(),
17950
18022
  project: projectRefSchema.nullable().optional()
17951
18023
  }
17952
- }, ({ prompt, ...fields }) => run(() => client2.updatePrompt(prompt, fields)));
18024
+ }, ({ prompt, ...fields }) => run(() => client2().updatePrompt(prompt, fields)));
17953
18025
  registerStrict("create_decision", {
17954
18026
  description: "Record ONE decision as a project-scoped decision record (`KEY-D{n}`): `title` names the decision and `body` says what was decided and why. A new record starts `proposed`; moving it to `accepted` IS the acceptance \u2014 there is no separate approval step. Returns the created record. Title and body can be corrected only while the record is `proposed`; from `accepted` onward it is frozen, and the way to change a decision is to write a NEW record and `supersede_decision` the old one \u2014 which leaves the original readable and says where the current decision went. Nothing on any surface deletes one. Writing guidance for this tool lives in the product doctrine, which `get_work_context` returns \u2014 see \u201CA decision record is written once\u201D and \u201CSearch before you create\u201D.",
17955
18027
  inputSchema: createDecisionInputSchema.shape
17956
- }, (args) => run(() => client2.createDecision(args)));
18028
+ }, (args) => run(() => client2().createDecision(args)));
17957
18029
  registerStrict("get_decision", {
17958
18030
  description: "Get a decision record by display id (`KEY-D{n}`) or uuid: title, body, lifecycle state (`proposed`/`accepted`/`superseded`), who accepted it and when, the record that replaced it, where the CURRENT decision lives when this one has been superseded, and everything that references it \u2014 every requirement and every work item, gathered from both directions.",
17959
18031
  inputSchema: getDecisionInputSchema.shape
17960
- }, (args) => run(() => client2.getDecision(args.decision), GUIDANCE_POINTER));
18032
+ }, (args) => run(() => client2().getDecision(args.decision), GUIDANCE_POINTER));
17961
18033
  registerStrict("list_decisions", {
17962
18034
  description: "List decision records filtered by `project` and `text`: display id, title, lifecycle state, the replacement when superseded, and how many requirements and work items cite each one. `text` matches over TITLE AND BODY, so search on what a decision was about rather than on what someone chose to call it.",
17963
18035
  inputSchema: listDecisionsFilterSchema.shape
17964
- }, (args) => run(() => client2.listDecisions(args), GUIDANCE_POINTER));
18036
+ }, (args) => run(() => client2().listDecisions(args), GUIDANCE_POINTER));
17965
18037
  registerStrict("supersede_decision", {
17966
18038
  description: "Replace an ACCEPTED decision record with another one: `decision` moves to `superseded` and names `replacedBy` as where the current decision now lives, so whoever opens the old record is sent to the standing one. This is the only way a decision changes \u2014 the original is never edited and never removed, and the whole chain stays readable. Refused when the record is still `proposed` (nothing has been decided yet, so correct it instead), when a record is named as its own replacement, when the replacement belongs to another project, or when the replacement\u2019s own chain already leads back to this record. Returns the superseded record.",
17967
18039
  inputSchema: supersedeDecisionInputSchema.shape
17968
- }, (args) => run(() => client2.supersedeDecision(args.decision, args.replacedBy)));
18040
+ }, (args) => run(() => client2().supersedeDecision(args.decision, args.replacedBy)));
17969
18041
  registerStrict("list_content", {
17970
18042
  description: "List content drafts filtered by project, text, area, and author: display id (KEY-C{n}), title, summary (latest revision), area, author, latest revision number, deliverable count, and linked-issue count. Content is a project-scoped sibling of requirements \u2014 raw material that gets promoted into work, not an issue type.",
17971
18043
  inputSchema: listContentFilterSchema.shape
17972
- }, (args) => run(() => client2.listContent(args), GUIDANCE_POINTER));
18044
+ }, (args) => run(() => client2().listContent(args), GUIDANCE_POINTER));
17973
18045
  registerStrict("get_content", {
17974
18046
  description: "Get a content draft by display id (KEY-C{n}) or uuid: its revision history (default latest, or `revision` to pin) plus every per-platform deliverable with its own revisions, posted metadata (url/postedAt), linked issues (with staleness), and linked assets.",
17975
18047
  inputSchema: { content: contentRefSchema, revision: positiveIntSchema.optional() }
17976
- }, (args) => run(() => client2.getContent(args.content, args.revision), GUIDANCE_POINTER));
18048
+ }, (args) => run(() => client2().getContent(args.content, args.revision), GUIDANCE_POINTER));
17977
18049
  registerStrict("create_content", {
17978
18050
  description: 'Create a project-scoped content draft with revision 1 (title, body). Optional summary is a short outline description (versioned on the revision, like title/body); optional area is a free-text product-area label (metadata). Optional author is the editorial byline the draft is credited to (free text, e.g. "jason") \u2014 distinct from the acting operator, and the field the list filters by. Optional metadata is an open bag for capture provenance (tags, score, sensitivity, source refs) \u2014 stored passively, never acted on. This is the capture-sink target: a captured topic becomes a draft here. Writing guidance for this tool lives in the product doctrine, which `get_work_context` returns \u2014 see \u201CSearch before you create\u201D.',
17979
18051
  inputSchema: createContentInputSchema.shape
17980
- }, (args) => run(() => client2.createContent(args)));
18052
+ }, (args) => run(() => client2().createContent(args)));
17981
18053
  registerStrict("update_content", {
17982
18054
  description: "Update a content draft: title, body, and/or summary APPENDS a new revision (nothing is edited in place); optional note records why. Optional area, author, and metadata are metadata changes (no revision). Supplying none of title/body/summary/area/author/metadata is an empty edit (400). Writing guidance for this tool lives in the product doctrine, which `get_work_context` returns.",
17983
18055
  inputSchema: updateContentInputSchema.shape
17984
- }, ({ content, ...fields }) => run(() => client2.updateContent(content, fields)));
18056
+ }, ({ content, ...fields }) => run(() => client2().updateContent(content, fields)));
17985
18057
  registerStrict("create_deliverable", {
17986
18058
  description: "Add a per-platform deliverable to a draft with revision 1 (the post text). `platform` is a slug configured for the project \u2014 one of its ACTIVE deliverable targets (see list_projects \u2192 deliverableTargets; defaults are bsky/x/reddit/hn/blog, but projects can add/remove them); an unconfigured slug is rejected. Optional body seeds revision 1. There is one deliverable per platform per draft \u2014 a variant is a revision (update_deliverable), not a second deliverable. Rendered id is DRAFT-KEY/platform (e.g. DWB-C3/bsky). Writing guidance for the post text lives in the product doctrine, which `get_work_context` returns.",
17987
18059
  inputSchema: createDeliverableInputSchema.shape
17988
- }, ({ content, ...fields }) => run(() => client2.createDeliverable(content, fields)));
18060
+ }, ({ content, ...fields }) => run(() => client2().createDeliverable(content, fields)));
17989
18061
  registerStrict("update_deliverable", {
17990
18062
  description: "Append a new revision (post text) to a deliverable, addressed as DRAFT-KEY/platform (e.g. DWB-C3/bsky); optional note records why. Platform identity is immutable \u2014 this only versions the post text. Writing guidance for the post text lives in the product doctrine, which `get_work_context` returns.",
17991
18063
  inputSchema: updateDeliverableInputSchema.shape
17992
- }, ({ deliverable, ...fields }) => run(() => client2.updateDeliverable(deliverable, fields)));
18064
+ }, ({ deliverable, ...fields }) => run(() => client2().updateDeliverable(deliverable, fields)));
17993
18065
  registerStrict("record_post", {
17994
18066
  description: "Record that a deliverable (DRAFT-KEY/platform) was posted: its public url and when (postedAt defaults to now), pinning the deliverable\u2019s current revision as the posted one. Pipebrain never posts \u2014 a human posts, then records the url here. Re-calling overwrites (a correction).",
17995
18067
  inputSchema: recordPostInputSchema.shape
17996
- }, ({ deliverable, ...fields }) => run(() => client2.recordPost(deliverable, fields)));
18068
+ }, ({ deliverable, ...fields }) => run(() => client2().recordPost(deliverable, fields)));
17997
18069
  registerStrict("promote_deliverable", {
17998
18070
  description: "Promote a deliverable (DRAFT-KEY/platform, e.g. DWB-C3/bsky) to a NEW issue: creates the issue (`title` + `type` required; optional `status` defaults to triage, optional `milestone` schedules it, optional `body` seeds it \u2014 typically the current post text) AND a PROTECTED link pinning the deliverable\u2019s current revision. That link CANNOT be unlinked \u2014 the issue exists to ship this deliverable. (To link an EXISTING issue instead, use update_issue.deliverable_links, which stays removable.) Returns the created issue. A `status` other than `triage` or `killed` REQUIRES `milestone` (PIPE-R10 rule 9), exactly as in create_issue: work past triage belongs to a release, and the promotion is refused (`milestone_required`) without one. Seeding the body with the deliverable\u2019s own text is the exception to linking rather than pasting \u2014 it is the point of this tool, and the protected link pins the revision that text came from. Writing guidance for this tool lives in the product doctrine, which `get_work_context` returns \u2014 see \u201CSearch before you create\u201D and \u201CLink by key; never paste another record\u2019s text\u201D.",
17999
18071
  inputSchema: {
@@ -18017,33 +18089,33 @@ function createMcpServer(client2, apiBaseUrl, orgInstructions2 = /* @__PURE__ */
18017
18089
  // that sentence before anything is called.
18018
18090
  ...refusedIssueHeaderFields
18019
18091
  }
18020
- }, ({ deliverable, ...fields }) => run(() => client2.promoteDeliverable(deliverable, fields)));
18092
+ }, ({ deliverable, ...fields }) => run(() => client2().promoteDeliverable(deliverable, fields)));
18021
18093
  registerStrict("list_assets", {
18022
18094
  description: "List project assets (S3-backed files of any type) filtered by project, status (pending/active/rejected), category (image/video/document), and filename text, sorted by date or size (asc/desc): id, filename, contentType, size, sha256, status, hasThumbnail, and linkCount (live references). Metadata only \u2014 the bytes move by path, never through this result.",
18023
18095
  inputSchema: listAssetsFilterSchema.shape
18024
- }, (args) => run(() => client2.listAssets(args), GUIDANCE_POINTER));
18096
+ }, (args) => run(() => client2().listAssets(args), GUIDANCE_POINTER));
18025
18097
  registerStrict("get_asset", {
18026
18098
  description: "Get an asset\u2019s metadata by uuid: filename, contentType, size, sha256 (client-computed, server-verified by read-back), status, hasThumbnail, linkCount (live references), and timestamps. Metadata only \u2014 no value/URL is returned over MCP. To get the bytes, use download_asset (a LOCAL server only \u2014 it writes to a path on the machine running the server) or `ppb assets download`.",
18027
18099
  inputSchema: { asset: uuidSchema }
18028
- }, (args) => run(() => client2.getAsset(args.asset), GUIDANCE_POINTER));
18100
+ }, (args) => run(() => client2().getAsset(args.asset), GUIDANCE_POINTER));
18029
18101
  if (surface === "local") {
18030
18102
  registerStrict("upload_asset", {
18031
18103
  description: "Upload a LOCAL FILE (by path) as a project asset and activate it: reads and SHA-256-hashes the file locally, registers the asset, PUTs the bytes directly to storage, and completes (server verifies the digest by read-back). Returns the asset metadata (status active on success). Only the file PATH crosses the wire \u2014 the bytes never do; do NOT pass base64 or file contents. contentType is guessed from the extension when omitted. Then use link_asset to attach the returned asset to a deliverable revision or a content draft.",
18032
18104
  inputSchema: uploadAssetInputSchema.shape
18033
- }, (args) => run(() => uploadAssetFromPath(client2, apiBaseUrl, args)));
18105
+ }, (args) => run(() => uploadAssetFromPath(client2(), apiBaseUrl, args)));
18034
18106
  registerStrict("download_asset", {
18035
18107
  description: "Download an ACTIVE asset\u2019s bytes to a LOCAL FILE at `path` (created/overwritten), so you can read or view an uploaded image, mockup, or document. The bytes are written to disk and re-verified against the recorded sha256; the RESULT is metadata + the written path \u2014 never the bytes or a URL. Addressed by asset uuid (from list_assets, get_asset, or get_content).",
18036
18108
  inputSchema: downloadAssetInputSchema.shape
18037
- }, (args) => run(() => downloadAssetToPath(client2, args)));
18109
+ }, (args) => run(() => downloadAssetToPath(client2(), args)));
18038
18110
  }
18039
18111
  registerStrict("link_asset", {
18040
18112
  description: "Reference an active asset FROM a target. Two targets are wired: `deliverable_revision` (targetId is a content_deliverable_revision uuid, e.g. from get_content) and `content_draft` (targetId is a content_draft uuid \u2014 the asset attaches to the topic doc and is snapshot-copied onto deliverables when they are created). Rejects a non-active asset or a cross-project link.",
18041
18113
  inputSchema: linkAssetInputSchema.shape
18042
- }, (args) => run(() => client2.linkAsset(args)));
18114
+ }, (args) => run(() => client2().linkAsset(args)));
18043
18115
  registerStrict("unlink_asset", {
18044
18116
  description: "Remove an asset reference by its link id (soft-delete). The asset itself is untouched \u2014 this only drops the reference from its target. A link whose target is a CHAT MESSAGE is author-only: anyone but the person who wrote that message is refused with `not_message_author` (403), so an attachment you did not post is not yours to detach. Every other target type is removable by any member.",
18045
18117
  inputSchema: unlinkAssetInputSchema.shape
18046
- }, (args) => run(() => client2.unlinkAsset(args.linkId)));
18118
+ }, (args) => run(() => client2().unlinkAsset(args.linkId)));
18047
18119
  registerStrict("set_secret", {
18048
18120
  description: "Create a secret or add a new version under a project + environment. THE VALUE CROSSES INBOUND ONLY \u2014 the response NEVER echoes it \u2014 but inbound is a direction, not a safe one: for a sensitive value prefer the CLI (`ppb secrets set` via stdin/`--from-file`), because a value typed here lands in the chat transcript before the server can encrypt it. `name` is UPPER_SNAKE_CASE (e.g. API_KEY); `environment` is the environment slug (dev/prod); optional `description`. Writing guidance for that description lives in the product doctrine, which `get_work_context` returns.",
18049
18121
  inputSchema: {
@@ -18053,14 +18125,14 @@ function createMcpServer(client2, apiBaseUrl, orgInstructions2 = /* @__PURE__ */
18053
18125
  value: external_exports.string().min(1),
18054
18126
  description: external_exports.string().optional()
18055
18127
  }
18056
- }, ({ project, environment, name, value, description }) => run(() => client2.setSecret(project, { env: environment, name, value, description })));
18128
+ }, ({ project, environment, name, value, description }) => run(() => client2().setSecret(project, { env: environment, name, value, description })));
18057
18129
  registerStrict("list_secrets", {
18058
18130
  description: "List a project's secrets as METADATA ONLY (id, name, environment, description, current version, timestamps) \u2014 never any value. Optional `environment` slug filter.",
18059
18131
  inputSchema: {
18060
18132
  project: projectKeySchema,
18061
18133
  environment: external_exports.string().min(1).optional()
18062
18134
  }
18063
- }, ({ project, environment }) => run(() => client2.listSecrets(project, { env: environment }), GUIDANCE_POINTER));
18135
+ }, ({ project, environment }) => run(() => client2().listSecrets(project, { env: environment }), GUIDANCE_POINTER));
18064
18136
  registerStrict("describe_secret", {
18065
18137
  description: "Describe one secret: its metadata plus its version history (version, created_at, created_by, and whether each version has been crypto-shredded). METADATA ONLY \u2014 no value is ever returned.",
18066
18138
  inputSchema: {
@@ -18068,7 +18140,7 @@ function createMcpServer(client2, apiBaseUrl, orgInstructions2 = /* @__PURE__ */
18068
18140
  environment: external_exports.string().min(1),
18069
18141
  name: secretNameSchema
18070
18142
  }
18071
- }, ({ project, environment, name }) => run(() => client2.describeSecret(project, name, { env: environment }), GUIDANCE_POINTER));
18143
+ }, ({ project, environment, name }) => run(() => client2().describeSecret(project, name, { env: environment }), GUIDANCE_POINTER));
18072
18144
  registerStrict("rotate_secret", {
18073
18145
  description: "Rotate an EXISTING secret: store a NEW version and advance the pointer. Same value rules as `set_secret`: the value crosses INBOUND ONLY and the response NEVER echoes it, and for a sensitive value prefer the CLI (`ppb secrets set` adds a new version from stdin/`--from-file`), because a value typed here lands in the chat transcript before the server can encrypt it.",
18074
18146
  inputSchema: {
@@ -18077,7 +18149,7 @@ function createMcpServer(client2, apiBaseUrl, orgInstructions2 = /* @__PURE__ */
18077
18149
  name: secretNameSchema,
18078
18150
  value: external_exports.string().min(1)
18079
18151
  }
18080
- }, ({ project, environment, name, value }) => run(() => client2.rotateSecret(project, name, { env: environment, value })));
18152
+ }, ({ project, environment, name, value }) => run(() => client2().rotateSecret(project, name, { env: environment, value })));
18081
18153
  registerStrict("update_secret_description", {
18082
18154
  description: "Update a secret's description (metadata-only edit \u2014 does not change the value or add a version). Writing guidance for that description lives in the product doctrine, which `get_work_context` returns.",
18083
18155
  inputSchema: {
@@ -18086,7 +18158,7 @@ function createMcpServer(client2, apiBaseUrl, orgInstructions2 = /* @__PURE__ */
18086
18158
  name: secretNameSchema,
18087
18159
  description: external_exports.string()
18088
18160
  }
18089
- }, ({ project, environment, name, description }) => run(() => client2.updateSecretDescription(project, name, { env: environment, description })));
18161
+ }, ({ project, environment, name, description }) => run(() => client2().updateSecretDescription(project, name, { env: environment, description })));
18090
18162
  registerStrict("delete_secret", {
18091
18163
  description: "Delete a secret: soft-delete the entry and crypto-shred all its versions (the value becomes unrecoverable). Returns confirmation metadata only.",
18092
18164
  inputSchema: {
@@ -18095,20 +18167,20 @@ function createMcpServer(client2, apiBaseUrl, orgInstructions2 = /* @__PURE__ */
18095
18167
  name: secretNameSchema
18096
18168
  }
18097
18169
  }, ({ project, environment, name }) => run(async () => {
18098
- await client2.deleteSecret(project, name, { env: environment });
18170
+ await client2().deleteSecret(project, name, { env: environment });
18099
18171
  return { deleted: true, project, environment, name };
18100
18172
  }));
18101
18173
  registerStrict("list_org_instructions", {
18102
18174
  description: "List the org\u2019s agent instructions \u2014 the per-scope texts this server composes into the guidance `get_work_context` returns, each under a heading naming its scope. Edits apply to NEW sessions only; use this to see the CURRENT saved values mid-session (at most one row per scope)."
18103
- }, () => run(() => client2.listOrgInstructions(), GUIDANCE_POINTER));
18175
+ }, () => run(() => client2().listOrgInstructions(), GUIDANCE_POINTER));
18104
18176
  registerStrict("set_org_instruction", {
18105
- description: "Set (create or replace) one scope\u2019s org-level agent instruction text, max 4000 characters \u2014 over-cap is rejected, never truncated. Scopes: `general` (server-wide), `requirements`, `content`, and `work.<type>` (one per issue type, e.g. `work.epic`). Requires the ADMIN role in the token\u2019s org. Takes effect at the NEXT session start \u2014 running sessions keep the text they launched with. Returns the saved instruction. Writing guidance for an instruction body lives in the product doctrine, which `get_work_context` returns \u2014 see \u201CSetting an instruction replaces the whole body\u201D.",
18177
+ description: "Set (create or replace) one scope\u2019s org-level agent instruction text, max 4000 characters \u2014 over-cap is rejected, never truncated. Scopes: `general` (server-wide), `requirements`, `content`, and `work.<type>` (one per issue type, e.g. `work.epic`). WHICH ORGANIZATION IS WRITTEN is whichever one this call acts in: pass `org` and you are rewriting THAT organization\u2019s standing instructions to every agent working there, not your own. It requires the ADMIN role in the organization named, checked against your live membership of it, so a call naming an organization you are only a CONTRIBUTOR in is refused. Takes effect at the NEXT session start \u2014 running sessions keep the text they launched with. Returns the saved instruction. Writing guidance for an instruction body lives in the product doctrine, which `get_work_context` returns \u2014 see \u201CSetting an instruction replaces the whole body\u201D.",
18106
18178
  inputSchema: setOrgInstructionInputSchema.shape
18107
- }, (args) => run(() => client2.setOrgInstruction(args.scope, args.body)));
18179
+ }, (args) => run(() => client2().setOrgInstruction(args.scope, args.body)));
18108
18180
  registerStrict("delete_org_instruction", {
18109
- description: "Clear one scope\u2019s org-level agent instruction (soft delete; an unset scope is an error naming it). Requires the ADMIN role in the token\u2019s org. Takes effect at the NEXT session start. Returns the cleared instruction.",
18181
+ description: "Clear one scope\u2019s org-level agent instruction (soft delete; an unset scope is an error naming it). WHICH ORGANIZATION IS CLEARED is whichever one this call acts in: pass `org` and you are removing THAT organization\u2019s standing instruction to every agent working there, not your own. It requires the ADMIN role in the organization named, checked against your live membership of it, so a call naming an organization you are only a CONTRIBUTOR in is refused. Takes effect at the NEXT session start. Returns the cleared instruction.",
18110
18182
  inputSchema: deleteOrgInstructionInputSchema.shape
18111
- }, (args) => run(() => client2.deleteOrgInstruction(args.scope)));
18183
+ }, (args) => run(() => client2().deleteOrgInstruction(args.scope)));
18112
18184
  return server2;
18113
18185
  }
18114
18186
 
@@ -18170,22 +18242,49 @@ function loadMcpConfig() {
18170
18242
  if (apiUrl === void 0 || token === void 0) {
18171
18243
  throw new EnvValidationError(issues, variables);
18172
18244
  }
18173
- return { apiUrl, token };
18245
+ const org = resolved.org?.value;
18246
+ return { apiUrl, token, org: org !== void 0 && isUnexpandedPlaceholder(org) ? void 0 : org };
18174
18247
  }
18175
18248
 
18176
18249
  // src/version.ts
18177
- var VERSION = "0.42.0";
18250
+ var VERSION = "0.43.0";
18178
18251
 
18179
18252
  // src/main.ts
18253
+ async function scopedClient(base, org) {
18254
+ if (org === void 0) return base;
18255
+ try {
18256
+ return base.forOrg(await resolveOrgReference(org, () => base.listOrgs()));
18257
+ } catch (err) {
18258
+ throw new Error(
18259
+ `PIPEBRAIN_ORG is set to "${org}", and this server could not act there: ${err instanceof Error ? err.message : String(err)}`
18260
+ );
18261
+ }
18262
+ }
18180
18263
  var config2 = loadMcpConfig();
18181
- var client = new ApiClient({
18182
- baseUrl: config2.apiUrl,
18183
- auth: { bearer: config2.token }
18184
- });
18264
+ var client = await scopedClient(
18265
+ new ApiClient({
18266
+ baseUrl: config2.apiUrl,
18267
+ auth: { bearer: config2.token }
18268
+ }),
18269
+ config2.org
18270
+ );
18185
18271
  var orgInstructions = await fetchOrgInstructionsSafe(client);
18186
18272
  var server = createMcpServer(client, config2.apiUrl, orgInstructions, {
18187
18273
  version: VERSION,
18188
- surface: "local"
18274
+ surface: "local",
18275
+ // The writing rules follow the organization the CALL acts in (PIPE-410). Without this,
18276
+ // a `get_work_context` naming another organization returns that organization's work,
18277
+ // requirements and conventions under THIS one's rules, in one document, with nothing in
18278
+ // it saying so.
18279
+ //
18280
+ // A call naming none is served the startup snapshot, so the common session — every call
18281
+ // in the default organization — still pays exactly one fetch, at launch, as it always
18282
+ // has. A call naming another organization fetches that organization's text then and
18283
+ // there rather than caching it: `get_work_context` is read once or twice in a session,
18284
+ // so the round trip is cheap, and a per-session cache would freeze a FAILED fetch —
18285
+ // fail-open returns an empty map — into "this organization has written nothing" for the
18286
+ // rest of the session.
18287
+ orgInstructionsFor: (actingOrgId) => actingOrgId === void 0 ? Promise.resolve(orgInstructions) : fetchOrgInstructionsSafe(client.forOrg(actingOrgId))
18189
18288
  });
18190
18289
  var transport = new StdioServerTransport();
18191
18290
  await server.connect(transport);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pipebrain-mcp",
3
- "version": "0.42.0",
3
+ "version": "0.43.0",
4
4
  "description": "Pipebrain MCP server for Claude Code and Claude Desktop — issues, requirements, decision records, conventions, prompts, content, assets, metadata-only secrets, and more of the platform's modules over the Pipebrain API.",
5
5
  "type": "module",
6
6
  "license": "MIT",