import { McpCapabilityRegistryBase } from './internal/McpCapabilityRegistry.mjs'; import { createSafeCapabilityRegistration } from './utils/createSafeCapabilityRegistration.mjs'; import { wrapCapabilityHandlerForMetrics } from './metrics/wrapCapabilityHandlerForMetrics.mjs'; // eslint-disable-next-line import/extensions function _class_private_field_loose_base(receiver, privateKey) { if (!Object.prototype.hasOwnProperty.call(receiver, privateKey)) { throw new TypeError("attempted to use private field on non-instance"); } return receiver; } var id = 0; function _class_private_field_loose_key(name) { return "__private_" + id++ + "_" + name; } /** * Defines a Strapi MCP prompt with full type inference, ready to pass to * `strapi.ai.mcp.registerPrompt()`. Exposed publicly as `ai.mcp.definePrompt`. * * The returned value is the definition unchanged — this builder only exists to * infer the `name`/`argsSchema` and narrow the access variant (`devModeOnly` vs * `auth`) so the result is directly assignable to `registerPrompt`. * * @param prompt - The prompt definition. Provide either `devModeOnly: true` * (dev-only, no auth) or an `auth` policy set — never both. * @returns The same definition, with its access variant narrowed. * * @example * ```ts * import { ai } from '@strapi/strapi'; * * const context = ai.mcp.definePrompt({ * name: 'app-context', * title: 'App Context', * description: 'Provides context about the app', * devModeOnly: true, * createHandler: (strapi) => async () => ({ * messages: [{ role: 'user', content: { type: 'text', text: 'You are connected to Strapi.' } }], * }), * }); * * // later, in register() or bootstrap(): * strapi.ai.mcp.registerPrompt(context); * ``` */ const makeMcpPromptDefinition = (definition)=>definition; var _strapi = /*#__PURE__*/ _class_private_field_loose_key("_strapi"); class McpPromptRegistry extends McpCapabilityRegistryBase { bind(mcpServer) { const strapi = _class_private_field_loose_base(this, _strapi)[_strapi]; super.register((definition)=>{ const { name, title, description, argsSchema, createHandler } = definition; return createSafeCapabilityRegistration({ strapi, capabilityType: 'Prompt', name, createHandler, createFallbackHandler (errorMessage) { return async ()=>({ messages: [ { role: 'user', content: { type: 'text', text: `Prompt "${name}" failed to initialize: ${errorMessage}` } } ] }); }, createErrorResult (error) { return { messages: [ { role: 'user', content: { type: 'text', text: `Prompt "${name}" execution failed: ${error.message}` } } ] }; }, registerWithSdk (safeHandler) { const sdkHandler = wrapCapabilityHandlerForMetrics(strapi, 'prompt', name, definition.telemetry, safeHandler); return mcpServer.registerPrompt(name, { title, description, // @ts-expect-error - Internal handler type mismatch due to optional argsSchema argsSchema }, sdkHandler); } }); }); } constructor(ctx){ super(ctx.definitions), Object.defineProperty(this, _strapi, { writable: true, value: void 0 }); _class_private_field_loose_base(this, _strapi)[_strapi] = ctx.strapi; } } export { McpPromptRegistry, makeMcpPromptDefinition }; //# sourceMappingURL=prompt-registry.mjs.map