@strapi/core 5.46.1 → 5.47.1
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/dist/Strapi.d.ts.map +1 -1
- package/dist/Strapi.js +12 -3
- package/dist/Strapi.js.map +1 -1
- package/dist/Strapi.mjs +12 -3
- package/dist/Strapi.mjs.map +1 -1
- package/dist/compile.d.ts.map +1 -1
- package/dist/compile.js +12 -5
- package/dist/compile.js.map +1 -1
- package/dist/compile.mjs +12 -5
- package/dist/compile.mjs.map +1 -1
- package/dist/core-api/routes/index.js +2 -0
- package/dist/core-api/routes/index.js.map +1 -1
- package/dist/core-api/routes/index.mjs +2 -0
- package/dist/core-api/routes/index.mjs.map +1 -1
- package/dist/core-api/routes/validation/content-type.d.ts +13 -1
- package/dist/core-api/routes/validation/content-type.d.ts.map +1 -1
- package/dist/core-api/routes/validation/content-type.js +15 -2
- package/dist/core-api/routes/validation/content-type.js.map +1 -1
- package/dist/core-api/routes/validation/content-type.mjs +15 -2
- package/dist/core-api/routes/validation/content-type.mjs.map +1 -1
- package/dist/middlewares/session.d.ts +2 -2
- package/dist/middlewares/session.d.ts.map +1 -1
- package/dist/middlewares/session.js +1 -1
- package/dist/middlewares/session.js.map +1 -1
- package/dist/middlewares/session.mjs +2 -2
- package/dist/middlewares/session.mjs.map +1 -1
- package/dist/migrations/database/5.0.0-discard-drafts.d.ts +2 -1
- package/dist/migrations/database/5.0.0-discard-drafts.d.ts.map +1 -1
- package/dist/migrations/database/5.0.0-discard-drafts.js +41 -30
- package/dist/migrations/database/5.0.0-discard-drafts.js.map +1 -1
- package/dist/migrations/database/5.0.0-discard-drafts.mjs +41 -30
- package/dist/migrations/database/5.0.0-discard-drafts.mjs.map +1 -1
- package/dist/package.json.js +16 -15
- package/dist/package.json.js.map +1 -1
- package/dist/package.json.mjs +16 -15
- package/dist/package.json.mjs.map +1 -1
- package/dist/providers/index.d.ts.map +1 -1
- package/dist/providers/index.js +3 -1
- package/dist/providers/index.js.map +1 -1
- package/dist/providers/index.mjs +3 -1
- package/dist/providers/index.mjs.map +1 -1
- package/dist/providers/mcp.d.ts +3 -0
- package/dist/providers/mcp.d.ts.map +1 -0
- package/dist/providers/mcp.js +39 -0
- package/dist/providers/mcp.js.map +1 -0
- package/dist/providers/mcp.mjs +37 -0
- package/dist/providers/mcp.mjs.map +1 -0
- package/dist/providers/session-manager.d.ts.map +1 -1
- package/dist/providers/session-manager.js +3 -0
- package/dist/providers/session-manager.js.map +1 -1
- package/dist/providers/session-manager.mjs +3 -0
- package/dist/providers/session-manager.mjs.map +1 -1
- package/dist/services/ai.d.ts.map +1 -1
- package/dist/services/ai.js +3 -0
- package/dist/services/ai.js.map +1 -1
- package/dist/services/ai.mjs +3 -0
- package/dist/services/ai.mjs.map +1 -1
- package/dist/services/cron.d.ts +1 -1
- package/dist/services/cron.d.ts.map +1 -1
- package/dist/services/cron.js +10 -2
- package/dist/services/cron.js.map +1 -1
- package/dist/services/cron.mjs +10 -2
- package/dist/services/cron.mjs.map +1 -1
- package/dist/services/document-service/draft-and-publish.d.ts +2 -16
- package/dist/services/document-service/draft-and-publish.d.ts.map +1 -1
- package/dist/services/document-service/draft-and-publish.js +0 -53
- package/dist/services/document-service/draft-and-publish.js.map +1 -1
- package/dist/services/document-service/draft-and-publish.mjs +2 -53
- package/dist/services/document-service/draft-and-publish.mjs.map +1 -1
- package/dist/services/document-service/params.d.ts +2 -2
- package/dist/services/document-service/params.d.ts.map +1 -1
- package/dist/services/document-service/publication-filter.d.ts +6 -0
- package/dist/services/document-service/publication-filter.d.ts.map +1 -0
- package/dist/services/document-service/publication-filter.js +20 -0
- package/dist/services/document-service/publication-filter.js.map +1 -0
- package/dist/services/document-service/publication-filter.mjs +15 -0
- package/dist/services/document-service/publication-filter.mjs.map +1 -0
- package/dist/services/document-service/transform/query.d.ts +1 -1
- package/dist/services/document-service/transform/query.d.ts.map +1 -1
- package/dist/services/document-service/transform/query.js +32 -19
- package/dist/services/document-service/transform/query.js.map +1 -1
- package/dist/services/document-service/transform/query.mjs +33 -20
- package/dist/services/document-service/transform/query.mjs.map +1 -1
- package/dist/services/entity-validator/blocks-validator.js +1 -1
- package/dist/services/entity-validator/blocks-validator.js.map +1 -1
- package/dist/services/entity-validator/blocks-validator.mjs +1 -1
- package/dist/services/entity-validator/blocks-validator.mjs.map +1 -1
- package/dist/services/mcp/authentication.d.ts +23 -0
- package/dist/services/mcp/authentication.d.ts.map +1 -0
- package/dist/services/mcp/authentication.js +45 -0
- package/dist/services/mcp/authentication.js.map +1 -0
- package/dist/services/mcp/authentication.mjs +43 -0
- package/dist/services/mcp/authentication.mjs.map +1 -0
- package/dist/services/mcp/handlers/handlePost.d.ts +4 -0
- package/dist/services/mcp/handlers/handlePost.d.ts.map +1 -0
- package/dist/services/mcp/handlers/handlePost.js +59 -0
- package/dist/services/mcp/handlers/handlePost.js.map +1 -0
- package/dist/services/mcp/handlers/handlePost.mjs +57 -0
- package/dist/services/mcp/handlers/handlePost.mjs.map +1 -0
- package/dist/services/mcp/handlers/types.d.ts +12 -0
- package/dist/services/mcp/handlers/types.d.ts.map +1 -0
- package/dist/services/mcp/index.d.ts +6 -0
- package/dist/services/mcp/index.d.ts.map +1 -0
- package/dist/services/mcp/index.js +101 -0
- package/dist/services/mcp/index.js.map +1 -0
- package/dist/services/mcp/index.mjs +99 -0
- package/dist/services/mcp/index.mjs.map +1 -0
- package/dist/services/mcp/internal/McpCapabilityDefinitionRegistry.d.ts +13 -0
- package/dist/services/mcp/internal/McpCapabilityDefinitionRegistry.d.ts.map +1 -0
- package/dist/services/mcp/internal/McpCapabilityDefinitionRegistry.js +53 -0
- package/dist/services/mcp/internal/McpCapabilityDefinitionRegistry.js.map +1 -0
- package/dist/services/mcp/internal/McpCapabilityDefinitionRegistry.mjs +51 -0
- package/dist/services/mcp/internal/McpCapabilityDefinitionRegistry.mjs.map +1 -0
- package/dist/services/mcp/internal/McpCapabilityRegistry.d.ts +43 -0
- package/dist/services/mcp/internal/McpCapabilityRegistry.d.ts.map +1 -0
- package/dist/services/mcp/internal/McpCapabilityRegistry.js +108 -0
- package/dist/services/mcp/internal/McpCapabilityRegistry.js.map +1 -0
- package/dist/services/mcp/internal/McpCapabilityRegistry.mjs +106 -0
- package/dist/services/mcp/internal/McpCapabilityRegistry.mjs.map +1 -0
- package/dist/services/mcp/internal/McpConfiguration.d.ts +11 -0
- package/dist/services/mcp/internal/McpConfiguration.d.ts.map +1 -0
- package/dist/services/mcp/internal/McpConfiguration.js +34 -0
- package/dist/services/mcp/internal/McpConfiguration.js.map +1 -0
- package/dist/services/mcp/internal/McpConfiguration.mjs +32 -0
- package/dist/services/mcp/internal/McpConfiguration.mjs.map +1 -0
- package/dist/services/mcp/internal/McpServerFactory.d.ts +37 -0
- package/dist/services/mcp/internal/McpServerFactory.d.ts.map +1 -0
- package/dist/services/mcp/internal/McpServerFactory.js +71 -0
- package/dist/services/mcp/internal/McpServerFactory.js.map +1 -0
- package/dist/services/mcp/internal/McpServerFactory.mjs +69 -0
- package/dist/services/mcp/internal/McpServerFactory.mjs.map +1 -0
- package/dist/services/mcp/internal/syncMcpSessionCapabilities.d.ts +21 -0
- package/dist/services/mcp/internal/syncMcpSessionCapabilities.d.ts.map +1 -0
- package/dist/services/mcp/internal/syncMcpSessionCapabilities.js +76 -0
- package/dist/services/mcp/internal/syncMcpSessionCapabilities.js.map +1 -0
- package/dist/services/mcp/internal/syncMcpSessionCapabilities.mjs +73 -0
- package/dist/services/mcp/internal/syncMcpSessionCapabilities.mjs.map +1 -0
- package/dist/services/mcp/metrics/metrics.d.ts +29 -0
- package/dist/services/mcp/metrics/metrics.d.ts.map +1 -0
- package/dist/services/mcp/metrics/metrics.js +97 -0
- package/dist/services/mcp/metrics/metrics.js.map +1 -0
- package/dist/services/mcp/metrics/metrics.mjs +88 -0
- package/dist/services/mcp/metrics/metrics.mjs.map +1 -0
- package/dist/services/mcp/metrics/normalizeMcpCapability.d.ts +11 -0
- package/dist/services/mcp/metrics/normalizeMcpCapability.d.ts.map +1 -0
- package/dist/services/mcp/metrics/normalizeMcpCapability.js +10 -0
- package/dist/services/mcp/metrics/normalizeMcpCapability.js.map +1 -0
- package/dist/services/mcp/metrics/normalizeMcpCapability.mjs +8 -0
- package/dist/services/mcp/metrics/normalizeMcpCapability.mjs.map +1 -0
- package/dist/services/mcp/metrics/wrapCapabilityHandlerForMetrics.d.ts +4 -0
- package/dist/services/mcp/metrics/wrapCapabilityHandlerForMetrics.d.ts.map +1 -0
- package/dist/services/mcp/metrics/wrapCapabilityHandlerForMetrics.js +27 -0
- package/dist/services/mcp/metrics/wrapCapabilityHandlerForMetrics.js.map +1 -0
- package/dist/services/mcp/metrics/wrapCapabilityHandlerForMetrics.mjs +25 -0
- package/dist/services/mcp/metrics/wrapCapabilityHandlerForMetrics.mjs.map +1 -0
- package/dist/services/mcp/middleware/oauthDiscoveryFallback.d.ts +3 -0
- package/dist/services/mcp/middleware/oauthDiscoveryFallback.d.ts.map +1 -0
- package/dist/services/mcp/middleware/oauthDiscoveryFallback.js +47 -0
- package/dist/services/mcp/middleware/oauthDiscoveryFallback.js.map +1 -0
- package/dist/services/mcp/middleware/oauthDiscoveryFallback.mjs +45 -0
- package/dist/services/mcp/middleware/oauthDiscoveryFallback.mjs.map +1 -0
- package/dist/services/mcp/prompt-registry.d.ts +16 -0
- package/dist/services/mcp/prompt-registry.d.ts.map +1 -0
- package/dist/services/mcp/prompt-registry.js +77 -0
- package/dist/services/mcp/prompt-registry.js.map +1 -0
- package/dist/services/mcp/prompt-registry.mjs +75 -0
- package/dist/services/mcp/prompt-registry.mjs.map +1 -0
- package/dist/services/mcp/resource-registry.d.ts +14 -0
- package/dist/services/mcp/resource-registry.d.ts.map +1 -0
- package/dist/services/mcp/resource-registry.js +67 -0
- package/dist/services/mcp/resource-registry.js.map +1 -0
- package/dist/services/mcp/resource-registry.mjs +65 -0
- package/dist/services/mcp/resource-registry.mjs.map +1 -0
- package/dist/services/mcp/routes.d.ts +11 -0
- package/dist/services/mcp/routes.d.ts.map +1 -0
- package/dist/services/mcp/routes.js +58 -0
- package/dist/services/mcp/routes.js.map +1 -0
- package/dist/services/mcp/routes.mjs +56 -0
- package/dist/services/mcp/routes.mjs.map +1 -0
- package/dist/services/mcp/tool-registry.d.ts +25 -0
- package/dist/services/mcp/tool-registry.d.ts.map +1 -0
- package/dist/services/mcp/tool-registry.js +102 -0
- package/dist/services/mcp/tool-registry.js.map +1 -0
- package/dist/services/mcp/tool-registry.mjs +99 -0
- package/dist/services/mcp/tool-registry.mjs.map +1 -0
- package/dist/services/mcp/tools/log.d.ts +87 -0
- package/dist/services/mcp/tools/log.d.ts.map +1 -0
- package/dist/services/mcp/tools/log.js +88 -0
- package/dist/services/mcp/tools/log.js.map +1 -0
- package/dist/services/mcp/tools/log.mjs +86 -0
- package/dist/services/mcp/tools/log.mjs.map +1 -0
- package/dist/services/mcp/utils/createSafeCapabilityRegistration.d.ts +36 -0
- package/dist/services/mcp/utils/createSafeCapabilityRegistration.d.ts.map +1 -0
- package/dist/services/mcp/utils/createSafeCapabilityRegistration.js +59 -0
- package/dist/services/mcp/utils/createSafeCapabilityRegistration.js.map +1 -0
- package/dist/services/mcp/utils/createSafeCapabilityRegistration.mjs +56 -0
- package/dist/services/mcp/utils/createSafeCapabilityRegistration.mjs.map +1 -0
- package/dist/services/mcp/utils/jsonRpcErrors.d.ts +22 -0
- package/dist/services/mcp/utils/jsonRpcErrors.d.ts.map +1 -0
- package/dist/services/mcp/utils/jsonRpcErrors.js +25 -0
- package/dist/services/mcp/utils/jsonRpcErrors.js.map +1 -0
- package/dist/services/mcp/utils/jsonRpcErrors.mjs +23 -0
- package/dist/services/mcp/utils/jsonRpcErrors.mjs.map +1 -0
- package/dist/services/mcp/utils/safeHandlerWrapper.d.ts +18 -0
- package/dist/services/mcp/utils/safeHandlerWrapper.d.ts.map +1 -0
- package/dist/services/mcp/utils/safeHandlerWrapper.js +29 -0
- package/dist/services/mcp/utils/safeHandlerWrapper.js.map +1 -0
- package/dist/services/mcp/utils/safeHandlerWrapper.mjs +27 -0
- package/dist/services/mcp/utils/safeHandlerWrapper.mjs.map +1 -0
- package/dist/services/mcp/utils/sendJsonRpcError.d.ts +5 -0
- package/dist/services/mcp/utils/sendJsonRpcError.d.ts.map +1 -0
- package/dist/services/mcp/utils/sendJsonRpcError.js +23 -0
- package/dist/services/mcp/utils/sendJsonRpcError.js.map +1 -0
- package/dist/services/mcp/utils/sendJsonRpcError.mjs +21 -0
- package/dist/services/mcp/utils/sendJsonRpcError.mjs.map +1 -0
- package/dist/services/mcp/utils/withTimeout.d.ts +7 -0
- package/dist/services/mcp/utils/withTimeout.d.ts.map +1 -0
- package/dist/services/mcp/utils/withTimeout.js +23 -0
- package/dist/services/mcp/utils/withTimeout.js.map +1 -0
- package/dist/services/mcp/utils/withTimeout.mjs +21 -0
- package/dist/services/mcp/utils/withTimeout.mjs.map +1 -0
- package/dist/services/metrics/index.d.ts.map +1 -1
- package/dist/services/metrics/index.js +9 -6
- package/dist/services/metrics/index.js.map +1 -1
- package/dist/services/metrics/index.mjs +9 -6
- package/dist/services/metrics/index.mjs.map +1 -1
- package/dist/services/metrics/sender.d.ts.map +1 -1
- package/dist/services/metrics/sender.js +11 -3
- package/dist/services/metrics/sender.js.map +1 -1
- package/dist/services/metrics/sender.mjs +11 -3
- package/dist/services/metrics/sender.mjs.map +1 -1
- package/package.json +16 -15
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"blocks-validator.js","sources":["../../../src/services/entity-validator/blocks-validator.ts"],"sourcesContent":["import { yup } from '@strapi/utils';\n\nconst textNodeValidator = yup.object().shape({\n type: yup.string().equals(['text']).required(),\n text: yup\n .string()\n .test(\n 'is-valid-text',\n 'Text must be defined with at least an empty string',\n (text: unknown) => {\n return typeof text === 'string' || text === '';\n }\n ),\n bold: yup.boolean(),\n italic: yup.boolean(),\n underline: yup.boolean(),\n strikethrough: yup.boolean(),\n code: yup.boolean(),\n});\n\nconst checkValidLink = (link: string) => {\n try {\n // eslint-disable-next-line no-new\n new URL(link.startsWith('/') ? `https://strapi.io${link}` : link);\n } catch (error) {\n return false;\n }\n return true;\n};\n\nconst linkNodeValidator = yup.object().shape({\n type: yup.string().equals(['link']).required(),\n url: yup\n .string()\n .test('invalid-url', 'Please specify a valid link.', (value) => checkValidLink(value ?? '')),\n children: yup.array().of(textNodeValidator).required(),\n});\n\n// TODO: remove any with a correct Type\nconst inlineNodeValidator: any = yup.lazy((value: { type: string }) => {\n switch (value.type) {\n case 'text':\n return textNodeValidator;\n case 'link':\n return linkNodeValidator;\n default:\n return yup.mixed().test('invalid-type', 'Inline node must be Text or Link', () => {\n return false;\n });\n }\n});\n\nconst paragraphNodeValidator = yup.object().shape({\n type: yup.string().equals(['paragraph']).required(),\n children: yup\n .array()\n .of(inlineNodeValidator)\n .min(1, 'Paragraph node children must have at least one Text or Link node')\n .required(),\n});\n\nconst headingNodeValidator = yup.object().shape({\n type: yup.string().equals(['heading']).required(),\n level: yup.number().oneOf([1, 2, 3, 4, 5, 6]).required(),\n children: yup\n .array()\n .of(inlineNodeValidator)\n .min(1, 'Heading node children must have at least one Text or Link node')\n .required(),\n});\n\nconst quoteNodeValidator = yup.object().shape({\n type: yup.string().equals(['quote']).required(),\n children: yup\n .array()\n .of(inlineNodeValidator)\n .min(1, 'Quote node children must have at least one Text or Link node')\n .required(),\n});\n\nconst codeBlockValidator = yup.object().shape({\n type: yup.string().equals(['code']).required(),\n syntax: yup.string().nullable(),\n children: yup\n .array()\n .of(textNodeValidator)\n .min(1, 'Quote node children must have at least one Text or Link node')\n .required(),\n});\n\nconst listItemNode = yup.object().shape({\n type: yup.string().equals(['list-item']).required(),\n children: yup.array().of(inlineNodeValidator).required(),\n});\n\n// Allow children to be either a listItemNode or a listNode itself\n// @ts-expect-error - listChildrenValidator needs a type\nconst listChildrenValidator = yup.lazy((value: { type: string }) => {\n switch (value.type) {\n case 'list':\n return listNodeValidator;\n case 'list-item':\n return listItemNode;\n default:\n return yup.mixed().test('invalid-type', 'Inline node must be list-item or list', () => {\n return false;\n });\n }\n});\n\n// @ts-expect-error - listNodeValidator needs a type\nconst listNodeValidator = yup.object().shape({\n type: yup.string().equals(['list']).required(),\n format: yup.string().equals(['ordered', 'unordered']).required(),\n children: yup\n .array()\n .of(listChildrenValidator)\n .min(1, 'List node children must have at least one ListItem or ListNode')\n .required(),\n});\n\nconst imageNodeValidator = yup.object().shape({\n type: yup.string().equals(['image']).required(),\n image: yup.object().shape({\n name: yup.string().required(),\n alternativeText: yup.string().nullable(),\n url: yup.string().required(),\n caption: yup.string().nullable(),\n width: yup.number().required(),\n height: yup.number().required(),\n formats: yup.object().nullable(),\n hash: yup.string().required(),\n ext: yup.string().required(),\n mime: yup.string().required(),\n size: yup.number().required(),\n previewUrl: yup.string().nullable(),\n provider: yup.string().required(),\n provider_metadata: yup.mixed().nullable(),\n createdAt: yup.string().required(),\n updatedAt: yup.string().required(),\n }),\n children: yup.array().of(inlineNodeValidator).required(),\n});\n\n// TODO: remove the any and replace with a correct Type\nconst blockNodeValidator: any = yup.lazy((value: { type: string }) => {\n switch (value.type) {\n case 'paragraph':\n return paragraphNodeValidator;\n case 'heading':\n return headingNodeValidator;\n case 'quote':\n return quoteNodeValidator;\n case 'list':\n return listNodeValidator;\n case 'image':\n return imageNodeValidator;\n case 'code':\n return codeBlockValidator;\n default:\n return yup.mixed().test('invalid-type', 'Block node is of invalid type', () => {\n return false;\n });\n }\n});\n\nconst blocksValidatorSchema = yup.array().of(blockNodeValidator);\n\nexport const blocksValidator = () => blocksValidatorSchema;\n"],"names":["textNodeValidator","yup","object","shape","type","string","equals","required","text","test","bold","boolean","italic","underline","strikethrough","code","checkValidLink","link","URL","startsWith","error","linkNodeValidator","url","value","children","array","of","inlineNodeValidator","lazy","mixed","paragraphNodeValidator","min","headingNodeValidator","level","number","oneOf","quoteNodeValidator","codeBlockValidator","syntax","nullable","listItemNode","listChildrenValidator","listNodeValidator","format","imageNodeValidator","image","name","alternativeText","caption","width","height","formats","hash","ext","mime","size","previewUrl","provider","provider_metadata","createdAt","updatedAt","blockNodeValidator","blocksValidatorSchema","blocksValidator"],"mappings":";;;;AAEA,MAAMA,iBAAAA,GAAoBC,eAAAA,CAAIC,MAAM,EAAA,CAAGC,KAAK,CAAC;AAC3CC,IAAAA,IAAAA,EAAMH,eAAAA,CAAII,MAAM,EAAA,CAAGC,MAAM,CAAC;AAAC,QAAA;AAAO,KAAA,CAAA,CAAEC,QAAQ,EAAA;AAC5CC,IAAAA,IAAAA,EAAMP,gBACHI,MAAM,EAAA,CACNI,IAAI,CACH,eAAA,EACA,sDACA,CAACD,IAAAA,GAAAA;QACC,OAAO,OAAOA,IAAAA,KAAS,QAAA,IAAYA,IAAAA,KAAS,EAAA;AAC9C,IAAA,CAAA,CAAA;AAEJE,IAAAA,IAAAA,EAAMT,gBAAIU,OAAO,EAAA;AACjBC,IAAAA,MAAAA,EAAQX,gBAAIU,OAAO,EAAA;AACnBE,IAAAA,SAAAA,EAAWZ,gBAAIU,OAAO,EAAA;AACtBG,IAAAA,aAAAA,EAAeb,gBAAIU,OAAO,EAAA;AAC1BI,IAAAA,IAAAA,EAAMd,gBAAIU,OAAO;AACnB,CAAA,CAAA;AAEA,MAAMK,iBAAiB,CAACC,IAAAA,GAAAA;IACtB,IAAI;;QAEF,IAAIC,GAAAA,CAAID,KAAKE,UAAU,CAAC,OAAO,CAAC,iBAAiB,EAAEF,IAAAA,CAAAA,CAAM,GAAGA,IAAAA,CAAAA;AAC9D,IAAA,CAAA,CAAE,OAAOG,KAAAA,EAAO;QACd,OAAO,KAAA;AACT,IAAA;IACA,OAAO,IAAA;AACT,CAAA;AAEA,MAAMC,iBAAAA,GAAoBpB,eAAAA,CAAIC,MAAM,EAAA,CAAGC,KAAK,CAAC;AAC3CC,IAAAA,IAAAA,EAAMH,eAAAA,CAAII,MAAM,EAAA,CAAGC,MAAM,CAAC;AAAC,QAAA;AAAO,KAAA,CAAA,CAAEC,QAAQ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;AAClC,KAAA,CAAA;AACAiB,IAAAA,QAAAA,EAAUvB,gBAAIwB,KAAK,EAAA,CAAGC,EAAE,CAACC,qBAAqBpB,QAAQ;AACxD,CAAA,CAAA;AAEA;AACA,MAAMsD,kBAAAA,GAA0B5D,eAAAA,CAAI2B,IAAI,CAAC,CAACL,KAAAA,GAAAA;AACxC,IAAA,OAAQA,MAAMnB,IAAI;QAChB,KAAK,WAAA;YACH,OAAO0B,sBAAAA;QACT,KAAK,SAAA;YACH,OAAOE,oBAAAA;QACT,KAAK,OAAA;YACH,OAAOI,kBAAAA;QACT,KAAK,MAAA;YACH,OAAOM,iBAAAA;QACT,KAAK,OAAA;YACH,OAAOE,kBAAAA;QACT,KAAK,MAAA;YACH,OAAOP,kBAAAA;AACT,QAAA;AACE,YAAA,OAAOpC,gBAAI4B,KAAK,EAAA,CAAGpB,IAAI,CAAC,gBAAgB,+BAAA,EAAiC,IAAA;gBACvE,OAAO,KAAA;AACT,YAAA,CAAA,CAAA;AACJ;AACF,CAAA,CAAA;AAEA,MAAMqD,qBAAAA,GAAwB7D,eAAAA,CAAIwB,KAAK,EAAA,CAAGC,EAAE,CAACmC,kBAAAA,CAAAA;AAEtC,MAAME,eAAAA,GAAkB,IAAMD;;;;"}
|
|
1
|
+
{"version":3,"file":"blocks-validator.js","sources":["../../../src/services/entity-validator/blocks-validator.ts"],"sourcesContent":["import { yup } from '@strapi/utils';\n\nconst textNodeValidator = yup.object().shape({\n type: yup.string().equals(['text']).required(),\n text: yup\n .string()\n .test(\n 'is-valid-text',\n 'Text must be defined with at least an empty string',\n (text: unknown) => {\n return typeof text === 'string' || text === '';\n }\n ),\n bold: yup.boolean(),\n italic: yup.boolean(),\n underline: yup.boolean(),\n strikethrough: yup.boolean(),\n code: yup.boolean(),\n});\n\nconst checkValidLink = (link: string) => {\n try {\n // eslint-disable-next-line no-new\n new URL(link.startsWith('/') ? `https://strapi.io${link}` : link);\n } catch (error) {\n return false;\n }\n return true;\n};\n\nconst linkNodeValidator = yup.object().shape({\n type: yup.string().equals(['link']).required(),\n url: yup\n .string()\n .test('invalid-url', 'Please specify a valid link.', (value) => checkValidLink(value ?? '')),\n children: yup.array().of(textNodeValidator).required(),\n});\n\n// TODO: remove any with a correct Type\nconst inlineNodeValidator: any = yup.lazy((value: { type: string }) => {\n switch (value.type) {\n case 'text':\n return textNodeValidator;\n case 'link':\n return linkNodeValidator;\n default:\n return yup.mixed().test('invalid-type', 'Inline node must be Text or Link', () => {\n return false;\n });\n }\n});\n\nconst paragraphNodeValidator = yup.object().shape({\n type: yup.string().equals(['paragraph']).required(),\n children: yup\n .array()\n .of(inlineNodeValidator)\n .min(1, 'Paragraph node children must have at least one Text or Link node')\n .required(),\n});\n\nconst headingNodeValidator = yup.object().shape({\n type: yup.string().equals(['heading']).required(),\n level: yup.number().oneOf([1, 2, 3, 4, 5, 6]).required(),\n children: yup\n .array()\n .of(inlineNodeValidator)\n .min(1, 'Heading node children must have at least one Text or Link node')\n .required(),\n});\n\nconst quoteNodeValidator = yup.object().shape({\n type: yup.string().equals(['quote']).required(),\n children: yup\n .array()\n .of(inlineNodeValidator)\n .min(1, 'Quote node children must have at least one Text or Link node')\n .required(),\n});\n\nconst codeBlockValidator = yup.object().shape({\n type: yup.string().equals(['code']).required(),\n language: yup.string().nullable(),\n children: yup\n .array()\n .of(textNodeValidator)\n .min(1, 'Quote node children must have at least one Text or Link node')\n .required(),\n});\n\nconst listItemNode = yup.object().shape({\n type: yup.string().equals(['list-item']).required(),\n children: yup.array().of(inlineNodeValidator).required(),\n});\n\n// Allow children to be either a listItemNode or a listNode itself\n// @ts-expect-error - listChildrenValidator needs a type\nconst listChildrenValidator = yup.lazy((value: { type: string }) => {\n switch (value.type) {\n case 'list':\n return listNodeValidator;\n case 'list-item':\n return listItemNode;\n default:\n return yup.mixed().test('invalid-type', 'Inline node must be list-item or list', () => {\n return false;\n });\n }\n});\n\n// @ts-expect-error - listNodeValidator needs a type\nconst listNodeValidator = yup.object().shape({\n type: yup.string().equals(['list']).required(),\n format: yup.string().equals(['ordered', 'unordered']).required(),\n children: yup\n .array()\n .of(listChildrenValidator)\n .min(1, 'List node children must have at least one ListItem or ListNode')\n .required(),\n});\n\nconst imageNodeValidator = yup.object().shape({\n type: yup.string().equals(['image']).required(),\n image: yup.object().shape({\n name: yup.string().required(),\n alternativeText: yup.string().nullable(),\n url: yup.string().required(),\n caption: yup.string().nullable(),\n width: yup.number().required(),\n height: yup.number().required(),\n formats: yup.object().nullable(),\n hash: yup.string().required(),\n ext: yup.string().required(),\n mime: yup.string().required(),\n size: yup.number().required(),\n previewUrl: yup.string().nullable(),\n provider: yup.string().required(),\n provider_metadata: yup.mixed().nullable(),\n createdAt: yup.string().required(),\n updatedAt: yup.string().required(),\n }),\n children: yup.array().of(inlineNodeValidator).required(),\n});\n\n// TODO: remove the any and replace with a correct Type\nconst blockNodeValidator: any = yup.lazy((value: { type: string }) => {\n switch (value.type) {\n case 'paragraph':\n return paragraphNodeValidator;\n case 'heading':\n return headingNodeValidator;\n case 'quote':\n return quoteNodeValidator;\n case 'list':\n return listNodeValidator;\n case 'image':\n return imageNodeValidator;\n case 'code':\n return codeBlockValidator;\n default:\n return yup.mixed().test('invalid-type', 'Block node is of invalid type', () => {\n return false;\n });\n }\n});\n\nconst blocksValidatorSchema = yup.array().of(blockNodeValidator);\n\nexport const blocksValidator = () => blocksValidatorSchema;\n"],"names":["textNodeValidator","yup","object","shape","type","string","equals","required","text","test","bold","boolean","italic","underline","strikethrough","code","checkValidLink","link","URL","startsWith","error","linkNodeValidator","url","value","children","array","of","inlineNodeValidator","lazy","mixed","paragraphNodeValidator","min","headingNodeValidator","level","number","oneOf","quoteNodeValidator","codeBlockValidator","language","nullable","listItemNode","listChildrenValidator","listNodeValidator","format","imageNodeValidator","image","name","alternativeText","caption","width","height","formats","hash","ext","mime","size","previewUrl","provider","provider_metadata","createdAt","updatedAt","blockNodeValidator","blocksValidatorSchema","blocksValidator"],"mappings":";;;;AAEA,MAAMA,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;AAEA;AACA,MAAMsD,kBAAAA,GAA0B5D,eAAAA,CAAI2B,IAAI,CAAC,CAACL,KAAAA,GAAAA;AACxC,IAAA,OAAQA,MAAMnB,IAAI;QAChB,KAAK,WAAA;YACH,OAAO0B,sBAAAA;QACT,KAAK,SAAA;YACH,OAAOE,oBAAAA;QACT,KAAK,OAAA;YACH,OAAOI,kBAAAA;QACT,KAAK,MAAA;YACH,OAAOM,iBAAAA;QACT,KAAK,OAAA;YACH,OAAOE,kBAAAA;QACT,KAAK,MAAA;YACH,OAAOP,kBAAAA;AACT,QAAA;AACE,YAAA,OAAOpC,gBAAI4B,KAAK,EAAA,CAAGpB,IAAI,CAAC,gBAAgB,+BAAA,EAAiC,IAAA;gBACvE,OAAO,KAAA;AACT,YAAA,CAAA,CAAA;AACJ;AACF,CAAA,CAAA;AAEA,MAAMqD,qBAAAA,GAAwB7D,eAAAA,CAAIwB,KAAK,EAAA,CAAGC,EAAE,CAACmC,kBAAAA,CAAAA;AAEtC,MAAME,eAAAA,GAAkB,IAAMD;;;;"}
|
|
@@ -72,7 +72,7 @@ const codeBlockValidator = yup.object().shape({
|
|
|
72
72
|
type: yup.string().equals([
|
|
73
73
|
'code'
|
|
74
74
|
]).required(),
|
|
75
|
-
|
|
75
|
+
language: yup.string().nullable(),
|
|
76
76
|
children: yup.array().of(textNodeValidator).min(1, 'Quote node children must have at least one Text or Link node').required()
|
|
77
77
|
});
|
|
78
78
|
const listItemNode = yup.object().shape({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"blocks-validator.mjs","sources":["../../../src/services/entity-validator/blocks-validator.ts"],"sourcesContent":["import { yup } from '@strapi/utils';\n\nconst textNodeValidator = yup.object().shape({\n type: yup.string().equals(['text']).required(),\n text: yup\n .string()\n .test(\n 'is-valid-text',\n 'Text must be defined with at least an empty string',\n (text: unknown) => {\n return typeof text === 'string' || text === '';\n }\n ),\n bold: yup.boolean(),\n italic: yup.boolean(),\n underline: yup.boolean(),\n strikethrough: yup.boolean(),\n code: yup.boolean(),\n});\n\nconst checkValidLink = (link: string) => {\n try {\n // eslint-disable-next-line no-new\n new URL(link.startsWith('/') ? `https://strapi.io${link}` : link);\n } catch (error) {\n return false;\n }\n return true;\n};\n\nconst linkNodeValidator = yup.object().shape({\n type: yup.string().equals(['link']).required(),\n url: yup\n .string()\n .test('invalid-url', 'Please specify a valid link.', (value) => checkValidLink(value ?? '')),\n children: yup.array().of(textNodeValidator).required(),\n});\n\n// TODO: remove any with a correct Type\nconst inlineNodeValidator: any = yup.lazy((value: { type: string }) => {\n switch (value.type) {\n case 'text':\n return textNodeValidator;\n case 'link':\n return linkNodeValidator;\n default:\n return yup.mixed().test('invalid-type', 'Inline node must be Text or Link', () => {\n return false;\n });\n }\n});\n\nconst paragraphNodeValidator = yup.object().shape({\n type: yup.string().equals(['paragraph']).required(),\n children: yup\n .array()\n .of(inlineNodeValidator)\n .min(1, 'Paragraph node children must have at least one Text or Link node')\n .required(),\n});\n\nconst headingNodeValidator = yup.object().shape({\n type: yup.string().equals(['heading']).required(),\n level: yup.number().oneOf([1, 2, 3, 4, 5, 6]).required(),\n children: yup\n .array()\n .of(inlineNodeValidator)\n .min(1, 'Heading node children must have at least one Text or Link node')\n .required(),\n});\n\nconst quoteNodeValidator = yup.object().shape({\n type: yup.string().equals(['quote']).required(),\n children: yup\n .array()\n .of(inlineNodeValidator)\n .min(1, 'Quote node children must have at least one Text or Link node')\n .required(),\n});\n\nconst codeBlockValidator = yup.object().shape({\n type: yup.string().equals(['code']).required(),\n syntax: yup.string().nullable(),\n children: yup\n .array()\n .of(textNodeValidator)\n .min(1, 'Quote node children must have at least one Text or Link node')\n .required(),\n});\n\nconst listItemNode = yup.object().shape({\n type: yup.string().equals(['list-item']).required(),\n children: yup.array().of(inlineNodeValidator).required(),\n});\n\n// Allow children to be either a listItemNode or a listNode itself\n// @ts-expect-error - listChildrenValidator needs a type\nconst listChildrenValidator = yup.lazy((value: { type: string }) => {\n switch (value.type) {\n case 'list':\n return listNodeValidator;\n case 'list-item':\n return listItemNode;\n default:\n return yup.mixed().test('invalid-type', 'Inline node must be list-item or list', () => {\n return false;\n });\n }\n});\n\n// @ts-expect-error - listNodeValidator needs a type\nconst listNodeValidator = yup.object().shape({\n type: yup.string().equals(['list']).required(),\n format: yup.string().equals(['ordered', 'unordered']).required(),\n children: yup\n .array()\n .of(listChildrenValidator)\n .min(1, 'List node children must have at least one ListItem or ListNode')\n .required(),\n});\n\nconst imageNodeValidator = yup.object().shape({\n type: yup.string().equals(['image']).required(),\n image: yup.object().shape({\n name: yup.string().required(),\n alternativeText: yup.string().nullable(),\n url: yup.string().required(),\n caption: yup.string().nullable(),\n width: yup.number().required(),\n height: yup.number().required(),\n formats: yup.object().nullable(),\n hash: yup.string().required(),\n ext: yup.string().required(),\n mime: yup.string().required(),\n size: yup.number().required(),\n previewUrl: yup.string().nullable(),\n provider: yup.string().required(),\n provider_metadata: yup.mixed().nullable(),\n createdAt: yup.string().required(),\n updatedAt: yup.string().required(),\n }),\n children: yup.array().of(inlineNodeValidator).required(),\n});\n\n// TODO: remove the any and replace with a correct Type\nconst blockNodeValidator: any = yup.lazy((value: { type: string }) => {\n switch (value.type) {\n case 'paragraph':\n return paragraphNodeValidator;\n case 'heading':\n return headingNodeValidator;\n case 'quote':\n return quoteNodeValidator;\n case 'list':\n return listNodeValidator;\n case 'image':\n return imageNodeValidator;\n case 'code':\n return codeBlockValidator;\n default:\n return yup.mixed().test('invalid-type', 'Block node is of invalid type', () => {\n return false;\n });\n }\n});\n\nconst blocksValidatorSchema = yup.array().of(blockNodeValidator);\n\nexport const blocksValidator = () => blocksValidatorSchema;\n"],"names":["textNodeValidator","yup","object","shape","type","string","equals","required","text","test","bold","boolean","italic","underline","strikethrough","code","checkValidLink","link","URL","startsWith","error","linkNodeValidator","url","value","children","array","of","inlineNodeValidator","lazy","mixed","paragraphNodeValidator","min","headingNodeValidator","level","number","oneOf","quoteNodeValidator","codeBlockValidator","syntax","nullable","listItemNode","listChildrenValidator","listNodeValidator","format","imageNodeValidator","image","name","alternativeText","caption","width","height","formats","hash","ext","mime","size","previewUrl","provider","provider_metadata","createdAt","updatedAt","blockNodeValidator","blocksValidatorSchema","blocksValidator"],"mappings":";;AAEA,MAAMA,iBAAAA,GAAoBC,GAAAA,CAAIC,MAAM,EAAA,CAAGC,KAAK,CAAC;AAC3CC,IAAAA,IAAAA,EAAMH,GAAAA,CAAII,MAAM,EAAA,CAAGC,MAAM,CAAC;AAAC,QAAA;AAAO,KAAA,CAAA,CAAEC,QAAQ,EAAA;AAC5CC,IAAAA,IAAAA,EAAMP,IACHI,MAAM,EAAA,CACNI,IAAI,CACH,eAAA,EACA,sDACA,CAACD,IAAAA,GAAAA;QACC,OAAO,OAAOA,IAAAA,KAAS,QAAA,IAAYA,IAAAA,KAAS,EAAA;AAC9C,IAAA,CAAA,CAAA;AAEJE,IAAAA,IAAAA,EAAMT,IAAIU,OAAO,EAAA;AACjBC,IAAAA,MAAAA,EAAQX,IAAIU,OAAO,EAAA;AACnBE,IAAAA,SAAAA,EAAWZ,IAAIU,OAAO,EAAA;AACtBG,IAAAA,aAAAA,EAAeb,IAAIU,OAAO,EAAA;AAC1BI,IAAAA,IAAAA,EAAMd,IAAIU,OAAO;AACnB,CAAA,CAAA;AAEA,MAAMK,iBAAiB,CAACC,IAAAA,GAAAA;IACtB,IAAI;;QAEF,IAAIC,GAAAA,CAAID,KAAKE,UAAU,CAAC,OAAO,CAAC,iBAAiB,EAAEF,IAAAA,CAAAA,CAAM,GAAGA,IAAAA,CAAAA;AAC9D,IAAA,CAAA,CAAE,OAAOG,KAAAA,EAAO;QACd,OAAO,KAAA;AACT,IAAA;IACA,OAAO,IAAA;AACT,CAAA;AAEA,MAAMC,iBAAAA,GAAoBpB,GAAAA,CAAIC,MAAM,EAAA,CAAGC,KAAK,CAAC;AAC3CC,IAAAA,IAAAA,EAAMH,GAAAA,CAAII,MAAM,EAAA,CAAGC,MAAM,CAAC;AAAC,QAAA;A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AAM,EAAA,CAAGE,QAAQ;AAClC,KAAA,CAAA;AACAiB,IAAAA,QAAAA,EAAUvB,IAAIwB,KAAK,EAAA,CAAGC,EAAE,CAACC,qBAAqBpB,QAAQ;AACxD,CAAA,CAAA;AAEA;AACA,MAAMsD,kBAAAA,GAA0B5D,GAAAA,CAAI2B,IAAI,CAAC,CAACL,KAAAA,GAAAA;AACxC,IAAA,OAAQA,MAAMnB,IAAI;QAChB,KAAK,WAAA;YACH,OAAO0B,sBAAAA;QACT,KAAK,SAAA;YACH,OAAOE,oBAAAA;QACT,KAAK,OAAA;YACH,OAAOI,kBAAAA;QACT,KAAK,MAAA;YACH,OAAOM,iBAAAA;QACT,KAAK,OAAA;YACH,OAAOE,kBAAAA;QACT,KAAK,MAAA;YACH,OAAOP,kBAAAA;AACT,QAAA;AACE,YAAA,OAAOpC,IAAI4B,KAAK,EAAA,CAAGpB,IAAI,CAAC,gBAAgB,+BAAA,EAAiC,IAAA;gBACvE,OAAO,KAAA;AACT,YAAA,CAAA,CAAA;AACJ;AACF,CAAA,CAAA;AAEA,MAAMqD,qBAAAA,GAAwB7D,GAAAA,CAAIwB,KAAK,EAAA,CAAGC,EAAE,CAACmC,kBAAAA,CAAAA;AAEtC,MAAME,eAAAA,GAAkB,IAAMD;;;;"}
|
|
1
|
+
{"version":3,"file":"blocks-validator.mjs","sources":["../../../src/services/entity-validator/blocks-validator.ts"],"sourcesContent":["import { yup } from '@strapi/utils';\n\nconst textNodeValidator = yup.object().shape({\n type: yup.string().equals(['text']).required(),\n text: yup\n .string()\n .test(\n 'is-valid-text',\n 'Text must be defined with at least an empty string',\n (text: unknown) => {\n return typeof text === 'string' || text === '';\n }\n ),\n bold: yup.boolean(),\n italic: yup.boolean(),\n underline: yup.boolean(),\n strikethrough: yup.boolean(),\n code: yup.boolean(),\n});\n\nconst checkValidLink = (link: string) => {\n try {\n // eslint-disable-next-line no-new\n new URL(link.startsWith('/') ? `https://strapi.io${link}` : link);\n } catch (error) {\n return false;\n }\n return true;\n};\n\nconst linkNodeValidator = yup.object().shape({\n type: yup.string().equals(['link']).required(),\n url: yup\n .string()\n .test('invalid-url', 'Please specify a valid link.', (value) => checkValidLink(value ?? '')),\n children: yup.array().of(textNodeValidator).required(),\n});\n\n// TODO: remove any with a correct Type\nconst inlineNodeValidator: any = yup.lazy((value: { type: string }) => {\n switch (value.type) {\n case 'text':\n return textNodeValidator;\n case 'link':\n return linkNodeValidator;\n default:\n return yup.mixed().test('invalid-type', 'Inline node must be Text or Link', () => {\n return false;\n });\n }\n});\n\nconst paragraphNodeValidator = yup.object().shape({\n type: yup.string().equals(['paragraph']).required(),\n children: yup\n .array()\n .of(inlineNodeValidator)\n .min(1, 'Paragraph node children must have at least one Text or Link node')\n .required(),\n});\n\nconst headingNodeValidator = yup.object().shape({\n type: yup.string().equals(['heading']).required(),\n level: yup.number().oneOf([1, 2, 3, 4, 5, 6]).required(),\n children: yup\n .array()\n .of(inlineNodeValidator)\n .min(1, 'Heading node children must have at least one Text or Link node')\n .required(),\n});\n\nconst quoteNodeValidator = yup.object().shape({\n type: yup.string().equals(['quote']).required(),\n children: yup\n .array()\n .of(inlineNodeValidator)\n .min(1, 'Quote node children must have at least one Text or Link node')\n .required(),\n});\n\nconst codeBlockValidator = yup.object().shape({\n type: yup.string().equals(['code']).required(),\n language: yup.string().nullable(),\n children: yup\n .array()\n .of(textNodeValidator)\n .min(1, 'Quote node children must have at least one Text or Link node')\n .required(),\n});\n\nconst listItemNode = yup.object().shape({\n type: yup.string().equals(['list-item']).required(),\n children: yup.array().of(inlineNodeValidator).required(),\n});\n\n// Allow children to be either a listItemNode or a listNode itself\n// @ts-expect-error - listChildrenValidator needs a type\nconst listChildrenValidator = yup.lazy((value: { type: string }) => {\n switch (value.type) {\n case 'list':\n return listNodeValidator;\n case 'list-item':\n return listItemNode;\n default:\n return yup.mixed().test('invalid-type', 'Inline node must be list-item or list', () => {\n return false;\n });\n }\n});\n\n// @ts-expect-error - listNodeValidator needs a type\nconst listNodeValidator = yup.object().shape({\n type: yup.string().equals(['list']).required(),\n format: yup.string().equals(['ordered', 'unordered']).required(),\n children: yup\n .array()\n .of(listChildrenValidator)\n .min(1, 'List node children must have at least one ListItem or ListNode')\n .required(),\n});\n\nconst imageNodeValidator = yup.object().shape({\n type: yup.string().equals(['image']).required(),\n image: yup.object().shape({\n name: yup.string().required(),\n alternativeText: yup.string().nullable(),\n url: yup.string().required(),\n caption: yup.string().nullable(),\n width: yup.number().required(),\n height: yup.number().required(),\n formats: yup.object().nullable(),\n hash: yup.string().required(),\n ext: yup.string().required(),\n mime: yup.string().required(),\n size: yup.number().required(),\n previewUrl: yup.string().nullable(),\n provider: yup.string().required(),\n provider_metadata: yup.mixed().nullable(),\n createdAt: yup.string().required(),\n updatedAt: yup.string().required(),\n }),\n children: yup.array().of(inlineNodeValidator).required(),\n});\n\n// TODO: remove the any and replace with a correct Type\nconst blockNodeValidator: any = yup.lazy((value: { type: string }) => {\n switch (value.type) {\n case 'paragraph':\n return paragraphNodeValidator;\n case 'heading':\n return headingNodeValidator;\n case 'quote':\n return quoteNodeValidator;\n case 'list':\n return listNodeValidator;\n case 'image':\n return imageNodeValidator;\n case 'code':\n return codeBlockValidator;\n default:\n return yup.mixed().test('invalid-type', 'Block node is of invalid type', () => {\n return false;\n });\n }\n});\n\nconst blocksValidatorSchema = yup.array().of(blockNodeValidator);\n\nexport const blocksValidator = () => blocksValidatorSchema;\n"],"names":["textNodeValidator","yup","object","shape","type","string","equals","required","text","test","bold","boolean","italic","underline","strikethrough","code","checkValidLink","link","URL","startsWith","error","linkNodeValidator","url","value","children","array","of","inlineNodeValidator","lazy","mixed","paragraphNodeValidator","min","headingNodeValidator","level","number","oneOf","quoteNodeValidator","codeBlockValidator","language","nullable","listItemNode","listChildrenValidator","listNodeValidator","format","imageNodeValidator","image","name","alternativeText","caption","width","height","formats","hash","ext","mime","size","previewUrl","provider","provider_metadata","createdAt","updatedAt","blockNodeValidator","blocksValidatorSchema","blocksValidator"],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AA,CAAA;AAEA;AACA,MAAMsD,kBAAAA,GAA0B5D,GAAAA,CAAI2B,IAAI,CAAC,CAACL,KAAAA,GAAAA;AACxC,IAAA,OAAQA,MAAMnB,IAAI;QAChB,KAAK,WAAA;YACH,OAAO0B,sBAAAA;QACT,KAAK,SAAA;YACH,OAAOE,oBAAAA;QACT,KAAK,OAAA;YACH,OAAOI,kBAAAA;QACT,KAAK,MAAA;YACH,OAAOM,iBAAAA;QACT,KAAK,OAAA;YACH,OAAOE,kBAAAA;QACT,KAAK,MAAA;YACH,OAAOP,kBAAAA;AACT,QAAA;AACE,YAAA,OAAOpC,IAAI4B,KAAK,EAAA,CAAGpB,IAAI,CAAC,gBAAgB,+BAAA,EAAiC,IAAA;gBACvE,OAAO,KAAA;AACT,YAAA,CAAA,CAAA;AACJ;AACF,CAAA,CAAA;AAEA,MAAMqD,qBAAAA,GAAwB7D,GAAAA,CAAIwB,KAAK,EAAA,CAAGC,EAAE,CAACmC,kBAAAA,CAAAA;AAEtC,MAAME,eAAAA,GAAkB,IAAMD;;;;"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { Core, Data } from '@strapi/types';
|
|
2
|
+
import type { Ability } from '@casl/ability';
|
|
3
|
+
import type { Context } from 'koa';
|
|
4
|
+
export type McpAdminTokenAbility = Ability;
|
|
5
|
+
export type McpAuthFailureReason = 'missing_token' | 'invalid_token';
|
|
6
|
+
export type McpAdminTokenAuthResult = {
|
|
7
|
+
authenticated: false;
|
|
8
|
+
reason: McpAuthFailureReason;
|
|
9
|
+
error?: Error;
|
|
10
|
+
} | {
|
|
11
|
+
authenticated: true;
|
|
12
|
+
credentials: {
|
|
13
|
+
id: Data.ID;
|
|
14
|
+
};
|
|
15
|
+
user: {
|
|
16
|
+
id: Data.ID;
|
|
17
|
+
};
|
|
18
|
+
ability: McpAdminTokenAbility;
|
|
19
|
+
};
|
|
20
|
+
export declare const createMcpAdminTokenAuthenticator: (strapi: Core.Strapi) => {
|
|
21
|
+
authenticate(ctx: Context): Promise<McpAdminTokenAuthResult>;
|
|
22
|
+
};
|
|
23
|
+
//# sourceMappingURL=authentication.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authentication.d.ts","sourceRoot":"","sources":["../../../src/services/mcp/authentication.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,KAAK,CAAC;AAEnC,MAAM,MAAM,oBAAoB,GAAG,OAAO,CAAC;AAE3C,MAAM,MAAM,oBAAoB,GAAG,eAAe,GAAG,eAAe,CAAC;AAErE,MAAM,MAAM,uBAAuB,GAC/B;IAAE,aAAa,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE,oBAAoB,CAAC;IAAC,KAAK,CAAC,EAAE,KAAK,CAAA;CAAE,GACrE;IACE,aAAa,EAAE,IAAI,CAAC;IACpB,WAAW,EAAE;QAAE,EAAE,EAAE,IAAI,CAAC,EAAE,CAAA;KAAE,CAAC;IAC7B,IAAI,EAAE;QAAE,EAAE,EAAE,IAAI,CAAC,EAAE,CAAA;KAAE,CAAC;IACtB,OAAO,EAAE,oBAAoB,CAAC;CAC/B,CAAC;AAkBN,eAAO,MAAM,gCAAgC,WAAY,KAAK,MAAM;sBAC1C,OAAO,GAAG,QAAQ,uBAAuB,CAAC;CA0BlE,CAAC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const extractBearerToken = (ctx)=>{
|
|
4
|
+
const authorization = ctx.request.header.authorization;
|
|
5
|
+
if (authorization === undefined) {
|
|
6
|
+
return null;
|
|
7
|
+
}
|
|
8
|
+
const parts = authorization.split(/\s+/);
|
|
9
|
+
if (parts[0].toLowerCase() !== 'bearer' || parts.length !== 2) {
|
|
10
|
+
return null;
|
|
11
|
+
}
|
|
12
|
+
return parts[1];
|
|
13
|
+
};
|
|
14
|
+
const createMcpAdminTokenAuthenticator = (strapi)=>({
|
|
15
|
+
async authenticate (ctx) {
|
|
16
|
+
const token = extractBearerToken(ctx);
|
|
17
|
+
if (token === null) {
|
|
18
|
+
return {
|
|
19
|
+
authenticated: false,
|
|
20
|
+
reason: 'missing_token'
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
const authResult = await strapi.admin.services['api-token-admin'].authenticateAdminToken(token);
|
|
24
|
+
if (authResult.authenticated === false) {
|
|
25
|
+
return {
|
|
26
|
+
authenticated: false,
|
|
27
|
+
reason: 'invalid_token',
|
|
28
|
+
error: authResult.error
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
return {
|
|
32
|
+
authenticated: true,
|
|
33
|
+
credentials: {
|
|
34
|
+
id: authResult.credentials.id
|
|
35
|
+
},
|
|
36
|
+
user: {
|
|
37
|
+
id: authResult.user.id
|
|
38
|
+
},
|
|
39
|
+
ability: authResult.ability
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
exports.createMcpAdminTokenAuthenticator = createMcpAdminTokenAuthenticator;
|
|
45
|
+
//# sourceMappingURL=authentication.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authentication.js","sources":["../../../src/services/mcp/authentication.ts"],"sourcesContent":["import type { Core, Data } from '@strapi/types';\nimport type { Ability } from '@casl/ability';\nimport type { Context } from 'koa';\n\nexport type McpAdminTokenAbility = Ability;\n\nexport type McpAuthFailureReason = 'missing_token' | 'invalid_token';\n\nexport type McpAdminTokenAuthResult =\n | { authenticated: false; reason: McpAuthFailureReason; error?: Error }\n | {\n authenticated: true;\n credentials: { id: Data.ID };\n user: { id: Data.ID };\n ability: McpAdminTokenAbility;\n };\n\nconst extractBearerToken = (ctx: Context): string | null => {\n const authorization = ctx.request.header.authorization;\n\n if (authorization === undefined) {\n return null;\n }\n\n const parts = authorization.split(/\\s+/);\n\n if (parts[0].toLowerCase() !== 'bearer' || parts.length !== 2) {\n return null;\n }\n\n return parts[1];\n};\n\nexport const createMcpAdminTokenAuthenticator = (strapi: Core.Strapi) => ({\n async authenticate(ctx: Context): Promise<McpAdminTokenAuthResult> {\n const token = extractBearerToken(ctx);\n\n if (token === null) {\n return { authenticated: false, reason: 'missing_token' };\n }\n\n const authResult = (await strapi.admin.services['api-token-admin'].authenticateAdminToken(\n token\n )) as McpAdminTokenAuthResult;\n\n if (authResult.authenticated === false) {\n return {\n authenticated: false,\n reason: 'invalid_token',\n error: authResult.error,\n };\n }\n\n return {\n authenticated: true,\n credentials: { id: authResult.credentials.id },\n user: { id: authResult.user.id },\n ability: authResult.ability,\n };\n },\n});\n"],"names":["extractBearerToken","ctx","authorization","request","header","undefined","parts","split","toLowerCase","length","createMcpAdminTokenAuthenticator","strapi","authenticate","token","authenticated","reason","authResult","admin","services","authenticateAdminToken","error","credentials","id","user","ability"],"mappings":";;AAiBA,MAAMA,qBAAqB,CAACC,GAAAA,GAAAA;AAC1B,IAAA,MAAMC,gBAAgBD,GAAAA,CAAIE,OAAO,CAACC,MAAM,CAACF,aAAa;AAEtD,IAAA,IAAIA,kBAAkBG,SAAAA,EAAW;QAC/B,OAAO,IAAA;AACT,IAAA;IAEA,MAAMC,KAAAA,GAAQJ,aAAAA,CAAcK,KAAK,CAAC,KAAA,CAAA;IAElC,IAAID,KAAK,CAAC,CAAA,CAAE,CAACE,WAAW,OAAO,QAAA,IAAYF,KAAAA,CAAMG,MAAM,KAAK,CAAA,EAAG;QAC7D,OAAO,IAAA;AACT,IAAA;IAEA,OAAOH,KAAK,CAAC,CAAA,CAAE;AACjB,CAAA;AAEO,MAAMI,gCAAAA,GAAmC,CAACC,MAAAA,IAAyB;AACxE,QAAA,MAAMC,cAAaX,GAAY,EAAA;AAC7B,YAAA,MAAMY,QAAQb,kBAAAA,CAAmBC,GAAAA,CAAAA;AAEjC,YAAA,IAAIY,UAAU,IAAA,EAAM;gBAClB,OAAO;oBAAEC,aAAAA,EAAe,KAAA;oBAAOC,MAAAA,EAAQ;AAAgB,iBAAA;AACzD,YAAA;YAEA,MAAMC,UAAAA,GAAc,MAAML,MAAAA,CAAOM,KAAK,CAACC,QAAQ,CAAC,iBAAA,CAAkB,CAACC,sBAAsB,CACvFN,KAAAA,CAAAA;YAGF,IAAIG,UAAAA,CAAWF,aAAa,KAAK,KAAA,EAAO;gBACtC,OAAO;oBACLA,aAAAA,EAAe,KAAA;oBACfC,MAAAA,EAAQ,eAAA;AACRK,oBAAAA,KAAAA,EAAOJ,WAAWI;AACpB,iBAAA;AACF,YAAA;YAEA,OAAO;gBACLN,aAAAA,EAAe,IAAA;gBACfO,WAAAA,EAAa;oBAAEC,EAAAA,EAAIN,UAAAA,CAAWK,WAAW,CAACC;AAAG,iBAAA;gBAC7CC,IAAAA,EAAM;oBAAED,EAAAA,EAAIN,UAAAA,CAAWO,IAAI,CAACD;AAAG,iBAAA;AAC/BE,gBAAAA,OAAAA,EAASR,WAAWQ;AACtB,aAAA;AACF,QAAA;AACF,KAAA;;;;"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
const extractBearerToken = (ctx)=>{
|
|
2
|
+
const authorization = ctx.request.header.authorization;
|
|
3
|
+
if (authorization === undefined) {
|
|
4
|
+
return null;
|
|
5
|
+
}
|
|
6
|
+
const parts = authorization.split(/\s+/);
|
|
7
|
+
if (parts[0].toLowerCase() !== 'bearer' || parts.length !== 2) {
|
|
8
|
+
return null;
|
|
9
|
+
}
|
|
10
|
+
return parts[1];
|
|
11
|
+
};
|
|
12
|
+
const createMcpAdminTokenAuthenticator = (strapi)=>({
|
|
13
|
+
async authenticate (ctx) {
|
|
14
|
+
const token = extractBearerToken(ctx);
|
|
15
|
+
if (token === null) {
|
|
16
|
+
return {
|
|
17
|
+
authenticated: false,
|
|
18
|
+
reason: 'missing_token'
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
const authResult = await strapi.admin.services['api-token-admin'].authenticateAdminToken(token);
|
|
22
|
+
if (authResult.authenticated === false) {
|
|
23
|
+
return {
|
|
24
|
+
authenticated: false,
|
|
25
|
+
reason: 'invalid_token',
|
|
26
|
+
error: authResult.error
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
return {
|
|
30
|
+
authenticated: true,
|
|
31
|
+
credentials: {
|
|
32
|
+
id: authResult.credentials.id
|
|
33
|
+
},
|
|
34
|
+
user: {
|
|
35
|
+
id: authResult.user.id
|
|
36
|
+
},
|
|
37
|
+
ability: authResult.ability
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
export { createMcpAdminTokenAuthenticator };
|
|
43
|
+
//# sourceMappingURL=authentication.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authentication.mjs","sources":["../../../src/services/mcp/authentication.ts"],"sourcesContent":["import type { Core, Data } from '@strapi/types';\nimport type { Ability } from '@casl/ability';\nimport type { Context } from 'koa';\n\nexport type McpAdminTokenAbility = Ability;\n\nexport type McpAuthFailureReason = 'missing_token' | 'invalid_token';\n\nexport type McpAdminTokenAuthResult =\n | { authenticated: false; reason: McpAuthFailureReason; error?: Error }\n | {\n authenticated: true;\n credentials: { id: Data.ID };\n user: { id: Data.ID };\n ability: McpAdminTokenAbility;\n };\n\nconst extractBearerToken = (ctx: Context): string | null => {\n const authorization = ctx.request.header.authorization;\n\n if (authorization === undefined) {\n return null;\n }\n\n const parts = authorization.split(/\\s+/);\n\n if (parts[0].toLowerCase() !== 'bearer' || parts.length !== 2) {\n return null;\n }\n\n return parts[1];\n};\n\nexport const createMcpAdminTokenAuthenticator = (strapi: Core.Strapi) => ({\n async authenticate(ctx: Context): Promise<McpAdminTokenAuthResult> {\n const token = extractBearerToken(ctx);\n\n if (token === null) {\n return { authenticated: false, reason: 'missing_token' };\n }\n\n const authResult = (await strapi.admin.services['api-token-admin'].authenticateAdminToken(\n token\n )) as McpAdminTokenAuthResult;\n\n if (authResult.authenticated === false) {\n return {\n authenticated: false,\n reason: 'invalid_token',\n error: authResult.error,\n };\n }\n\n return {\n authenticated: true,\n credentials: { id: authResult.credentials.id },\n user: { id: authResult.user.id },\n ability: authResult.ability,\n };\n },\n});\n"],"names":["extractBearerToken","ctx","authorization","request","header","undefined","parts","split","toLowerCase","length","createMcpAdminTokenAuthenticator","strapi","authenticate","token","authenticated","reason","authResult","admin","services","authenticateAdminToken","error","credentials","id","user","ability"],"mappings":"AAiBA,MAAMA,qBAAqB,CAACC,GAAAA,GAAAA;AAC1B,IAAA,MAAMC,gBAAgBD,GAAAA,CAAIE,OAAO,CAACC,MAAM,CAACF,aAAa;AAEtD,IAAA,IAAIA,kBAAkBG,SAAAA,EAAW;QAC/B,OAAO,IAAA;AACT,IAAA;IAEA,MAAMC,KAAAA,GAAQJ,aAAAA,CAAcK,KAAK,CAAC,KAAA,CAAA;IAElC,IAAID,KAAK,CAAC,CAAA,CAAE,CAACE,WAAW,OAAO,QAAA,IAAYF,KAAAA,CAAMG,MAAM,KAAK,CAAA,EAAG;QAC7D,OAAO,IAAA;AACT,IAAA;IAEA,OAAOH,KAAK,CAAC,CAAA,CAAE;AACjB,CAAA;AAEO,MAAMI,gCAAAA,GAAmC,CAACC,MAAAA,IAAyB;AACxE,QAAA,MAAMC,cAAaX,GAAY,EAAA;AAC7B,YAAA,MAAMY,QAAQb,kBAAAA,CAAmBC,GAAAA,CAAAA;AAEjC,YAAA,IAAIY,UAAU,IAAA,EAAM;gBAClB,OAAO;oBAAEC,aAAAA,EAAe,KAAA;oBAAOC,MAAAA,EAAQ;AAAgB,iBAAA;AACzD,YAAA;YAEA,MAAMC,UAAAA,GAAc,MAAML,MAAAA,CAAOM,KAAK,CAACC,QAAQ,CAAC,iBAAA,CAAkB,CAACC,sBAAsB,CACvFN,KAAAA,CAAAA;YAGF,IAAIG,UAAAA,CAAWF,aAAa,KAAK,KAAA,EAAO;gBACtC,OAAO;oBACLA,aAAAA,EAAe,KAAA;oBACfC,MAAAA,EAAQ,eAAA;AACRK,oBAAAA,KAAAA,EAAOJ,WAAWI;AACpB,iBAAA;AACF,YAAA;YAEA,OAAO;gBACLN,aAAAA,EAAe,IAAA;gBACfO,WAAAA,EAAa;oBAAEC,EAAAA,EAAIN,UAAAA,CAAWK,WAAW,CAACC;AAAG,iBAAA;gBAC7CC,IAAAA,EAAM;oBAAED,EAAAA,EAAIN,UAAAA,CAAWO,IAAI,CAACD;AAAG,iBAAA;AAC/BE,gBAAAA,OAAAA,EAASR,WAAWQ;AACtB,aAAA;AACF,QAAA;AACF,KAAA;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handlePost.d.ts","sourceRoot":"","sources":["../../../../src/services/mcp/handlers/handlePost.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAS1C,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,SAAS,CAAC;AAEtD,eAAO,MAAM,iBAAiB,SAAU,sBAAsB,KAAG,KAAK,iBAuErE,CAAC"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var streamableHttp_js = require('@modelcontextprotocol/sdk/server/streamableHttp.js');
|
|
4
|
+
var metrics = require('../metrics/metrics.js');
|
|
5
|
+
var sendJsonRpcError = require('../utils/sendJsonRpcError.js');
|
|
6
|
+
var withTimeout = require('../utils/withTimeout.js');
|
|
7
|
+
|
|
8
|
+
// eslint-disable-next-line import/extensions
|
|
9
|
+
const createPostHandler = (deps)=>{
|
|
10
|
+
const { strapi, authenticationStrategy, config, createServerWithRegistries, capabilityDefinitions } = deps;
|
|
11
|
+
return async (ctx)=>{
|
|
12
|
+
// Opt out of Koa's response phase — the MCP SDK writes directly to ctx.res
|
|
13
|
+
// (via res.writeHead / res.end / SSE streaming). Without this, Koa's respond()
|
|
14
|
+
// would also try to write ctx.body to the socket after the handler returns.
|
|
15
|
+
ctx.respond = false;
|
|
16
|
+
const req = ctx.req;
|
|
17
|
+
const res = ctx.res;
|
|
18
|
+
let hadAuthenticatedMcpRequest = false;
|
|
19
|
+
try {
|
|
20
|
+
const authResult = await authenticationStrategy.authenticate(ctx);
|
|
21
|
+
if (authResult.authenticated === false) {
|
|
22
|
+
metrics.sendDidNotAuthenticateMcpRequest(strapi, authResult.reason);
|
|
23
|
+
sendJsonRpcError.sendJsonRpcError(res, 'AUTHENTICATION_REQUIRED');
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
hadAuthenticatedMcpRequest = true;
|
|
27
|
+
metrics.sendDidUseMcpServer(strapi);
|
|
28
|
+
const { mcpServer } = createServerWithRegistries({
|
|
29
|
+
strapi,
|
|
30
|
+
definitions: capabilityDefinitions,
|
|
31
|
+
isDevMode: config.isDevMode(),
|
|
32
|
+
ability: authResult.ability,
|
|
33
|
+
user: authResult.user
|
|
34
|
+
});
|
|
35
|
+
const transport = new streamableHttp_js.StreamableHTTPServerTransport({
|
|
36
|
+
sessionIdGenerator: undefined
|
|
37
|
+
});
|
|
38
|
+
try {
|
|
39
|
+
await withTimeout.withTimeout(mcpServer.connect(transport), config.connectTimeoutMs, 'mcpServer.connect');
|
|
40
|
+
const requestBody = ctx.request.body ?? null;
|
|
41
|
+
await withTimeout.withTimeout(transport.handleRequest(req, res, requestBody), config.requestTimeoutMs, 'transport.handleRequest');
|
|
42
|
+
} finally{
|
|
43
|
+
await mcpServer.close();
|
|
44
|
+
}
|
|
45
|
+
} catch (error) {
|
|
46
|
+
strapi.log.error('[MCP] Error handling POST request', {
|
|
47
|
+
error: error instanceof Error ? error.message : 'Unknown error',
|
|
48
|
+
stack: error instanceof Error ? error.stack : undefined
|
|
49
|
+
});
|
|
50
|
+
sendJsonRpcError.sendJsonRpcError(res, 'INTERNAL_ERROR');
|
|
51
|
+
if (hadAuthenticatedMcpRequest) {
|
|
52
|
+
metrics.sendDidNotHandleMcpRequest(strapi, metrics.classifyMcpRequestFailure(error));
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
exports.createPostHandler = createPostHandler;
|
|
59
|
+
//# sourceMappingURL=handlePost.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handlePost.js","sources":["../../../../src/services/mcp/handlers/handlePost.ts"],"sourcesContent":["// eslint-disable-next-line import/extensions\nimport { StreamableHTTPServerTransport } from '@modelcontextprotocol/sdk/server/streamableHttp.js';\nimport type { Core } from '@strapi/types';\nimport {\n classifyMcpRequestFailure,\n sendDidNotAuthenticateMcpRequest,\n sendDidNotHandleMcpRequest,\n sendDidUseMcpServer,\n} from '../metrics/metrics';\nimport { sendJsonRpcError } from '../utils/sendJsonRpcError';\nimport { withTimeout } from '../utils/withTimeout';\nimport type { McpHandlerDependencies } from './types';\n\nexport const createPostHandler = (deps: McpHandlerDependencies): Core.MiddlewareHandler => {\n const {\n strapi,\n authenticationStrategy,\n config,\n createServerWithRegistries,\n capabilityDefinitions,\n } = deps;\n\n return async (ctx) => {\n // Opt out of Koa's response phase — the MCP SDK writes directly to ctx.res\n // (via res.writeHead / res.end / SSE streaming). Without this, Koa's respond()\n // would also try to write ctx.body to the socket after the handler returns.\n ctx.respond = false;\n const req = ctx.req;\n const res = ctx.res;\n\n let hadAuthenticatedMcpRequest = false;\n\n try {\n const authResult = await authenticationStrategy.authenticate(ctx);\n if (authResult.authenticated === false) {\n sendDidNotAuthenticateMcpRequest(strapi, authResult.reason);\n sendJsonRpcError(res, 'AUTHENTICATION_REQUIRED');\n return;\n }\n\n hadAuthenticatedMcpRequest = true;\n sendDidUseMcpServer(strapi);\n\n const { mcpServer } = createServerWithRegistries({\n strapi,\n definitions: capabilityDefinitions,\n isDevMode: config.isDevMode(),\n ability: authResult.ability,\n user: authResult.user,\n });\n\n const transport = new StreamableHTTPServerTransport({\n sessionIdGenerator: undefined,\n });\n\n try {\n await withTimeout(\n mcpServer.connect(transport),\n config.connectTimeoutMs,\n 'mcpServer.connect'\n );\n\n const requestBody = ctx.request.body ?? null;\n await withTimeout(\n transport.handleRequest(req, res, requestBody),\n config.requestTimeoutMs,\n 'transport.handleRequest'\n );\n } finally {\n await mcpServer.close();\n }\n } catch (error) {\n strapi.log.error('[MCP] Error handling POST request', {\n error: error instanceof Error ? error.message : 'Unknown error',\n stack: error instanceof Error ? error.stack : undefined,\n });\n\n sendJsonRpcError(res, 'INTERNAL_ERROR');\n\n if (hadAuthenticatedMcpRequest) {\n sendDidNotHandleMcpRequest(strapi, classifyMcpRequestFailure(error));\n }\n }\n };\n};\n"],"names":["createPostHandler","deps","strapi","authenticationStrategy","config","createServerWithRegistries","capabilityDefinitions","ctx","respond","req","res","hadAuthenticatedMcpRequest","authResult","authenticate","authenticated","sendDidNotAuthenticateMcpRequest","reason","sendJsonRpcError","sendDidUseMcpServer","mcpServer","definitions","isDevMode","ability","user","transport","StreamableHTTPServerTransport","sessionIdGenerator","undefined","withTimeout","connect","connectTimeoutMs","requestBody","request","body","handleRequest","requestTimeoutMs","close","error","log","Error","message","stack","sendDidNotHandleMcpRequest","classifyMcpRequestFailure"],"mappings":";;;;;;;AAAA;AAaO,MAAMA,oBAAoB,CAACC,IAAAA,GAAAA;IAChC,MAAM,EACJC,MAAM,EACNC,sBAAsB,EACtBC,MAAM,EACNC,0BAA0B,EAC1BC,qBAAqB,EACtB,GAAGL,IAAAA;AAEJ,IAAA,OAAO,OAAOM,GAAAA,GAAAA;;;;AAIZA,QAAAA,GAAAA,CAAIC,OAAO,GAAG,KAAA;QACd,MAAMC,GAAAA,GAAMF,IAAIE,GAAG;QACnB,MAAMC,GAAAA,GAAMH,IAAIG,GAAG;AAEnB,QAAA,IAAIC,0BAAAA,GAA6B,KAAA;QAEjC,IAAI;AACF,YAAA,MAAMC,UAAAA,GAAa,MAAMT,sBAAAA,CAAuBU,YAAY,CAACN,GAAAA,CAAAA;YAC7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AAO,GAAG,eAAA;AAChDC,gBAAAA,KAAAA,EAAOJ,KAAAA,YAAiBE,KAAAA,GAAQF,KAAAA,CAAMI,KAAK,GAAGd;AAChD,aAAA,CAAA;AAEAV,YAAAA,iCAAAA,CAAiBP,GAAAA,EAAK,gBAAA,CAAA;AAEtB,YAAA,IAAIC,0BAAAA,EAA4B;AAC9B+B,gBAAAA,kCAAAA,CAA2BxC,QAAQyC,iCAAAA,CAA0BN,KAAAA,CAAAA,CAAAA;AAC/D,YAAA;AACF,QAAA;AACF,IAAA,CAAA;AACF;;;;"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { StreamableHTTPServerTransport } from '@modelcontextprotocol/sdk/server/streamableHttp.js';
|
|
2
|
+
import { sendDidNotAuthenticateMcpRequest, sendDidUseMcpServer, sendDidNotHandleMcpRequest, classifyMcpRequestFailure } from '../metrics/metrics.mjs';
|
|
3
|
+
import { sendJsonRpcError } from '../utils/sendJsonRpcError.mjs';
|
|
4
|
+
import { withTimeout } from '../utils/withTimeout.mjs';
|
|
5
|
+
|
|
6
|
+
// eslint-disable-next-line import/extensions
|
|
7
|
+
const createPostHandler = (deps)=>{
|
|
8
|
+
const { strapi, authenticationStrategy, config, createServerWithRegistries, capabilityDefinitions } = deps;
|
|
9
|
+
return async (ctx)=>{
|
|
10
|
+
// Opt out of Koa's response phase — the MCP SDK writes directly to ctx.res
|
|
11
|
+
// (via res.writeHead / res.end / SSE streaming). Without this, Koa's respond()
|
|
12
|
+
// would also try to write ctx.body to the socket after the handler returns.
|
|
13
|
+
ctx.respond = false;
|
|
14
|
+
const req = ctx.req;
|
|
15
|
+
const res = ctx.res;
|
|
16
|
+
let hadAuthenticatedMcpRequest = false;
|
|
17
|
+
try {
|
|
18
|
+
const authResult = await authenticationStrategy.authenticate(ctx);
|
|
19
|
+
if (authResult.authenticated === false) {
|
|
20
|
+
sendDidNotAuthenticateMcpRequest(strapi, authResult.reason);
|
|
21
|
+
sendJsonRpcError(res, 'AUTHENTICATION_REQUIRED');
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
hadAuthenticatedMcpRequest = true;
|
|
25
|
+
sendDidUseMcpServer(strapi);
|
|
26
|
+
const { mcpServer } = createServerWithRegistries({
|
|
27
|
+
strapi,
|
|
28
|
+
definitions: capabilityDefinitions,
|
|
29
|
+
isDevMode: config.isDevMode(),
|
|
30
|
+
ability: authResult.ability,
|
|
31
|
+
user: authResult.user
|
|
32
|
+
});
|
|
33
|
+
const transport = new StreamableHTTPServerTransport({
|
|
34
|
+
sessionIdGenerator: undefined
|
|
35
|
+
});
|
|
36
|
+
try {
|
|
37
|
+
await withTimeout(mcpServer.connect(transport), config.connectTimeoutMs, 'mcpServer.connect');
|
|
38
|
+
const requestBody = ctx.request.body ?? null;
|
|
39
|
+
await withTimeout(transport.handleRequest(req, res, requestBody), config.requestTimeoutMs, 'transport.handleRequest');
|
|
40
|
+
} finally{
|
|
41
|
+
await mcpServer.close();
|
|
42
|
+
}
|
|
43
|
+
} catch (error) {
|
|
44
|
+
strapi.log.error('[MCP] Error handling POST request', {
|
|
45
|
+
error: error instanceof Error ? error.message : 'Unknown error',
|
|
46
|
+
stack: error instanceof Error ? error.stack : undefined
|
|
47
|
+
});
|
|
48
|
+
sendJsonRpcError(res, 'INTERNAL_ERROR');
|
|
49
|
+
if (hadAuthenticatedMcpRequest) {
|
|
50
|
+
sendDidNotHandleMcpRequest(strapi, classifyMcpRequestFailure(error));
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
export { createPostHandler };
|
|
57
|
+
//# sourceMappingURL=handlePost.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handlePost.mjs","sources":["../../../../src/services/mcp/handlers/handlePost.ts"],"sourcesContent":["// eslint-disable-next-line import/extensions\nimport { StreamableHTTPServerTransport } from '@modelcontextprotocol/sdk/server/streamableHttp.js';\nimport type { Core } from '@strapi/types';\nimport {\n classifyMcpRequestFailure,\n sendDidNotAuthenticateMcpRequest,\n sendDidNotHandleMcpRequest,\n sendDidUseMcpServer,\n} from '../metrics/metrics';\nimport { sendJsonRpcError } from '../utils/sendJsonRpcError';\nimport { withTimeout } from '../utils/withTimeout';\nimport type { McpHandlerDependencies } from './types';\n\nexport const createPostHandler = (deps: McpHandlerDependencies): Core.MiddlewareHandler => {\n const {\n strapi,\n authenticationStrategy,\n config,\n createServerWithRegistries,\n capabilityDefinitions,\n } = deps;\n\n return async (ctx) => {\n // Opt out of Koa's response phase — the MCP SDK writes directly to ctx.res\n // (via res.writeHead / res.end / SSE streaming). Without this, Koa's respond()\n // would also try to write ctx.body to the socket after the handler returns.\n ctx.respond = false;\n const req = ctx.req;\n const res = ctx.res;\n\n let hadAuthenticatedMcpRequest = false;\n\n try {\n const authResult = await authenticationStrategy.authenticate(ctx);\n if (authResult.authenticated === false) {\n sendDidNotAuthenticateMcpRequest(strapi, authResult.reason);\n sendJsonRpcError(res, 'AUTHENTICATION_REQUIRED');\n return;\n }\n\n hadAuthenticatedMcpRequest = true;\n sendDidUseMcpServer(strapi);\n\n const { mcpServer } = createServerWithRegistries({\n strapi,\n definitions: capabilityDefinitions,\n isDevMode: config.isDevMode(),\n ability: authResult.ability,\n user: authResult.user,\n });\n\n const transport = new StreamableHTTPServerTransport({\n sessionIdGenerator: undefined,\n });\n\n try {\n await withTimeout(\n mcpServer.connect(transport),\n config.connectTimeoutMs,\n 'mcpServer.connect'\n );\n\n const requestBody = ctx.request.body ?? null;\n await withTimeout(\n transport.handleRequest(req, res, requestBody),\n config.requestTimeoutMs,\n 'transport.handleRequest'\n );\n } finally {\n await mcpServer.close();\n }\n } catch (error) {\n strapi.log.error('[MCP] Error handling POST request', {\n error: error instanceof Error ? error.message : 'Unknown error',\n stack: error instanceof Error ? error.stack : undefined,\n });\n\n sendJsonRpcError(res, 'INTERNAL_ERROR');\n\n if (hadAuthenticatedMcpRequest) {\n sendDidNotHandleMcpRequest(strapi, classifyMcpRequestFailure(error));\n }\n }\n };\n};\n"],"names":["createPostHandler","deps","strapi","authenticationStrategy","config","createServerWithRegistries","capabilityDefinitions","ctx","respond","req","res","hadAuthenticatedMcpRequest","authResult","authenticate","authenticated","sendDidNotAuthenticateMcpRequest","reason","sendJsonRpcError","sendDidUseMcpServer","mcpServer","definitions","isDevMode","ability","user","transport","StreamableHTTPServerTransport","sessionIdGenerator","undefined","withTimeout","connect","connectTimeoutMs","requestBody","request","body","handleRequest","requestTimeoutMs","close","error","log","Error","message","stack","sendDidNotHandleMcpRequest","classifyMcpRequestFailure"],"mappings":";;;;;AAAA;AAaO,MAAMA,oBAAoB,CAACC,IAAAA,GAAAA;IAChC,MAAM,EACJC,MAAM,EACNC,sBAAsB,EACtBC,MAAM,EACNC,0BAA0B,EAC1BC,qBAAqB,EACtB,GAAGL,IAAAA;AAEJ,IAAA,OAAO,OAAOM,GAAAA,GAAAA;;;;AAIZA,QAAAA,GAAAA,CAAIC,OAAO,GAAG,KAAA;QACd,MAAMC,GAAAA,GAAMF,IAAIE,GAAG;QACnB,MAAMC,GAAAA,GAAMH,IAAIG,GAAG;AAEnB,QAAA,IAAIC,0BAAAA,GAA6B,KAAA;QAEjC,IAAI;AACF,YAAA,MAAMC,UAAAA,GAAa,MAAMT,sBAAAA,CAAuBU,YAAY,CAACN,GAAAA,CAAAA;YAC7D,IAAIK,UAAAA,CAAWE,aAAa,KAAK,KAAA,EAAO;gBACtCC,gCAAAA,CAAiCb,MAAAA,EAAQU,WAAWI,MAAM,CAAA;AAC1DC,gBAAAA,gBAAAA,CAAiBP,GAAAA,EAAK,yBAAA,CAAA;AACtB,gBAAA;AACF,YAAA;YAEAC,0BAAAA,GAA6B,IAAA;YAC7BO,mBAAAA,CAAoBhB,MAAAA,CAAAA;AAEpB,YAAA,MAAM,EAAEiB,SAAS,EAAE,GAAGd,0BAAAA,CAA2B;AAC/CH,gBAAAA,MAAAA;gBACAkB,WAAAA,EAAad,qBAAAA;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|
|
1
|
+
import type { Core } from '@strapi/types';
|
|
2
|
+
import type { McpConfiguration } from '../internal/McpConfiguration';
|
|
3
|
+
import type { McpCapabilityDefinitions, createMcpServerWithRegistries } from '../internal/McpServerFactory';
|
|
4
|
+
import type { createMcpAdminTokenAuthenticator } from '../authentication';
|
|
5
|
+
export type McpHandlerDependencies = {
|
|
6
|
+
strapi: Core.Strapi;
|
|
7
|
+
authenticationStrategy: ReturnType<typeof createMcpAdminTokenAuthenticator>;
|
|
8
|
+
config: McpConfiguration;
|
|
9
|
+
createServerWithRegistries: typeof createMcpServerWithRegistries;
|
|
10
|
+
capabilityDefinitions: McpCapabilityDefinitions;
|
|
11
|
+
};
|
|
12
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/services/mcp/handlers/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAC1C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AACrE,OAAO,KAAK,EACV,wBAAwB,EACxB,6BAA6B,EAC9B,MAAM,8BAA8B,CAAC;AACtC,OAAO,KAAK,EAAE,gCAAgC,EAAE,MAAM,mBAAmB,CAAC;AAE1E,MAAM,MAAM,sBAAsB,GAAG;IACnC,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC;IACpB,sBAAsB,EAAE,UAAU,CAAC,OAAO,gCAAgC,CAAC,CAAC;IAC5E,MAAM,EAAE,gBAAgB,CAAC;IACzB,0BAA0B,EAAE,OAAO,6BAA6B,CAAC;IACjE,qBAAqB,EAAE,wBAAwB,CAAC;CACjD,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/services/mcp/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAYnD;;GAEG;AACH,eAAO,MAAM,gBAAgB,WAAY,KAAK,MAAM,KAAG,QAAQ,GAAG,CAAC,UAgHlE,CAAC"}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var authentication = require('./authentication.js');
|
|
4
|
+
var handlePost = require('./handlers/handlePost.js');
|
|
5
|
+
var McpCapabilityDefinitionRegistry = require('./internal/McpCapabilityDefinitionRegistry.js');
|
|
6
|
+
var McpConfiguration = require('./internal/McpConfiguration.js');
|
|
7
|
+
var McpServerFactory = require('./internal/McpServerFactory.js');
|
|
8
|
+
var oauthDiscoveryFallback = require('./middleware/oauthDiscoveryFallback.js');
|
|
9
|
+
var routes = require('./routes.js');
|
|
10
|
+
var metrics = require('./metrics/metrics.js');
|
|
11
|
+
var log = require('./tools/log.js');
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Creates an MCP service instance for Strapi Core
|
|
15
|
+
*/ const createMcpService = (strapi)=>{
|
|
16
|
+
// Initialize configuration
|
|
17
|
+
const config = new McpConfiguration.McpConfiguration(strapi);
|
|
18
|
+
const authenticationStrategy = authentication.createMcpAdminTokenAuthenticator(strapi);
|
|
19
|
+
// Status tracking
|
|
20
|
+
let serverStatus = 'idle';
|
|
21
|
+
// Definition registries
|
|
22
|
+
const toolDefinitions = new McpCapabilityDefinitionRegistry.McpCapabilityDefinitionRegistry('tool');
|
|
23
|
+
const promptDefinitions = new McpCapabilityDefinitionRegistry.McpCapabilityDefinitionRegistry('prompt');
|
|
24
|
+
const resourceDefinitions = new McpCapabilityDefinitionRegistry.McpCapabilityDefinitionRegistry('resource');
|
|
25
|
+
// Prepare handler dependencies
|
|
26
|
+
const handlerDependencies = {
|
|
27
|
+
strapi,
|
|
28
|
+
authenticationStrategy,
|
|
29
|
+
config,
|
|
30
|
+
createServerWithRegistries: McpServerFactory.createMcpServerWithRegistries,
|
|
31
|
+
capabilityDefinitions: {
|
|
32
|
+
tools: toolDefinitions,
|
|
33
|
+
prompts: promptDefinitions,
|
|
34
|
+
resources: resourceDefinitions
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
// Create HTTP handlers
|
|
38
|
+
const handlePost$1 = handlePost.createPostHandler(handlerDependencies);
|
|
39
|
+
const service = {
|
|
40
|
+
isEnabled () {
|
|
41
|
+
return config.isEnabled();
|
|
42
|
+
},
|
|
43
|
+
isRunning () {
|
|
44
|
+
return serverStatus === 'running';
|
|
45
|
+
},
|
|
46
|
+
registerTool (tool) {
|
|
47
|
+
if (serverStatus !== 'idle') {
|
|
48
|
+
throw new Error('[MCP] Cannot register tools after the MCP server has started.');
|
|
49
|
+
}
|
|
50
|
+
toolDefinitions.define(tool);
|
|
51
|
+
},
|
|
52
|
+
registerPrompt (prompt) {
|
|
53
|
+
if (serverStatus !== 'idle') {
|
|
54
|
+
throw new Error('[MCP] Cannot register prompts after the MCP server has started.');
|
|
55
|
+
}
|
|
56
|
+
promptDefinitions.define(prompt);
|
|
57
|
+
},
|
|
58
|
+
registerResource (resource) {
|
|
59
|
+
if (serverStatus !== 'idle') {
|
|
60
|
+
throw new Error('[MCP] Cannot register resources after the MCP server has started.');
|
|
61
|
+
}
|
|
62
|
+
resourceDefinitions.define(resource);
|
|
63
|
+
},
|
|
64
|
+
async start () {
|
|
65
|
+
if (service.isEnabled() === false) {
|
|
66
|
+
strapi.log.debug('[MCP] Server is disabled');
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
if (serverStatus === 'error') {
|
|
70
|
+
throw new Error('[MCP] Cannot start server: previous error state');
|
|
71
|
+
}
|
|
72
|
+
if (serverStatus !== 'idle') {
|
|
73
|
+
throw new Error(`[MCP] Server already started or starting (status: ${serverStatus})`);
|
|
74
|
+
}
|
|
75
|
+
serverStatus = 'starting';
|
|
76
|
+
strapi.server.use(oauthDiscoveryFallback.createOAuthDiscoveryFallbackMiddleware());
|
|
77
|
+
const routes$1 = routes.createMcpRoutes(config, {
|
|
78
|
+
handlePost: handlePost$1
|
|
79
|
+
});
|
|
80
|
+
strapi.server.routes(routes$1);
|
|
81
|
+
serverStatus = 'running';
|
|
82
|
+
metrics.sendDidStartMcpServer(strapi, {
|
|
83
|
+
path: config.path,
|
|
84
|
+
numberOfTools: toolDefinitions.size,
|
|
85
|
+
numberOfPrompts: promptDefinitions.size,
|
|
86
|
+
numberOfResources: resourceDefinitions.size
|
|
87
|
+
});
|
|
88
|
+
const baseUrl = strapi.config.get('server.url', 'http://localhost:1337');
|
|
89
|
+
strapi.log.info(`[MCP] Server available at ${baseUrl}${config.path}`);
|
|
90
|
+
},
|
|
91
|
+
async stop () {
|
|
92
|
+
serverStatus = 'idle';
|
|
93
|
+
strapi.log.info('[MCP] Service stopped');
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
service.registerTool(log.logToolDefinition);
|
|
97
|
+
return service;
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
exports.createMcpService = createMcpService;
|
|
101
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../src/services/mcp/index.ts"],"sourcesContent":["import type { Core, Modules } from '@strapi/types';\nimport { createMcpAdminTokenAuthenticator } from './authentication';\nimport { createPostHandler } from './handlers/handlePost';\nimport type { McpHandlerDependencies } from './handlers/types';\nimport { McpCapabilityDefinitionRegistry } from './internal/McpCapabilityDefinitionRegistry';\nimport { McpConfiguration } from './internal/McpConfiguration';\nimport { createMcpServerWithRegistries } from './internal/McpServerFactory';\nimport { createOAuthDiscoveryFallbackMiddleware } from './middleware/oauthDiscoveryFallback';\nimport { createMcpRoutes } from './routes';\nimport { sendDidStartMcpServer } from './metrics/metrics';\nimport { logToolDefinition } from './tools/log';\n\n/**\n * Creates an MCP service instance for Strapi Core\n */\nexport const createMcpService = (strapi: Core.Strapi): Modules.MCP.McpService => {\n // Initialize configuration\n const config = new McpConfiguration(strapi);\n\n const authenticationStrategy = createMcpAdminTokenAuthenticator(strapi);\n\n // Status tracking\n let serverStatus: Modules.MCP.McpServiceStatus = 'idle';\n\n // Definition registries\n const toolDefinitions = new McpCapabilityDefinitionRegistry<\n 'tool',\n Modules.MCP.McpToolDefinition\n >('tool');\n\n const promptDefinitions = new McpCapabilityDefinitionRegistry<\n 'prompt',\n Modules.MCP.McpPromptDefinition\n >('prompt');\n\n const resourceDefinitions = new McpCapabilityDefinitionRegistry<\n 'resource',\n Modules.MCP.McpResourceDefinition\n >('resource');\n\n // Prepare handler dependencies\n const handlerDependencies: McpHandlerDependencies = {\n strapi,\n authenticationStrategy,\n config,\n createServerWithRegistries: createMcpServerWithRegistries,\n capabilityDefinitions: {\n tools: toolDefinitions,\n prompts: promptDefinitions,\n resources: resourceDefinitions,\n },\n };\n\n // Create HTTP handlers\n const handlePost = createPostHandler(handlerDependencies);\n\n const service: Modules.MCP.McpService = {\n isEnabled() {\n return config.isEnabled();\n },\n\n isRunning() {\n return serverStatus === 'running';\n },\n\n registerTool(tool: Modules.MCP.McpToolDefinition) {\n if (serverStatus !== 'idle') {\n throw new Error('[MCP] Cannot register tools after the MCP server has started.');\n }\n\n toolDefinitions.define(tool);\n },\n\n registerPrompt(prompt) {\n if (serverStatus !== 'idle') {\n throw new Error('[MCP] Cannot register prompts after the MCP server has started.');\n }\n promptDefinitions.define(prompt);\n },\n\n registerResource(resource) {\n if (serverStatus !== 'idle') {\n throw new Error('[MCP] Cannot register resources after the MCP server has started.');\n }\n resourceDefinitions.define(resource);\n },\n\n async start() {\n if (service.isEnabled() === false) {\n strapi.log.debug('[MCP] Server is disabled');\n return;\n }\n if (serverStatus === 'error') {\n throw new Error('[MCP] Cannot start server: previous error state');\n }\n if (serverStatus !== 'idle') {\n throw new Error(`[MCP] Server already started or starting (status: ${serverStatus})`);\n }\n serverStatus = 'starting';\n\n strapi.server.use(createOAuthDiscoveryFallbackMiddleware());\n\n const routes = createMcpRoutes(config, { handlePost });\n strapi.server.routes(routes);\n\n serverStatus = 'running';\n\n sendDidStartMcpServer(strapi, {\n path: config.path,\n numberOfTools: toolDefinitions.size,\n numberOfPrompts: promptDefinitions.size,\n numberOfResources: resourceDefinitions.size,\n });\n\n const baseUrl = strapi.config.get('server.url', 'http://localhost:1337');\n strapi.log.info(`[MCP] Server available at ${baseUrl}${config.path}`);\n },\n\n async stop() {\n serverStatus = 'idle';\n strapi.log.info('[MCP] Service stopped');\n },\n };\n\n service.registerTool(logToolDefinition);\n\n return service;\n};\n"],"names":["createMcpService","strapi","config","McpConfiguration","authenticationStrategy","createMcpAdminTokenAuthenticator","serverStatus","toolDefinitions","McpCapabilityDefinitionRegistry","promptDefinitions","resourceDefinitions","handlerDependencies","createServerWithRegistries","createMcpServerWithRegistries","capabilityDefinitions","tools","prompts","resources","handlePost","createPostHandler","service","isEnabled","isRunning","registerTool","tool","Error","define","registerPrompt","prompt","registerResource","resource","start","log","debug","server","use","createOAuthDiscoveryFallbackMiddleware","routes","createMcpRoutes","sendDidStartMcpServer","path","numberOfTools","size","numberOfPrompts","numberOfResources","baseUrl","get","info","stop","logToolDefinition"],"mappings":";;;;;;;;;;;;AAYA;;IAGO,MAAMA,gBAAAA,GAAmB,CAACC,MAAAA,GAAAA;;IAE/B,MAAMC,MAAAA,GAAS,IAAIC,iCAAAA,CAAiBF,MAAAA,CAAAA;AAEpC,IAAA,MAAMG,yBAAyBC,+CAAAA,CAAiCJ,MAAAA,CAAAA;;AAGhE,IAAA,IAAIK,YAAAA,GAA6C,MAAA;;IAGjD,MAAMC,eAAAA,GAAkB,IAAIC,+DAAAA,CAG1B,MAAA,CAAA;IAEF,MAAMC,iBAAAA,GAAoB,IAAID,+DAAAA,CAG5B,QAAA,CAAA;IAEF,MAAME,mBAAAA,GAAsB,IAAIF,+DAAAA,CAG9B,UAAA,CAAA;;AAGF,IAAA,MAAMG,mBAAAA,GAA8C;AAClDV,QAAAA,MAAAA;AACAG,QAAAA,sBAAAA;AACAF,QAAAA,MAAAA;QACAU,0BAAAA,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