@webpieces/api-doc-model 0.4.806 → 0.4.808

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.
@@ -1 +1 @@
1
- {"version":3,"file":"ApiDocModel.js","sourceRoot":"","sources":["../../../../../../packages/docs/api-doc-model/src/model/ApiDocModel.ts"],"names":[],"mappings":";;;AAEA;;;;;;;;GAQG;AAEH,qGAAqG;AACrG,MAAa,YAAY;IAGR;IAEA;IAEA;IANb;IACI,qEAAqE;IAC5D,QAAgB;IACzB,sDAAsD;IAC7C,QAAgB;IACzB,wEAAwE;IAC/D,MAAc;QAJd,aAAQ,GAAR,QAAQ,CAAQ;QAEhB,aAAQ,GAAR,QAAQ,CAAQ;QAEhB,WAAM,GAAN,MAAM,CAAQ;IACxB,CAAC;CACP;AATD,oCASC;AAED,wGAAwG;AACxG,MAAa,kBAAkB;IAGd;IAEA;IAJb;IACI,yCAAyC;IAChC,YAAoB;IAC7B,kFAAkF;IACzE,YAAyC;QAFzC,iBAAY,GAAZ,YAAY,CAAQ;QAEpB,iBAAY,GAAZ,YAAY,CAA6B;IACnD,CAAC;CACP;AAPD,gDAOC;AAED,4BAA4B;AAC5B,MAAa,eAAe;IAEX;IACA;IAMA;IAEA;IAEA;IAMA;IAEA;IAEA;IAEA;IAWA;IAnCb,YACa,IAAY,EACZ,IAAa;IACtB;;;;OAIG;IACM,QAAiB;IAC1B,sFAAsF;IAC7E,QAAiB;IAC1B,uEAAuE;IAC9D,WAAmB;IAC5B;;;;OAIG;IACM,cAAkC;IAC3C,8EAA8E;IACrE,MAA0B;IACnC,2EAA2E;IAClE,GAAuB;IAChC,2EAA2E;IAClE,GAAuB;IAChC;;;;;;;;;OASG;IACM,SAA6B;QAlC7B,SAAI,GAAJ,IAAI,CAAQ;QACZ,SAAI,GAAJ,IAAI,CAAS;QAMb,aAAQ,GAAR,QAAQ,CAAS;QAEjB,aAAQ,GAAR,QAAQ,CAAS;QAEjB,gBAAW,GAA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J,IAAI,CAAQ;QAMZ,WAAM,GAAN,MAAM,CAAS;QAEf,cAAS,GAAT,SAAS,CAAS;QAClB,YAAO,GAAP,OAAO,CAA2B;QAClC,SAAI,GAAJ,IAAI,CAA4B;QAChC,YAAO,GAAP,OAAO,CAA+B;QAEtC,gBAAW,GAAX,WAAW,CAAoB;QAE/B,YAAO,GAAP,OAAO,CAA6B;QACpC,gBAAW,GAAX,WAAW,CAAQ;QAEnB,mBAAc,GAAd,cAAc,CAAoB;QAClC,YAAO,GAAP,OAAO,CAAqB;QAC5B,aAAQ,GAAR,QAAQ,CAAqB;IACvC,CAAC;CACP;AAvCD,gDAuCC;AAED,2FAA2F;AAC3F,MAAa,WAAW;IAGP;IAQA;IAEA;IAEA;IACA;IAEA;IAEA;IAnBb;IACI,+CAA+C;IACtC,YAAoB;IAC7B;;;;;;OAMG;IACM,QAA2B;IACpC,wCAAwC;IAC/B,QAAgB;IACzB,wDAAwD;IAC/C,WAAmB,EACnB,SAAwC;IACjD,8FAA8F;IACrF,KAA0C;IACnD,wEAAwE;IAC/D,QAAiC;QAjBjC,iBAAY,GAAZ,YAAY,CAAQ;QAQpB,aAAQ,GAAR,QAAQ,CAAmB;QAE3B,aAAQ,GAAR,QAAQ,CAAQ;QAEhB,gBAAW,GAAX,WAAW,CAAQ;QACnB,cAAS,GAAT,SAAS,CAA+B;QAExC,UAAK,GAAL,KAAK,CAAqC;QAE1C,aAAQ,GAAR,QAAQ,CAAyB;IAC3C,CAAC;CACP;AAtBD,kCAsBC","sourcesContent":["import { TypeRef } from './TypeRef';\n\n/**\n * The model classes. Every one of them is a CLASS with an explicit constructor per `CLAUDE.md` §1 —\n * these are data-only structures, and a renderer (#982) builds nothing, it only reads.\n *\n * Nothing in this file imports anything but {@link TypeRef}: the package depends on `typescript` and\n * NOTHING else, so it can be pointed at any upstream project's contract. One app-specific import\n * here would end that, which is why `responsibilities.md` states the constraint rather than leaving\n * it to be discovered.\n */\n\n/** A type the extractor could not represent. RECORDED, never dropped — #982's guard needs a name. */\nexport class UnmappedType {\n constructor(\n /** The verbatim TypeScript type text, e.g. `Map<string, Widget>`. */\n readonly typeText: string,\n /** Pointer-style location: `path/to/File.ts:12:5`. */\n readonly location: string,\n /** Why it could not be mapped, in one sentence a renderer can print. */\n readonly reason: string,\n ) {}\n}\n\n/** The DERIVED discriminator of a union — never invented, only observed. See {@link DocumentedType}. */\nexport class UnionDiscriminator {\n constructor(\n /** The property every branch carries. */\n readonly propertyName: string,\n /** branch type name -> the single string literal that branch's property holds. */\n readonly branchValues: ReadonlyMap<string, string>,\n ) {}\n}\n\n/** One field of one DTO. */\nexport class DocumentedField {\n constructor(\n readonly name: string,\n readonly type: TypeRef,\n /**\n * OPTIONAL (`name?: string`) — the property may be ABSENT. Distinguished from\n * {@link nullable} on purpose: `{}` and `{name: null}` are different wire documents, and a\n * renderer that conflates them emits a schema that rejects one of them.\n */\n readonly optional: boolean,\n /** NULLABLE (`name: string | null`) — the property is present and may hold `null`. */\n readonly nullable: boolean,\n /** The JSDoc body, links flattened. Empty string when undocumented. */\n readonly description: string,\n /**\n * The `@mcp` block tag — an OPTIONAL agent-facing override. Undefined means \"no override\",\n * and a renderer falls back to {@link description}; the fallback is NOT applied here so a\n * renderer can tell a deliberate agent-facing sentence from a reused human one.\n */\n readonly mcpDescription: string | undefined,\n /** The `@format` tag, lifted onto the SCALAR (on an array, onto the ITEM). */\n readonly format: string | undefined,\n /** `@WpMin(n)` — numeric fields only; anything else is a build failure. */\n readonly min: number | undefined,\n /** `@WpMax(n)` — numeric fields only; anything else is a build failure. */\n readonly max: number | undefined,\n /**\n * The `@mcpHeader <token>` JSDoc tag — the MCP 2026 SEP-2243 header this PRIMITIVE field is\n * mirrored into (`Mcp-Param-{token}`). Undefined for every field that is not mirrored, which\n * is nearly all of them.\n *\n * It is documentation and therefore lives in JSDoc, next to the sentence describing the\n * field, rather than in a decorator argument. The runtime spells it `WpMcpHeader` inside\n * `@WpDtoField`; the two are proved identical by the equivalence gate (#983) before #984\n * deletes the decorator spelling.\n */\n readonly mcpHeader: string | undefined,\n ) {}\n}\n\n/** One named type reachable from a contract: an object DTO, a string-literal enum, or a union. */\nexport class DocumentedType {\n constructor(\n readonly name: string,\n readonly description: string,\n /** Object shape. Empty for an enum or a union. */\n readonly fields: readonly DocumentedField[],\n /** Set for a string-literal union that has a name. */\n readonly enumValues: readonly string[],\n /** Set for a union of named object types. */\n readonly unionRefNames: readonly string[],\n /** Set only when EVERY branch carries the same property typed as one string literal. */\n readonly discriminator: UnionDiscriminator | undefined,\n /** An index signature (`[k: string]: X`) — the OPEN-MAP half of an object that also has fields. */\n readonly indexSignatureValue: TypeRef | undefined,\n ) {}\n}\n\n/** `@Endpoint(httpMethod, path, operation, kind, options?)`'s LAST argument, as a document sees it. */\nexport class DocumentedEndpointOptions {\n constructor(\n readonly formPost: boolean,\n /** `calledBy` — REQUIRED by the decorator for `external`, absent otherwise. */\n readonly calledBy: string | undefined,\n readonly callerKind: string | undefined,\n ) {}\n}\n\n/**\n * The `@WpMcpTool(...)` declaration, when the method carries one — the TWO facts the source cannot\n * otherwise state, and nothing else.\n *\n * `description` is deliberately NOT read off the decorator. The method's JSDoc is the description, for\n * the agent and for the partner alike, byte-identical: two authored copies of one paragraph is the\n * two-spellings shim, and its failure mode is concrete — the partner reads the JSDoc in the OpenAPI\n * document while the agent reads the decorator string in `tools/list`, and they drift the first time\n * somebody edits one. (The field still exists on the decorator; #984 deletes it across its 29 call\n * sites. Nothing here reads it, so nothing here depends on a field that is about to disappear.)\n *\n * The three side-effect hints are not read either: they are COMPUTED from the endpoint's `operation`\n * by `mcpHintsForOperation` in `@webpieces/core-util`, which is the one place that mapping lives.\n * `READ | WRITE_IDEMPOTENT | WRITE` already says whether repeating a call is safe, so a hand-declared\n * hint would be a second answer to a question the contract has answered.\n */\nexport class DocumentedMcpTool {\n constructor(\n /**\n * The STABLE protocol name. Deliberately independent of the method name, because renaming a\n * method must not break a saved agent workflow.\n */\n readonly name: string,\n ) {}\n}\n\n/**\n * ONE credential of an api-key regime, PARSED — `{ in: 'header', name: 'x-api-key' }` or\n * `{ in: 'bearer' }`.\n *\n * Parsed rather than left as source text because it is the one auth argument a renderer must turn\n * into a STRUCTURE: an OpenAPI `securityScheme` is `{type: apiKey, in, name}` or\n * `{type: http, scheme: bearer}`, and those are different documents. A renderer handed the string\n * `\"{ in: 'header', name: 'x-api-key' }\"` would have to parse TypeScript to emit either one, which\n * is this package's job and not a renderer's.\n */\nexport class DocumentedApiKeyCredential {\n constructor(\n /** `header` or `bearer`, verbatim from the declaration. */\n readonly location: string,\n /** The header name. Undefined for `bearer`, whose location IS `Authorization`. */\n readonly name: string | undefined,\n /** The prose a docs site renders on its authorization card. */\n readonly description: string | undefined,\n ) {}\n}\n\n/** `@WpAuthApiKey(regime, credentials)`, parsed. See {@link DocumentedApiKeyCredential}. */\nexport class DocumentedApiKey {\n constructor(\n readonly regime: string,\n /**\n * Every credential the regime requires, IN DECLARATION ORDER. They are an AND — all of them\n * are presented together — and the order is the order a published document lists them in.\n */\n readonly credentials: readonly DocumentedApiKeyCredential[],\n ) {}\n}\n\n/** WHICH credential an endpoint demands — `@WpAuthPublic`, `@WpAuthJwt`, … — verbatim from the source. */\nexport class DocumentedAuth {\n constructor(\n /** The decorator name as written, e.g. `WpAuthJwt`. */\n readonly decorator: string,\n /** Every argument's text, verbatim and in order. Empty for `@WpAuthPublic()`. */\n readonly argumentTexts: readonly string[],\n /**\n * The PARSED api-key declaration, set only for `@WpAuthApiKey`. Every other decorator's\n * argument is prose or a role list that a document quotes rather than restructures, so\n * {@link argumentTexts} is all they need — see {@link DocumentedApiKeyCredential} for why\n * this one is different.\n */\n readonly apiKey: DocumentedApiKey | undefined,\n ) {}\n}\n\n/** One `@Endpoint` method of one contract. */\nexport class DocumentedEndpoint {\n constructor(\n readonly methodName: string,\n /**\n * `GET` or `POST`, constant-folded from `@Endpoint`'s FIRST argument. A document cannot be\n * written without it — the verb is the key an operation hangs under in `paths`.\n */\n readonly httpMethod: string,\n /** The path, constant-folded. A const that cannot be folded is a HARD FAILURE, never a guess. */\n readonly path: string,\n /**\n * `read` | `write-idempotent` | `write`, verbatim. The SIDE-EFFECT contract, which is\n * independent of the verb: webpieces POSTs a read. A renderer publishes it rather than\n * inferring safety from the verb, which for this framework would be wrong.\n */\n readonly operation: string,\n /** `rpc` | `cloudtasks` | `cron` | `external`, verbatim — this package invents no taxonomy. */\n readonly kind: string,\n /**\n * `{ hidden: true }` — this method is absent from the CUSTOMER document. It stays in the\n * private one, and in the MCP one when it is a tool. WHICH documents the CONTRACT feeds at\n * all is a different, class-level decision; see {@link ApiDocModel.apiTypes}.\n */\n readonly hidden: boolean,\n /** `{ openWorld: true }` — this operation may touch systems outside this service. */\n readonly openWorld: boolean,\n readonly options: DocumentedEndpointOptions,\n readonly auth: DocumentedAuth | undefined,\n readonly mcpTool: DocumentedMcpTool | undefined,\n /** `@WpMcpAuthJwt(...)`'s argument text, when present. */\n readonly mcpAuthText: string | undefined,\n /** `@MaskLog({...})` — field name -> mask mode. */\n readonly maskLog: ReadonlyMap<string, string>,\n readonly description: string,\n /** The `@mcp` override. See {@link DocumentedField.mcpDescription}. */\n readonly mcpDescription: string | undefined,\n readonly request: TypeRef | undefined,\n readonly response: TypeRef | undefined,\n ) {}\n}\n\n/** ONE extraction pass over ONE contract file. Both #982's renderers read exactly this. */\nexport class ApiDocModel {\n constructor(\n /** The contract class name, e.g. `SaveApi`. */\n readonly contractName: string,\n /**\n * WHICH generated documents this contract feeds — `svc-to-svc`, `external-customer`, `mcp`,\n * verbatim from `@ApiType(...)`, defaulting to `svc-to-svc` alone when it declares nothing.\n *\n * A named list rather than a falsy default, because the grant has to be the TOKEN: a default\n * that reached customers would publish a contract whose author typed nothing about it.\n */\n readonly apiTypes: readonly string[],\n /** `@ApiPath(...)`, constant-folded. */\n readonly basePath: string,\n /** The JSDoc on the contract class, links flattened. */\n readonly description: string,\n readonly endpoints: readonly DocumentedEndpoint[],\n /** Every named type reachable from the endpoints, by name. A `$ref` target for a renderer. */\n readonly types: ReadonlyMap<string, DocumentedType>,\n /** Everything that could not be represented — recorded, not dropped. */\n readonly unmapped: readonly UnmappedType[],\n ) {}\n}\n"]}
1
+ {"version":3,"file":"ApiDocModel.js","sourceRoot":"","sources":["../../../../../../packages/docs/api-doc-model/src/model/ApiDocModel.ts"],"names":[],"mappings":";;;AAEA;;;;;;;;GAQG;AAEH,qGAAqG;AACrG,MAAa,YAAY;IAGR;IAEA;IAEA;IANb;IACI,qEAAqE;IAC5D,QAAgB;IACzB,sDAAsD;IAC7C,QAAgB;IACzB,wEAAwE;IAC/D,MAAc;QAJd,aAAQ,GAAR,QAAQ,CAAQ;QAEhB,aAAQ,GAAR,QAAQ,CAAQ;QAEhB,WAAM,GAAN,MAAM,CAAQ;IACxB,CAAC;CACP;AATD,oCASC;AAED,wGAAwG;AACxG,MAAa,kBAAkB;IAGd;IAEA;IAJb;IACI,yCAAyC;IAChC,YAAoB;IAC7B,kFAAkF;IACzE,YAAyC;QAFzC,iBAAY,GAAZ,YAAY,CAAQ;QAEpB,iBAAY,GAAZ,YAAY,CAA6B;IACnD,CAAC;CACP;AAPD,gDAOC;AAED,4BAA4B;AAC5B,MAAa,eAAe;IAEX;IACA;IAMA;IAEA;IAEA;IAMA;IAEA;IAEA;IAEA;IAUA;IAlCb,YACa,IAAY,EACZ,IAAa;IACtB;;;;OAIG;IACM,QAAiB;IAC1B,sFAAsF;IAC7E,QAAiB;IAC1B,uEAAuE;IAC9D,WAAmB;IAC5B;;;;OAIG;IACM,cAAkC;IAC3C,8EAA8E;IACrE,MAA0B;IACnC,2EAA2E;IAClE,GAAuB;IAChC,2EAA2E;IAClE,GAAuB;IAChC;;;;;;;;OAQG;IACM,SAA6B;QAjC7B,SAAI,GAAJ,IAAI,CAAQ;QACZ,SAAI,GAAJ,IAAI,CAAS;QAMb,aAAQ,GAAR,QAAQ,CAAS;QAEjB,aAAQ,GAAR,QAAQ,CAAS;QAEjB,gBA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I,GAAJ,IAAI,CAAQ;QAMZ,WAAM,GAAN,MAAM,CAAS;QAEf,cAAS,GAAT,SAAS,CAAS;QAClB,YAAO,GAAP,OAAO,CAA2B;QAClC,SAAI,GAAJ,IAAI,CAA4B;QAChC,YAAO,GAAP,OAAO,CAA+B;QAEtC,gBAAW,GAAX,WAAW,CAAoB;QAE/B,YAAO,GAAP,OAAO,CAA6B;QACpC,gBAAW,GAAX,WAAW,CAAQ;QAEnB,mBAAc,GAAd,cAAc,CAAoB;QAClC,YAAO,GAAP,OAAO,CAAqB;QAC5B,aAAQ,GAAR,QAAQ,CAAqB;IACvC,CAAC;CACP;AAvCD,gDAuCC;AAED,2FAA2F;AAC3F,MAAa,WAAW;IAGP;IAQA;IAEA;IAEA;IACA;IAEA;IAEA;IAnBb;IACI,+CAA+C;IACtC,YAAoB;IAC7B;;;;;;OAMG;IACM,QAA2B;IACpC,wCAAwC;IAC/B,QAAgB;IACzB,wDAAwD;IAC/C,WAAmB,EACnB,SAAwC;IACjD,8FAA8F;IACrF,KAA0C;IACnD,wEAAwE;IAC/D,QAAiC;QAjBjC,iBAAY,GAAZ,YAAY,CAAQ;QAQpB,aAAQ,GAAR,QAAQ,CAAmB;QAE3B,aAAQ,GAAR,QAAQ,CAAQ;QAEhB,gBAAW,GAAX,WAAW,CAAQ;QACnB,cAAS,GAAT,SAAS,CAA+B;QAExC,UAAK,GAAL,KAAK,CAAqC;QAE1C,aAAQ,GAAR,QAAQ,CAAyB;IAC3C,CAAC;CACP;AAtBD,kCAsBC","sourcesContent":["import { TypeRef } from './TypeRef';\n\n/**\n * The model classes. Every one of them is a CLASS with an explicit constructor per `CLAUDE.md` §1 —\n * these are data-only structures, and a renderer (#982) builds nothing, it only reads.\n *\n * Nothing in this file imports anything but {@link TypeRef}: the package depends on `typescript` and\n * NOTHING else, so it can be pointed at any upstream project's contract. One app-specific import\n * here would end that, which is why `responsibilities.md` states the constraint rather than leaving\n * it to be discovered.\n */\n\n/** A type the extractor could not represent. RECORDED, never dropped — #982's guard needs a name. */\nexport class UnmappedType {\n constructor(\n /** The verbatim TypeScript type text, e.g. `Map<string, Widget>`. */\n readonly typeText: string,\n /** Pointer-style location: `path/to/File.ts:12:5`. */\n readonly location: string,\n /** Why it could not be mapped, in one sentence a renderer can print. */\n readonly reason: string,\n ) {}\n}\n\n/** The DERIVED discriminator of a union — never invented, only observed. See {@link DocumentedType}. */\nexport class UnionDiscriminator {\n constructor(\n /** The property every branch carries. */\n readonly propertyName: string,\n /** branch type name -> the single string literal that branch's property holds. */\n readonly branchValues: ReadonlyMap<string, string>,\n ) {}\n}\n\n/** One field of one DTO. */\nexport class DocumentedField {\n constructor(\n readonly name: string,\n readonly type: TypeRef,\n /**\n * OPTIONAL (`name?: string`) — the property may be ABSENT. Distinguished from\n * {@link nullable} on purpose: `{}` and `{name: null}` are different wire documents, and a\n * renderer that conflates them emits a schema that rejects one of them.\n */\n readonly optional: boolean,\n /** NULLABLE (`name: string | null`) — the property is present and may hold `null`. */\n readonly nullable: boolean,\n /** The JSDoc body, links flattened. Empty string when undocumented. */\n readonly description: string,\n /**\n * The `@mcp` block tag — an OPTIONAL agent-facing override. Undefined means \"no override\",\n * and a renderer falls back to {@link description}; the fallback is NOT applied here so a\n * renderer can tell a deliberate agent-facing sentence from a reused human one.\n */\n readonly mcpDescription: string | undefined,\n /** The `@format` tag, lifted onto the SCALAR (on an array, onto the ITEM). */\n readonly format: string | undefined,\n /** `@WpMin(n)` — numeric fields only; anything else is a build failure. */\n readonly min: number | undefined,\n /** `@WpMax(n)` — numeric fields only; anything else is a build failure. */\n readonly max: number | undefined,\n /**\n * The `@mcpHeader <token>` JSDoc tag — the MCP 2026 SEP-2243 header this PRIMITIVE field is\n * mirrored into (`Mcp-Param-{token}`). Undefined for every field that is not mirrored, which\n * is nearly all of them.\n *\n * It is documentation and therefore lives in JSDoc, next to the sentence describing the\n * field, rather than in a decorator argument — and since #984 it is the only spelling of the\n * fact at all.\n */\n readonly mcpHeader: string | undefined,\n ) {}\n}\n\n/** One named type reachable from a contract: an object DTO, a string-literal enum, or a union. */\nexport class DocumentedType {\n constructor(\n readonly name: string,\n readonly description: string,\n /** Object shape. Empty for an enum or a union. */\n readonly fields: readonly DocumentedField[],\n /** Set for a string-literal union that has a name. */\n readonly enumValues: readonly string[],\n /** Set for a union of named object types. */\n readonly unionRefNames: readonly string[],\n /** Set only when EVERY branch carries the same property typed as one string literal. */\n readonly discriminator: UnionDiscriminator | undefined,\n /** An index signature (`[k: string]: X`) — the OPEN-MAP half of an object that also has fields. */\n readonly indexSignatureValue: TypeRef | undefined,\n ) {}\n}\n\n/** `@Endpoint(httpMethod, path, operation, kind, options?)`'s LAST argument, as a document sees it. */\nexport class DocumentedEndpointOptions {\n constructor(\n readonly formPost: boolean,\n /** `calledBy` — REQUIRED by the decorator for `external`, absent otherwise. */\n readonly calledBy: string | undefined,\n readonly callerKind: string | undefined,\n ) {}\n}\n\n/**\n * The `@WpMcpTool('search_stores')` declaration, when the method carries one — the ONE fact the\n * source cannot otherwise state, and nothing else.\n *\n * `description` used to sit on the decorator too. The method's JSDoc is the description, for the\n * agent and for the partner alike, byte-identical: two authored copies of one paragraph is the\n * two-spellings shim, and its failure mode is concrete — the partner reads the JSDoc in the OpenAPI\n * document while the agent reads the decorator string in `tools/list`, and they drift the first time\n * somebody edits one. #984 deleted it, which left the decorator holding one field, so it takes the\n * name as a plain string.\n *\n * The three side-effect hints are COMPUTED from the endpoint's `operation` by `mcpHintsForOperation`\n * in `@webpieces/core-util`, which is the one place that mapping lives — `READ | WRITE_IDEMPOTENT |\n * WRITE` already says whether repeating a call is safe, so a hand-declared hint would be a second\n * answer to a question the contract has answered. `openWorldHint` is `@Endpoint`'s `openWorld`.\n */\nexport class DocumentedMcpTool {\n constructor(\n /**\n * The STABLE protocol name. Deliberately independent of the method name, because renaming a\n * method must not break a saved agent workflow.\n */\n readonly name: string,\n ) {}\n}\n\n/**\n * ONE credential of an api-key regime, PARSED — `{ in: 'header', name: 'x-api-key' }` or\n * `{ in: 'bearer' }`.\n *\n * Parsed rather than left as source text because it is the one auth argument a renderer must turn\n * into a STRUCTURE: an OpenAPI `securityScheme` is `{type: apiKey, in, name}` or\n * `{type: http, scheme: bearer}`, and those are different documents. A renderer handed the string\n * `\"{ in: 'header', name: 'x-api-key' }\"` would have to parse TypeScript to emit either one, which\n * is this package's job and not a renderer's.\n */\nexport class DocumentedApiKeyCredential {\n constructor(\n /** `header` or `bearer`, verbatim from the declaration. */\n readonly location: string,\n /** The header name. Undefined for `bearer`, whose location IS `Authorization`. */\n readonly name: string | undefined,\n /** The prose a docs site renders on its authorization card. */\n readonly description: string | undefined,\n ) {}\n}\n\n/** `@WpAuthApiKey(regime, credentials)`, parsed. See {@link DocumentedApiKeyCredential}. */\nexport class DocumentedApiKey {\n constructor(\n readonly regime: string,\n /**\n * Every credential the regime requires, IN DECLARATION ORDER. They are an AND — all of them\n * are presented together — and the order is the order a published document lists them in.\n */\n readonly credentials: readonly DocumentedApiKeyCredential[],\n ) {}\n}\n\n/** WHICH credential an endpoint demands — `@WpAuthPublic`, `@WpAuthJwt`, … — verbatim from the source. */\nexport class DocumentedAuth {\n constructor(\n /** The decorator name as written, e.g. `WpAuthJwt`. */\n readonly decorator: string,\n /** Every argument's text, verbatim and in order. Empty for `@WpAuthPublic()`. */\n readonly argumentTexts: readonly string[],\n /**\n * The PARSED api-key declaration, set only for `@WpAuthApiKey`. Every other decorator's\n * argument is prose or a role list that a document quotes rather than restructures, so\n * {@link argumentTexts} is all they need — see {@link DocumentedApiKeyCredential} for why\n * this one is different.\n */\n readonly apiKey: DocumentedApiKey | undefined,\n ) {}\n}\n\n/** One `@Endpoint` method of one contract. */\nexport class DocumentedEndpoint {\n constructor(\n readonly methodName: string,\n /**\n * `GET` or `POST`, constant-folded from `@Endpoint`'s FIRST argument. A document cannot be\n * written without it — the verb is the key an operation hangs under in `paths`.\n */\n readonly httpMethod: string,\n /** The path, constant-folded. A const that cannot be folded is a HARD FAILURE, never a guess. */\n readonly path: string,\n /**\n * `read` | `write-idempotent` | `write`, verbatim. The SIDE-EFFECT contract, which is\n * independent of the verb: webpieces POSTs a read. A renderer publishes it rather than\n * inferring safety from the verb, which for this framework would be wrong.\n */\n readonly operation: string,\n /** `rpc` | `cloudtasks` | `cron` | `external`, verbatim — this package invents no taxonomy. */\n readonly kind: string,\n /**\n * `{ hidden: true }` — this method is absent from the CUSTOMER document. It stays in the\n * private one, and in the MCP one when it is a tool. WHICH documents the CONTRACT feeds at\n * all is a different, class-level decision; see {@link ApiDocModel.apiTypes}.\n */\n readonly hidden: boolean,\n /** `{ openWorld: true }` — this operation may touch systems outside this service. */\n readonly openWorld: boolean,\n readonly options: DocumentedEndpointOptions,\n readonly auth: DocumentedAuth | undefined,\n readonly mcpTool: DocumentedMcpTool | undefined,\n /** `@WpMcpAuthJwt(...)`'s argument text, when present. */\n readonly mcpAuthText: string | undefined,\n /** `@MaskLog({...})` — field name -> mask mode. */\n readonly maskLog: ReadonlyMap<string, string>,\n readonly description: string,\n /** The `@mcp` override. See {@link DocumentedField.mcpDescription}. */\n readonly mcpDescription: string | undefined,\n readonly request: TypeRef | undefined,\n readonly response: TypeRef | undefined,\n ) {}\n}\n\n/** ONE extraction pass over ONE contract file. Both #982's renderers read exactly this. */\nexport class ApiDocModel {\n constructor(\n /** The contract class name, e.g. `SaveApi`. */\n readonly contractName: string,\n /**\n * WHICH generated documents this contract feeds — `svc-to-svc`, `external-customer`, `mcp`,\n * verbatim from `@ApiType(...)`, defaulting to `svc-to-svc` alone when it declares nothing.\n *\n * A named list rather than a falsy default, because the grant has to be the TOKEN: a default\n * that reached customers would publish a contract whose author typed nothing about it.\n */\n readonly apiTypes: readonly string[],\n /** `@ApiPath(...)`, constant-folded. */\n readonly basePath: string,\n /** The JSDoc on the contract class, links flattened. */\n readonly description: string,\n readonly endpoints: readonly DocumentedEndpoint[],\n /** Every named type reachable from the endpoints, by name. A `$ref` target for a renderer. */\n readonly types: ReadonlyMap<string, DocumentedType>,\n /** Everything that could not be represented — recorded, not dropped. */\n readonly unmapped: readonly UnmappedType[],\n ) {}\n}\n"]}
@@ -1,41 +1,81 @@
1
- import { ApiDocModel } from '../model/ApiDocModel';
2
- import { McpToolDefinition } from './McpToolDefinition';
1
+ import { McpToolCatalog, McpToolDefinition } from '@webpieces/core-util';
2
+ import { ApiDocModel, DocumentedEndpoint } from '../model/ApiDocModel';
3
+ /** ONE `@WpMcpTool` the build could not give a schema, and why. See {@link McpSchemaRenderer.catalogOf}. */
4
+ export declare class SkippedMcpTool {
5
+ /** The stable protocol name it declared. */
6
+ readonly name: string;
7
+ readonly contractName: string;
8
+ /** The render refusal, verbatim, including the declaration it points at. */
9
+ readonly reason: string;
10
+ constructor(
11
+ /** The stable protocol name it declared. */
12
+ name: string, contractName: string,
13
+ /** The render refusal, verbatim, including the declaration it points at. */
14
+ reason: string);
15
+ toString(): string;
16
+ }
17
+ /** What one catalog render produced: the tools, and the ones it could not produce. */
18
+ export declare class McpCatalogRender {
19
+ readonly catalog: McpToolCatalog;
20
+ readonly skipped: readonly SkippedMcpTool[];
21
+ constructor(catalog: McpToolCatalog, skipped: readonly SkippedMcpTool[]);
22
+ }
3
23
  /**
4
- * `ApiDocModel` -> the MCP tool list, in exactly the shape `DtoSchemaBuilder` produces at boot from
5
- * reflect-metadata.
6
- *
7
- * ## Why this exists at all, and why it is READ-ONLY
24
+ * `ApiDocModel` -> the MCP tool list an agent is shown, and the server accepts calls against.
8
25
  *
9
- * #984 wants the MCP runtime off reflect-metadata, which deletes every erasure-repair argument of
10
- * `@WpDtoField` — `required`, `arrayItems`, `integer`, `minimum`, `maximum`, `enumValues`. That is a
11
- * behaviour change on a live protocol surface, and its failure mode is silent: a tool whose input
12
- * schema quietly loses a `required` entry or an `enum` starts failing agent calls at RUNTIME, not at
13
- * build. This renderer plus the equivalence spec beside it turn "the compiler can obviously replace
14
- * those arguments" from a plausible argument into a MEASURED one (#983).
26
+ * ## It is the ONLY source of an MCP schema
15
27
  *
16
- * ## It deliberately reproduces `DtoSchemaBuilder`, defect-for-defect
28
+ * It was written for #983 as a MEASUREMENT: it rendered the same `ApiJsonSchema` the reflect-metadata
29
+ * runtime built, so the two could be compared field by field. They matched for every DTO shape the
30
+ * runtime could build, which is what licensed #984 to delete `@WpDtoField` and its erasure-repair
31
+ * arguments — `required`, `arrayItems`, `integer`, `minimum`, `maximum`, `enumValues`, `mapValues`,
32
+ * `mcpHeader` — along with `DtoSchemaBuilder` itself. There is now one schema, built here, written to
33
+ * `mcp-tools.json` by `wp-openapi`, and read at boot by `McpToolRegistry`.
17
34
  *
18
- * Where MCP's `ApiJsonSchema` subset could express MORE than the runtime does, this renderer emits
19
- * what the RUNTIME emits, and the gate's report names the difference. Three concrete cases:
35
+ * ## Where it now goes FURTHER than the deleted runtime could
20
36
  *
21
- * - **NULLABLE is not rendered.** `ApiJsonSchema.type` holds one string, so `type: [T, "null"]` is
22
- * not expressible in the type the runtime publishes. The compiler can SEE `externalId: string | null`
23
- * and the runtime cannot; emitting it here would fail the gate on a difference that is a runtime
24
- * capability GAP rather than an extractor bug, and hide the real mismatches under it.
25
- * - **A nested DTO is INLINED**, with the FIELD's prose on it, because `buildAt` inlines and then
26
- * `fieldSchema` overwrites `description`. MCP has no `$ref`.
27
- * - **A bound on an ARRAY of numbers** is put on the ITEM, where OpenAPI puts it; the runtime cannot
28
- * express it at all (`@WpDtoField` rejects numeric constraints on a non-`Number` field).
37
+ * The three reproductions #983 documented were runtime capability gaps, and two of them are closed:
29
38
  *
30
- * Making the comparison agree by WEAKENING it would destroy the only thing the gate is for, so every
31
- * one of those is a documented, deliberate reproduction rather than a relaxation.
39
+ * - **NULLABLE is rendered**, as `type: [T, "null"]`. `ApiJsonSchema.type` used to hold one string,
40
+ * so the runtime could not write it down even where the compiler could see `externalId: string | null`
41
+ * — and `{}` and `{externalId: null}` are different wire documents. `type` is now
42
+ * `ApiJsonSchemaType | readonly ApiJsonSchemaType[]` and the union is emitted.
43
+ * - **A bound on an ARRAY of numbers** lands on the ITEM, where OpenAPI puts it. `@WpDtoField`
44
+ * rejected numeric constraints on a non-`Number` field, so it had nowhere to go at all.
45
+ * - **A nested DTO is INLINED**, with the FIELD's prose on it — not a gap but the protocol: MCP tool
46
+ * schemas are inline and have no `$ref`.
32
47
  */
