@payloadcms/plugin-mcp 4.0.0-canary.0 → 4.0.0-canary.2
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/collection/getAccessField.d.ts.map +1 -1
- package/dist/collection/getAccessField.js +25 -10
- package/dist/collection/getAccessField.js.map +1 -1
- package/dist/collection/index.d.ts.map +1 -1
- package/dist/collection/index.js +73 -27
- package/dist/collection/index.js.map +1 -1
- package/dist/components/APIKeyField/index.client.d.ts +9 -0
- package/dist/components/APIKeyField/index.client.d.ts.map +1 -0
- package/dist/components/APIKeyField/index.client.js +85 -0
- package/dist/components/APIKeyField/index.client.js.map +1 -0
- package/dist/components/APIKeyField/index.css +105 -0
- package/dist/components/APIKeysEmptyState/index.client.d.ts +4 -0
- package/dist/components/APIKeysEmptyState/index.client.d.ts.map +1 -0
- package/dist/components/APIKeysEmptyState/index.client.js +21 -0
- package/dist/components/APIKeysEmptyState/index.client.js.map +1 -0
- package/dist/components/AccessField/index.client.d.ts.map +1 -1
- package/dist/components/AccessField/index.client.js +149 -207
- package/dist/components/AccessField/index.client.js.map +1 -1
- package/dist/components/AccessField/index.css +50 -44
- package/dist/components/SettingsMenu/index.client.d.ts +8 -0
- package/dist/components/SettingsMenu/index.client.d.ts.map +1 -0
- package/dist/components/SettingsMenu/index.client.js +29 -0
- package/dist/components/SettingsMenu/index.client.js.map +1 -0
- package/dist/endpoint/access.js +21 -5
- package/dist/endpoint/access.js.map +1 -1
- package/dist/exports/client.d.ts +3 -0
- package/dist/exports/client.d.ts.map +1 -1
- package/dist/exports/client.js +3 -0
- package/dist/exports/client.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +46 -3
- package/dist/index.js.map +1 -1
- package/dist/mcp/buildMcpServer.d.ts.map +1 -1
- package/dist/mcp/buildMcpServer.js +100 -64
- package/dist/mcp/buildMcpServer.js.map +1 -1
- package/dist/mcp/builtin/collections/createTool.d.ts +1 -1
- package/dist/mcp/builtin/collections/createTool.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/createTool.js +28 -21
- package/dist/mcp/builtin/collections/createTool.js.map +1 -1
- package/dist/mcp/builtin/collections/deleteTool.d.ts +1 -1
- package/dist/mcp/builtin/collections/deleteTool.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/deleteTool.js +5 -20
- package/dist/mcp/builtin/collections/deleteTool.js.map +1 -1
- package/dist/mcp/builtin/collections/findTool.d.ts +1 -1
- package/dist/mcp/builtin/collections/findTool.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/findTool.js +6 -21
- package/dist/mcp/builtin/collections/findTool.js.map +1 -1
- package/dist/mcp/builtin/collections/formatCollectionError.d.ts +9 -0
- package/dist/mcp/builtin/collections/formatCollectionError.d.ts.map +1 -0
- package/dist/mcp/builtin/collections/formatCollectionError.js +60 -0
- package/dist/mcp/builtin/collections/formatCollectionError.js.map +1 -0
- package/dist/mcp/builtin/collections/getCollectionSchemaTool.d.ts +2 -0
- package/dist/mcp/builtin/collections/getCollectionSchemaTool.d.ts.map +1 -0
- package/dist/mcp/builtin/collections/getCollectionSchemaTool.js +35 -0
- package/dist/mcp/builtin/collections/getCollectionSchemaTool.js.map +1 -0
- package/dist/mcp/builtin/collections/updateTool.d.ts +1 -1
- package/dist/mcp/builtin/collections/updateTool.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/updateTool.js +74 -62
- package/dist/mcp/builtin/collections/updateTool.js.map +1 -1
- package/dist/mcp/builtin/getConfigInfoTool.d.ts +2 -0
- package/dist/mcp/builtin/getConfigInfoTool.d.ts.map +1 -0
- package/dist/mcp/builtin/getConfigInfoTool.js +49 -0
- package/dist/mcp/builtin/getConfigInfoTool.js.map +1 -0
- package/dist/mcp/builtin/globals/findTool.js +1 -1
- package/dist/mcp/builtin/globals/findTool.js.map +1 -1
- package/dist/mcp/builtin/globals/getGlobalSchemaTool.d.ts +2 -0
- package/dist/mcp/builtin/globals/getGlobalSchemaTool.d.ts.map +1 -0
- package/dist/mcp/builtin/globals/getGlobalSchemaTool.js +35 -0
- package/dist/mcp/builtin/globals/getGlobalSchemaTool.js.map +1 -0
- package/dist/mcp/builtin/globals/updateTool.d.ts.map +1 -1
- package/dist/mcp/builtin/globals/updateTool.js +21 -19
- package/dist/mcp/builtin/globals/updateTool.js.map +1 -1
- package/dist/mcp/builtin/validateEntityData.d.ts +14 -0
- package/dist/mcp/builtin/validateEntityData.d.ts.map +1 -0
- package/dist/mcp/builtin/validateEntityData.js +82 -0
- package/dist/mcp/builtin/validateEntityData.js.map +1 -0
- package/dist/mcp/builtinTools.d.ts +84 -16
- package/dist/mcp/builtinTools.d.ts.map +1 -1
- package/dist/mcp/builtinTools.js +54 -11
- package/dist/mcp/builtinTools.js.map +1 -1
- package/dist/mcp/sanitizeMCPConfig.d.ts.map +1 -1
- package/dist/mcp/sanitizeMCPConfig.js +61 -40
- package/dist/mcp/sanitizeMCPConfig.js.map +1 -1
- package/dist/translations/index.d.ts +11 -0
- package/dist/translations/index.d.ts.map +1 -0
- package/dist/translations/index.js +92 -0
- package/dist/translations/index.js.map +1 -0
- package/dist/translations/languages/ar.d.ts +31 -0
- package/dist/translations/languages/ar.d.ts.map +1 -0
- package/dist/translations/languages/ar.js +34 -0
- package/dist/translations/languages/ar.js.map +1 -0
- package/dist/translations/languages/az.d.ts +31 -0
- package/dist/translations/languages/az.d.ts.map +1 -0
- package/dist/translations/languages/az.js +34 -0
- package/dist/translations/languages/az.js.map +1 -0
- package/dist/translations/languages/bg.d.ts +31 -0
- package/dist/translations/languages/bg.d.ts.map +1 -0
- package/dist/translations/languages/bg.js +34 -0
- package/dist/translations/languages/bg.js.map +1 -0
- package/dist/translations/languages/bnBd.d.ts +31 -0
- package/dist/translations/languages/bnBd.d.ts.map +1 -0
- package/dist/translations/languages/bnBd.js +34 -0
- package/dist/translations/languages/bnBd.js.map +1 -0
- package/dist/translations/languages/bnIn.d.ts +31 -0
- package/dist/translations/languages/bnIn.d.ts.map +1 -0
- package/dist/translations/languages/bnIn.js +34 -0
- package/dist/translations/languages/bnIn.js.map +1 -0
- package/dist/translations/languages/ca.d.ts +31 -0
- package/dist/translations/languages/ca.d.ts.map +1 -0
- package/dist/translations/languages/ca.js +34 -0
- package/dist/translations/languages/ca.js.map +1 -0
- package/dist/translations/languages/cs.d.ts +31 -0
- package/dist/translations/languages/cs.d.ts.map +1 -0
- package/dist/translations/languages/cs.js +34 -0
- package/dist/translations/languages/cs.js.map +1 -0
- package/dist/translations/languages/da.d.ts +31 -0
- package/dist/translations/languages/da.d.ts.map +1 -0
- package/dist/translations/languages/da.js +34 -0
- package/dist/translations/languages/da.js.map +1 -0
- package/dist/translations/languages/de.d.ts +31 -0
- package/dist/translations/languages/de.d.ts.map +1 -0
- package/dist/translations/languages/de.js +34 -0
- package/dist/translations/languages/de.js.map +1 -0
- package/dist/translations/languages/en.d.ts +31 -0
- package/dist/translations/languages/en.d.ts.map +1 -0
- package/dist/translations/languages/en.js +34 -0
- package/dist/translations/languages/en.js.map +1 -0
- package/dist/translations/languages/es.d.ts +31 -0
- package/dist/translations/languages/es.d.ts.map +1 -0
- package/dist/translations/languages/es.js +34 -0
- package/dist/translations/languages/es.js.map +1 -0
- package/dist/translations/languages/et.d.ts +31 -0
- package/dist/translations/languages/et.d.ts.map +1 -0
- package/dist/translations/languages/et.js +34 -0
- package/dist/translations/languages/et.js.map +1 -0
- package/dist/translations/languages/fa.d.ts +31 -0
- package/dist/translations/languages/fa.d.ts.map +1 -0
- package/dist/translations/languages/fa.js +34 -0
- package/dist/translations/languages/fa.js.map +1 -0
- package/dist/translations/languages/fr.d.ts +31 -0
- package/dist/translations/languages/fr.d.ts.map +1 -0
- package/dist/translations/languages/fr.js +34 -0
- package/dist/translations/languages/fr.js.map +1 -0
- package/dist/translations/languages/he.d.ts +31 -0
- package/dist/translations/languages/he.d.ts.map +1 -0
- package/dist/translations/languages/he.js +34 -0
- package/dist/translations/languages/he.js.map +1 -0
- package/dist/translations/languages/hr.d.ts +31 -0
- package/dist/translations/languages/hr.d.ts.map +1 -0
- package/dist/translations/languages/hr.js +34 -0
- package/dist/translations/languages/hr.js.map +1 -0
- package/dist/translations/languages/hu.d.ts +31 -0
- package/dist/translations/languages/hu.d.ts.map +1 -0
- package/dist/translations/languages/hu.js +34 -0
- package/dist/translations/languages/hu.js.map +1 -0
- package/dist/translations/languages/hy.d.ts +31 -0
- package/dist/translations/languages/hy.d.ts.map +1 -0
- package/dist/translations/languages/hy.js +34 -0
- package/dist/translations/languages/hy.js.map +1 -0
- package/dist/translations/languages/id.d.ts +31 -0
- package/dist/translations/languages/id.d.ts.map +1 -0
- package/dist/translations/languages/id.js +34 -0
- package/dist/translations/languages/id.js.map +1 -0
- package/dist/translations/languages/is.d.ts +31 -0
- package/dist/translations/languages/is.d.ts.map +1 -0
- package/dist/translations/languages/is.js +34 -0
- package/dist/translations/languages/is.js.map +1 -0
- package/dist/translations/languages/it.d.ts +31 -0
- package/dist/translations/languages/it.d.ts.map +1 -0
- package/dist/translations/languages/it.js +34 -0
- package/dist/translations/languages/it.js.map +1 -0
- package/dist/translations/languages/ja.d.ts +31 -0
- package/dist/translations/languages/ja.d.ts.map +1 -0
- package/dist/translations/languages/ja.js +34 -0
- package/dist/translations/languages/ja.js.map +1 -0
- package/dist/translations/languages/ko.d.ts +31 -0
- package/dist/translations/languages/ko.d.ts.map +1 -0
- package/dist/translations/languages/ko.js +34 -0
- package/dist/translations/languages/ko.js.map +1 -0
- package/dist/translations/languages/lt.d.ts +31 -0
- package/dist/translations/languages/lt.d.ts.map +1 -0
- package/dist/translations/languages/lt.js +34 -0
- package/dist/translations/languages/lt.js.map +1 -0
- package/dist/translations/languages/lv.d.ts +31 -0
- package/dist/translations/languages/lv.d.ts.map +1 -0
- package/dist/translations/languages/lv.js +34 -0
- package/dist/translations/languages/lv.js.map +1 -0
- package/dist/translations/languages/my.d.ts +31 -0
- package/dist/translations/languages/my.d.ts.map +1 -0
- package/dist/translations/languages/my.js +34 -0
- package/dist/translations/languages/my.js.map +1 -0
- package/dist/translations/languages/nb.d.ts +31 -0
- package/dist/translations/languages/nb.d.ts.map +1 -0
- package/dist/translations/languages/nb.js +34 -0
- package/dist/translations/languages/nb.js.map +1 -0
- package/dist/translations/languages/nl.d.ts +31 -0
- package/dist/translations/languages/nl.d.ts.map +1 -0
- package/dist/translations/languages/nl.js +34 -0
- package/dist/translations/languages/nl.js.map +1 -0
- package/dist/translations/languages/pl.d.ts +31 -0
- package/dist/translations/languages/pl.d.ts.map +1 -0
- package/dist/translations/languages/pl.js +34 -0
- package/dist/translations/languages/pl.js.map +1 -0
- package/dist/translations/languages/pt.d.ts +31 -0
- package/dist/translations/languages/pt.d.ts.map +1 -0
- package/dist/translations/languages/pt.js +34 -0
- package/dist/translations/languages/pt.js.map +1 -0
- package/dist/translations/languages/ro.d.ts +31 -0
- package/dist/translations/languages/ro.d.ts.map +1 -0
- package/dist/translations/languages/ro.js +34 -0
- package/dist/translations/languages/ro.js.map +1 -0
- package/dist/translations/languages/rs.d.ts +31 -0
- package/dist/translations/languages/rs.d.ts.map +1 -0
- package/dist/translations/languages/rs.js +34 -0
- package/dist/translations/languages/rs.js.map +1 -0
- package/dist/translations/languages/rsLatin.d.ts +31 -0
- package/dist/translations/languages/rsLatin.d.ts.map +1 -0
- package/dist/translations/languages/rsLatin.js +34 -0
- package/dist/translations/languages/rsLatin.js.map +1 -0
- package/dist/translations/languages/ru.d.ts +31 -0
- package/dist/translations/languages/ru.d.ts.map +1 -0
- package/dist/translations/languages/ru.js +34 -0
- package/dist/translations/languages/ru.js.map +1 -0
- package/dist/translations/languages/sk.d.ts +31 -0
- package/dist/translations/languages/sk.d.ts.map +1 -0
- package/dist/translations/languages/sk.js +34 -0
- package/dist/translations/languages/sk.js.map +1 -0
- package/dist/translations/languages/sl.d.ts +31 -0
- package/dist/translations/languages/sl.d.ts.map +1 -0
- package/dist/translations/languages/sl.js +34 -0
- package/dist/translations/languages/sl.js.map +1 -0
- package/dist/translations/languages/sv.d.ts +31 -0
- package/dist/translations/languages/sv.d.ts.map +1 -0
- package/dist/translations/languages/sv.js +34 -0
- package/dist/translations/languages/sv.js.map +1 -0
- package/dist/translations/languages/ta.d.ts +31 -0
- package/dist/translations/languages/ta.d.ts.map +1 -0
- package/dist/translations/languages/ta.js +34 -0
- package/dist/translations/languages/ta.js.map +1 -0
- package/dist/translations/languages/th.d.ts +31 -0
- package/dist/translations/languages/th.d.ts.map +1 -0
- package/dist/translations/languages/th.js +34 -0
- package/dist/translations/languages/th.js.map +1 -0
- package/dist/translations/languages/tr.d.ts +31 -0
- package/dist/translations/languages/tr.d.ts.map +1 -0
- package/dist/translations/languages/tr.js +34 -0
- package/dist/translations/languages/tr.js.map +1 -0
- package/dist/translations/languages/uk.d.ts +31 -0
- package/dist/translations/languages/uk.d.ts.map +1 -0
- package/dist/translations/languages/uk.js +34 -0
- package/dist/translations/languages/uk.js.map +1 -0
- package/dist/translations/languages/vi.d.ts +31 -0
- package/dist/translations/languages/vi.d.ts.map +1 -0
- package/dist/translations/languages/vi.js +34 -0
- package/dist/translations/languages/vi.js.map +1 -0
- package/dist/translations/languages/zh.d.ts +31 -0
- package/dist/translations/languages/zh.d.ts.map +1 -0
- package/dist/translations/languages/zh.js +34 -0
- package/dist/translations/languages/zh.js.map +1 -0
- package/dist/translations/languages/zhTw.d.ts +31 -0
- package/dist/translations/languages/zhTw.d.ts.map +1 -0
- package/dist/translations/languages/zhTw.js +34 -0
- package/dist/translations/languages/zhTw.js.map +1 -0
- package/dist/translations/types.d.ts +32 -0
- package/dist/translations/types.d.ts.map +1 -0
- package/dist/translations/types.js +3 -0
- package/dist/translations/types.js.map +1 -0
- package/dist/types.d.ts +22 -28
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/utils/schemaConversion/getEntityInputSchema.d.ts +11 -0
- package/dist/utils/schemaConversion/getEntityInputSchema.d.ts.map +1 -0
- package/dist/utils/schemaConversion/getEntityInputSchema.js +34 -0
- package/dist/utils/schemaConversion/getEntityInputSchema.js.map +1 -0
- package/dist/utils/schemaConversion/sanitizeEntitySchema.d.ts +15 -0
- package/dist/utils/schemaConversion/sanitizeEntitySchema.d.ts.map +1 -0
- package/dist/utils/schemaConversion/sanitizeEntitySchema.js +464 -0
- package/dist/utils/schemaConversion/sanitizeEntitySchema.js.map +1 -0
- package/dist/utils/schemaConversion/sanitizeEntitySchema.spec.js +158 -0
- package/dist/utils/schemaConversion/sanitizeEntitySchema.spec.js.map +1 -0
- package/dist/utils/whereSchema.d.ts +9 -0
- package/dist/utils/whereSchema.d.ts.map +1 -0
- package/dist/utils/whereSchema.js +13 -0
- package/dist/utils/whereSchema.js.map +1 -0
- package/package.json +7 -6
- package/src/collection/getAccessField.ts +33 -13
- package/src/collection/index.ts +64 -22
- package/src/components/APIKeyField/index.client.tsx +73 -0
- package/src/components/APIKeyField/index.css +105 -0
- package/src/components/APIKeysEmptyState/index.client.tsx +36 -0
- package/src/components/AccessField/index.client.tsx +175 -220
- package/src/components/AccessField/index.css +50 -44
- package/src/components/SettingsMenu/index.client.tsx +34 -0
- package/src/endpoint/access.ts +17 -5
- package/src/exports/client.ts +3 -0
- package/src/index.ts +49 -3
- package/src/mcp/buildMcpServer.ts +123 -90
- package/src/mcp/builtin/collections/createTool.ts +46 -50
- package/src/mcp/builtin/collections/deleteTool.ts +9 -16
- package/src/mcp/builtin/collections/findTool.ts +7 -17
- package/src/mcp/builtin/collections/formatCollectionError.ts +84 -0
- package/src/mcp/builtin/collections/getCollectionSchemaTool.ts +28 -0
- package/src/mcp/builtin/collections/updateTool.ts +97 -91
- package/src/mcp/builtin/getConfigInfoTool.ts +44 -0
- package/src/mcp/builtin/globals/findTool.ts +1 -1
- package/src/mcp/builtin/globals/getGlobalSchemaTool.ts +28 -0
- package/src/mcp/builtin/globals/updateTool.ts +40 -43
- package/src/mcp/builtin/validateEntityData.ts +132 -0
- package/src/mcp/builtinTools.ts +52 -38
- package/src/mcp/sanitizeMCPConfig.ts +78 -57
- package/src/translations/index.ts +108 -0
- package/src/translations/languages/ar.ts +35 -0
- package/src/translations/languages/az.ts +35 -0
- package/src/translations/languages/bg.ts +35 -0
- package/src/translations/languages/bnBd.ts +35 -0
- package/src/translations/languages/bnIn.ts +35 -0
- package/src/translations/languages/ca.ts +35 -0
- package/src/translations/languages/cs.ts +35 -0
- package/src/translations/languages/da.ts +35 -0
- package/src/translations/languages/de.ts +35 -0
- package/src/translations/languages/en.ts +35 -0
- package/src/translations/languages/es.ts +35 -0
- package/src/translations/languages/et.ts +35 -0
- package/src/translations/languages/fa.ts +35 -0
- package/src/translations/languages/fr.ts +35 -0
- package/src/translations/languages/he.ts +35 -0
- package/src/translations/languages/hr.ts +35 -0
- package/src/translations/languages/hu.ts +35 -0
- package/src/translations/languages/hy.ts +35 -0
- package/src/translations/languages/id.ts +35 -0
- package/src/translations/languages/is.ts +35 -0
- package/src/translations/languages/it.ts +35 -0
- package/src/translations/languages/ja.ts +35 -0
- package/src/translations/languages/ko.ts +35 -0
- package/src/translations/languages/lt.ts +35 -0
- package/src/translations/languages/lv.ts +35 -0
- package/src/translations/languages/my.ts +35 -0
- package/src/translations/languages/nb.ts +35 -0
- package/src/translations/languages/nl.ts +35 -0
- package/src/translations/languages/pl.ts +35 -0
- package/src/translations/languages/pt.ts +35 -0
- package/src/translations/languages/ro.ts +35 -0
- package/src/translations/languages/rs.ts +35 -0
- package/src/translations/languages/rsLatin.ts +35 -0
- package/src/translations/languages/ru.ts +35 -0
- package/src/translations/languages/sk.ts +35 -0
- package/src/translations/languages/sl.ts +35 -0
- package/src/translations/languages/sv.ts +35 -0
- package/src/translations/languages/ta.ts +35 -0
- package/src/translations/languages/th.ts +35 -0
- package/src/translations/languages/tr.ts +35 -0
- package/src/translations/languages/uk.ts +35 -0
- package/src/translations/languages/vi.ts +35 -0
- package/src/translations/languages/zh.ts +35 -0
- package/src/translations/languages/zhTw.ts +35 -0
- package/src/translations/types.ts +34 -0
- package/src/types.ts +30 -30
- package/src/utils/schemaConversion/getEntityInputSchema.ts +78 -0
- package/src/utils/schemaConversion/sanitizeEntitySchema.spec.ts +103 -0
- package/src/utils/schemaConversion/sanitizeEntitySchema.ts +529 -0
- package/src/utils/whereSchema.ts +24 -0
- package/dist/utils/schemaConversion/prepareCollectionSchema.d.ts +0 -7
- package/dist/utils/schemaConversion/prepareCollectionSchema.d.ts.map +0 -1
- package/dist/utils/schemaConversion/prepareCollectionSchema.js +0 -37
- package/dist/utils/schemaConversion/prepareCollectionSchema.js.map +0 -1
- package/dist/utils/schemaConversion/sanitizeJsonSchema.d.ts +0 -13
- package/dist/utils/schemaConversion/sanitizeJsonSchema.d.ts.map +0 -1
- package/dist/utils/schemaConversion/sanitizeJsonSchema.js +0 -56
- package/dist/utils/schemaConversion/sanitizeJsonSchema.js.map +0 -1
- package/dist/utils/schemaConversion/simplifyRelationshipFields.d.ts +0 -20
- package/dist/utils/schemaConversion/simplifyRelationshipFields.d.ts.map +0 -1
- package/dist/utils/schemaConversion/simplifyRelationshipFields.js +0 -56
- package/dist/utils/schemaConversion/simplifyRelationshipFields.js.map +0 -1
- package/dist/utils/schemaConversion/transformPointFields.d.ts +0 -3
- package/dist/utils/schemaConversion/transformPointFields.d.ts.map +0 -1
- package/dist/utils/schemaConversion/transformPointFields.js +0 -57
- package/dist/utils/schemaConversion/transformPointFields.js.map +0 -1
- package/src/utils/schemaConversion/prepareCollectionSchema.ts +0 -39
- package/src/utils/schemaConversion/sanitizeJsonSchema.ts +0 -62
- package/src/utils/schemaConversion/simplifyRelationshipFields.ts +0 -70
- package/src/utils/schemaConversion/transformPointFields.ts +0 -56
|
@@ -0,0 +1,529 @@
|
|
|
1
|
+
import type { JsonSchemaType } from '../../types.js'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Turns the JSON Schema that Payload generates for a collection or global into the input schema for
|
|
5
|
+
* an MCP create/update tool. In short, it:
|
|
6
|
+
*
|
|
7
|
+
* - drops fields a client can't set (`id`, `createdAt`, the draft `_status`, …),
|
|
8
|
+
* - rewrites Payload-specific field shapes (points, relationships) into plain JSON the model can fill,
|
|
9
|
+
* - and shrinks the result so it's cheaper for the model to read,
|
|
10
|
+
*
|
|
11
|
+
* while keeping every node valid JSON Schema draft 2020-12. Each step below is tagged with why it runs -
|
|
12
|
+
* **Correctness** (valid input the API accepts), **Size** (equivalence-preserving shrink), or **LLM
|
|
13
|
+
* ergonomics** (easier for the model to read/fill) - and carries a before/after example on its definition.
|
|
14
|
+
*/
|
|
15
|
+
export const sanitizeEntitySchema = (schema: JsonSchemaType): JsonSchemaType => {
|
|
16
|
+
// Work on a copy — the caller reuses the original schema elsewhere (e.g. when listing tools).
|
|
17
|
+
let result = structuredClone(schema)
|
|
18
|
+
|
|
19
|
+
// Correctness — drop the fields a client can't set (id, createdAt, updatedAt, draft _status) + collapse nullable types.
|
|
20
|
+
result = removeManagedFields(result)
|
|
21
|
+
|
|
22
|
+
// LLM ergonomics — rewrite point fields from a `[number, number]` tuple into a `{ longitude, latitude }` object.
|
|
23
|
+
result = pointFieldsToObjects(result)
|
|
24
|
+
|
|
25
|
+
// Correctness — a relationship value can be an ID or a populated doc; on input only the ID is valid, so keep that.
|
|
26
|
+
result = relationshipsToIds(result)
|
|
27
|
+
|
|
28
|
+
// Size — strip inert type-gen leftovers that only bloat the schema (`tsType`, block-collision notes).
|
|
29
|
+
result = removeTypeGenArtifacts(result)
|
|
30
|
+
|
|
31
|
+
// Size — where a `const` already pins a value, the sibling `type` is redundant; remove it.
|
|
32
|
+
result = dropRedundantConstType(result)
|
|
33
|
+
|
|
34
|
+
// Size — fold per-collection relationship/upload variants (identical but for `relationTo`) into one `enum`.
|
|
35
|
+
result = mergeConstDiscriminatedUnions(result)
|
|
36
|
+
|
|
37
|
+
// Size — pull any subschema that appears more than once into a single shared `$defs` entry.
|
|
38
|
+
result = deduplicateIntoDefinitions(result)
|
|
39
|
+
|
|
40
|
+
// LLM ergonomics — give `$defs` short, readable names (`Code`, `paragraph`, `node`) so the `$ref`s read nicely.
|
|
41
|
+
result = shortenDefinitionNames(result)
|
|
42
|
+
|
|
43
|
+
return result
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Rebuilds a schema bottom-up, calling `visit` on each node after its children. Shared by the
|
|
48
|
+
* transforms that need to touch every node in the tree.
|
|
49
|
+
*/
|
|
50
|
+
const mapNodes = (node: unknown, visit: (node: JsonSchemaType) => JsonSchemaType): unknown => {
|
|
51
|
+
if (Array.isArray(node)) {
|
|
52
|
+
return node.map((child) => mapNodes(child, visit))
|
|
53
|
+
}
|
|
54
|
+
if (!node || typeof node !== 'object') {
|
|
55
|
+
return node
|
|
56
|
+
}
|
|
57
|
+
const out: Record<string, unknown> = {}
|
|
58
|
+
for (const [key, value] of Object.entries(node)) {
|
|
59
|
+
out[key] = mapNodes(value, visit)
|
|
60
|
+
}
|
|
61
|
+
return visit(out as JsonSchemaType)
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// Payload sets these on every document, so an MCP client never provides them when creating/updating.
|
|
65
|
+
const PAYLOAD_MANAGED_FIELDS = new Set(['_status', 'createdAt', 'id', 'updatedAt'])
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* **Correctness.** Removes the fields a client can't set on create/update - `id`, `createdAt`, `updatedAt`, and the draft
|
|
69
|
+
* `_status` - from every field object's `properties` and `required` (recursing into nested objects and
|
|
70
|
+
* array items). Along the way it also collapses optional array/object types via {@link collapseNullableType}.
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* { properties: { id: { type: 'string' }, tags: { type: ['array', 'null'], items: {} } }, required: ['id', 'tags'] }
|
|
74
|
+
* → { properties: { tags: { type: 'array', items: {} } }, required: ['tags'] }
|
|
75
|
+
*/
|
|
76
|
+
const removeManagedFields = (schema: JsonSchemaType): JsonSchemaType => {
|
|
77
|
+
if (schema.properties && typeof schema.properties === 'object') {
|
|
78
|
+
for (const field of PAYLOAD_MANAGED_FIELDS) {
|
|
79
|
+
delete schema.properties[field]
|
|
80
|
+
}
|
|
81
|
+
for (const key of Object.keys(schema.properties)) {
|
|
82
|
+
const prop = schema.properties[key] as JsonSchemaType
|
|
83
|
+
if (!prop || typeof prop !== 'object') {
|
|
84
|
+
continue
|
|
85
|
+
}
|
|
86
|
+
const isRequired = Array.isArray(schema.required) && schema.required.includes(key)
|
|
87
|
+
collapseNullableType(prop, isRequired)
|
|
88
|
+
if (prop.properties) {
|
|
89
|
+
removeManagedFields(prop)
|
|
90
|
+
}
|
|
91
|
+
if (prop.items && typeof prop.items === 'object' && !Array.isArray(prop.items)) {
|
|
92
|
+
removeManagedFields(prop.items)
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
if (Array.isArray(schema.required)) {
|
|
98
|
+
schema.required = schema.required.filter((name) => !PAYLOAD_MANAGED_FIELDS.has(name))
|
|
99
|
+
if (schema.required.length === 0) {
|
|
100
|
+
delete schema.required
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
return schema
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Drops the `'null'` from an optional array/object type (`['array', 'null']` → `'array'`, likewise
|
|
109
|
+
* `'object'`). Payload marks a field optional by unioning its type with `'null'`, but a create/update
|
|
110
|
+
* tool already conveys "optional" through the `required` list - the client just omits the field - so the
|
|
111
|
+
* `'null'` is redundant here. Dropping it shows the model a plain `type: 'array'` instead of implying it
|
|
112
|
+
* should send a literal `null`.
|
|
113
|
+
*
|
|
114
|
+
* We never touch the `required` list, so this can't change whether a field is required. And we skip fields
|
|
115
|
+
* that ARE required (`isRequired`): there a `'null'` is a value the field genuinely accepts, not optionality
|
|
116
|
+
* encoding. Nullable scalars (`['string', 'null']`) are also left alone - they read fine as `string | null`.
|
|
117
|
+
*
|
|
118
|
+
* @example
|
|
119
|
+
* optional { type: ['array', 'null'] } → { type: 'array' } (still optional, just no longer null-valued)
|
|
120
|
+
* required { type: ['array', 'null'] } → unchanged
|
|
121
|
+
* { type: ['string', 'null'] } → unchanged
|
|
122
|
+
*/
|
|
123
|
+
const collapseNullableType = (schema: JsonSchemaType, isRequired: boolean): void => {
|
|
124
|
+
if (isRequired || !Array.isArray(schema.type)) {
|
|
125
|
+
return
|
|
126
|
+
}
|
|
127
|
+
const nonNullTypes = schema.type.filter((t) => t !== 'null')
|
|
128
|
+
if (nonNullTypes.length === 1 && (nonNullTypes[0] === 'array' || nonNullTypes[0] === 'object')) {
|
|
129
|
+
schema.type = nonNullTypes[0]
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* **LLM ergonomics.** Rewrites a point field (stored as a two-number tuple) into a `{ longitude, latitude }` object, which
|
|
135
|
+
* is far easier for the model to fill in than a positional array. This is input-only and lossless: the
|
|
136
|
+
* create/update handler converts the object back to the `[longitude, latitude]` tuple Payload stores,
|
|
137
|
+
* via `transformPointDataToPayload`.
|
|
138
|
+
*
|
|
139
|
+
* @example
|
|
140
|
+
* { type: 'array', items: [{ type: 'number' }, { type: 'number' }] }
|
|
141
|
+
* → { type: 'object', properties: { longitude: { type: 'number' }, latitude: { type: 'number' } }, required: ['longitude', 'latitude'] }
|
|
142
|
+
*/
|
|
143
|
+
const pointFieldsToObjects = (schema: JsonSchemaType): JsonSchemaType => {
|
|
144
|
+
if (!schema || typeof schema !== 'object') {
|
|
145
|
+
return schema
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
const transformed = { ...schema }
|
|
149
|
+
|
|
150
|
+
if (transformed.properties && typeof transformed.properties === 'object') {
|
|
151
|
+
transformed.properties = Object.fromEntries(
|
|
152
|
+
Object.entries(transformed.properties).map(([key, value]) => {
|
|
153
|
+
if (!value || typeof value !== 'object') {
|
|
154
|
+
return [key, value]
|
|
155
|
+
}
|
|
156
|
+
const isArrayType =
|
|
157
|
+
value.type === 'array' || (Array.isArray(value.type) && value.type.includes('array'))
|
|
158
|
+
const isPointField =
|
|
159
|
+
isArrayType &&
|
|
160
|
+
Array.isArray(value.items) &&
|
|
161
|
+
value.items.length === 2 &&
|
|
162
|
+
value.items.every((item) => item && typeof item === 'object' && item.type === 'number')
|
|
163
|
+
|
|
164
|
+
if (isPointField) {
|
|
165
|
+
const isNullable = Array.isArray(value.type) && value.type.includes('null')
|
|
166
|
+
return [
|
|
167
|
+
key,
|
|
168
|
+
{
|
|
169
|
+
type: isNullable ? ['object', 'null'] : 'object',
|
|
170
|
+
description: value.description || 'Geographic coordinates (longitude, latitude)',
|
|
171
|
+
properties: {
|
|
172
|
+
latitude: { type: 'number', description: 'Latitude coordinate' },
|
|
173
|
+
longitude: { type: 'number', description: 'Longitude coordinate' },
|
|
174
|
+
},
|
|
175
|
+
required: ['longitude', 'latitude'],
|
|
176
|
+
},
|
|
177
|
+
]
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
return [key, pointFieldsToObjects(value)]
|
|
181
|
+
}),
|
|
182
|
+
)
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
if (
|
|
186
|
+
transformed.items &&
|
|
187
|
+
typeof transformed.items === 'object' &&
|
|
188
|
+
!Array.isArray(transformed.items)
|
|
189
|
+
) {
|
|
190
|
+
transformed.items = pointFieldsToObjects(transformed.items)
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
return transformed
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* **Correctness.** Reduces relationship/upload fields to the IDs a client actually sends. Payload types the value as
|
|
198
|
+
* "an ID or the full related document" - but the populated-document form only appears in read responses;
|
|
199
|
+
* on create/update you always reference a relationship by its ID. So we drop that `$ref` option, leaving
|
|
200
|
+
* the bare ID. A single remaining target collapses inline (with a description naming the target
|
|
201
|
+
* collection); several targets become an `anyOf` of IDs.
|
|
202
|
+
*
|
|
203
|
+
* @example
|
|
204
|
+
* { oneOf: [{ type: 'string' }, { $ref: '#/$defs/posts' }] }
|
|
205
|
+
* → { type: 'string', description: 'The ID of the related "posts" document.' }
|
|
206
|
+
*/
|
|
207
|
+
const relationshipsToIds = (schema: JsonSchemaType): JsonSchemaType => {
|
|
208
|
+
if (!schema || typeof schema !== 'object') {
|
|
209
|
+
return schema
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
const processed = { ...schema }
|
|
213
|
+
|
|
214
|
+
if (Array.isArray(processed.oneOf)) {
|
|
215
|
+
const isRelatedDocRef = (option: unknown): option is { $ref: string } =>
|
|
216
|
+
!!option && typeof option === 'object' && '$ref' in option
|
|
217
|
+
|
|
218
|
+
if (processed.oneOf.some(isRelatedDocRef)) {
|
|
219
|
+
// A relationship value is "an ID, or the populated related document". Keep the ID option(s) and
|
|
220
|
+
// drop the `$ref`s to the related collections, since a client only ever sends the ID.
|
|
221
|
+
const idOptions = processed.oneOf
|
|
222
|
+
.filter((option) => !isRelatedDocRef(option))
|
|
223
|
+
.map((option) => (typeof option === 'object' ? relationshipsToIds(option) : option))
|
|
224
|
+
const targetCollections = processed.oneOf
|
|
225
|
+
.filter(isRelatedDocRef)
|
|
226
|
+
.map((option) => option.$ref.replace('#/$defs/', ''))
|
|
227
|
+
|
|
228
|
+
if (idOptions.length === 1) {
|
|
229
|
+
delete processed.oneOf
|
|
230
|
+
Object.assign(processed, idOptions[0])
|
|
231
|
+
if (targetCollections.length > 0 && !processed.description) {
|
|
232
|
+
processed.description = `The ID of the related "${targetCollections.join('" or "')}" document.`
|
|
233
|
+
}
|
|
234
|
+
} else if (idOptions.length > 1) {
|
|
235
|
+
delete processed.oneOf
|
|
236
|
+
processed.anyOf = idOptions
|
|
237
|
+
}
|
|
238
|
+
} else {
|
|
239
|
+
processed.oneOf = processed.oneOf.map((option) =>
|
|
240
|
+
typeof option === 'object' ? relationshipsToIds(option) : option,
|
|
241
|
+
)
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
if (processed.properties && typeof processed.properties === 'object') {
|
|
246
|
+
processed.properties = Object.fromEntries(
|
|
247
|
+
Object.entries(processed.properties).map(([key, value]) => [
|
|
248
|
+
key,
|
|
249
|
+
typeof value === 'object' ? relationshipsToIds(value) : value,
|
|
250
|
+
]),
|
|
251
|
+
)
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
if (processed.items && typeof processed.items === 'object' && !Array.isArray(processed.items)) {
|
|
255
|
+
processed.items = relationshipsToIds(processed.items)
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
// Lexical node unions and blocks live under `$defs` and have their own relationship fields, so walk
|
|
259
|
+
// those too — otherwise their `$ref`s would dangle once we don't bundle the related collections.
|
|
260
|
+
if (processed.$defs && typeof processed.$defs === 'object') {
|
|
261
|
+
processed.$defs = Object.fromEntries(
|
|
262
|
+
Object.entries(processed.$defs).map(([key, value]) => [
|
|
263
|
+
key,
|
|
264
|
+
typeof value === 'object' ? relationshipsToIds(value) : value,
|
|
265
|
+
]),
|
|
266
|
+
)
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
return processed
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
/**
|
|
273
|
+
* **Size.** Strips type-generation leftovers that bloat the schema without helping the model: the `tsType`
|
|
274
|
+
* hint (a `json-schema-to-typescript` extension; JSON Schema validators just ignore it, they don't reject it)
|
|
275
|
+
* and the block-interface-collision note Payload adds to some block descriptions (the
|
|
276
|
+
* `block-interface-name-collisions` docs link set in `registerBlockInterface`, see configToJSONSchema.ts).
|
|
277
|
+
* Both are inert here - removing them only shrinks the schema (and spares the model irrelevant noise).
|
|
278
|
+
*
|
|
279
|
+
* @example
|
|
280
|
+
* { type: 'object', tsType: 'SerializedBlockNode', description: 'see …#block-interface-name-collisions' }
|
|
281
|
+
* → { type: 'object' }
|
|
282
|
+
*/
|
|
283
|
+
const removeTypeGenArtifacts = (schema: JsonSchemaType): JsonSchemaType =>
|
|
284
|
+
mapNodes(schema, (node) => {
|
|
285
|
+
delete (node as { tsType?: unknown }).tsType
|
|
286
|
+
const { description } = node as { description?: string }
|
|
287
|
+
if (
|
|
288
|
+
typeof description === 'string' &&
|
|
289
|
+
description.includes('block-interface-name-collisions')
|
|
290
|
+
) {
|
|
291
|
+
delete (node as { description?: unknown }).description
|
|
292
|
+
}
|
|
293
|
+
return node
|
|
294
|
+
}) as JsonSchemaType
|
|
295
|
+
|
|
296
|
+
/**
|
|
297
|
+
* **Size.** Removes `type` whenever a `const` sits next to it — the constant already fixes the value.
|
|
298
|
+
*
|
|
299
|
+
* @example
|
|
300
|
+
* { type: 'string', const: 'paragraph' } → { const: 'paragraph' }
|
|
301
|
+
*/
|
|
302
|
+
const dropRedundantConstType = (schema: JsonSchemaType): JsonSchemaType =>
|
|
303
|
+
mapNodes(schema, (node) => {
|
|
304
|
+
if ('const' in node && 'type' in node) {
|
|
305
|
+
delete (node as { type?: unknown }).type
|
|
306
|
+
}
|
|
307
|
+
return node
|
|
308
|
+
}) as JsonSchemaType
|
|
309
|
+
|
|
310
|
+
/**
|
|
311
|
+
* **Size.** Merges the members of a `oneOf`/`anyOf` that are identical except for one `const`-valued property
|
|
312
|
+
* into a single member with that property as an `enum`. Since the members differ only by that one
|
|
313
|
+
* constant, the `enum` form accepts exactly the same values - it's just smaller. This folds the
|
|
314
|
+
* per-collection relationship and upload variants, which differ only in their `relationTo` constant.
|
|
315
|
+
*
|
|
316
|
+
* @example
|
|
317
|
+
* { oneOf: [
|
|
318
|
+
* { properties: { relationTo: { const: 'posts' }, value: { type: 'string' } } },
|
|
319
|
+
* { properties: { relationTo: { const: 'pages' }, value: { type: 'string' } } },
|
|
320
|
+
* ] }
|
|
321
|
+
* → { properties: { relationTo: { enum: ['posts', 'pages'] }, value: { type: 'string' } } }
|
|
322
|
+
*/
|
|
323
|
+
const mergeConstDiscriminatedUnions = (schema: JsonSchemaType): JsonSchemaType =>
|
|
324
|
+
mapNodes(schema, (node) => {
|
|
325
|
+
for (const keyword of ['oneOf', 'anyOf'] as const) {
|
|
326
|
+
const members = node[keyword]
|
|
327
|
+
if (Array.isArray(members) && members.length > 1) {
|
|
328
|
+
const merged = mergeMembersByConst(members)
|
|
329
|
+
if (merged) {
|
|
330
|
+
delete node[keyword]
|
|
331
|
+
Object.assign(node, merged)
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
return node
|
|
336
|
+
}) as JsonSchemaType
|
|
337
|
+
|
|
338
|
+
/** Returns the merged member for {@link mergeConstDiscriminatedUnions}, or `null` if they can't merge. */
|
|
339
|
+
const mergeMembersByConst = (members: Array<boolean | JsonSchemaType>): JsonSchemaType | null => {
|
|
340
|
+
const objects = members.filter(
|
|
341
|
+
(member): member is JsonSchemaType =>
|
|
342
|
+
typeof member === 'object' && member !== null && typeof member.properties === 'object',
|
|
343
|
+
)
|
|
344
|
+
if (objects.length < 2 || objects.length !== members.length) {
|
|
345
|
+
return null
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
for (const discriminator of Object.keys(objects[0]!.properties!)) {
|
|
349
|
+
// Each member must pin this property to a `const`...
|
|
350
|
+
const constValues: unknown[] = []
|
|
351
|
+
const everyMemberPinsConst = objects.every((member) => {
|
|
352
|
+
const prop = member.properties![discriminator]
|
|
353
|
+
if (prop && typeof prop === 'object' && 'const' in prop) {
|
|
354
|
+
constValues.push(prop.const)
|
|
355
|
+
return true
|
|
356
|
+
}
|
|
357
|
+
return false
|
|
358
|
+
})
|
|
359
|
+
if (!everyMemberPinsConst) {
|
|
360
|
+
continue
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
// ...and be otherwise identical (compare each member with the discriminator removed).
|
|
364
|
+
const fingerprintWithoutDiscriminator = (member: JsonSchemaType): string => {
|
|
365
|
+
const { [discriminator]: _discriminator, ...otherProperties } = member.properties!
|
|
366
|
+
return JSON.stringify({ ...member, properties: otherProperties })
|
|
367
|
+
}
|
|
368
|
+
if (new Set(objects.map(fingerprintWithoutDiscriminator)).size !== 1) {
|
|
369
|
+
continue
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
const uniqueConstValues = [...new Set(constValues)]
|
|
373
|
+
if (uniqueConstValues.length < 2) {
|
|
374
|
+
continue
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
// Replace the per-member `const` with a single `enum` of every value.
|
|
378
|
+
const merged = structuredClone(objects[0]!)
|
|
379
|
+
const discriminatorProp = merged.properties![discriminator]
|
|
380
|
+
if (discriminatorProp && typeof discriminatorProp === 'object') {
|
|
381
|
+
delete discriminatorProp.const
|
|
382
|
+
discriminatorProp.enum = uniqueConstValues as NonNullable<typeof discriminatorProp.enum>
|
|
383
|
+
}
|
|
384
|
+
return merged
|
|
385
|
+
}
|
|
386
|
+
return null
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
// A `$ref` costs ~30 characters once names are shortened, so sharing a subschema only pays off when
|
|
390
|
+
// it's larger than that and appears more than once.
|
|
391
|
+
const MIN_SHARED_SIZE = 64
|
|
392
|
+
|
|
393
|
+
/** A subschema worth sharing: a standalone object/union/described schema, not a `$ref` or a primitive. */
|
|
394
|
+
const isShareable = (node: unknown): node is Record<string, unknown> => {
|
|
395
|
+
if (!node || typeof node !== 'object' || Array.isArray(node) || '$ref' in node) {
|
|
396
|
+
return false
|
|
397
|
+
}
|
|
398
|
+
const schema = node as JsonSchemaType
|
|
399
|
+
return (
|
|
400
|
+
Array.isArray(schema.oneOf) ||
|
|
401
|
+
Array.isArray(schema.anyOf) ||
|
|
402
|
+
Boolean(schema.properties) ||
|
|
403
|
+
Boolean(schema.items) ||
|
|
404
|
+
typeof schema.description === 'string'
|
|
405
|
+
)
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
/**
|
|
409
|
+
* **Size.** Replaces any subschema that appears more than once with a single shared `$defs` entry referenced by
|
|
410
|
+
* `$ref`. Lossless — only the serialized size shrinks. A collection with several rich-text fields, for
|
|
411
|
+
* example, inlines the same large lexical node schema once per field; this collapses them into one.
|
|
412
|
+
*
|
|
413
|
+
* @example
|
|
414
|
+
* { properties: { billing: address, shipping: address } }
|
|
415
|
+
* → { properties: { billing: { $ref: '#/$defs/shared_0' }, shipping: { $ref: '#/$defs/shared_0' } }, $defs: { shared_0: address } }
|
|
416
|
+
*/
|
|
417
|
+
const deduplicateIntoDefinitions = (schema: JsonSchemaType): JsonSchemaType => {
|
|
418
|
+
// Count how often each shareable subschema appears, keyed by its serialized form.
|
|
419
|
+
const counts = new Map<string, number>()
|
|
420
|
+
const count = (node: unknown): void => {
|
|
421
|
+
if (isShareable(node)) {
|
|
422
|
+
const key = JSON.stringify(node)
|
|
423
|
+
if (key.length >= MIN_SHARED_SIZE) {
|
|
424
|
+
counts.set(key, (counts.get(key) ?? 0) + 1)
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
if (Array.isArray(node)) {
|
|
428
|
+
node.forEach(count)
|
|
429
|
+
} else if (node && typeof node === 'object') {
|
|
430
|
+
Object.values(node).forEach(count)
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
count(schema)
|
|
434
|
+
|
|
435
|
+
if (![...counts.values()].some((n) => n >= 2)) {
|
|
436
|
+
return schema
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
// Replace each subschema seen 2+ times with a `$ref`. The first time we meet one it becomes a shared
|
|
440
|
+
// entry; we never descend into a stored entry, so shared entries never reference one another.
|
|
441
|
+
const sharedEntries: Record<string, JsonSchemaType> = {}
|
|
442
|
+
const nameByKey = new Map<string, string>()
|
|
443
|
+
const share = (node: unknown): unknown => {
|
|
444
|
+
if (isShareable(node)) {
|
|
445
|
+
const key = JSON.stringify(node)
|
|
446
|
+
if ((counts.get(key) ?? 0) >= 2) {
|
|
447
|
+
let name = nameByKey.get(key)
|
|
448
|
+
if (!name) {
|
|
449
|
+
name = `shared_${nameByKey.size}`
|
|
450
|
+
nameByKey.set(key, name)
|
|
451
|
+
sharedEntries[name] = node as JsonSchemaType
|
|
452
|
+
}
|
|
453
|
+
return { $ref: `#/$defs/${name}` }
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
if (Array.isArray(node)) {
|
|
457
|
+
return node.map(share)
|
|
458
|
+
}
|
|
459
|
+
if (node && typeof node === 'object') {
|
|
460
|
+
return Object.fromEntries(
|
|
461
|
+
Object.entries(node).map(([childKey, value]) => [childKey, share(value)]),
|
|
462
|
+
)
|
|
463
|
+
}
|
|
464
|
+
return node
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
const result = share(schema) as JsonSchemaType
|
|
468
|
+
result.$defs = { ...result.$defs, ...sharedEntries }
|
|
469
|
+
return result
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
/**
|
|
473
|
+
* **LLM ergonomics.** Renames `$defs` entries to short, readable names so the `$ref`s stay legible to the model: a block's
|
|
474
|
+
* `blockType` (`Code`), a node's `type` (`paragraph`), `node` for a rich-text node union, otherwise the
|
|
475
|
+
* generated name with its disambiguating hash dropped. A numeric suffix keeps collisions unique.
|
|
476
|
+
*
|
|
477
|
+
* @example
|
|
478
|
+
* { properties: { body: { $ref: '#/$defs/LexicalNodes_9FBEC708' } }, $defs: { LexicalNodes_9FBEC708: {} } }
|
|
479
|
+
* → { properties: { body: { $ref: '#/$defs/node' } }, $defs: { node: {} } }
|
|
480
|
+
*/
|
|
481
|
+
const shortenDefinitionNames = (schema: JsonSchemaType): JsonSchemaType => {
|
|
482
|
+
const definitions = schema.$defs
|
|
483
|
+
if (!definitions || Object.keys(definitions).length === 0) {
|
|
484
|
+
return schema
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
const shortNameFor = (name: string, definition: boolean | JsonSchemaType): string => {
|
|
488
|
+
const properties = (typeof definition === 'object' && definition.properties) || {}
|
|
489
|
+
const constString = (key: string): string | undefined => {
|
|
490
|
+
const prop = properties[key]
|
|
491
|
+
return prop && typeof prop === 'object' && typeof prop.const === 'string'
|
|
492
|
+
? prop.const
|
|
493
|
+
: undefined
|
|
494
|
+
}
|
|
495
|
+
const members =
|
|
496
|
+
typeof definition === 'object' ? (definition.anyOf ?? definition.oneOf) : undefined
|
|
497
|
+
const isNodeUnion =
|
|
498
|
+
Array.isArray(members) &&
|
|
499
|
+
members.some((m) => typeof m === 'object' && Boolean(m.$ref || m.properties?.type))
|
|
500
|
+
return (
|
|
501
|
+
constString('blockType') ??
|
|
502
|
+
constString('type') ??
|
|
503
|
+
(isNodeUnion ? 'node' : undefined) ??
|
|
504
|
+
name.replace(/_[0-9A-F]{6,}$/i, '')
|
|
505
|
+
)
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
const prefix = '#/$defs/'
|
|
509
|
+
const usedNames = new Map<string, number>()
|
|
510
|
+
const rename = new Map<string, string>()
|
|
511
|
+
for (const [name, definition] of Object.entries(definitions)) {
|
|
512
|
+
const shortName = shortNameFor(name, definition)
|
|
513
|
+
const used = usedNames.get(shortName) ?? 0
|
|
514
|
+
usedNames.set(shortName, used + 1)
|
|
515
|
+
rename.set(name, used === 0 ? shortName : `${shortName}${used + 1}`)
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
const result = mapNodes(schema, (node) => {
|
|
519
|
+
if (typeof node.$ref === 'string' && node.$ref.startsWith(prefix)) {
|
|
520
|
+
const name = node.$ref.slice(prefix.length)
|
|
521
|
+
node.$ref = `${prefix}${rename.get(name) ?? name}`
|
|
522
|
+
}
|
|
523
|
+
return node
|
|
524
|
+
}) as JsonSchemaType
|
|
525
|
+
result.$defs = Object.fromEntries(
|
|
526
|
+
Object.entries(result.$defs!).map(([name, body]) => [rename.get(name) ?? name, body]),
|
|
527
|
+
)
|
|
528
|
+
return result
|
|
529
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { Where } from 'payload'
|
|
2
|
+
|
|
3
|
+
import { validOperators } from 'payload/shared'
|
|
4
|
+
import { z } from 'zod'
|
|
5
|
+
|
|
6
|
+
const whereFieldSchema = z
|
|
7
|
+
.partialRecord(z.enum(validOperators), z.unknown())
|
|
8
|
+
.describe('Field query operators')
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* - Validates the `where` input of collection tools against Payload's `Where` shape
|
|
12
|
+
* - Field keys map to operator objects restricted to `validOperators`
|
|
13
|
+
* - `and` / `or` nest recursively
|
|
14
|
+
*/
|
|
15
|
+
export const whereSchema: z.ZodType<Where> = z
|
|
16
|
+
.lazy(() =>
|
|
17
|
+
z
|
|
18
|
+
.object({
|
|
19
|
+
and: z.array(whereSchema).optional(),
|
|
20
|
+
or: z.array(whereSchema).optional(),
|
|
21
|
+
})
|
|
22
|
+
.catchall(whereFieldSchema),
|
|
23
|
+
)
|
|
24
|
+
.describe('Where clause using field names with Payload query operators, plus and/or groups')
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import type { JsonSchemaType } from '../../types.js';
|
|
2
|
-
/**
|
|
3
|
-
* Sanitizes Payload's auto-generated collection JSON Schema so it can be safely
|
|
4
|
-
* fed into the MCP server's `fromJsonSchema()` adapter (no zod intermediate step).
|
|
5
|
-
*/
|
|
6
|
-
export declare const prepareCollectionSchema: (schema: JsonSchemaType) => JsonSchemaType;
|
|
7
|
-
//# sourceMappingURL=prepareCollectionSchema.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"prepareCollectionSchema.d.ts","sourceRoot":"","sources":["../../../src/utils/schemaConversion/prepareCollectionSchema.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAapD;;;GAGG;AACH,eAAO,MAAM,uBAAuB,GAAI,QAAQ,cAAc,KAAG,cAqBhE,CAAA"}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { sanitizeJsonSchema } from './sanitizeJsonSchema.js';
|
|
2
|
-
import { simplifyRelationshipFields } from './simplifyRelationshipFields.js';
|
|
3
|
-
import { transformPointFieldsForMCP } from './transformPointFields.js';
|
|
4
|
-
/**
|
|
5
|
-
* Fields Payload manages automatically — clients should never be required to provide
|
|
6
|
-
* them. Stripped from `required` and `properties` so they don't appear in tool
|
|
7
|
-
* inputs.
|
|
8
|
-
*/ const PAYLOAD_MANAGED_FIELDS = new Set([
|
|
9
|
-
'_status',
|
|
10
|
-
'createdAt',
|
|
11
|
-
'id',
|
|
12
|
-
'updatedAt'
|
|
13
|
-
]);
|
|
14
|
-
/**
|
|
15
|
-
* Sanitizes Payload's auto-generated collection JSON Schema so it can be safely
|
|
16
|
-
* fed into the MCP server's `fromJsonSchema()` adapter (no zod intermediate step).
|
|
17
|
-
*/ export const prepareCollectionSchema = (schema)=>{
|
|
18
|
-
// Clone to avoid mutating the original schema (used elsewhere for tool listing)
|
|
19
|
-
const schemaClone = JSON.parse(JSON.stringify(schema));
|
|
20
|
-
const sanitized = sanitizeJsonSchema(schemaClone);
|
|
21
|
-
const pointTransformed = transformPointFieldsForMCP(sanitized);
|
|
22
|
-
const simplified = simplifyRelationshipFields(pointTransformed);
|
|
23
|
-
if (simplified.properties) {
|
|
24
|
-
for (const field of PAYLOAD_MANAGED_FIELDS){
|
|
25
|
-
delete simplified.properties[field];
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
if (Array.isArray(simplified.required)) {
|
|
29
|
-
simplified.required = simplified.required.filter((name)=>!PAYLOAD_MANAGED_FIELDS.has(name));
|
|
30
|
-
if (simplified.required.length === 0) {
|
|
31
|
-
delete simplified.required;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
return simplified;
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
//# sourceMappingURL=prepareCollectionSchema.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/utils/schemaConversion/prepareCollectionSchema.ts"],"sourcesContent":["import type { JsonSchemaType } from '../../types.js'\n\nimport { sanitizeJsonSchema } from './sanitizeJsonSchema.js'\nimport { simplifyRelationshipFields } from './simplifyRelationshipFields.js'\nimport { transformPointFieldsForMCP } from './transformPointFields.js'\n\n/**\n * Fields Payload manages automatically — clients should never be required to provide\n * them. Stripped from `required` and `properties` so they don't appear in tool\n * inputs.\n */\nconst PAYLOAD_MANAGED_FIELDS = new Set(['_status', 'createdAt', 'id', 'updatedAt'])\n\n/**\n * Sanitizes Payload's auto-generated collection JSON Schema so it can be safely\n * fed into the MCP server's `fromJsonSchema()` adapter (no zod intermediate step).\n */\nexport const prepareCollectionSchema = (schema: JsonSchemaType): JsonSchemaType => {\n // Clone to avoid mutating the original schema (used elsewhere for tool listing)\n const schemaClone = JSON.parse(JSON.stringify(schema)) as JsonSchemaType\n\n const sanitized = sanitizeJsonSchema(schemaClone)\n const pointTransformed = transformPointFieldsForMCP(sanitized)\n const simplified = simplifyRelationshipFields(pointTransformed)\n\n if (simplified.properties) {\n for (const field of PAYLOAD_MANAGED_FIELDS) {\n delete simplified.properties[field]\n }\n }\n if (Array.isArray(simplified.required)) {\n simplified.required = simplified.required.filter((name) => !PAYLOAD_MANAGED_FIELDS.has(name))\n if (simplified.required.length === 0) {\n delete simplified.required\n }\n }\n\n return simplified\n}\n"],"names":["sanitizeJsonSchema","simplifyRelationshipFields","transformPointFieldsForMCP","PAYLOAD_MANAGED_FIELDS","Set","prepareCollectionSchema","schema","schemaClone","JSON","parse","stringify","sanitized","pointTransformed","simplified","properties","field","Array","isArray","required","filter","name","has","length"],"mappings":"AAEA,SAASA,kBAAkB,QAAQ,0BAAyB;AAC5D,SAASC,0BAA0B,QAAQ,kCAAiC;AAC5E,SAASC,0BAA0B,QAAQ,4BAA2B;AAEtE;;;;CAIC,GACD,MAAMC,yBAAyB,IAAIC,IAAI;IAAC;IAAW;IAAa;IAAM;CAAY;AAElF;;;CAGC,GACD,OAAO,MAAMC,0BAA0B,CAACC;IACtC,gFAAgF;IAChF,MAAMC,cAAcC,KAAKC,KAAK,CAACD,KAAKE,SAAS,CAACJ;IAE9C,MAAMK,YAAYX,mBAAmBO;IACrC,MAAMK,mBAAmBV,2BAA2BS;IACpD,MAAME,aAAaZ,2BAA2BW;IAE9C,IAAIC,WAAWC,UAAU,EAAE;QACzB,KAAK,MAAMC,SAASZ,uBAAwB;YAC1C,OAAOU,WAAWC,UAAU,CAACC,MAAM;QACrC;IACF;IACA,IAAIC,MAAMC,OAAO,CAACJ,WAAWK,QAAQ,GAAG;QACtCL,WAAWK,QAAQ,GAAGL,WAAWK,QAAQ,CAACC,MAAM,CAAC,CAACC,OAAS,CAACjB,uBAAuBkB,GAAG,CAACD;QACvF,IAAIP,WAAWK,QAAQ,CAACI,MAAM,KAAK,GAAG;YACpC,OAAOT,WAAWK,QAAQ;QAC5B;IACF;IAEA,OAAOL;AACT,EAAC"}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { JsonSchemaType } from '../../types.js';
|
|
2
|
-
/**
|
|
3
|
-
* Removes internal Payload properties (id, createdAt, updatedAt) from a
|
|
4
|
-
* JSON Schema so they don't appear in the generated Zod validation schema.
|
|
5
|
-
* Also strips `id` from the `required` array when present.
|
|
6
|
-
*
|
|
7
|
-
* Additionally normalizes nullable type arrays (e.g. `['array', 'null']` →
|
|
8
|
-
* `'array'`) throughout the schema tree. Without this, `json-schema-to-zod`
|
|
9
|
-
* emits a Zod union which the MCP SDK serialises back as `anyOf`, stripping
|
|
10
|
-
* the concrete `type` from the output and breaking schema introspection.
|
|
11
|
-
*/
|
|
12
|
-
export declare function sanitizeJsonSchema(schema: JsonSchemaType): JsonSchemaType;
|
|
13
|
-
//# sourceMappingURL=sanitizeJsonSchema.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"sanitizeJsonSchema.d.ts","sourceRoot":"","sources":["../../../src/utils/schemaConversion/sanitizeJsonSchema.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAEpD;;;;;;;;;GASG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,cAAc,GAAG,cAAc,CA6BzE"}
|