import { McpCapabilityRegistryBase } from './internal/McpCapabilityRegistry.mjs'; import { createSafeCapabilityRegistration } from './utils/createSafeCapabilityRegistration.mjs'; import { wrapCapabilityHandlerForMetrics } from './metrics/wrapCapabilityHandlerForMetrics.mjs'; 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 resource with full type inference, ready to pass to * `strapi.ai.mcp.registerResource()`. Exposed publicly as `ai.mcp.defineResource`. * * The returned value is the definition unchanged — this builder only exists to * infer the `name` and narrow the access variant (`devModeOnly` vs `auth`) so the * result is directly assignable to `registerResource`. * * @param resource - The resource 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 appInfo = ai.mcp.defineResource({ * name: 'app-info', * uri: 'strapi://app/info', * metadata: { description: 'Metadata about the app', mimeType: 'application/json' }, * devModeOnly: true, * createHandler: (strapi) => async (uri) => ({ * contents: [{ uri: uri.href, mimeType: 'application/json', text: JSON.stringify({ ok: true }) }], * }), * }); * * // later, in register() or bootstrap(): * strapi.ai.mcp.registerResource(appInfo); * ``` */ const makeMcpResourceDefinition = (definition)=>definition; var _strapi = /*#__PURE__*/ _class_private_field_loose_key("_strapi"); class McpResourceRegistry extends McpCapabilityRegistryBase { bind(mcpServer) { const strapi = _class_private_field_loose_base(this, _strapi)[_strapi]; super.register((definition)=>{ const { name, uri, metadata, createHandler } = definition; return createSafeCapabilityRegistration({ strapi, capabilityType: 'Resource', name, createHandler, createFallbackHandler (errorMessage) { return async (resourceUri)=>({ contents: [ { uri: resourceUri.href, text: `Resource "${name}" failed to initialize: ${errorMessage}`, mimeType: 'text/plain' } ] }); }, createErrorResult (error, args) { return { contents: [ { uri: args[0] instanceof URL ? args[0].href : uri, text: `Resource "${name}" execution failed: ${error.message}`, mimeType: 'text/plain' } ] }; }, registerWithSdk (safeHandler) { const sdkHandler = wrapCapabilityHandlerForMetrics(strapi, 'resource', name, definition.telemetry, safeHandler); return mcpServer.registerResource(name, uri, metadata, 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 { McpResourceRegistry, makeMcpResourceDefinition }; //# sourceMappingURL=resource-registry.mjs.map