33
48
  export declare class McpSchemaRenderer {
34
49
  private readonly model;
35
50
  constructor(model: ApiDocModel);
36
51
  /** Every `@WpMcpTool` method of the contract, in declaration order. */
37
52
  render(): readonly McpToolDefinition[];
38
- private tool;
53
+ /**
54
+ * The tools of SEVERAL contracts as one catalog — the artifact a server boots from — plus every
55
+ * tool that could not be rendered and why.
56
+ *
57
+ * A catalog rather than a per-contract list because the protocol namespace is flat: two contracts
58
+ * declaring one tool name is a collision an agent would see, and {@link McpToolCatalog} refuses it
59
+ * here, at build time, rather than at somebody's boot.
60
+ *
61
+ * ## Why an unrenderable tool is REPORTED here rather than throwing
62
+ *
63
+ * Some shapes have no MCP schema at all — a recursive DTO, an undocumented tool, a request that
64
+ * is not a named object — and the first of those is a limit of the PROTOCOL rather than a defect
65
+ * in a contract that is otherwise perfectly good HTTP. (A DISCRIMINATED UNION used to be on this
66
+ * list and no longer is: #1009 taught `ApiJsonSchema` `oneOf`, so one publishes.) Such a
67
+ * tool was never servable: the reflect-metadata runtime refused it too, for its own reasons. So
68
+ * failing the whole document build over one would stop a repo publishing its OpenAPI over a tool
69
+ * nobody could ever have called.
70
+ *
71
+ * It is not silence either. The build NAMES every skipped tool with its reason, and
72
+ * `McpToolRegistry` REFUSES TO BOOT when a registered `@WpMcpTool` is missing from the catalog —
73
+ * which is the right place for that failure, because that is the process actually claiming to
74
+ * serve it.
75
+ */
76
+ static catalogOf(models: readonly ApiDocModel[]): McpCatalogRender;
77
+ /** ONE tool. Visible to {@link catalogOf}, which renders tool by tool so it can report one. */
78
+ tool(endpoint: DocumentedEndpoint): McpToolDefinition;
39
79
  /**
40
80
  * `operation` verbatim from the model, mapped back onto the REAL constant.
41
81
  *
@@ -44,27 +84,66 @@ export declare class McpSchemaRenderer {
44
84
  * are exhaustive, means falling off the end and publishing a tool with NO hints.
45
85
  */
46
86
  private static operationOf;
47
- /** A tool's input/output schema: always a closed object, exactly as `DtoSchemaBuilder.build` is. */
87
+ /**
88
+ * A tool's input/output schema: always a CLOSED OBJECT, because MCP publishes objects — and
89
+ * because a union at the ROOT of a tool schema is refused by the function-calling APIs that
90
+ * consume it. Both OpenAI and Anthropic reject a top-level `oneOf`/`anyOf`/`allOf`, and a server
91
+ * sends its WHOLE tool list on every request, so one such tool makes every request 400 and bricks
92
+ * the session — not just that tool. Nested composition, inside a property, is fine.
93
+ *
94
+ * The build-time rule `no-root-union-api-type` refuses the same shape across every `@ApiPath`
95
+ * contract in the workspace, `@ApiType` or not. This is the renderer's own backstop, so a catalog
96
+ * can never carry one even if it is reached some other way.
97
+ */
48
98
  private rootSchema;
49
99
  private namedType;
50
100
  /**
51
- * One object DTO. CLOSED (`additionalProperties: false`), `required` only when non-empty — both
52
- * exactly as `DtoSchemaBuilder.buildAt` writes them, because that is what is being compared.
101
+ * One object DTO. CLOSED (`additionalProperties: false`), with `required` written only when it is
102
+ * non-empty, so an all-optional DTO carries no empty list.
53
103
  *
54
- * The cycle stop is `parents`, and it THROWS rather than truncating, which is again what the
55
- * runtime does: an inline schema cannot express a recursive DTO, and one that silently stopped a
56
- * level down would publish a shape the server does not accept.
104
+ * The cycle stop is `parents`, and it THROWS rather than truncating: an inline schema cannot
105
+ * express a recursive DTO, and one that silently stopped a level down would publish a shape the
106
+ * server does not accept.
57
107
  */
58
108
  private objectSchema;
109
+ /**
110
+ * A UNION, as `oneOf` with its branches INLINE and its DERIVED discriminator.
111
+ *
112
+ * MCP tool schemas are JSON Schema 2020-12 — the same dialect OpenAPI 3.1 uses — so `oneOf` was
113
+ * never the obstacle; the obstacle was this repo's own subset, which had no spelling for it
114
+ * (#1009). The shape written here MIRRORS `SchemaRenderer.union` in `@webpieces/openapi-generator`
115
+ * branch for branch, because a union has ONE published spelling and that renderer is the
116
+ * reference implementation of it. The only difference is the absence of `$ref`: a tool schema is
117
+ * inline, so each branch is rendered in full and the discriminator maps to branch NAMES.
118
+ *
119
+ * `discriminator` is written ONLY when the model DERIVED one. A union TypeScript itself cannot
120
+ * narrow is published as a bare `oneOf` rather than with an invented discriminator — claiming a
121
+ * narrowing the source does not have is worse than admitting there is none.
122
+ */
123
+ private unionSchema;
124
+ /**
125
+ * A FIELD whose type is a union: the model registers `type X = A | B` as its OWN entry carrying
126
+ * the derived discriminator, while the field holds a bare list of branch names. Rendering that
127
+ * list directly would publish the `oneOf` and silently DROP the discriminator — the one part of a
128
+ * union a client needs to narrow on — so the alias is looked up by its branch list first. This is
129
+ * the same lookup `SchemaRenderer.namedUnion` does to emit its `$ref`.
130
+ */
131
+ private fieldUnion;
59
132
  /**
60
133
  * One FIELD: its type, then the prose and the constraints that hang off the field.
61
134
  *
62
- * The ORDER matters and mirrors `fieldSchema`: the type is built first and `description` is
63
- * written over whatever the type produced, so a nested DTO carries the FIELD's sentence rather
64
- * than the DTO's. `@WpMin` / `@WpMax` land on the numeric LEAF — on an array, on the item — for
65
- * the same reason `SchemaRenderer` puts them there: a `minimum` on an array means nothing.
135
+ * The ORDER matters: the type is built first and `description` is written over whatever the type
136
+ * produced, so a nested DTO carries the FIELD's sentence rather than the DTO's. `@WpMin` /
137
+ * `@WpMax` land on the numeric LEAF — on an array, on the item — for the same reason
138
+ * `SchemaRenderer` puts them there: a `minimum` on an array means nothing.
139
+ *
140
+ * NULLABLE widens the type to `[T, "null"]` and is deliberately NOT the same thing as OPTIONAL,
141
+ * which is an absent entry in the object's `required` list. `{}` and `{externalId: null}` are
142
+ * different wire documents, and an agent told only "optional" would send the wrong one.
66
143
  */
67
144
  private fieldSchema;
145
+ /** `T` -> `[T, "null"]`, refusing a field with no type at all rather than publishing `["null"]`. */
146
+ private static nullable;
68
147
  /**
69
148
  * `@mcpHeader` mirrors a PRIMITIVE parameter into `Mcp-Param-{name}` (MCP 2026 SEP-2243). The
70
149
  * three conditions are the runtime's, restated against the compiler's view of the field, so a
@@ -1,40 +1,63 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.McpSchemaRenderer = void 0;
3
+ exports.McpSchemaRenderer = exports.McpCatalogRender = exports.SkippedMcpTool = void 0;
4
4
  const core_util_1 = require("@webpieces/core-util");
5
5
  const McpRenderError_1 = require("./McpRenderError");
6
- const McpToolDefinition_1 = require("./McpToolDefinition");
7
6
  /** RFC 9110 token, which is what an `Mcp-Param-{name}` header name has to be. */
8
7
  const HEADER_TOKEN = /^[!#$%&'*+\-.^_`|~0-9A-Za-z]+$/;
8
+ /** ONE `@WpMcpTool` the build could not give a schema, and why. See {@link McpSchemaRenderer.catalogOf}. */
9
+ class SkippedMcpTool {
10
+ name;
11
+ contractName;
12
+ reason;
13
+ constructor(
14
+ /** The stable protocol name it declared. */
15
+ name, contractName,
16
+ /** The render refusal, verbatim, including the declaration it points at. */
17
+ reason) {
18
+ this.name = name;
19
+ this.contractName = contractName;
20
+ this.reason = reason;
21
+ }
22
+ toString() {
23
+ return `${this.contractName}/${this.name}: ${this.reason}`;
24
+ }
25
+ }
26
+ exports.SkippedMcpTool = SkippedMcpTool;
27
+ /** What one catalog render produced: the tools, and the ones it could not produce. */
28
+ class McpCatalogRender {
29
+ catalog;
30
+ skipped;
31
+ constructor(catalog, skipped) {
32
+ this.catalog = catalog;
33
+ this.skipped = skipped;
34
+ }
35
+ }
36
+ exports.McpCatalogRender = McpCatalogRender;
9
37
  /**
10
- * `ApiDocModel` -> the MCP tool list, in exactly the shape `DtoSchemaBuilder` produces at boot from
11
- * reflect-metadata.
12
- *
13
- * ## Why this exists at all, and why it is READ-ONLY
38
+ * `ApiDocModel` -> the MCP tool list an agent is shown, and the server accepts calls against.
14
39
  *
15
- * #984 wants the MCP runtime off reflect-metadata, which deletes every erasure-repair argument of
16
- * `@WpDtoField` — `required`, `arrayItems`, `integer`, `minimum`, `maximum`, `enumValues`. That is a
17
- * behaviour change on a live protocol surface, and its failure mode is silent: a tool whose input
18
- * schema quietly loses a `required` entry or an `enum` starts failing agent calls at RUNTIME, not at
19
- * build. This renderer plus the equivalence spec beside it turn "the compiler can obviously replace
20
- * those arguments" from a plausible argument into a MEASURED one (#983).
40
+ * ## It is the ONLY source of an MCP schema
21
41
  *
22
- * ## It deliberately reproduces `DtoSchemaBuilder`, defect-for-defect
42
+ * It was written for #983 as a MEASUREMENT: it rendered the same `ApiJsonSchema` the reflect-metadata
43
+ * runtime built, so the two could be compared field by field. They matched for every DTO shape the
44
+ * runtime could build, which is what licensed #984 to delete `@WpDtoField` and its erasure-repair
45
+ * arguments — `required`, `arrayItems`, `integer`, `minimum`, `maximum`, `enumValues`, `mapValues`,
46
+ * `mcpHeader` — along with `DtoSchemaBuilder` itself. There is now one schema, built here, written to
47
+ * `mcp-tools.json` by `wp-openapi`, and read at boot by `McpToolRegistry`.
23
48
  *
24
- * Where MCP's `ApiJsonSchema` subset could express MORE than the runtime does, this renderer emits
25
- * what the RUNTIME emits, and the gate's report names the difference. Three concrete cases:
49
+ * ## Where it now goes FURTHER than the deleted runtime could
26
50
  *
27
- * - **NULLABLE is not rendered.** `ApiJsonSchema.type` holds one string, so `type: [T, "null"]` is
28
- * not expressible in the type the runtime publishes. The compiler can SEE `externalId: string | null`
29
- * and the runtime cannot; emitting it here would fail the gate on a difference that is a runtime
30
- * capability GAP rather than an extractor bug, and hide the real mismatches under it.
31
- * - **A nested DTO is INLINED**, with the FIELD's prose on it, because `buildAt` inlines and then
32
- * `fieldSchema` overwrites `description`. MCP has no `$ref`.
33
- * - **A bound on an ARRAY of numbers** is put on the ITEM, where OpenAPI puts it; the runtime cannot
34
- * express it at all (`@WpDtoField` rejects numeric constraints on a non-`Number` field).
51
+ * The three reproductions #983 documented were runtime capability gaps, and two of them are closed:
35
52
  *
36
- * Making the comparison agree by WEAKENING it would destroy the only thing the gate is for, so every
37
- * one of those is a documented, deliberate reproduction rather than a relaxation.
53
+ * - **NULLABLE is rendered**, as `type: [T, "null"]`. `ApiJsonSchema.type` used to hold one string,
54
+ * so the runtime could not write it down even where the compiler could see `externalId: string | null`
55
+ * — and `{}` and `{externalId: null}` are different wire documents. `type` is now
56
+ * `ApiJsonSchemaType | readonly ApiJsonSchemaType[]` and the union is emitted.
57
+ * - **A bound on an ARRAY of numbers** lands on the ITEM, where OpenAPI puts it. `@WpDtoField`
58
+ * rejected numeric constraints on a non-`Number` field, so it had nowhere to go at all.
59
+ * - **A nested DTO is INLINED**, with the FIELD's prose on it — not a gap but the protocol: MCP tool
60
+ * schemas are inline and have no `$ref`.
38
61
  */
39
62
  class McpSchemaRenderer {
40
63
  model;
@@ -51,6 +74,54 @@ class McpSchemaRenderer {
51
74
  }
52
75
  return tools;
53
76
  }
77
+ /**
78
+ * The tools of SEVERAL contracts as one catalog — the artifact a server boots from — plus every
79
+ * tool that could not be rendered and why.
80
+ *
81
+ * A catalog rather than a per-contract list because the protocol namespace is flat: two contracts
82
+ * declaring one tool name is a collision an agent would see, and {@link McpToolCatalog} refuses it
83
+ * here, at build time, rather than at somebody's boot.
84
+ *
85
+ * ## Why an unrenderable tool is REPORTED here rather than throwing
86
+ *
87
+ * Some shapes have no MCP schema at all — a recursive DTO, an undocumented tool, a request that
88
+ * is not a named object — and the first of those is a limit of the PROTOCOL rather than a defect
89
+ * in a contract that is otherwise perfectly good HTTP. (A DISCRIMINATED UNION used to be on this
90
+ * list and no longer is: #1009 taught `ApiJsonSchema` `oneOf`, so one publishes.) Such a
91
+ * tool was never servable: the reflect-metadata runtime refused it too, for its own reasons. So
92
+ * failing the whole document build over one would stop a repo publishing its OpenAPI over a tool
93
+ * nobody could ever have called.
94
+ *
95
+ * It is not silence either. The build NAMES every skipped tool with its reason, and
96
+ * `McpToolRegistry` REFUSES TO BOOT when a registered `@WpMcpTool` is missing from the catalog —
97
+ * which is the right place for that failure, because that is the process actually claiming to
98
+ * serve it.
99
+ */
100
+ // webpieces-disable no-function-outside-class -- static factory over this class
101
+ static catalogOf(models) {
102
+ const tools = [];
103
+ const skipped = [];
104
+ for (const model of models) {
105
+ const renderer = new McpSchemaRenderer(model);
106
+ for (const endpoint of model.endpoints) {
107
+ if (endpoint.mcpTool === undefined) {
108
+ continue;
109
+ }
110
+ // eslint-disable-next-line @webpieces/no-unmanaged-exceptions -- a per-tool render refusal is REPORTED, see the docstring
111
+ try {
112
+ tools.push(renderer.tool(endpoint));
113
+ }
114
+ catch (err) {
115
+ //const error = toError(err);
116
+ if (!(err instanceof McpRenderError_1.McpRenderError))
117
+ throw err;
118
+ skipped.push(new SkippedMcpTool(endpoint.mcpTool.name, model.contractName, err.message));
119
+ }
120
+ }
121
+ }
122
+ return new McpCatalogRender(new core_util_1.McpToolCatalog(tools), skipped);
123
+ }
124
+ /** ONE tool. Visible to {@link catalogOf}, which renders tool by tool so it can report one. */
54
125
  tool(endpoint) {
55
126
  const where = `${this.model.contractName}.${endpoint.methodName}`;
56
127
  const description = endpoint.mcpDescription ?? endpoint.description;
@@ -61,7 +132,7 @@ class McpSchemaRenderer {
61
132
  if (endpoint.request === undefined || endpoint.response === undefined) {
62
133
  throw new McpRenderError_1.McpRenderError('an MCP tool has no declared request or response type', where, 'Declare both: one request parameter and a Promise<Response> return type.');
63
134
  }
64
- return new McpToolDefinition_1.McpToolDefinition(endpoint.mcpTool.name, endpoint.methodName, description, (0, core_util_1.mcpHintsForOperation)(McpSchemaRenderer.operationOf(endpoint, where), endpoint.openWorld), this.rootSchema(endpoint.request, where, 'request'), this.rootSchema(endpoint.response, where, 'response'));
135
+ return new core_util_1.McpToolDefinition(endpoint.mcpTool.name, endpoint.methodName, description, (0, core_util_1.mcpHintsForOperation)(McpSchemaRenderer.operationOf(endpoint, where), endpoint.openWorld), this.rootSchema(endpoint.request, where, 'request'), this.rootSchema(endpoint.response, where, 'response'));
65
136
  }
66
137
  /**
67
138
  * `operation` verbatim from the model, mapped back onto the REAL constant.
@@ -83,13 +154,34 @@ class McpSchemaRenderer {
83
154
  throw new McpRenderError_1.McpRenderError(`@Endpoint declares operation '${endpoint.operation}', which has no MCP hints`, where, `Use one of the exported constants: ${core_util_1.READ}, ${core_util_1.WRITE_IDEMPOTENT}, ${core_util_1.WRITE}.`);
84
155
  }
85
156
  }
86
- /** A tool's input/output schema: always a closed object, exactly as `DtoSchemaBuilder.build` is. */
157
+ /**
158
+ * A tool's input/output schema: always a CLOSED OBJECT, because MCP publishes objects — and
159
+ * because a union at the ROOT of a tool schema is refused by the function-calling APIs that
160
+ * consume it. Both OpenAI and Anthropic reject a top-level `oneOf`/`anyOf`/`allOf`, and a server
161
+ * sends its WHOLE tool list on every request, so one such tool makes every request 400 and bricks
162
+ * the session — not just that tool. Nested composition, inside a property, is fine.
163
+ *
164
+ * The build-time rule `no-root-union-api-type` refuses the same shape across every `@ApiPath`
165
+ * contract in the workspace, `@ApiType` or not. This is the renderer's own backstop, so a catalog
166
+ * can never carry one even if it is reached some other way.
167
+ */
87
168
  rootSchema(ref, where, side) {
169
+ if (ref.kind === 'union') {
170
+ throw new McpRenderError_1.McpRenderError(`an MCP tool's ${side} is itself a union`, where, `Wrap it in a property of an object ${side} — a top-level oneOf is rejected by the ` +
171
+ 'OpenAI and Anthropic function-calling APIs, and one such tool 400s every ' +
172
+ 'request in the session.');
173
+ }
88
174
  if (ref.kind !== 'ref') {
89
175
  throw new McpRenderError_1.McpRenderError(`an MCP tool's ${side} is not a named DTO`, where, 'Give it a named interface or class. An inline or primitive ' +
90
176
  `${side} has no object schema, and MCP publishes objects.`);
91
177
  }
92
- return this.objectSchema(this.namedType(ref.refName, where), new Set());
178
+ const type = this.namedType(ref.refName, where);
179
+ if (type.unionRefNames.length > 0) {
180
+ throw new McpRenderError_1.McpRenderError(`an MCP tool's ${side} '${type.name}' is itself a union`, where, `Wrap it in a property of an object ${side} — a top-level oneOf is rejected by the ` +
181
+ 'OpenAI and Anthropic function-calling APIs, and one such tool 400s every ' +
182
+ 'request in the session.');
183
+ }
184
+ return this.objectSchema(type, new Set());
93
185
  }
94
186
  namedType(name, where) {
95
187
  const type = this.model.types.get(name);
@@ -99,12 +191,12 @@ class McpSchemaRenderer {
99
191
  return type;
100
192
  }
101
193
  /**
102
- * One object DTO. CLOSED (`additionalProperties: false`), `required` only when non-empty — both
103
- * exactly as `DtoSchemaBuilder.buildAt` writes them, because that is what is being compared.
194
+ * One object DTO. CLOSED (`additionalProperties: false`), with `required` written only when it is
195
+ * non-empty, so an all-optional DTO carries no empty list.
104
196
  *
105
- * The cycle stop is `parents`, and it THROWS rather than truncating, which is again what the
106
- * runtime does: an inline schema cannot express a recursive DTO, and one that silently stopped a
107
- * level down would publish a shape the server does not accept.
197
+ * The cycle stop is `parents`, and it THROWS rather than truncating: an inline schema cannot
198
+ * express a recursive DTO, and one that silently stopped a level down would publish a shape the
199
+ * server does not accept.
108
200
  */
109
201
  objectSchema(type, parents) {
110
202
  if (parents.has(type.name)) {
@@ -112,7 +204,7 @@ class McpSchemaRenderer {
112
204
  'inline and has no $ref to close a loop with.');
113
205
  }
114
206
  if (type.unionRefNames.length > 0) {
115
- throw new McpRenderError_1.McpRenderError(`'${type.name}' is a union, which an MCP input schema cannot express`, type.name, 'Publish a single object shape to agents, or keep this contract off MCP.');
207
+ return this.unionSchema(type, parents);
116
208
  }
117
209
  if (type.indexSignatureValue !== undefined && type.fields.length > 0) {
118
210
  throw new McpRenderError_1.McpRenderError(`'${type.name}' has both named fields and an index signature`, type.name, 'Split the open map into a field of its own: a schema is either closed or a typed ' +
@@ -135,13 +227,70 @@ class McpSchemaRenderer {
135
227
  }
136
228
  return schema;
137
229
  }
230
+ /**
231
+ * A UNION, as `oneOf` with its branches INLINE and its DERIVED discriminator.
232
+ *
233
+ * MCP tool schemas are JSON Schema 2020-12 — the same dialect OpenAPI 3.1 uses — so `oneOf` was
234
+ * never the obstacle; the obstacle was this repo's own subset, which had no spelling for it
235
+ * (#1009). The shape written here MIRRORS `SchemaRenderer.union` in `@webpieces/openapi-generator`
236
+ * branch for branch, because a union has ONE published spelling and that renderer is the
237
+ * reference implementation of it. The only difference is the absence of `$ref`: a tool schema is
238
+ * inline, so each branch is rendered in full and the discriminator maps to branch NAMES.
239
+ *
240
+ * `discriminator` is written ONLY when the model DERIVED one. A union TypeScript itself cannot
241
+ * narrow is published as a bare `oneOf` rather than with an invented discriminator — claiming a
242
+ * narrowing the source does not have is worse than admitting there is none.
243
+ */
244
+ unionSchema(type, parents) {
245
+ const nested = new Set(parents);
246
+ nested.add(type.name);
247
+ const schema = new core_util_1.ApiJsonSchema();
248
+ schema.oneOf = type.unionRefNames.map((name) => this.objectSchema(this.namedType(name, type.name), nested));
249
+ if (type.description.trim() !== '') {
250
+ schema.description = type.description;
251
+ }
252
+ if (type.discriminator !== undefined) {
253
+ const mapping = {};
254
+ for (const branch of type.unionRefNames) {
255
+ const value = type.discriminator.branchValues.get(branch);
256
+ if (value !== undefined) {
257
+ mapping[value] = branch;
258
+ }
259
+ }
260
+ schema.discriminator = new core_util_1.ApiJsonSchemaDiscriminator(type.discriminator.propertyName, mapping);
261
+ }
262
+ return schema;
263
+ }
264
+ /**
265
+ * A FIELD whose type is a union: the model registers `type X = A | B` as its OWN entry carrying
266
+ * the derived discriminator, while the field holds a bare list of branch names. Rendering that
267
+ * list directly would publish the `oneOf` and silently DROP the discriminator — the one part of a
268
+ * union a client needs to narrow on — so the alias is looked up by its branch list first. This is
269
+ * the same lookup `SchemaRenderer.namedUnion` does to emit its `$ref`.
270
+ */
271
+ fieldUnion(branchNames, where, parents) {
272
+ const key = branchNames.join(',');
273
+ for (const name of this.model.types.keys()) {
274
+ const candidate = this.model.types.get(name);
275
+ if (candidate.unionRefNames.length > 0 && candidate.unionRefNames.join(',') === key) {
276
+ return this.unionSchema(candidate, parents);
277
+ }
278
+ }
279
+ const schema = new core_util_1.ApiJsonSchema();
280
+ schema.oneOf = branchNames.map((name) => this.objectSchema(this.namedType(name, where), parents));
281
+ return schema;
282
+ }
138
283
  /**
139
284
  * One FIELD: its type, then the prose and the constraints that hang off the field.
140
285
  *
141
- * The ORDER matters and mirrors `fieldSchema`: the type is built first and `description` is
142
- * written over whatever the type produced, so a nested DTO carries the FIELD's sentence rather
143
- * than the DTO's. `@WpMin` / `@WpMax` land on the numeric LEAF — on an array, on the item — for
144
- * the same reason `SchemaRenderer` puts them there: a `minimum` on an array means nothing.
286
+ * The ORDER matters: the type is built first and `description` is written over whatever the type
287
+ * produced, so a nested DTO carries the FIELD's sentence rather than the DTO's. `@WpMin` /
288
+ * `@WpMax` land on the numeric LEAF — on an array, on the item — for the same reason
289
+ * `SchemaRenderer` puts them there: a `minimum` on an array means nothing.
290
+ *
291
+ * NULLABLE widens the type to `[T, "null"]` and is deliberately NOT the same thing as OPTIONAL,
292
+ * which is an absent entry in the object's `required` list. `{}` and `{externalId: null}` are
293
+ * different wire documents, and an agent told only "optional" would send the wrong one.
145
294
  */
146
295
  fieldSchema(owner, field, parents) {
147
296
  const where = `${owner.name}.${field.name}`;
@@ -163,8 +312,20 @@ class McpSchemaRenderer {
163
312
  McpSchemaRenderer.assertHeaderFits(field, schema, where);
164
313
  schema['x-mcp-header'] = field.mcpHeader;
165
314
  }
315
+ if (field.nullable) {
316
+ schema.type = McpSchemaRenderer.nullable(schema, where);
317
+ }
166
318
  return schema;
167
319
  }
320
+ /** `T` -> `[T, "null"]`, refusing a field with no type at all rather than publishing `["null"]`. */
321
+ // webpieces-disable no-function-outside-class -- private static mapping of this class
322
+ static nullable(schema, where) {
323
+ const base = core_util_1.ApiJsonSchema.baseTypeOf(schema);
324
+ if (base === undefined) {
325
+ throw new McpRenderError_1.McpRenderError('a nullable field has no other type', where, 'A field typed only `null` carries no information — give it a real type beside it.');
326
+ }
327
+ return [base, 'null'];
328
+ }
168
329
  /**
169
330
  * `@mcpHeader` mirrors a PRIMITIVE parameter into `Mcp-Param-{name}` (MCP 2026 SEP-2243). The
170
331
  * three conditions are the runtime's, restated against the compiler's view of the field, so a
@@ -203,7 +364,7 @@ class McpSchemaRenderer {
203
364
  case 'ref':
204
365
  return this.referencedSchema(ref.refName, where, parents);
205
366
  case 'union':
206
- throw new McpRenderError_1.McpRenderError('a union has no MCP input-schema shape', where, 'Publish one object shape to agents, or keep this method off MCP.');
367
+ return this.fieldUnion(ref.unionRefNames, where, parents);
207
368
  default:
208
369
  throw new McpRenderError_1.McpRenderError(`no MCP schema for the declared type '${ref.unmappedText ?? '<unknown>'}'`, where, 'Give the field a shape the model can represent — a named DTO, an array of one, ' +
209
370
  'a string-literal union, a Record, or a primitive.');