@webpieces/api-doc-model 0.4.1000 → 0.4.1001

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webpieces/api-doc-model",
3
- "version": "0.4.1000",
3
+ "version": "0.4.1001",
4
4
  "description": "TypeScript-compiler-API extractor producing one in-memory ApiDocModel from a webpieces API contract. No renderer, no runtime, no app-specific import.",
5
5
  "type": "commonjs",
6
6
  "main": "./src/index.js",
@@ -23,7 +23,7 @@
23
23
  "access": "public"
24
24
  },
25
25
  "dependencies": {
26
- "@webpieces/core-util": "0.4.1000",
26
+ "@webpieces/core-util": "0.4.1001",
27
27
  "typescript": "5.9.3",
28
28
  "minimatch": "10.0.1"
29
29
  }
@@ -119,7 +119,8 @@ export declare class McpSchemaRenderer {
119
119
  */
120
120
  private static operationOf;
121
121
  /**
122
- * A tool's input/output schema: always a CLOSED OBJECT, because MCP publishes objects — and
122
+ * A tool's input/output schema: always an OBJECT, rendered CLOSED (the published `outputSchema` is
123
+ * then opened by {@link tool}, #1441), because MCP publishes objects — and
123
124
  * because a union at the ROOT of a tool schema is refused by the function-calling APIs that
124
125
  * consume it. Both OpenAI and Anthropic reject a top-level `oneOf`/`anyOf`/`allOf`, and a server
125
126
  * sends its WHOLE tool list on every request, so one such tool makes every request 400 and bricks
@@ -143,7 +144,8 @@ export declare class McpSchemaRenderer {
143
144
  private namedType;
144
145
  /**
145
146
  * One object DTO. CLOSED (`additionalProperties: false`), with `required` written only when it is
146
- * non-empty, so an all-optional DTO carries no empty list.
147
+ * non-empty, so an all-optional DTO carries no empty list. Closed is what an `inputSchema`
148
+ * publishes; an `outputSchema` is opened at every depth by `ApiJsonSchema.openForClients` (#1441).
147
149
  *
148
150
  * The cycle stop is `parents`, and it THROWS rather than truncating: an inline schema cannot
149
151
  * express a recursive DTO, and one that silently stopped a level down would publish a shape the
@@ -233,7 +233,10 @@ class McpSchemaRenderer {
233
233
  if (nameProblem !== undefined) {
234
234
  throw new McpRenderError_1.McpRenderError(`the MCP tool name '${endpoint.mcpTool.name}' ${nameProblem}`, where, core_util_1.McpToolName.cure());
235
235
  }
236
- return new core_util_1.McpToolDefinition(endpoint.mcpTool.name, this.prose(endpoint.summary), endpoint.methodName, this.prose(description), (0, core_util_1.mcpHintsForOperation)(McpSchemaRenderer.operationOf(endpoint, where), endpoint.openWorld, endpoint.additive), this.rootSchema(endpoint.request, where, 'request', undefined), this.rootSchema(endpoint.response, where, 'response', endpoint.returnsDescription), endpoint.mcpTool.profiles);
236
+ return new core_util_1.McpToolDefinition(endpoint.mcpTool.name, this.prose(endpoint.summary), endpoint.methodName, this.prose(description), (0, core_util_1.mcpHintsForOperation)(McpSchemaRenderer.operationOf(endpoint, where), endpoint.openWorld, endpoint.additive), this.rootSchema(endpoint.request, where, 'request', undefined),
237
+ // OPEN for clients (#1441): a client caches the outputSchema at connect and validates
238
+ // every result against it, so a closed one made ADDING a response field a break.
239
+ core_util_1.ApiJsonSchema.openForClients(this.rootSchema(endpoint.response, where, 'response', endpoint.returnsDescription)), endpoint.mcpTool.profiles);
237
240
  }
238
241
  /**
239
242
  * `operation` verbatim from the model, mapped back onto the REAL constant.
@@ -256,7 +259,8 @@ class McpSchemaRenderer {
256
259
  }
257
260
  }
258
261
  /**
259
- * A tool's input/output schema: always a CLOSED OBJECT, because MCP publishes objects — and
262
+ * A tool's input/output schema: always an OBJECT, rendered CLOSED (the published `outputSchema` is
263
+ * then opened by {@link tool}, #1441), because MCP publishes objects — and
260
264
  * because a union at the ROOT of a tool schema is refused by the function-calling APIs that
261
265
  * consume it. Both OpenAI and Anthropic reject a top-level `oneOf`/`anyOf`/`allOf`, and a server
262
266
  * sends its WHOLE tool list on every request, so one such tool makes every request 400 and bricks
@@ -310,7 +314,8 @@ class McpSchemaRenderer {
310
314
  }
311
315
  /**
312
316
  * One object DTO. CLOSED (`additionalProperties: false`), with `required` written only when it is
313
- * non-empty, so an all-optional DTO carries no empty list.
317
+ * non-empty, so an all-optional DTO carries no empty list. Closed is what an `inputSchema`
318
+ * publishes; an `outputSchema` is opened at every depth by `ApiJsonSchema.openForClients` (#1441).
314
319
  *
315
320
  * The cycle stop is `parents`, and it THROWS rather than truncating: an inline schema cannot
316
321
  * express a recursive DTO, and one that silently stopped a level down would publish a shape the
@@ -1 +1 @@
1
- {"version":3,"file":"McpSchemaRenderer.js","sourceRoot":"","sources":["../../../../../../packages/docs/api-doc-model/src/render/McpSchemaRenderer.ts"],"names":[],"mappings":";;;AAAA,oDAa8B;AAO9B,8CAAoG;AACpG,8DAA2D;AAG3D,qDAAkD;AAElD,iFAAiF;AACjF,MAAM,YAAY,GAAG,gCAAgC,CAAC;AAEtD,4GAA4G;AAC5G,MAAa,cAAc;IAGV;IACA;IAEA;IALb;IACI,4CAA4C;IACnC,IAAY,EACZ,YAAoB;IAC7B,4EAA4E;IACnE,MAAc;QAHd,SAAI,GAAJ,IAAI,CAAQ;QACZ,iBAAY,GAAZ,YAAY,CAAQ;QAEpB,WAAM,GAAN,MAAM,CAAQ;IACxB,CAAC;IAEJ,QAAQ;QACJ,OAAO,GAAG,IAAI,CAAC,YAAY,IAAI,IAAI,CAAC,IAAI,KAAK,IAAI,CAAC,MAAM,EAAE,CAAC;IAC/D,CAAC;CACJ;AAZD,wCAYC;AAED,oDAAoD;AACpD,MAAM,UAAU,GAAG,sBAAsB,CAAC;AAE1C;;;;GAIG;AACH,MAAM,aAAa;IACc;IAA7B,YAA6B,YAA0B;QAA1B,iBAAY,GAAZ,YAAY,CAAc;IAAG,CAAC;IAE3D,aAAa,CAAC,IAAa;QACvB,IAAI,IAAI,CAAC,IAAI,KAAK,qBAAW,CAAC,IAAI,EAAE,CAAC;YACjC,OAAO,IAAI,CAAC,SAAS,CAAC;QAC1B,CAAC;QACD,IAAI,IAAI,CAAC,IAAI,KAAK,qBAAW,CAAC,SAAS,EAAE,CAAC;YACtC,OAAO,IAAI,CAAC,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,EAC1E,KAAK,EACL,iFAAiF;oBAC7E,mDAAmD,CAC1D,CAAC;QACV,CAAC;IACL,CAAC;IAED,gGAAgG;IACxF,gBAAgB,CACpB,IAAY,EACZ,KAAa,EACb,OAA4B;QAE5B,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;QACzC,IAAI,IAAI,CAAC,UAAU,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAC7B,MAAM,MAAM,GAAG,IAAI,yBAAa,CAAC,QAAQ,CAAC,CAAC;YAC3C,MAAM,CAAC,IAAI,GAAG,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC;YACtC,OAAO,MAAM,CAAC;QAClB,CAAC;QACD,OAAO,IAAI,CAAC,YAAY,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IAC5C,CAAC;IAED,sFAAsF;IAC9E,MAAM,CAAC,SAAS,CAAC,GAAY,EAAE,KAAa;QAChD,IAAI,GAAG,CAAC,SAAS,KAAK,QAAQ,IAAI,GAAG,CAAC,SAAS,KAAK,SAAS,EAAE,CAAC;YAC5D,OAAO,IAAI,yBAAa,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;QAC5C,CAAC;QACD,IAAI,GAAG,CAAC,SAAS,KAAK,QAAQ,EAAE,CAAC;YAC7B,OAAO,IAAI,yBAAa,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC;QACjE,CAAC;QACD,MAAM,IAAI,+BAAc,CACpB,IAAI,GAAG,CAAC,SAAS,qBAAqB,EACtC,KAAK,EACL,wFAAwF;YACpF,4CAA4C,CACnD,CAAC;IACN,CAAC;CACJ;AA1jBD,8CA0jBC","sourcesContent":["import {\n ApiJsonSchema,\n ApiJsonSchemaDiscriminator,\n ApiJsonSchemaType,\n EndpointOperation,\n McpToolCatalogError,\n McpToolCatalogFile,\n McpToolDefinition,\n McpToolName,\n mcpHintsForOperation,\n READ,\n WRITE,\n WRITE_IDEMPOTENT,\n} from '@webpieces/core-util';\nimport {\n ApiDocModel,\n DocumentedEndpoint,\n DocumentedField,\n DocumentedType,\n} from '../model/ApiDocModel';\nimport { DocLink, DocLinkKind, DocLinkNaming, DocLinkProblem, DocLinkText } from '../model/DocLink';\nimport { EndpointSummary } from '../model/EndpointSummary';\nimport { OperationIds } from '../model/OperationIds';\nimport { TypeRef } from '../model/TypeRef';\nimport { McpRenderError } from './McpRenderError';\n\n/** RFC 9110 token, which is what an `Mcp-Param-{name}` header name has to be. */\nconst HEADER_TOKEN = /^[!#$%&'*+\\-.^_`|~0-9A-Za-z]+$/;\n\n/** ONE `@WpMcpTool` the build could not give a schema, and why. See {@link McpSchemaRenderer.catalogOf}. */\nexport class SkippedMcpTool {\n constructor(\n /** The stable protocol name it declared. */\n readonly name: string,\n readonly contractName: string,\n /** The render refusal, verbatim, including the declaration it points at. */\n readonly reason: string,\n ) {}\n\n toString(): string {\n return `${this.contractName}/${this.name}: ${this.reason}`;\n }\n}\n\n/** The output name every MCP link refusal names. */\nconst MCP_OUTPUT = 'the MCP tool catalog';\n\n/**\n * How an MCP tool catalog names a `{@link}` target (#1284). A tool schema is fully inline, so a type\n * is named by its published schema name; a contract method that IS a tool by its tool `name` — the\n * one thing an MCP client can call — and any other method by its operationId.\n */\nclass McpLinkNaming implements DocLinkNaming {\n constructor(private readonly operationIds: OperationIds) {}\n\n publishedName(link: DocLink): string | undefined {\n if (link.kind === DocLinkKind.TYPE) {\n return link.ownerName;\n }\n if (link.kind === DocLinkKind.OPERATION) {\n return link.mcpToolName ?? this.operationIds.of(link.owner, link.ownerName);\n }\n // A bare member is its own name. A `@hidden` field is published to MCP (#1246), as a\n // hidden method is, so a link to one is never refused here.\n return link.kind === DocLinkKind.MEMBER ? link.member : undefined;\n }\n}\n\n/**\n * What one catalog render produced: ONE catalog per contract that has at least one renderable tool\n * (`mcp-<ContractClass>-tools.json` each), and the tools it could not produce.\n */\nexport class McpCatalogRender {\n constructor(\n readonly catalogs: readonly McpToolCatalogFile[],\n readonly skipped: readonly SkippedMcpTool[],\n ) {}\n}\n\n/**\n * `ApiDocModel` -> the MCP tool list an agent is shown, and the server accepts calls against.\n *\n * ## It is the ONLY source of an MCP schema\n *\n * It was written for #983 as a MEASUREMENT: it rendered the same `ApiJsonSchema` the reflect-metadata\n * runtime built, so the two could be compared field by field. They matched for every DTO shape the\n * runtime could build, which is what licensed #984 to delete `@WpDtoField` and its erasure-repair\n * arguments — `required`, `arrayItems`, `integer`, `minimum`, `maximum`, `enumValues`, `mapValues`,\n * `mcpHeader` — along with `DtoSchemaBuilder` itself. There is now one schema, built here, written to\n * one `mcp-<ContractClass>-tools.json` per contract by `wp-openapi`, and read at boot by\n * `McpToolRegistry`.\n *\n * ## Where it now goes FURTHER than the deleted runtime could\n *\n * The three reproductions #983 documented were runtime capability gaps, and two of them are closed:\n *\n * - **NULLABLE is rendered**, as `type: [T, \"null\"]` — and, on an enum, with `null` added to `enum` too. `ApiJsonSchema.type` used to hold one string,\n * so the runtime could not write it down even where the compiler could see `externalId: string | null`\n * — and `{}` and `{externalId: null}` are different wire documents. `type` is now\n * `ApiJsonSchemaType | readonly ApiJsonSchemaType[]` and the union is emitted.\n * - **A bound on an ARRAY of numbers** lands on the ITEM, where OpenAPI puts it. `@WpDtoField`\n * rejected numeric constraints on a non-`Number` field, so it had nowhere to go at all.\n * - **A nested DTO is INLINED**, with the FIELD's prose on it — not a gap but the protocol: MCP tool\n * schemas are inline and have no `$ref`.\n */\nexport class McpSchemaRenderer {\n private readonly naming: McpLinkNaming;\n private readonly problems: DocLinkProblem[] = [];\n\n constructor(\n private readonly model: ApiDocModel,\n /**\n * The manifest's operationId spelling — what a `{@link}` to a contract method that is NOT a\n * tool publishes as (#1284).\n */\n operationIds: OperationIds,\n private readonly requireDescriptions = true,\n ) {\n this.naming = new McpLinkNaming(operationIds);\n }\n\n /**\n * Every `{@link}` this renderer could not name, so far. A caller that PUBLISHES what it rendered\n * refuses when this is non-empty — {@link catalogOf} does.\n */\n linkProblems(): readonly DocLinkProblem[] {\n return this.problems;\n }\n\n /** The shared inline runtime schema projection, also used by streaming catalog generation. */\n schemaFor(ref: TypeRef, where: string): ApiJsonSchema {\n return this.typeSchema(ref, where, new Set<string>());\n }\n\n /** Every `@WpMcpTool` method of the contract, in declaration order. */\n render(): readonly McpToolDefinition[] {\n const tools: McpToolDefinition[] = [];\n for (const endpoint of this.model.endpoints) {\n if (endpoint.mcpTool !== undefined) {\n tools.push(this.tool(endpoint));\n }\n }\n return tools;\n }\n\n /**\n * The tools of SEVERAL contracts as ONE CATALOG PER CONTRACT — the artifacts a server boots from,\n * one `mcp-<ContractClass>-tools.json` each — plus every tool that could not be rendered and why.\n *\n * Per contract because a server binds contracts, and checks each `McpApiBinding` against the file\n * generated from exactly that contract (#1021). The protocol namespace is still FLAT, though: two\n * contracts declaring one tool name is a collision an agent would see, so it is refused here, at\n * build time, across every contract of the run, rather than at somebody's boot.\n *\n * ## Why an unrenderable tool is REPORTED here rather than throwing\n *\n * Some shapes have no MCP schema at all — a recursive DTO, an undocumented tool, a request that\n * is not a named object — and the first of those is a limit of the PROTOCOL rather than a defect\n * in a contract that is otherwise perfectly good HTTP. (A DISCRIMINATED UNION used to be on this\n * list and no longer is: #1009 taught `ApiJsonSchema` `oneOf`, so one publishes.) Such a\n * tool was never servable: the reflect-metadata runtime refused it too, for its own reasons. So\n * failing the whole document build over one would stop a repo publishing its OpenAPI over a tool\n * nobody could ever have called.\n *\n * It is not silence either. The build NAMES every skipped tool with its reason, and\n * `McpToolRegistry` REFUSES TO BOOT when a registered `@WpMcpTool` is missing from the catalog —\n * which is the right place for that failure, because that is the process actually claiming to\n * serve it.\n */\n // webpieces-disable no-function-outside-class -- static factory over this class\n static catalogOf(models: readonly ApiDocModel[], operationIds: OperationIds): McpCatalogRender {\n const catalogs: McpToolCatalogFile[] = [];\n const skipped: SkippedMcpTool[] = [];\n const owners = new Map<string, string>();\n const problems: DocLinkProblem[] = [];\n for (const model of models) {\n const renderer = new McpSchemaRenderer(model, operationIds);\n const tools: McpToolDefinition[] = [];\n for (const endpoint of model.endpoints) {\n if (endpoint.mcpTool === undefined) {\n continue;\n }\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions -- a per-tool render refusal is REPORTED, see the docstring\n try {\n tools.push(renderer.tool(endpoint));\n } catch (err: unknown) {\n //const error = toError(err);\n if (!(err instanceof McpRenderError)) throw err;\n skipped.push(\n new SkippedMcpTool(endpoint.mcpTool.name, model.contractName, err.message),\n );\n }\n }\n McpSchemaRenderer.claimNames(owners, model.contractName, tools);\n problems.push(...renderer.linkProblems());\n if (tools.length > 0) {\n catalogs.push(new McpToolCatalogFile(model.contractName, tools));\n }\n }\n McpSchemaRenderer.refuseLinks(problems);\n return new McpCatalogRender(catalogs, skipped);\n }\n\n /**\n * A `{@link}` no catalog can name is REFUSED, not skipped (#1284): it is a defect in prose, not a\n * protocol limit, and a tool published with a dangling reference tells an agent about something it\n * cannot find. Every offender is named in one run. `wp-openapi` refuses the same links in\n * `mcp-openapi.json` first; this is the catalog's own backstop.\n */\n // webpieces-disable no-function-outside-class -- private static helper of this class\n private static refuseLinks(problems: readonly DocLinkProblem[]): void {\n if (problems.length === 0) {\n return;\n }\n throw new McpToolCatalogError(\n `${problems.length} {@link} reference(s) in MCP tool prose name nothing the catalog ` +\n `publishes: ${problems.map((each: DocLinkProblem) => each.toString()).join('; ')}.`,\n 'Point each {@link} at a published type or an @Endpoint method of an @ApiPath contract, ' +\n 'imported into the file the JSDoc is in, or write the name as plain text.',\n );\n }\n\n /** `text` as published: every `{@link}` named, every miss recorded — see {@link linkProblems}. */\n private prose(text: string): string {\n return DocLinkText.resolve(text, this.naming, MCP_OUTPUT, this.problems);\n }\n\n /** Refuse a tool name some OTHER contract of this run already declared: the namespace is flat. */\n // webpieces-disable no-function-outside-class -- private static helper of this class\n private static claimNames(\n owners: Map<string, string>,\n contractName: string,\n tools: readonly McpToolDefinition[],\n ): void {\n for (const tool of tools) {\n const owner = owners.get(tool.name);\n if (owner !== undefined && owner !== contractName) {\n throw new McpToolCatalogError(\n `Duplicate MCP tool name '${tool.name}': declared by both ${owner} and ${contractName}.`,\n 'Tool names are the protocol identity and must be globally unique — rename one ' +\n \"of the two @WpMcpTool('<name>') declarations.\",\n );\n }\n owners.set(tool.name, contractName);\n }\n }\n\n /** ONE tool. Visible to {@link catalogOf}, which renders tool by tool so it can report one. */\n tool(endpoint: DocumentedEndpoint): McpToolDefinition {\n const where = `${this.model.contractName}.${endpoint.methodName}`;\n const description = endpoint.mcpDescription ?? endpoint.description;\n if (description.trim() === '') {\n throw new McpRenderError(\n 'an MCP tool has no documentation',\n where,\n 'Write a JSDoc block on the method, or an @mcp tag for agent-facing wording. It is ' +\n 'published verbatim by tools/list, so an agent has nothing else to go on.',\n );\n }\n if (endpoint.request === undefined || endpoint.response === undefined) {\n throw new McpRenderError(\n 'an MCP tool has no declared request or response type',\n where,\n 'Declare both: one request parameter and a Promise<Response> return type.',\n );\n }\n const summaryProblem = EndpointSummary.problemWith(endpoint.summary);\n if (summaryProblem !== undefined) {\n throw new McpRenderError(\n `an MCP tool ${summaryProblem}, so it has no title`,\n where,\n `${EndpointSummary.cure()} tools/list publishes it as title and annotations.title ` +\n '(#1296); it is never derived from the tool name.',\n );\n }\n const nameProblem = McpToolName.problemWith(endpoint.mcpTool!.name);\n if (nameProblem !== undefined) {\n throw new McpRenderError(\n `the MCP tool name '${endpoint.mcpTool!.name}' ${nameProblem}`,\n where,\n McpToolName.cure(),\n );\n }\n return new McpToolDefinition(\n endpoint.mcpTool!.name,\n this.prose(endpoint.summary!),\n endpoint.methodName,\n this.prose(description),\n mcpHintsForOperation(\n McpSchemaRenderer.operationOf(endpoint, where),\n endpoint.openWorld,\n endpoint.additive,\n ),\n this.rootSchema(endpoint.request, where, 'request', undefined),\n this.rootSchema(endpoint.response, where, 'response', endpoint.returnsDescription),\n endpoint.mcpTool!.profiles,\n );\n }\n\n /**\n * `operation` verbatim from the model, mapped back onto the REAL constant.\n *\n * A `switch` and not a cast, because the model carries the operation as a string and a cast would\n * hand `mcpHintsForOperation` a value it has no case for — which, for a function whose three arms\n * are exhaustive, means falling off the end and publishing a tool with NO hints.\n */\n // webpieces-disable no-function-outside-class -- private static mapping of this class\n private static operationOf(endpoint: DocumentedEndpoint, where: string): EndpointOperation {\n switch (endpoint.operation) {\n case READ:\n return READ;\n case WRITE_IDEMPOTENT:\n return WRITE_IDEMPOTENT;\n case WRITE:\n return WRITE;\n default:\n throw new McpRenderError(\n `@Endpoint declares operation '${endpoint.operation}', which has no MCP hints`,\n where,\n `Use one of the exported constants: ${READ}, ${WRITE_IDEMPOTENT}, ${WRITE}.`,\n );\n }\n }\n\n /**\n * A tool's input/output schema: always a CLOSED OBJECT, because MCP publishes objects — and\n * because a union at the ROOT of a tool schema is refused by the function-calling APIs that\n * consume it. Both OpenAI and Anthropic reject a top-level `oneOf`/`anyOf`/`allOf`, and a server\n * sends its WHOLE tool list on every request, so one such tool makes every request 400 and bricks\n * the session — not just that tool. Nested composition, inside a property, is fine.\n *\n * The build-time rule `no-root-union-api-type` refuses the same shape across every `@ApiPath`\n * contract in the workspace, `@ApiType` or not. This is the renderer's own backstop, so a catalog\n * can never carry one even if it is reached some other way.\n */\n private rootSchema(\n ref: TypeRef,\n where: string,\n side: string,\n returns: string | undefined,\n ): ApiJsonSchema {\n if (ref.kind === 'union') {\n throw new McpRenderError(\n `an MCP tool's ${side} is itself a union`,\n where,\n `Wrap it in a property of an object ${side} — a top-level oneOf is rejected by the ` +\n 'OpenAI and Anthropic function-calling APIs, and one such tool 400s every ' +\n 'request in the session.',\n );\n }\n if (ref.kind !== 'ref') {\n throw new McpRenderError(\n `an MCP tool's ${side} is not a named DTO`,\n where,\n 'Give it a named interface or class. An inline or primitive ' +\n `${side} has no object schema, and MCP publishes objects.`,\n );\n }\n const type = this.namedType(ref.refName!, where);\n if (type.unionRefNames.length > 0) {\n throw new McpRenderError(\n `an MCP tool's ${side} '${type.name}' is itself a union`,\n where,\n `Wrap it in a property of an object ${side} — a top-level oneOf is rejected by the ` +\n 'OpenAI and Anthropic function-calling APIs, and one such tool 400s every ' +\n 'request in the session.',\n );\n }\n const schema = this.objectSchema(type, new Set<string>());\n McpSchemaRenderer.describeRoot(schema, this.prose(returns ?? type.description));\n return schema;\n }\n\n /**\n * The ROOT schema's `description` (#1292): the request DTO's JSDoc on `inputSchema`, and the\n * method's `@returns` sentence on `outputSchema` — the one slot a tool catalog has for \"what this\n * tool returns\", so an agent reads the same sentence a partner reads as the OpenAPI success\n * response's description. Falls back to the response DTO's own JSDoc when the method has no\n * `@returns`, which only a caller outside `wp-openapi` can reach: the generator refuses a tool\n * without one before any catalog is written. Nested DTOs keep the FIELD's prose (see\n * {@link fieldSchema}); only the root has no field to take it from.\n */\n // webpieces-disable no-function-outside-class -- private static helper of this class\n private static describeRoot(schema: ApiJsonSchema, prose: string): void {\n if (prose.trim() !== '') {\n schema.description = prose;\n }\n }\n\n private namedType(name: string, where: string): DocumentedType {\n const type = this.model.types.get(name);\n if (type === undefined) {\n throw new McpRenderError(\n `no model entry for type '${name}'`,\n where,\n 'Declare the type in a file the extractor reaches from this contract.',\n );\n }\n return type;\n }\n\n /**\n * One object DTO. CLOSED (`additionalProperties: false`), with `required` written only when it is\n * non-empty, so an all-optional DTO carries no empty list.\n *\n * The cycle stop is `parents`, and it THROWS rather than truncating: an inline schema cannot\n * express a recursive DTO, and one that silently stopped a level down would publish a shape the\n * server does not accept.\n */\n private objectSchema(type: DocumentedType, parents: ReadonlySet<string>): ApiJsonSchema {\n if (parents.has(type.name)) {\n throw new McpRenderError(\n `recursive DTO '${type.name}' cannot use an inline MCP schema`,\n type.name,\n 'Break the cycle, or keep this DTO out of the MCP document — a tool schema is ' +\n 'inline and has no $ref to close a loop with.',\n );\n }\n if (type.unionRefNames.length > 0) {\n return this.unionSchema(type, parents);\n }\n if (type.indexSignatureValue !== undefined && type.fields.length > 0) {\n throw new McpRenderError(\n `'${type.name}' has both named fields and an index signature`,\n type.name,\n 'Split the open map into a field of its own: a schema is either closed or a typed ' +\n 'map, and MCP has no spelling for half of each.',\n );\n }\n const nested = new Set(parents);\n nested.add(type.name);\n\n const schema = new ApiJsonSchema('object');\n schema.properties = {};\n schema.additionalProperties = false;\n const required: string[] = [];\n for (const field of type.fields) {\n schema.properties[field.name] = this.fieldSchema(type, field, nested);\n if (!field.optional) {\n required.push(field.name);\n }\n }\n if (required.length > 0) {\n schema.required = required;\n }\n return schema;\n }\n\n /**\n * A UNION, as `oneOf` with its branches INLINE and its DERIVED discriminator.\n *\n * MCP tool schemas are JSON Schema 2020-12 — the same dialect OpenAPI 3.1 uses — so `oneOf` was\n * never the obstacle; the obstacle was this repo's own subset, which had no spelling for it\n * (#1009). The shape written here MIRRORS `SchemaRenderer.union` in `@webpieces/openapi-generator`\n * branch for branch, because a union has ONE published spelling and that renderer is the\n * reference implementation of it. The only difference is the absence of `$ref`: a tool schema is\n * inline, so each branch is rendered in full and the discriminator maps to branch NAMES.\n *\n * `discriminator` is written ONLY when the model DERIVED one. A union TypeScript itself cannot\n * narrow is published as a bare `oneOf` rather than with an invented discriminator — claiming a\n * narrowing the source does not have is worse than admitting there is none.\n */\n private unionSchema(type: DocumentedType, parents: ReadonlySet<string>): ApiJsonSchema {\n const nested = new Set(parents);\n nested.add(type.name);\n const schema = new ApiJsonSchema();\n schema.oneOf = type.unionRefNames.map((name: string) =>\n this.objectSchema(this.namedType(name, type.name), nested),\n );\n if (type.description.trim() !== '') {\n schema.description = this.prose(type.description);\n }\n if (type.discriminator !== undefined) {\n const mapping: Record<string, string> = {};\n for (const branch of type.unionRefNames) {\n // The branch's NAME, never its model key: a branch declared by another package is\n // keyed `<package>:<name>` (#1058), and the published mapping names the type.\n const branchName = this.namedType(branch, type.name).schemaName;\n for (const value of type.discriminator.branchValues.get(branch) ?? []) {\n mapping[value] = branchName;\n }\n }\n schema.discriminator = new ApiJsonSchemaDiscriminator(\n type.discriminator.propertyName,\n mapping,\n );\n }\n return schema;\n }\n\n /**\n * A FIELD whose type is a union: the model registers `type X = A | B` as its OWN entry carrying\n * the derived discriminator, while the field holds a bare list of branch names. Rendering that\n * list directly would publish the `oneOf` and silently DROP the discriminator — the one part of a\n * union a client needs to narrow on — so the alias is looked up by its branch list first. This is\n * the same lookup `SchemaRenderer.namedUnion` does to emit its `$ref`.\n */\n private fieldUnion(\n branchNames: readonly string[],\n where: string,\n parents: ReadonlySet<string>,\n ): ApiJsonSchema {\n const key = branchNames.join(',');\n for (const name of this.model.types.keys()) {\n const candidate = this.model.types.get(name)!;\n if (candidate.unionRefNames.length > 0 && candidate.unionRefNames.join(',') === key) {\n return this.unionSchema(candidate, parents);\n }\n }\n const schema = new ApiJsonSchema();\n schema.oneOf = branchNames.map((name: string) =>\n this.objectSchema(this.namedType(name, where), parents),\n );\n return schema;\n }\n\n /**\n * One FIELD: its type, then the prose and the constraints that hang off the field.\n *\n * The ORDER matters: the type is built first and `description` is written over whatever the type\n * produced, so a nested DTO carries the FIELD's sentence rather than the DTO's. `@WpMin` /\n * `@WpMax` land on the numeric LEAF — on an array, on the item — for the same reason\n * `SchemaRenderer` puts them there: a `minimum` on an array means nothing.\n *\n * NULLABLE widens the type to `[T, \"null\"]` and is deliberately NOT the same thing as OPTIONAL,\n * which is an absent entry in the object's `required` list. `{}` and `{externalId: null}` are\n * different wire documents, and an agent told only \"optional\" would send the wrong one.\n */\n private fieldSchema(\n owner: DocumentedType,\n field: DocumentedField,\n parents: ReadonlySet<string>,\n ): ApiJsonSchema {\n const where = `${owner.name}.${field.name}`;\n const schema = this.typeSchema(field.type, where, parents);\n const description = field.mcpDescription ?? field.description;\n if (this.requireDescriptions && description.trim() === '') {\n throw new McpRenderError(\n 'a published DTO field has no documentation',\n where,\n 'Write a JSDoc sentence on the field. It is the only thing an agent is told about ' +\n 'that parameter.',\n );\n }\n schema.description = this.prose(description);\n\n const leaf = field.type.kind === 'array' ? schema.items! : schema;\n if (field.min !== undefined) {\n leaf.minimum = field.min;\n }\n if (field.max !== undefined) {\n leaf.maximum = field.max;\n }\n if (field.mcpHeader !== undefined) {\n McpSchemaRenderer.assertHeaderFits(field, schema, where);\n schema['x-mcp-header'] = field.mcpHeader;\n }\n if (field.nullable) {\n schema.type = McpSchemaRenderer.nullable(schema, where);\n if (schema.enum !== undefined && !schema.enum.includes(null)) {\n // JSON Schema checks `enum` independently of `type`: without `null` here the widened\n // type admits null and the enum still rejects it, so a nullable string enum\n // (`x: SomeEnumDto | null`, or `'a' | 'b' | null`) failed output validation (#1197).\n schema.enum = [...schema.enum, null];\n }\n }\n return schema;\n }\n\n /** `T` -> `[T, \"null\"]`, refusing a field with no type at all rather than publishing `[\"null\"]`. */\n // webpieces-disable no-function-outside-class -- private static mapping of this class\n private static nullable(schema: ApiJsonSchema, where: string): readonly ApiJsonSchemaType[] {\n const base = ApiJsonSchema.baseTypeOf(schema);\n if (base === undefined) {\n throw new McpRenderError(\n 'a nullable field has no other type',\n where,\n 'A field typed only `null` carries no information — give it a real type beside it.',\n );\n }\n return [base, 'null'];\n }\n\n /**\n * `@mcpHeader` mirrors a PRIMITIVE parameter into `Mcp-Param-{name}` (MCP 2026 SEP-2243). The\n * three conditions are the runtime's, restated against the compiler's view of the field, so a\n * declaration the server would reject at boot fails the document build instead.\n */\n // webpieces-disable no-function-outside-class -- private static validator of this class\n private static assertHeaderFits(\n field: DocumentedField,\n schema: ApiJsonSchema,\n where: string,\n ): void {\n if (!HEADER_TOKEN.test(field.mcpHeader!)) {\n throw new McpRenderError(\n `@mcpHeader '${field.mcpHeader}' is not an RFC 9110 token`,\n where,\n 'Use letters, digits and the token punctuation only — it becomes an HTTP header name.',\n );\n }\n if (schema.type !== 'string' && schema.type !== 'boolean' && schema.type !== 'integer') {\n throw new McpRenderError(\n '@mcpHeader is on a field that is not a primitive an MCP header can carry',\n where,\n 'Mirror a string, a boolean or an Integer. A non-integer number and every object ' +\n 'shape are excluded by MCP 2026-07-28.',\n );\n }\n }\n\n /** One resolved type, with no field-level prose or constraints on it. */\n private typeSchema(ref: TypeRef, where: string, parents: ReadonlySet<string>): ApiJsonSchema {\n switch (ref.kind) {\n case 'primitive':\n return McpSchemaRenderer.primitive(ref, where);\n case 'enum': {\n const schema = new ApiJsonSchema('string');\n schema.enum = ref.enumValues.slice();\n return schema;\n }\n case 'array': {\n const schema = new ApiJsonSchema('array');\n schema.items = this.typeSchema(ref.items!, where, parents);\n return schema;\n }\n case 'openMap': {\n const schema = new ApiJsonSchema('object');\n schema.additionalProperties = this.typeSchema(ref.values!, where, parents);\n return schema;\n }\n case 'ref':\n return this.referencedSchema(ref.refName!, where, parents);\n case 'union':\n return this.fieldUnion(ref.unionRefNames, where, parents);\n default:\n throw new McpRenderError(\n `no MCP schema for the declared type '${ref.unmappedText ?? '<unknown>'}'`,\n where,\n 'Give the field a shape the model can represent — a named DTO, an array of one, ' +\n 'a string-literal union, a Record, or a primitive.',\n );\n }\n }\n\n /** A named type: a string enum becomes `enum`, an object DTO is INLINED (MCP has no `$ref`). */\n private referencedSchema(\n name: string,\n where: string,\n parents: ReadonlySet<string>,\n ): ApiJsonSchema {\n const type = this.namedType(name, where);\n if (type.enumValues.length > 0) {\n const schema = new ApiJsonSchema('string');\n schema.enum = type.enumValues.slice();\n return schema;\n }\n return this.objectSchema(type, parents);\n }\n\n // webpieces-disable no-function-outside-class -- private static mapping of this class\n private static primitive(ref: TypeRef, where: string): ApiJsonSchema {\n if (ref.primitive === 'string' || ref.primitive === 'boolean') {\n return new ApiJsonSchema(ref.primitive);\n }\n if (ref.primitive === 'number') {\n return new ApiJsonSchema(ref.integer ? 'integer' : 'number');\n }\n throw new McpRenderError(\n `'${ref.primitive}' has no MCP schema`,\n where,\n 'Give the field a concrete type. `unknown`, `any`, `void` and a bare `null` publish as ' +\n '\"anything\", which an agent cannot fill in.',\n );\n }\n}\n"]}
1
+ {"version":3,"file":"McpSchemaRenderer.js","sourceRoot":"","sources":["../../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I,IAAI,CAAC,UAAU,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAC7B,MAAM,MAAM,GAAG,IAAI,yBAAa,CAAC,QAAQ,CAAC,CAAC;YAC3C,MAAM,CAAC,IAAI,GAAG,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC;YACtC,OAAO,MAAM,CAAC;QAClB,CAAC;QACD,OAAO,IAAI,CAAC,YAAY,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IAC5C,CAAC;IAED,sFAAsF;IAC9E,MAAM,CAAC,SAAS,CAAC,GAAY,EAAE,KAAa;QAChD,IAAI,GAAG,CAAC,SAAS,KAAK,QAAQ,IAAI,GAAG,CAAC,SAAS,KAAK,SAAS,EAAE,CAAC;YAC5D,OAAO,IAAI,yBAAa,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;QAC5C,CAAC;QACD,IAAI,GAAG,CAAC,SAAS,KAAK,QAAQ,EAAE,CAAC;YAC7B,OAAO,IAAI,yBAAa,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC;QACjE,CAAC;QACD,MAAM,IAAI,+BAAc,CACpB,IAAI,GAAG,CAAC,SAAS,qBAAqB,EACtC,KAAK,EACL,wFAAwF;YACpF,4CAA4C,CACnD,CAAC;IACN,CAAC;CACJ;AAhkBD,8CAgkBC","sourcesContent":["import {\n ApiJsonSchema,\n ApiJsonSchemaDiscriminator,\n ApiJsonSchemaType,\n EndpointOperation,\n McpToolCatalogError,\n McpToolCatalogFile,\n McpToolDefinition,\n McpToolName,\n mcpHintsForOperation,\n READ,\n WRITE,\n WRITE_IDEMPOTENT,\n} from '@webpieces/core-util';\nimport {\n ApiDocModel,\n DocumentedEndpoint,\n DocumentedField,\n DocumentedType,\n} from '../model/ApiDocModel';\nimport { DocLink, DocLinkKind, DocLinkNaming, DocLinkProblem, DocLinkText } from '../model/DocLink';\nimport { EndpointSummary } from '../model/EndpointSummary';\nimport { OperationIds } from '../model/OperationIds';\nimport { TypeRef } from '../model/TypeRef';\nimport { McpRenderError } from './McpRenderError';\n\n/** RFC 9110 token, which is what an `Mcp-Param-{name}` header name has to be. */\nconst HEADER_TOKEN = /^[!#$%&'*+\\-.^_`|~0-9A-Za-z]+$/;\n\n/** ONE `@WpMcpTool` the build could not give a schema, and why. See {@link McpSchemaRenderer.catalogOf}. */\nexport class SkippedMcpTool {\n constructor(\n /** The stable protocol name it declared. */\n readonly name: string,\n readonly contractName: string,\n /** The render refusal, verbatim, including the declaration it points at. */\n readonly reason: string,\n ) {}\n\n toString(): string {\n return `${this.contractName}/${this.name}: ${this.reason}`;\n }\n}\n\n/** The output name every MCP link refusal names. */\nconst MCP_OUTPUT = 'the MCP tool catalog';\n\n/**\n * How an MCP tool catalog names a `{@link}` target (#1284). A tool schema is fully inline, so a type\n * is named by its published schema name; a contract method that IS a tool by its tool `name` — the\n * one thing an MCP client can call — and any other method by its operationId.\n */\nclass McpLinkNaming implements DocLinkNaming {\n constructor(private readonly operationIds: OperationIds) {}\n\n publishedName(link: DocLink): string | undefined {\n if (link.kind === DocLinkKind.TYPE) {\n return link.ownerName;\n }\n if (link.kind === DocLinkKind.OPERATION) {\n return link.mcpToolName ?? this.operationIds.of(link.owner, link.ownerName);\n }\n // A bare member is its own name. A `@hidden` field is published to MCP (#1246), as a\n // hidden method is, so a link to one is never refused here.\n return link.kind === DocLinkKind.MEMBER ? link.member : undefined;\n }\n}\n\n/**\n * What one catalog render produced: ONE catalog per contract that has at least one renderable tool\n * (`mcp-<ContractClass>-tools.json` each), and the tools it could not produce.\n */\nexport class McpCatalogRender {\n constructor(\n readonly catalogs: readonly McpToolCatalogFile[],\n readonly skipped: readonly SkippedMcpTool[],\n ) {}\n}\n\n/**\n * `ApiDocModel` -> the MCP tool list an agent is shown, and the server accepts calls against.\n *\n * ## It is the ONLY source of an MCP schema\n *\n * It was written for #983 as a MEASUREMENT: it rendered the same `ApiJsonSchema` the reflect-metadata\n * runtime built, so the two could be compared field by field. They matched for every DTO shape the\n * runtime could build, which is what licensed #984 to delete `@WpDtoField` and its erasure-repair\n * arguments — `required`, `arrayItems`, `integer`, `minimum`, `maximum`, `enumValues`, `mapValues`,\n * `mcpHeader` — along with `DtoSchemaBuilder` itself. There is now one schema, built here, written to\n * one `mcp-<ContractClass>-tools.json` per contract by `wp-openapi`, and read at boot by\n * `McpToolRegistry`.\n *\n * ## Where it now goes FURTHER than the deleted runtime could\n *\n * The three reproductions #983 documented were runtime capability gaps, and two of them are closed:\n *\n * - **NULLABLE is rendered**, as `type: [T, \"null\"]` — and, on an enum, with `null` added to `enum` too. `ApiJsonSchema.type` used to hold one string,\n * so the runtime could not write it down even where the compiler could see `externalId: string | null`\n * — and `{}` and `{externalId: null}` are different wire documents. `type` is now\n * `ApiJsonSchemaType | readonly ApiJsonSchemaType[]` and the union is emitted.\n * - **A bound on an ARRAY of numbers** lands on the ITEM, where OpenAPI puts it. `@WpDtoField`\n * rejected numeric constraints on a non-`Number` field, so it had nowhere to go at all.\n * - **A nested DTO is INLINED**, with the FIELD's prose on it — not a gap but the protocol: MCP tool\n * schemas are inline and have no `$ref`.\n */\nexport class McpSchemaRenderer {\n private readonly naming: McpLinkNaming;\n private readonly problems: DocLinkProblem[] = [];\n\n constructor(\n private readonly model: ApiDocModel,\n /**\n * The manifest's operationId spelling — what a `{@link}` to a contract method that is NOT a\n * tool publishes as (#1284).\n */\n operationIds: OperationIds,\n private readonly requireDescriptions = true,\n ) {\n this.naming = new McpLinkNaming(operationIds);\n }\n\n /**\n * Every `{@link}` this renderer could not name, so far. A caller that PUBLISHES what it rendered\n * refuses when this is non-empty — {@link catalogOf} does.\n */\n linkProblems(): readonly DocLinkProblem[] {\n return this.problems;\n }\n\n /** The shared inline runtime schema projection, also used by streaming catalog generation. */\n schemaFor(ref: TypeRef, where: string): ApiJsonSchema {\n return this.typeSchema(ref, where, new Set<string>());\n }\n\n /** Every `@WpMcpTool` method of the contract, in declaration order. */\n render(): readonly McpToolDefinition[] {\n const tools: McpToolDefinition[] = [];\n for (const endpoint of this.model.endpoints) {\n if (endpoint.mcpTool !== undefined) {\n tools.push(this.tool(endpoint));\n }\n }\n return tools;\n }\n\n /**\n * The tools of SEVERAL contracts as ONE CATALOG PER CONTRACT — the artifacts a server boots from,\n * one `mcp-<ContractClass>-tools.json` each — plus every tool that could not be rendered and why.\n *\n * Per contract because a server binds contracts, and checks each `McpApiBinding` against the file\n * generated from exactly that contract (#1021). The protocol namespace is still FLAT, though: two\n * contracts declaring one tool name is a collision an agent would see, so it is refused here, at\n * build time, across every contract of the run, rather than at somebody's boot.\n *\n * ## Why an unrenderable tool is REPORTED here rather than throwing\n *\n * Some shapes have no MCP schema at all — a recursive DTO, an undocumented tool, a request that\n * is not a named object — and the first of those is a limit of the PROTOCOL rather than a defect\n * in a contract that is otherwise perfectly good HTTP. (A DISCRIMINATED UNION used to be on this\n * list and no longer is: #1009 taught `ApiJsonSchema` `oneOf`, so one publishes.) Such a\n * tool was never servable: the reflect-metadata runtime refused it too, for its own reasons. So\n * failing the whole document build over one would stop a repo publishing its OpenAPI over a tool\n * nobody could ever have called.\n *\n * It is not silence either. The build NAMES every skipped tool with its reason, and\n * `McpToolRegistry` REFUSES TO BOOT when a registered `@WpMcpTool` is missing from the catalog —\n * which is the right place for that failure, because that is the process actually claiming to\n * serve it.\n */\n // webpieces-disable no-function-outside-class -- static factory over this class\n static catalogOf(models: readonly ApiDocModel[], operationIds: OperationIds): McpCatalogRender {\n const catalogs: McpToolCatalogFile[] = [];\n const skipped: SkippedMcpTool[] = [];\n const owners = new Map<string, string>();\n const problems: DocLinkProblem[] = [];\n for (const model of models) {\n const renderer = new McpSchemaRenderer(model, operationIds);\n const tools: McpToolDefinition[] = [];\n for (const endpoint of model.endpoints) {\n if (endpoint.mcpTool === undefined) {\n continue;\n }\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions -- a per-tool render refusal is REPORTED, see the docstring\n try {\n tools.push(renderer.tool(endpoint));\n } catch (err: unknown) {\n //const error = toError(err);\n if (!(err instanceof McpRenderError)) throw err;\n skipped.push(\n new SkippedMcpTool(endpoint.mcpTool.name, model.contractName, err.message),\n );\n }\n }\n McpSchemaRenderer.claimNames(owners, model.contractName, tools);\n problems.push(...renderer.linkProblems());\n if (tools.length > 0) {\n catalogs.push(new McpToolCatalogFile(model.contractName, tools));\n }\n }\n McpSchemaRenderer.refuseLinks(problems);\n return new McpCatalogRender(catalogs, skipped);\n }\n\n /**\n * A `{@link}` no catalog can name is REFUSED, not skipped (#1284): it is a defect in prose, not a\n * protocol limit, and a tool published with a dangling reference tells an agent about something it\n * cannot find. Every offender is named in one run. `wp-openapi` refuses the same links in\n * `mcp-openapi.json` first; this is the catalog's own backstop.\n */\n // webpieces-disable no-function-outside-class -- private static helper of this class\n private static refuseLinks(problems: readonly DocLinkProblem[]): void {\n if (problems.length === 0) {\n return;\n }\n throw new McpToolCatalogError(\n `${problems.length} {@link} reference(s) in MCP tool prose name nothing the catalog ` +\n `publishes: ${problems.map((each: DocLinkProblem) => each.toString()).join('; ')}.`,\n 'Point each {@link} at a published type or an @Endpoint method of an @ApiPath contract, ' +\n 'imported into the file the JSDoc is in, or write the name as plain text.',\n );\n }\n\n /** `text` as published: every `{@link}` named, every miss recorded — see {@link linkProblems}. */\n private prose(text: string): string {\n return DocLinkText.resolve(text, this.naming, MCP_OUTPUT, this.problems);\n }\n\n /** Refuse a tool name some OTHER contract of this run already declared: the namespace is flat. */\n // webpieces-disable no-function-outside-class -- private static helper of this class\n private static claimNames(\n owners: Map<string, string>,\n contractName: string,\n tools: readonly McpToolDefinition[],\n ): void {\n for (const tool of tools) {\n const owner = owners.get(tool.name);\n if (owner !== undefined && owner !== contractName) {\n throw new McpToolCatalogError(\n `Duplicate MCP tool name '${tool.name}': declared by both ${owner} and ${contractName}.`,\n 'Tool names are the protocol identity and must be globally unique — rename one ' +\n \"of the two @WpMcpTool('<name>') declarations.\",\n );\n }\n owners.set(tool.name, contractName);\n }\n }\n\n /** ONE tool. Visible to {@link catalogOf}, which renders tool by tool so it can report one. */\n tool(endpoint: DocumentedEndpoint): McpToolDefinition {\n const where = `${this.model.contractName}.${endpoint.methodName}`;\n const description = endpoint.mcpDescription ?? endpoint.description;\n if (description.trim() === '') {\n throw new McpRenderError(\n 'an MCP tool has no documentation',\n where,\n 'Write a JSDoc block on the method, or an @mcp tag for agent-facing wording. It is ' +\n 'published verbatim by tools/list, so an agent has nothing else to go on.',\n );\n }\n if (endpoint.request === undefined || endpoint.response === undefined) {\n throw new McpRenderError(\n 'an MCP tool has no declared request or response type',\n where,\n 'Declare both: one request parameter and a Promise<Response> return type.',\n );\n }\n const summaryProblem = EndpointSummary.problemWith(endpoint.summary);\n if (summaryProblem !== undefined) {\n throw new McpRenderError(\n `an MCP tool ${summaryProblem}, so it has no title`,\n where,\n `${EndpointSummary.cure()} tools/list publishes it as title and annotations.title ` +\n '(#1296); it is never derived from the tool name.',\n );\n }\n const nameProblem = McpToolName.problemWith(endpoint.mcpTool!.name);\n if (nameProblem !== undefined) {\n throw new McpRenderError(\n `the MCP tool name '${endpoint.mcpTool!.name}' ${nameProblem}`,\n where,\n McpToolName.cure(),\n );\n }\n return new McpToolDefinition(\n endpoint.mcpTool!.name,\n this.prose(endpoint.summary!),\n endpoint.methodName,\n this.prose(description),\n mcpHintsForOperation(\n McpSchemaRenderer.operationOf(endpoint, where),\n endpoint.openWorld,\n endpoint.additive,\n ),\n this.rootSchema(endpoint.request, where, 'request', undefined),\n // OPEN for clients (#1441): a client caches the outputSchema at connect and validates\n // every result against it, so a closed one made ADDING a response field a break.\n ApiJsonSchema.openForClients(\n this.rootSchema(endpoint.response, where, 'response', endpoint.returnsDescription),\n ),\n endpoint.mcpTool!.profiles,\n );\n }\n\n /**\n * `operation` verbatim from the model, mapped back onto the REAL constant.\n *\n * A `switch` and not a cast, because the model carries the operation as a string and a cast would\n * hand `mcpHintsForOperation` a value it has no case for — which, for a function whose three arms\n * are exhaustive, means falling off the end and publishing a tool with NO hints.\n */\n // webpieces-disable no-function-outside-class -- private static mapping of this class\n private static operationOf(endpoint: DocumentedEndpoint, where: string): EndpointOperation {\n switch (endpoint.operation) {\n case READ:\n return READ;\n case WRITE_IDEMPOTENT:\n return WRITE_IDEMPOTENT;\n case WRITE:\n return WRITE;\n default:\n throw new McpRenderError(\n `@Endpoint declares operation '${endpoint.operation}', which has no MCP hints`,\n where,\n `Use one of the exported constants: ${READ}, ${WRITE_IDEMPOTENT}, ${WRITE}.`,\n );\n }\n }\n\n /**\n * A tool's input/output schema: always an OBJECT, rendered CLOSED (the published `outputSchema` is\n * then opened by {@link tool}, #1441), because MCP publishes objects — and\n * because a union at the ROOT of a tool schema is refused by the function-calling APIs that\n * consume it. Both OpenAI and Anthropic reject a top-level `oneOf`/`anyOf`/`allOf`, and a server\n * sends its WHOLE tool list on every request, so one such tool makes every request 400 and bricks\n * the session — not just that tool. Nested composition, inside a property, is fine.\n *\n * The build-time rule `no-root-union-api-type` refuses the same shape across every `@ApiPath`\n * contract in the workspace, `@ApiType` or not. This is the renderer's own backstop, so a catalog\n * can never carry one even if it is reached some other way.\n */\n private rootSchema(\n ref: TypeRef,\n where: string,\n side: string,\n returns: string | undefined,\n ): ApiJsonSchema {\n if (ref.kind === 'union') {\n throw new McpRenderError(\n `an MCP tool's ${side} is itself a union`,\n where,\n `Wrap it in a property of an object ${side} — a top-level oneOf is rejected by the ` +\n 'OpenAI and Anthropic function-calling APIs, and one such tool 400s every ' +\n 'request in the session.',\n );\n }\n if (ref.kind !== 'ref') {\n throw new McpRenderError(\n `an MCP tool's ${side} is not a named DTO`,\n where,\n 'Give it a named interface or class. An inline or primitive ' +\n `${side} has no object schema, and MCP publishes objects.`,\n );\n }\n const type = this.namedType(ref.refName!, where);\n if (type.unionRefNames.length > 0) {\n throw new McpRenderError(\n `an MCP tool's ${side} '${type.name}' is itself a union`,\n where,\n `Wrap it in a property of an object ${side} — a top-level oneOf is rejected by the ` +\n 'OpenAI and Anthropic function-calling APIs, and one such tool 400s every ' +\n 'request in the session.',\n );\n }\n const schema = this.objectSchema(type, new Set<string>());\n McpSchemaRenderer.describeRoot(schema, this.prose(returns ?? type.description));\n return schema;\n }\n\n /**\n * The ROOT schema's `description` (#1292): the request DTO's JSDoc on `inputSchema`, and the\n * method's `@returns` sentence on `outputSchema` — the one slot a tool catalog has for \"what this\n * tool returns\", so an agent reads the same sentence a partner reads as the OpenAPI success\n * response's description. Falls back to the response DTO's own JSDoc when the method has no\n * `@returns`, which only a caller outside `wp-openapi` can reach: the generator refuses a tool\n * without one before any catalog is written. Nested DTOs keep the FIELD's prose (see\n * {@link fieldSchema}); only the root has no field to take it from.\n */\n // webpieces-disable no-function-outside-class -- private static helper of this class\n private static describeRoot(schema: ApiJsonSchema, prose: string): void {\n if (prose.trim() !== '') {\n schema.description = prose;\n }\n }\n\n private namedType(name: string, where: string): DocumentedType {\n const type = this.model.types.get(name);\n if (type === undefined) {\n throw new McpRenderError(\n `no model entry for type '${name}'`,\n where,\n 'Declare the type in a file the extractor reaches from this contract.',\n );\n }\n return type;\n }\n\n /**\n * One object DTO. CLOSED (`additionalProperties: false`), with `required` written only when it is\n * non-empty, so an all-optional DTO carries no empty list. Closed is what an `inputSchema`\n * publishes; an `outputSchema` is opened at every depth by `ApiJsonSchema.openForClients` (#1441).\n *\n * The cycle stop is `parents`, and it THROWS rather than truncating: an inline schema cannot\n * express a recursive DTO, and one that silently stopped a level down would publish a shape the\n * server does not accept.\n */\n private objectSchema(type: DocumentedType, parents: ReadonlySet<string>): ApiJsonSchema {\n if (parents.has(type.name)) {\n throw new McpRenderError(\n `recursive DTO '${type.name}' cannot use an inline MCP schema`,\n type.name,\n 'Break the cycle, or keep this DTO out of the MCP document — a tool schema is ' +\n 'inline and has no $ref to close a loop with.',\n );\n }\n if (type.unionRefNames.length > 0) {\n return this.unionSchema(type, parents);\n }\n if (type.indexSignatureValue !== undefined && type.fields.length > 0) {\n throw new McpRenderError(\n `'${type.name}' has both named fields and an index signature`,\n type.name,\n 'Split the open map into a field of its own: a schema is either closed or a typed ' +\n 'map, and MCP has no spelling for half of each.',\n );\n }\n const nested = new Set(parents);\n nested.add(type.name);\n\n const schema = new ApiJsonSchema('object');\n schema.properties = {};\n schema.additionalProperties = false;\n const required: string[] = [];\n for (const field of type.fields) {\n schema.properties[field.name] = this.fieldSchema(type, field, nested);\n if (!field.optional) {\n required.push(field.name);\n }\n }\n if (required.length > 0) {\n schema.required = required;\n }\n return schema;\n }\n\n /**\n * A UNION, as `oneOf` with its branches INLINE and its DERIVED discriminator.\n *\n * MCP tool schemas are JSON Schema 2020-12 — the same dialect OpenAPI 3.1 uses — so `oneOf` was\n * never the obstacle; the obstacle was this repo's own subset, which had no spelling for it\n * (#1009). The shape written here MIRRORS `SchemaRenderer.union` in `@webpieces/openapi-generator`\n * branch for branch, because a union has ONE published spelling and that renderer is the\n * reference implementation of it. The only difference is the absence of `$ref`: a tool schema is\n * inline, so each branch is rendered in full and the discriminator maps to branch NAMES.\n *\n * `discriminator` is written ONLY when the model DERIVED one. A union TypeScript itself cannot\n * narrow is published as a bare `oneOf` rather than with an invented discriminator — claiming a\n * narrowing the source does not have is worse than admitting there is none.\n */\n private unionSchema(type: DocumentedType, parents: ReadonlySet<string>): ApiJsonSchema {\n const nested = new Set(parents);\n nested.add(type.name);\n const schema = new ApiJsonSchema();\n schema.oneOf = type.unionRefNames.map((name: string) =>\n this.objectSchema(this.namedType(name, type.name), nested),\n );\n if (type.description.trim() !== '') {\n schema.description = this.prose(type.description);\n }\n if (type.discriminator !== undefined) {\n const mapping: Record<string, string> = {};\n for (const branch of type.unionRefNames) {\n // The branch's NAME, never its model key: a branch declared by another package is\n // keyed `<package>:<name>` (#1058), and the published mapping names the type.\n const branchName = this.namedType(branch, type.name).schemaName;\n for (const value of type.discriminator.branchValues.get(branch) ?? []) {\n mapping[value] = branchName;\n }\n }\n schema.discriminator = new ApiJsonSchemaDiscriminator(\n type.discriminator.propertyName,\n mapping,\n );\n }\n return schema;\n }\n\n /**\n * A FIELD whose type is a union: the model registers `type X = A | B` as its OWN entry carrying\n * the derived discriminator, while the field holds a bare list of branch names. Rendering that\n * list directly would publish the `oneOf` and silently DROP the discriminator — the one part of a\n * union a client needs to narrow on — so the alias is looked up by its branch list first. This is\n * the same lookup `SchemaRenderer.namedUnion` does to emit its `$ref`.\n */\n private fieldUnion(\n branchNames: readonly string[],\n where: string,\n parents: ReadonlySet<string>,\n ): ApiJsonSchema {\n const key = branchNames.join(',');\n for (const name of this.model.types.keys()) {\n const candidate = this.model.types.get(name)!;\n if (candidate.unionRefNames.length > 0 && candidate.unionRefNames.join(',') === key) {\n return this.unionSchema(candidate, parents);\n }\n }\n const schema = new ApiJsonSchema();\n schema.oneOf = branchNames.map((name: string) =>\n this.objectSchema(this.namedType(name, where), parents),\n );\n return schema;\n }\n\n /**\n * One FIELD: its type, then the prose and the constraints that hang off the field.\n *\n * The ORDER matters: the type is built first and `description` is written over whatever the type\n * produced, so a nested DTO carries the FIELD's sentence rather than the DTO's. `@WpMin` /\n * `@WpMax` land on the numeric LEAF — on an array, on the item — for the same reason\n * `SchemaRenderer` puts them there: a `minimum` on an array means nothing.\n *\n * NULLABLE widens the type to `[T, \"null\"]` and is deliberately NOT the same thing as OPTIONAL,\n * which is an absent entry in the object's `required` list. `{}` and `{externalId: null}` are\n * different wire documents, and an agent told only \"optional\" would send the wrong one.\n */\n private fieldSchema(\n owner: DocumentedType,\n field: DocumentedField,\n parents: ReadonlySet<string>,\n ): ApiJsonSchema {\n const where = `${owner.name}.${field.name}`;\n const schema = this.typeSchema(field.type, where, parents);\n const description = field.mcpDescription ?? field.description;\n if (this.requireDescriptions && description.trim() === '') {\n throw new McpRenderError(\n 'a published DTO field has no documentation',\n where,\n 'Write a JSDoc sentence on the field. It is the only thing an agent is told about ' +\n 'that parameter.',\n );\n }\n schema.description = this.prose(description);\n\n const leaf = field.type.kind === 'array' ? schema.items! : schema;\n if (field.min !== undefined) {\n leaf.minimum = field.min;\n }\n if (field.max !== undefined) {\n leaf.maximum = field.max;\n }\n if (field.mcpHeader !== undefined) {\n McpSchemaRenderer.assertHeaderFits(field, schema, where);\n schema['x-mcp-header'] = field.mcpHeader;\n }\n if (field.nullable) {\n schema.type = McpSchemaRenderer.nullable(schema, where);\n if (schema.enum !== undefined && !schema.enum.includes(null)) {\n // JSON Schema checks `enum` independently of `type`: without `null` here the widened\n // type admits null and the enum still rejects it, so a nullable string enum\n // (`x: SomeEnumDto | null`, or `'a' | 'b' | null`) failed output validation (#1197).\n schema.enum = [...schema.enum, null];\n }\n }\n return schema;\n }\n\n /** `T` -> `[T, \"null\"]`, refusing a field with no type at all rather than publishing `[\"null\"]`. */\n // webpieces-disable no-function-outside-class -- private static mapping of this class\n private static nullable(schema: ApiJsonSchema, where: string): readonly ApiJsonSchemaType[] {\n const base = ApiJsonSchema.baseTypeOf(schema);\n if (base === undefined) {\n throw new McpRenderError(\n 'a nullable field has no other type',\n where,\n 'A field typed only `null` carries no information — give it a real type beside it.',\n );\n }\n return [base, 'null'];\n }\n\n /**\n * `@mcpHeader` mirrors a PRIMITIVE parameter into `Mcp-Param-{name}` (MCP 2026 SEP-2243). The\n * three conditions are the runtime's, restated against the compiler's view of the field, so a\n * declaration the server would reject at boot fails the document build instead.\n */\n // webpieces-disable no-function-outside-class -- private static validator of this class\n private static assertHeaderFits(\n field: DocumentedField,\n schema: ApiJsonSchema,\n where: string,\n ): void {\n if (!HEADER_TOKEN.test(field.mcpHeader!)) {\n throw new McpRenderError(\n `@mcpHeader '${field.mcpHeader}' is not an RFC 9110 token`,\n where,\n 'Use letters, digits and the token punctuation only — it becomes an HTTP header name.',\n );\n }\n if (schema.type !== 'string' && schema.type !== 'boolean' && schema.type !== 'integer') {\n throw new McpRenderError(\n '@mcpHeader is on a field that is not a primitive an MCP header can carry',\n where,\n 'Mirror a string, a boolean or an Integer. A non-integer number and every object ' +\n 'shape are excluded by MCP 2026-07-28.',\n );\n }\n }\n\n /** One resolved type, with no field-level prose or constraints on it. */\n private typeSchema(ref: TypeRef, where: string, parents: ReadonlySet<string>): ApiJsonSchema {\n switch (ref.kind) {\n case 'primitive':\n return McpSchemaRenderer.primitive(ref, where);\n case 'enum': {\n const schema = new ApiJsonSchema('string');\n schema.enum = ref.enumValues.slice();\n return schema;\n }\n case 'array': {\n const schema = new ApiJsonSchema('array');\n schema.items = this.typeSchema(ref.items!, where, parents);\n return schema;\n }\n case 'openMap': {\n const schema = new ApiJsonSchema('object');\n schema.additionalProperties = this.typeSchema(ref.values!, where, parents);\n return schema;\n }\n case 'ref':\n return this.referencedSchema(ref.refName!, where, parents);\n case 'union':\n return this.fieldUnion(ref.unionRefNames, where, parents);\n default:\n throw new McpRenderError(\n `no MCP schema for the declared type '${ref.unmappedText ?? '<unknown>'}'`,\n where,\n 'Give the field a shape the model can represent — a named DTO, an array of one, ' +\n 'a string-literal union, a Record, or a primitive.',\n );\n }\n }\n\n /** A named type: a string enum becomes `enum`, an object DTO is INLINED (MCP has no `$ref`). */\n private referencedSchema(\n name: string,\n where: string,\n parents: ReadonlySet<string>,\n ): ApiJsonSchema {\n const type = this.namedType(name, where);\n if (type.enumValues.length > 0) {\n const schema = new ApiJsonSchema('string');\n schema.enum = type.enumValues.slice();\n return schema;\n }\n return this.objectSchema(type, parents);\n }\n\n // webpieces-disable no-function-outside-class -- private static mapping of this class\n private static primitive(ref: TypeRef, where: string): ApiJsonSchema {\n if (ref.primitive === 'string' || ref.primitive === 'boolean') {\n return new ApiJsonSchema(ref.primitive);\n }\n if (ref.primitive === 'number') {\n return new ApiJsonSchema(ref.integer ? 'integer' : 'number');\n }\n throw new McpRenderError(\n `'${ref.primitive}' has no MCP schema`,\n where,\n 'Give the field a concrete type. `unknown`, `any`, `void` and a bare `null` publish as ' +\n '\"anything\", which an agent cannot fill in.',\n );\n }\n}\n"]}