{"version":3,"file":"prompt-registry.mjs","sources":["../../../src/services/mcp/prompt-registry.ts"],"sourcesContent":["// eslint-disable-next-line import/extensions\nimport type { McpServer, RegisteredPrompt } from '@modelcontextprotocol/sdk/server/mcp.js';\nimport type { Core, Modules } from '@strapi/types';\n\nimport { McpCapabilityDefinitionRegistry } from './internal/McpCapabilityDefinitionRegistry';\nimport {\n type McpCapabilityRegistry,\n McpCapabilityRegistryBase,\n} from './internal/McpCapabilityRegistry';\nimport { createSafeCapabilityRegistration } from './utils/createSafeCapabilityRegistration';\nimport { wrapCapabilityHandlerForMetrics } from './metrics/wrapCapabilityHandlerForMetrics';\n\n/**\n * Defines a Strapi MCP prompt with full type inference, ready to pass to\n * `strapi.ai.mcp.registerPrompt()`. Exposed publicly as `ai.mcp.definePrompt`.\n *\n * The returned value is the definition unchanged — this builder only exists to\n * infer the `name`/`argsSchema` and narrow the access variant (`devModeOnly` vs\n * `auth`) so the result is directly assignable to `registerPrompt`.\n *\n * @param prompt - The prompt definition. Provide either `devModeOnly: true`\n * (dev-only, no auth) or an `auth` policy set — never both.\n * @returns The same definition, with its access variant narrowed.\n *\n * @example\n * ```ts\n * import { ai } from '@strapi/strapi';\n *\n * const context = ai.mcp.definePrompt({\n * name: 'app-context',\n * title: 'App Context',\n * description: 'Provides context about the app',\n * devModeOnly: true,\n * createHandler: (strapi) => async () => ({\n * messages: [{ role: 'user', content: { type: 'text', text: 'You are connected to Strapi.' } }],\n * }),\n * });\n *\n * // later, in register() or bootstrap():\n * strapi.ai.mcp.registerPrompt(context);\n * ```\n */\nexport const makeMcpPromptDefinition = ((definition: Modules.MCP.McpPromptDefinition) =>\n definition) as unknown as Modules.MCP.McpPromptBuilder;\n\nexport class McpPromptRegistry\n extends McpCapabilityRegistryBase<'prompt', Modules.MCP.McpPromptDefinition, RegisteredPrompt>\n implements McpCapabilityRegistry\n{\n #strapi: Core.Strapi;\n\n constructor(ctx: {\n strapi: Core.Strapi;\n definitions: McpCapabilityDefinitionRegistry<'prompt', Modules.MCP.McpPromptDefinition>;\n }) {\n super(ctx.definitions);\n this.#strapi = ctx.strapi;\n }\n\n bind(mcpServer: McpServer) {\n const strapi = this.#strapi;\n\n super.register((definition) => {\n const { name, title, description, argsSchema, createHandler } = definition;\n\n return createSafeCapabilityRegistration({\n strapi,\n capabilityType: 'Prompt',\n name,\n createHandler,\n createFallbackHandler(errorMessage) {\n return async () => ({\n messages: [\n {\n role: 'user' as const,\n content: {\n type: 'text' as const,\n text: `Prompt \"${name}\" failed to initialize: ${errorMessage}`,\n },\n },\n ],\n });\n },\n createErrorResult(error) {\n return {\n messages: [\n {\n role: 'user' as const,\n content: {\n type: 'text' as const,\n text: `Prompt \"${name}\" execution failed: ${error.message}`,\n },\n },\n ],\n };\n },\n registerWithSdk(safeHandler) {\n const sdkHandler = wrapCapabilityHandlerForMetrics(\n strapi,\n 'prompt',\n name,\n definition.telemetry,\n safeHandler\n );\n\n return mcpServer.registerPrompt(\n name,\n {\n title,\n description,\n // @ts-expect-error - Internal handler type mismatch due to optional argsSchema\n argsSchema,\n },\n sdkHandler\n );\n },\n });\n });\n }\n}\n"],"names":["makeMcpPromptDefinition","definition","McpPromptRegistry","McpCapabilityRegistryBase","bind","mcpServer","strapi","register","name","title","description","argsSchema","createHandler","createSafeCapabilityRegistration","capabilityType","createFallbackHandler","errorMessage","messages","role","content","type","text","createErrorResult","error","message","registerWithSdk","safeHandler","sdkHandler","wrapCapabilityHandlerForMetrics","telemetry","registerPrompt","ctx","definitions"],"mappings":";;;;AAAA;;;;;;;;;;;AAYA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6BC,IACM,MAAMA,uBAAAA,GAA2B,CAACC,aACvCA;AAMA,IAAA,OAAA,iBAAA,8BAAA,CAAA,SAAA,CAAA;AAJK,MAAMC,iBAAAA,SACHC,yBAAAA,CAAAA;AAaRC,IAAAA,IAAAA,CAAKC,SAAoB,EAAE;AACzB,QAAA,MAAMC,MAAAA,GAAS,+BAAA,CAAA,IAAI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