@webpieces/core-util 0.4.1011 → 0.4.1013
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
package/src/mcp/McpMetadata.d.ts
CHANGED
|
@@ -35,6 +35,10 @@ export declare class WpMcpToolMetadata {
|
|
|
35
35
|
* @WpMcpTool('learner_get_passages')
|
|
36
36
|
* ```
|
|
37
37
|
*
|
|
38
|
+
* Repeat this decorator for different names in different profiles on the same method. Each name
|
|
39
|
+
* must be declared once; combine its memberships in one profiles array. Identities of one method
|
|
40
|
+
* are ordered by name, independent of decorator order.
|
|
41
|
+
*
|
|
38
42
|
* The optional second argument selects profiles; omission selects only Mcp.DEFAULT. The name is the
|
|
39
43
|
* one fact the source cannot otherwise state:
|
|
40
44
|
*
|
package/src/mcp/McpMetadata.js
CHANGED
|
@@ -52,6 +52,10 @@ exports.WpMcpToolMetadata = WpMcpToolMetadata;
|
|
|
52
52
|
* @WpMcpTool('learner_get_passages')
|
|
53
53
|
* ```
|
|
54
54
|
*
|
|
55
|
+
* Repeat this decorator for different names in different profiles on the same method. Each name
|
|
56
|
+
* must be declared once; combine its memberships in one profiles array. Identities of one method
|
|
57
|
+
* are ordered by name, independent of decorator order.
|
|
58
|
+
*
|
|
55
59
|
* The optional second argument selects profiles; omission selects only Mcp.DEFAULT. The name is the
|
|
56
60
|
* one fact the source cannot otherwise state:
|
|
57
61
|
*
|
|
@@ -93,9 +97,14 @@ function WpMcpTool(name, options) {
|
|
|
93
97
|
}
|
|
94
98
|
return (target, propertyKey, _descriptor) => {
|
|
95
99
|
const apiClass = target.constructor;
|
|
96
|
-
const tools = Reflect.getMetadata(decorators_1.METADATA_KEYS.MCP_TOOLS, apiClass)
|
|
100
|
+
const tools = new Map(Reflect.getMetadata(decorators_1.METADATA_KEYS.MCP_TOOLS, apiClass));
|
|
97
101
|
const methodName = String(propertyKey);
|
|
98
|
-
|
|
102
|
+
const identities = tools.get(methodName) ?? [];
|
|
103
|
+
if (identities.some((tool) => tool.name === name)) {
|
|
104
|
+
throw new Error(`Duplicate @WpMcpTool name '${name}' on ${apiClass.name}.${methodName}. ` +
|
|
105
|
+
'Declare each identity once, with all its profiles in one profiles array.');
|
|
106
|
+
}
|
|
107
|
+
tools.set(methodName, [...identities, Object.freeze(new WpMcpToolMetadata(methodName, name, profiles))].sort((a, b) => a.name.localeCompare(b.name)));
|
|
99
108
|
Reflect.defineMetadata(decorators_1.METADATA_KEYS.MCP_TOOLS, tools, apiClass);
|
|
100
109
|
};
|
|
101
110
|
}
|
|
@@ -234,7 +243,7 @@ function operationForMcpHints(hints) {
|
|
|
234
243
|
/** Returns only methods explicitly opted in through {@link WpMcpTool}. */
|
|
235
244
|
// webpieces-disable no-function-outside-class -- metadata reader paired with the decorator
|
|
236
245
|
function getWpMcpTools(apiClass) {
|
|
237
|
-
const tools = Reflect.getMetadata(decorators_1.METADATA_KEYS.MCP_TOOLS, apiClass) ??
|
|
238
|
-
return
|
|
246
|
+
const tools = Reflect.getMetadata(decorators_1.METADATA_KEYS.MCP_TOOLS, apiClass) ?? new Map();
|
|
247
|
+
return [...tools.values()].flat();
|
|
239
248
|
}
|
|
240
249
|
//# sourceMappingURL=McpMetadata.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"McpMetadata.js","sourceRoot":"","sources":["../../../../../../packages/core/core-util/src/mcp/McpMetadata.ts"],"names":[],"mappings":";;;AA8EA,8BAiCC;AAgDD,sDAeC;AAID,8DAIC;AAoBD,oDAmBC;AAyCD,oDAIC;AAID,sCAIC;AAlRD,4BAA0B;AAC1B,+BAAoD;AACpD,+CAA4C;AAC5C,mDAAmD;AACnD,qEAA+F;AAE/F,wFAAwF;AACxF,MAAa,cAAc;IAEH;IACA;IACA;IACA;IAJpB,YACoB,YAAqB,EACrB,eAAwB,EACxB,cAAuB,EACvB,aAAsB;QAHtB,iBAAY,GAAZ,YAAY,CAAS;QACrB,oBAAe,GAAf,eAAe,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S,IAAI,OAAO,KAAK,CAAC,YAAY,KAAK,SAAS;QAAE,OAAO,yBAAiB,CAAC;IAC7F,IAAI,KAAK,CAAC,YAAY;QAAE,OAAO,0BAAI,CAAC;IACpC,OAAO,KAAK,CAAC,cAAc,KAAK,IAAI,CAAC,CAAC,CAAC,sCAAgB,CAAC,CAAC,CAAC,2BAAK,CAAC;AACpE,CAAC;AAED,0EAA0E;AAC1E,2FAA2F;AAC3F,SAAgB,aAAa,CAAC,QAAkB;IAC5C,MAAM,KAAK,GACP,OAAO,CAAC,WAAW,CAAC,0BAAa,CAAC,SAAS,EAAE,QAAQ,CAAC,IAAI,EAAE,CAAC;IACjE,OAAO,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAChC,CAAC","sourcesContent":["import 'reflect-metadata';\nimport { Mcp, McpToolProfilesOptions } from './Mcp';\nimport { McpToolName } from './McpToolName';\nimport { METADATA_KEYS } from '../http/decorators';\nimport { EndpointOperation, READ, WRITE_IDEMPOTENT, WRITE } from '../http/HttpEndpointOptions';\n\n/** The immutable hints MCP clients use when deciding whether and how to call a tool. */\nexport class WpMcpToolHints {\n constructor(\n public readonly readOnlyHint: boolean,\n public readonly destructiveHint: boolean,\n public readonly idempotentHint: boolean,\n public readonly openWorldHint: boolean,\n ) {}\n}\n\ntype AsyncObjectMethod = (...args: never[]) => Promise<object>;\ntype ExactOneParameter<TMethod extends AsyncObjectMethod> = Parameters<TMethod>['length'] extends 1\n ? object\n : never;\ntype ExactOneMethodDescriptor<TMethod extends AsyncObjectMethod> =\n TypedPropertyDescriptor<TMethod> & ExactOneParameter<TMethod>;\n\n/** Method decorator restricted to one request DTO and one async response DTO. */\nexport type WpMcpMethodDecorator = <TMethod extends AsyncObjectMethod>(\n target: object,\n propertyKey: string | symbol,\n descriptor: ExactOneMethodDescriptor<TMethod>,\n) => void;\n\n/** Runtime metadata for one explicitly exposed endpoint. */\nexport class WpMcpToolMetadata {\n constructor(\n public readonly methodName: string,\n public readonly name: string,\n public readonly profiles: readonly string[],\n ) {}\n}\n\n/**\n * Explicitly publishes an existing `@Endpoint(POST, path, WRITE, RPC)` method as an MCP tool, under\n * the STABLE protocol name given here.\n *\n * ```typescript\n * /**\n * * Every passage the learner can open, newest first.\n * *\n * * @summary Get your passages\n * * @returns The learner's passages, newest first.\n * *\\/\n * @WpMcpTool('learner_get_passages')\n * ```\n *\n * The optional second argument selects profiles; omission selects only Mcp.DEFAULT. The name is the\n * one fact the source cannot otherwise state:\n *\n * | fact | where it comes from |\n * |---|---|\n * | `name` | this decorator — the stable protocol identity, independent of the method name because renaming a method must not break a saved agent workflow. 1-64 characters of `[A-Za-z0-9_-]` ({@link McpToolName}) |\n * | `title` | the method's REQUIRED `@summary` JSDoc tag — the same line OpenAPI publishes as the operation's `summary`; published as BOTH `Tool.title` and `annotations.title` |\n * | `description` | the method's JSDoc body, or its `@mcp` tag — the same words the partner reads |\n * | `readOnlyHint` / `idempotentHint` | `@Endpoint`'s `operation`, via {@link mcpHintsForOperation} |\n * | `destructiveHint` | `@Endpoint`'s `operation` and its `additive` option (a write is destructive unless `additive: true`), via {@link mcpHintsForOperation} |\n * | `openWorldHint` | `@Endpoint`'s `openWorld` option |\n * | `inputSchema` / `outputSchema` | the declared request and response types |\n *\n * ## Why the title is NOT an argument here (#1296)\n *\n * It used to be the second argument (#1180). That was a second place to write an endpoint's short\n * title: it never reached OpenAPI, whose operation `summary` was the bare method name, and the two\n * drifted. The title now has ONE source, the `@summary` JSDoc tag, which `wp-openapi` REQUIRES on every\n * published operation and publishes as OpenAPI `summary`, MCP `title` and MCP `annotations.title`.\n * Passing a title here is a compile error; the second parameter is the profiles object.\n *\n * Until #984 the decorator also took a `description`, duplicating the JSDoc, and was cut for the same\n * reason: two authored copies of one fact drift the first time somebody edits one.\n */\n// webpieces-disable no-function-outside-class -- decorator factories are inherently module-scope\nexport function WpMcpTool(name: string, options?: McpToolProfilesOptions): WpMcpMethodDecorator {\n if (\n options !== undefined &&\n (typeof options !== 'object' ||\n options === null ||\n Array.isArray(options) ||\n Object.keys(options).some((key: string) => key !== 'profiles'))\n ) {\n throw new Error(\n '@WpMcpTool options must be an object containing only profiles. The tool title is the ' +\n \"method's @summary JSDoc tag, never a decorator argument.\",\n );\n }\n const profiles = Mcp.profiles(\n options !== undefined && 'profiles' in options ? options.profiles! : [Mcp.DEFAULT],\n '@WpMcpTool',\n );\n const problem = McpToolName.problemWith(name);\n if (problem !== undefined) {\n throw new Error(`@WpMcpTool('${name}'): the tool name ${problem}. ${McpToolName.cure()}`);\n }\n return <TMethod extends AsyncObjectMethod>(\n target: object,\n propertyKey: string | symbol,\n _descriptor: ExactOneMethodDescriptor<TMethod>,\n ): void => {\n const apiClass = target.constructor;\n const tools: Record<string, WpMcpToolMetadata> =\n Reflect.getMetadata(METADATA_KEYS.MCP_TOOLS, apiClass) ?? {};\n const methodName = String(propertyKey);\n tools[methodName] = new WpMcpToolMetadata(methodName, name, profiles);\n Reflect.defineMetadata(METADATA_KEYS.MCP_TOOLS, tools, apiClass);\n };\n}\n\n/** Runtime metadata for one endpoint declared PERMANENTLY outside MCP. */\nexport class InvalidEndpointForMcpMetadata {\n constructor(\n public readonly methodName: string,\n /** WHY it can never be a tool. Non-empty, enforced at decoration time. */\n public readonly reason: string,\n ) {}\n}\n\n/**\n * Declares that this endpoint is PERMANENTLY outside MCP, and says why.\n *\n * ## It is not a suppression, and that distinction is the whole feature\n *\n * `// webpieces-disable api-rules-for-mcp -- <reason>` says \"stop complaining\". This says \"this is\n * structurally impossible, forever\", and the two have different futures: a suppression is something\n * somebody should eventually come back to, and this is something nobody should. Both measured cases\n * are types that are CORRECT and must not be \"fixed\" —\n *\n * - a webhook TRANSPORT envelope, whose `data` is owned by each event's own published contract;\n * typing it here would fork that ownership and make adding an event type a change to the\n * transport contract rather than a registration, and\n * - a freeform-SQL escape hatch, whose result columns depend on the model-authored `SELECT`.\n *\n * The second one is worth stating rather than burying: it is the most obviously useful tool in that\n * repo, and it is excluded by a type that is right.\n *\n * ## Absence already says \"not a tool YET\"\n *\n * A method with no `@WpMcpTool` is simply not published. This decorator is the NEVER, and the reason\n * is what makes `grep -rn InvalidEndpointForMcp` a list of permanent exclusions with their arguments\n * rather than a list of names. `api-rules-for-mcp` restates that list on every run, so an exclusion\n * stays visible instead of being announced once and forgotten.\n *\n * ## It contradicts `@WpMcpTool`\n *\n * Both on one method is an ERROR, asserted by {@link assertApiTypeMatchesMcpTools}. \"Publish this as\n * a tool\" and \"this can never be a tool\" are two spellings of one decision, which is exactly the\n * defect `.claude/rules/no-backwards-compat.md` shim shape #1 rejects.\n *\n * ```typescript\n * @InvalidEndpointForMcp('a transport envelope body is opaque by design; the published partner ' +\n * 'contract for each event type owns its shape')\n * ```\n */\n// webpieces-disable no-function-outside-class -- decorator factories are inherently module-scope\nexport function InvalidEndpointForMcp(reason: string): MethodDecorator {\n if (reason.trim() === '') {\n throw new Error(\n '@InvalidEndpointForMcp requires a non-empty reason. The reason IS the declaration — ' +\n 'without it this is a suppression with a longer name.',\n );\n }\n return (target: object, propertyKey: string | symbol): void => {\n const apiClass = target.constructor;\n const excluded: Record<string, InvalidEndpointForMcpMetadata> =\n Reflect.getMetadata(METADATA_KEYS.MCP_INVALID, apiClass) ?? {};\n const methodName = String(propertyKey);\n excluded[methodName] = new InvalidEndpointForMcpMetadata(methodName, reason);\n Reflect.defineMetadata(METADATA_KEYS.MCP_INVALID, excluded, apiClass);\n };\n}\n\n/** Every method declared permanently outside MCP by {@link InvalidEndpointForMcp}. */\n// webpieces-disable no-function-outside-class -- metadata reader paired with the decorator\nexport function getInvalidEndpointsForMcp(apiClass: Function): InvalidEndpointForMcpMetadata[] {\n const excluded: Record<string, InvalidEndpointForMcpMetadata> =\n Reflect.getMetadata(METADATA_KEYS.MCP_INVALID, apiClass) ?? {};\n return Object.values(excluded);\n}\n\n/**\n * The one mapping from endpoint side effects to MCP advisory annotations, and {@link operationForMcpHints}\n * beside it is the one mapping back. The two are tested against each other.\n *\n * | `@Endpoint` operation | `additive` | readOnly | destructive | idempotent |\n * |---|---|---|---|---|\n * | READ | (cannot be stated) | true | false | true |\n * | WRITE_IDEMPOTENT | absent | false | true | true |\n * | WRITE_IDEMPOTENT | `true` | false | **false** | true |\n * | WRITE | absent | false | true | false |\n * | WRITE | `true` | false | **false** | false |\n *\n * `openWorldHint` is `@Endpoint`'s `openWorld` option, verbatim. `destructiveHint: true` is the MCP\n * specification's safe default for a write; only an author who declared `additive: true` lowers it\n * (#1422). `@Endpoint` refuses `additive` on a READ at compile time; this function throws for it too,\n * because a generator reads the options from SOURCE and must not publish a hint the type forbade.\n */\n// webpieces-disable no-function-outside-class -- pure metadata mapping shared by MCP registration\nexport function mcpHintsForOperation(\n operation: EndpointOperation,\n openWorldHint: boolean,\n additive: boolean,\n): WpMcpToolHints {\n switch (operation) {\n case READ:\n if (additive) {\n throw new Error(\n '`additive: true` is meaningful only on a WRITE or WRITE_IDEMPOTENT endpoint; a ' +\n 'READ changes nothing. Remove `additive` from the READ endpoint.',\n );\n }\n return new WpMcpToolHints(true, false, true, openWorldHint);\n case WRITE_IDEMPOTENT:\n return new WpMcpToolHints(false, !additive, true, openWorldHint);\n case WRITE:\n return new WpMcpToolHints(false, !additive, false, openWorldHint);\n }\n}\n\n/** Nominal backing for {@link UNKNOWN_OPERATION}. */\nenum McpUnknownOperationValue {\n UNKNOWN = 'unknown',\n}\n\n/**\n * The operation of a tool whose server sent no annotations, or that the server does not list — the\n * fourth answer {@link operationForMcpHints} can give besides READ, WRITE and WRITE_IDEMPOTENT.\n */\nexport const UNKNOWN_OPERATION = McpUnknownOperationValue.UNKNOWN;\n\n/** What a remote tool is known to do: an `@Endpoint` operation, or {@link UNKNOWN_OPERATION}. */\nexport type McpToolOperation = EndpointOperation | typeof UNKNOWN_OPERATION;\n\n/**\n * The two annotations {@link operationForMcpHints} reads. A structural view, never constructed:\n * both {@link WpMcpToolHints} and the MCP SDK's `ToolAnnotations` (as a server sent them, every field\n * optional) satisfy it, so the reverse mapping needs no dependency on the SDK.\n */\nexport interface McpOperationHints {\n readonly readOnlyHint?: boolean;\n readonly idempotentHint?: boolean;\n}\n\n/**\n * The reverse of {@link mcpHintsForOperation}: which `@Endpoint` operation produced these hints.\n *\n * | `readOnlyHint` | `idempotentHint` | operation |\n * |---|---|---|\n * | true | any | READ |\n * | false | true | WRITE_IDEMPOTENT |\n * | false | false / absent | WRITE |\n * | absent (or no annotations at all) | | {@link UNKNOWN_OPERATION} |\n *\n * Only `readOnlyHint` and `idempotentHint` are read. `destructiveHint` is not, so an `additive`\n * write reverses to the same operation as a destructive one. An MCP host (`WpMcpRemote`'s approval\n * hook) uses this to tell a READ from a WRITE without a hard-coded list of tool names (#1422).\n */\n// webpieces-disable no-function-outside-class -- pure metadata mapping paired with mcpHintsForOperation\nexport function operationForMcpHints(hints: McpOperationHints | undefined): McpToolOperation {\n if (hints === undefined || typeof hints.readOnlyHint !== 'boolean') return UNKNOWN_OPERATION;\n if (hints.readOnlyHint) return READ;\n return hints.idempotentHint === true ? WRITE_IDEMPOTENT : WRITE;\n}\n\n/** Returns only methods explicitly opted in through {@link WpMcpTool}. */\n// webpieces-disable no-function-outside-class -- metadata reader paired with the decorator\nexport function getWpMcpTools(apiClass: Function): WpMcpToolMetadata[] {\n const tools: Record<string, WpMcpToolMetadata> =\n Reflect.getMetadata(METADATA_KEYS.MCP_TOOLS, apiClass) ?? {};\n return Object.values(tools);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"McpMetadata.js","sourceRoot":"","sources":["../../../../../../packages/core/core-util/src/mcp/McpMetadata.ts"],"names":[],"mappings":";;;AAkFA,8BA8CC;AAgDD,sDAeC;AAID,8DAIC;AAoBD,oDAmBC;AAyCD,oDAIC;AAID,sCAIC;AAnSD,4BAA0B;AAC1B,+BAAoD;AACpD,+CAA4C;AAC5C,mDAAmD;AACnD,qEAA+F;AAE/F,wFAAwF;AACxF,MAAa,cAAc;IAEH;IACA;IACA;IACA;IAJpB,YACoB,YAAqB,EACrB,eA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CAAC;YACD,OAAO,IAAI,cAAc,CAAC,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,aAAa,CAAC,CAAC;QAChE,KAAK,sCAAgB;YACjB,OAAO,IAAI,cAAc,CAAC,KAAK,EAAE,CAAC,QAAQ,EAAE,IAAI,EAAE,aAAa,CAAC,CAAC;QACrE,KAAK,2BAAK;YACN,OAAO,IAAI,cAAc,CAAC,KAAK,EAAE,CAAC,QAAQ,EAAE,KAAK,EAAE,aAAa,CAAC,CAAC;IAC1E,CAAC;AACL,CAAC;AAED,qDAAqD;AACrD,IAAK,wBAEJ;AAFD,WAAK,wBAAwB;IACzB,+CAAmB,CAAA;AACvB,CAAC,EAFI,wBAAwB,KAAxB,wBAAwB,QAE5B;AAED;;;GAGG;AACU,QAAA,iBAAiB,GAAG,wBAAwB,CAAC,OAAO,CAAC;AAelE;;;;;;;;;;;;;GAaG;AACH,wGAAwG;AACxG,SAAgB,oBAAoB,CAAC,KAAoC;IACrE,IAAI,KAAK,KAAK,SAAS,IAAI,OAAO,KAAK,CAAC,YAAY,KAAK,SAAS;QAAE,OAAO,yBAAiB,CAAC;IAC7F,IAAI,KAAK,CAAC,YAAY;QAAE,OAAO,0BAAI,CAAC;IACpC,OAAO,KAAK,CAAC,cAAc,KAAK,IAAI,CAAC,CAAC,CAAC,sCAAgB,CAAC,CAAC,CAAC,2BAAK,CAAC;AACpE,CAAC;AAED,0EAA0E;AAC1E,2FAA2F;AAC3F,SAAgB,aAAa,CAAC,QAAkB;IAC5C,MAAM,KAAK,GACP,OAAO,CAAC,WAAW,CAAC,0BAAa,CAAC,SAAS,EAAE,QAAQ,CAAC,IAAI,IAAI,GAAG,EAAE,CAAC;IACxE,OAAO,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;AACtC,CAAC","sourcesContent":["import 'reflect-metadata';\nimport { Mcp, McpToolProfilesOptions } from './Mcp';\nimport { McpToolName } from './McpToolName';\nimport { METADATA_KEYS } from '../http/decorators';\nimport { EndpointOperation, READ, WRITE_IDEMPOTENT, WRITE } from '../http/HttpEndpointOptions';\n\n/** The immutable hints MCP clients use when deciding whether and how to call a tool. */\nexport class WpMcpToolHints {\n constructor(\n public readonly readOnlyHint: boolean,\n public readonly destructiveHint: boolean,\n public readonly idempotentHint: boolean,\n public readonly openWorldHint: boolean,\n ) {}\n}\n\ntype AsyncObjectMethod = (...args: never[]) => Promise<object>;\ntype ExactOneParameter<TMethod extends AsyncObjectMethod> = Parameters<TMethod>['length'] extends 1\n ? object\n : never;\ntype ExactOneMethodDescriptor<TMethod extends AsyncObjectMethod> =\n TypedPropertyDescriptor<TMethod> & ExactOneParameter<TMethod>;\n\n/** Method decorator restricted to one request DTO and one async response DTO. */\nexport type WpMcpMethodDecorator = <TMethod extends AsyncObjectMethod>(\n target: object,\n propertyKey: string | symbol,\n descriptor: ExactOneMethodDescriptor<TMethod>,\n) => void;\n\n/** Runtime metadata for one explicitly exposed endpoint. */\nexport class WpMcpToolMetadata {\n constructor(\n public readonly methodName: string,\n public readonly name: string,\n public readonly profiles: readonly string[],\n ) {}\n}\n\n/**\n * Explicitly publishes an existing `@Endpoint(POST, path, WRITE, RPC)` method as an MCP tool, under\n * the STABLE protocol name given here.\n *\n * ```typescript\n * /**\n * * Every passage the learner can open, newest first.\n * *\n * * @summary Get your passages\n * * @returns The learner's passages, newest first.\n * *\\/\n * @WpMcpTool('learner_get_passages')\n * ```\n *\n * Repeat this decorator for different names in different profiles on the same method. Each name\n * must be declared once; combine its memberships in one profiles array. Identities of one method\n * are ordered by name, independent of decorator order.\n *\n * The optional second argument selects profiles; omission selects only Mcp.DEFAULT. The name is the\n * one fact the source cannot otherwise state:\n *\n * | fact | where it comes from |\n * |---|---|\n * | `name` | this decorator — the stable protocol identity, independent of the method name because renaming a method must not break a saved agent workflow. 1-64 characters of `[A-Za-z0-9_-]` ({@link McpToolName}) |\n * | `title` | the method's REQUIRED `@summary` JSDoc tag — the same line OpenAPI publishes as the operation's `summary`; published as BOTH `Tool.title` and `annotations.title` |\n * | `description` | the method's JSDoc body, or its `@mcp` tag — the same words the partner reads |\n * | `readOnlyHint` / `idempotentHint` | `@Endpoint`'s `operation`, via {@link mcpHintsForOperation} |\n * | `destructiveHint` | `@Endpoint`'s `operation` and its `additive` option (a write is destructive unless `additive: true`), via {@link mcpHintsForOperation} |\n * | `openWorldHint` | `@Endpoint`'s `openWorld` option |\n * | `inputSchema` / `outputSchema` | the declared request and response types |\n *\n * ## Why the title is NOT an argument here (#1296)\n *\n * It used to be the second argument (#1180). That was a second place to write an endpoint's short\n * title: it never reached OpenAPI, whose operation `summary` was the bare method name, and the two\n * drifted. The title now has ONE source, the `@summary` JSDoc tag, which `wp-openapi` REQUIRES on every\n * published operation and publishes as OpenAPI `summary`, MCP `title` and MCP `annotations.title`.\n * Passing a title here is a compile error; the second parameter is the profiles object.\n *\n * Until #984 the decorator also took a `description`, duplicating the JSDoc, and was cut for the same\n * reason: two authored copies of one fact drift the first time somebody edits one.\n */\n// webpieces-disable no-function-outside-class -- decorator factories are inherently module-scope\nexport function WpMcpTool(name: string, options?: McpToolProfilesOptions): WpMcpMethodDecorator {\n if (\n options !== undefined &&\n (typeof options !== 'object' ||\n options === null ||\n Array.isArray(options) ||\n Object.keys(options).some((key: string) => key !== 'profiles'))\n ) {\n throw new Error(\n '@WpMcpTool options must be an object containing only profiles. The tool title is the ' +\n \"method's @summary JSDoc tag, never a decorator argument.\",\n );\n }\n const profiles = Mcp.profiles(\n options !== undefined && 'profiles' in options ? options.profiles! : [Mcp.DEFAULT],\n '@WpMcpTool',\n );\n const problem = McpToolName.problemWith(name);\n if (problem !== undefined) {\n throw new Error(`@WpMcpTool('${name}'): the tool name ${problem}. ${McpToolName.cure()}`);\n }\n return <TMethod extends AsyncObjectMethod>(\n target: object,\n propertyKey: string | symbol,\n _descriptor: ExactOneMethodDescriptor<TMethod>,\n ): void => {\n const apiClass = target.constructor;\n const tools = new Map<string, readonly WpMcpToolMetadata[]>(\n Reflect.getMetadata(METADATA_KEYS.MCP_TOOLS, apiClass),\n );\n const methodName = String(propertyKey);\n const identities = tools.get(methodName) ?? [];\n if (identities.some((tool: WpMcpToolMetadata) => tool.name === name)) {\n throw new Error(\n `Duplicate @WpMcpTool name '${name}' on ${apiClass.name}.${methodName}. ` +\n 'Declare each identity once, with all its profiles in one profiles array.',\n );\n }\n tools.set(\n methodName,\n [...identities, Object.freeze(new WpMcpToolMetadata(methodName, name, profiles))].sort(\n (a: WpMcpToolMetadata, b: WpMcpToolMetadata) => a.name.localeCompare(b.name),\n ),\n );\n Reflect.defineMetadata(METADATA_KEYS.MCP_TOOLS, tools, apiClass);\n };\n}\n\n/** Runtime metadata for one endpoint declared PERMANENTLY outside MCP. */\nexport class InvalidEndpointForMcpMetadata {\n constructor(\n public readonly methodName: string,\n /** WHY it can never be a tool. Non-empty, enforced at decoration time. */\n public readonly reason: string,\n ) {}\n}\n\n/**\n * Declares that this endpoint is PERMANENTLY outside MCP, and says why.\n *\n * ## It is not a suppression, and that distinction is the whole feature\n *\n * `// webpieces-disable api-rules-for-mcp -- <reason>` says \"stop complaining\". This says \"this is\n * structurally impossible, forever\", and the two have different futures: a suppression is something\n * somebody should eventually come back to, and this is something nobody should. Both measured cases\n * are types that are CORRECT and must not be \"fixed\" —\n *\n * - a webhook TRANSPORT envelope, whose `data` is owned by each event's own published contract;\n * typing it here would fork that ownership and make adding an event type a change to the\n * transport contract rather than a registration, and\n * - a freeform-SQL escape hatch, whose result columns depend on the model-authored `SELECT`.\n *\n * The second one is worth stating rather than burying: it is the most obviously useful tool in that\n * repo, and it is excluded by a type that is right.\n *\n * ## Absence already says \"not a tool YET\"\n *\n * A method with no `@WpMcpTool` is simply not published. This decorator is the NEVER, and the reason\n * is what makes `grep -rn InvalidEndpointForMcp` a list of permanent exclusions with their arguments\n * rather than a list of names. `api-rules-for-mcp` restates that list on every run, so an exclusion\n * stays visible instead of being announced once and forgotten.\n *\n * ## It contradicts `@WpMcpTool`\n *\n * Both on one method is an ERROR, asserted by {@link assertApiTypeMatchesMcpTools}. \"Publish this as\n * a tool\" and \"this can never be a tool\" are two spellings of one decision, which is exactly the\n * defect `.claude/rules/no-backwards-compat.md` shim shape #1 rejects.\n *\n * ```typescript\n * @InvalidEndpointForMcp('a transport envelope body is opaque by design; the published partner ' +\n * 'contract for each event type owns its shape')\n * ```\n */\n// webpieces-disable no-function-outside-class -- decorator factories are inherently module-scope\nexport function InvalidEndpointForMcp(reason: string): MethodDecorator {\n if (reason.trim() === '') {\n throw new Error(\n '@InvalidEndpointForMcp requires a non-empty reason. The reason IS the declaration — ' +\n 'without it this is a suppression with a longer name.',\n );\n }\n return (target: object, propertyKey: string | symbol): void => {\n const apiClass = target.constructor;\n const excluded: Record<string, InvalidEndpointForMcpMetadata> =\n Reflect.getMetadata(METADATA_KEYS.MCP_INVALID, apiClass) ?? {};\n const methodName = String(propertyKey);\n excluded[methodName] = new InvalidEndpointForMcpMetadata(methodName, reason);\n Reflect.defineMetadata(METADATA_KEYS.MCP_INVALID, excluded, apiClass);\n };\n}\n\n/** Every method declared permanently outside MCP by {@link InvalidEndpointForMcp}. */\n// webpieces-disable no-function-outside-class -- metadata reader paired with the decorator\nexport function getInvalidEndpointsForMcp(apiClass: Function): InvalidEndpointForMcpMetadata[] {\n const excluded: Record<string, InvalidEndpointForMcpMetadata> =\n Reflect.getMetadata(METADATA_KEYS.MCP_INVALID, apiClass) ?? {};\n return Object.values(excluded);\n}\n\n/**\n * The one mapping from endpoint side effects to MCP advisory annotations, and {@link operationForMcpHints}\n * beside it is the one mapping back. The two are tested against each other.\n *\n * | `@Endpoint` operation | `additive` | readOnly | destructive | idempotent |\n * |---|---|---|---|---|\n * | READ | (cannot be stated) | true | false | true |\n * | WRITE_IDEMPOTENT | absent | false | true | true |\n * | WRITE_IDEMPOTENT | `true` | false | **false** | true |\n * | WRITE | absent | false | true | false |\n * | WRITE | `true` | false | **false** | false |\n *\n * `openWorldHint` is `@Endpoint`'s `openWorld` option, verbatim. `destructiveHint: true` is the MCP\n * specification's safe default for a write; only an author who declared `additive: true` lowers it\n * (#1422). `@Endpoint` refuses `additive` on a READ at compile time; this function throws for it too,\n * because a generator reads the options from SOURCE and must not publish a hint the type forbade.\n */\n// webpieces-disable no-function-outside-class -- pure metadata mapping shared by MCP registration\nexport function mcpHintsForOperation(\n operation: EndpointOperation,\n openWorldHint: boolean,\n additive: boolean,\n): WpMcpToolHints {\n switch (operation) {\n case READ:\n if (additive) {\n throw new Error(\n '`additive: true` is meaningful only on a WRITE or WRITE_IDEMPOTENT endpoint; a ' +\n 'READ changes nothing. Remove `additive` from the READ endpoint.',\n );\n }\n return new WpMcpToolHints(true, false, true, openWorldHint);\n case WRITE_IDEMPOTENT:\n return new WpMcpToolHints(false, !additive, true, openWorldHint);\n case WRITE:\n return new WpMcpToolHints(false, !additive, false, openWorldHint);\n }\n}\n\n/** Nominal backing for {@link UNKNOWN_OPERATION}. */\nenum McpUnknownOperationValue {\n UNKNOWN = 'unknown',\n}\n\n/**\n * The operation of a tool whose server sent no annotations, or that the server does not list — the\n * fourth answer {@link operationForMcpHints} can give besides READ, WRITE and WRITE_IDEMPOTENT.\n */\nexport const UNKNOWN_OPERATION = McpUnknownOperationValue.UNKNOWN;\n\n/** What a remote tool is known to do: an `@Endpoint` operation, or {@link UNKNOWN_OPERATION}. */\nexport type McpToolOperation = EndpointOperation | typeof UNKNOWN_OPERATION;\n\n/**\n * The two annotations {@link operationForMcpHints} reads. A structural view, never constructed:\n * both {@link WpMcpToolHints} and the MCP SDK's `ToolAnnotations` (as a server sent them, every field\n * optional) satisfy it, so the reverse mapping needs no dependency on the SDK.\n */\nexport interface McpOperationHints {\n readonly readOnlyHint?: boolean;\n readonly idempotentHint?: boolean;\n}\n\n/**\n * The reverse of {@link mcpHintsForOperation}: which `@Endpoint` operation produced these hints.\n *\n * | `readOnlyHint` | `idempotentHint` | operation |\n * |---|---|---|\n * | true | any | READ |\n * | false | true | WRITE_IDEMPOTENT |\n * | false | false / absent | WRITE |\n * | absent (or no annotations at all) | | {@link UNKNOWN_OPERATION} |\n *\n * Only `readOnlyHint` and `idempotentHint` are read. `destructiveHint` is not, so an `additive`\n * write reverses to the same operation as a destructive one. An MCP host (`WpMcpRemote`'s approval\n * hook) uses this to tell a READ from a WRITE without a hard-coded list of tool names (#1422).\n */\n// webpieces-disable no-function-outside-class -- pure metadata mapping paired with mcpHintsForOperation\nexport function operationForMcpHints(hints: McpOperationHints | undefined): McpToolOperation {\n if (hints === undefined || typeof hints.readOnlyHint !== 'boolean') return UNKNOWN_OPERATION;\n if (hints.readOnlyHint) return READ;\n return hints.idempotentHint === true ? WRITE_IDEMPOTENT : WRITE;\n}\n\n/** Returns only methods explicitly opted in through {@link WpMcpTool}. */\n// webpieces-disable no-function-outside-class -- metadata reader paired with the decorator\nexport function getWpMcpTools(apiClass: Function): WpMcpToolMetadata[] {\n const tools: ReadonlyMap<string, readonly WpMcpToolMetadata[]> =\n Reflect.getMetadata(METADATA_KEYS.MCP_TOOLS, apiClass) ?? new Map();\n return [...tools.values()].flat();\n}\n"]}
|