@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
package/src/endpoint/access.ts
CHANGED
|
@@ -25,15 +25,15 @@ export const getAuthorizedMCP: (args: { req: PayloadRequest }) => Promise<Author
|
|
|
25
25
|
items: pluginConfig.items.filter((item) => {
|
|
26
26
|
switch (item.type) {
|
|
27
27
|
case 'collectionTool':
|
|
28
|
-
return apiKeyDoc.access.collections?.[item.collectionSlug]?.[item.
|
|
28
|
+
return apiKeyDoc.access.collections?.[item.collectionSlug]?.[item.configKey] !== false
|
|
29
29
|
case 'globalTool':
|
|
30
|
-
return apiKeyDoc.access.globals?.[item.globalSlug]?.[item.
|
|
30
|
+
return apiKeyDoc.access.globals?.[item.globalSlug]?.[item.configKey] !== false
|
|
31
31
|
case 'prompt':
|
|
32
|
-
return apiKeyDoc.access.prompts?.[item.
|
|
32
|
+
return apiKeyDoc.access.prompts?.[item.configKey] !== false
|
|
33
33
|
case 'resource':
|
|
34
|
-
return apiKeyDoc.access.resources?.[item.
|
|
34
|
+
return apiKeyDoc.access.resources?.[item.configKey] !== false
|
|
35
35
|
case 'tool':
|
|
36
|
-
return apiKeyDoc.access.tools?.[item.
|
|
36
|
+
return apiKeyDoc.access.tools?.[item.configKey] !== false
|
|
37
37
|
}
|
|
38
38
|
}),
|
|
39
39
|
overrideAccess:
|
|
@@ -121,6 +121,18 @@ const getAPIKeyDoc = async ({
|
|
|
121
121
|
throw new UnauthorizedError()
|
|
122
122
|
}
|
|
123
123
|
|
|
124
|
+
try {
|
|
125
|
+
await req.payload.db.updateOne({
|
|
126
|
+
id: doc.id,
|
|
127
|
+
collection: 'payload-mcp-api-keys',
|
|
128
|
+
data: { lastUsed: new Date().toISOString() },
|
|
129
|
+
req,
|
|
130
|
+
returning: false,
|
|
131
|
+
})
|
|
132
|
+
} catch (err) {
|
|
133
|
+
logger.warn({ err, msg: 'Failed to update MCP API key last-used timestamp' })
|
|
134
|
+
}
|
|
135
|
+
|
|
124
136
|
return {
|
|
125
137
|
...doc,
|
|
126
138
|
user: {
|
package/src/exports/client.ts
CHANGED
|
@@ -1,2 +1,5 @@
|
|
|
1
1
|
'use client'
|
|
2
2
|
export { AccessField } from '../components/AccessField/index.client.js'
|
|
3
|
+
export { APIKeyField } from '../components/APIKeyField/index.client.js'
|
|
4
|
+
export { APIKeysEmptyState } from '../components/APIKeysEmptyState/index.client.js'
|
|
5
|
+
export { MCPSettingsMenu } from '../components/SettingsMenu/index.client.js'
|
package/src/index.ts
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
|
+
import type { AcceptedLanguages } from '@payloadcms/translations'
|
|
2
|
+
|
|
1
3
|
import { defaultUserCollection, definePlugin } from 'payload'
|
|
2
4
|
|
|
5
|
+
import type { PluginDefaultTranslationsObject } from './translations/types.js'
|
|
3
6
|
import type { AuthorizedMCP, MCPPluginConfig, SanitizedMCPPluginConfig } from './types.js'
|
|
4
7
|
|
|
5
8
|
import { getAPIKeysCollection } from './collection/index.js'
|
|
6
9
|
import { mcpEndpoint } from './endpoint/index.js'
|
|
7
10
|
import { sanitizeMCPConfig } from './mcp/sanitizeMCPConfig.js'
|
|
11
|
+
import { translations } from './translations/index.js'
|
|
8
12
|
|
|
9
13
|
declare module 'payload' {
|
|
10
14
|
export interface PayloadRequest {
|
|
@@ -24,9 +28,8 @@ export const mcpPlugin = definePlugin<MCPPluginConfig>({
|
|
|
24
28
|
slug: '@payloadcms/plugin-mcp',
|
|
25
29
|
order: 10,
|
|
26
30
|
plugin: ({ config, plugins, ...rawConfig }) => {
|
|
27
|
-
//
|
|
28
|
-
//
|
|
29
|
-
// Pre-seed the default user collection to prevent that.
|
|
31
|
+
// If a project has no auth collection yet, add the default users collection
|
|
32
|
+
// so the relationship target and default `userCollection` exist.
|
|
30
33
|
if (!config.admin?.user) {
|
|
31
34
|
const firstCollectionWithAuth = (config.collections ?? []).find(({ auth }) => Boolean(auth))
|
|
32
35
|
if (!firstCollectionWithAuth) {
|
|
@@ -45,6 +48,32 @@ export const mcpPlugin = definePlugin<MCPPluginConfig>({
|
|
|
45
48
|
|
|
46
49
|
;(config.collections ??= []).push(getAPIKeysCollection({ pluginConfig }))
|
|
47
50
|
|
|
51
|
+
if (!config.i18n) {
|
|
52
|
+
config.i18n = {}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (!config.i18n.translations) {
|
|
56
|
+
config.i18n.translations = {}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const supportedLanguageKeys = config.i18n.supportedLanguages
|
|
60
|
+
? Object.keys(config.i18n.supportedLanguages)
|
|
61
|
+
: ['en']
|
|
62
|
+
|
|
63
|
+
for (const lang of supportedLanguageKeys) {
|
|
64
|
+
const pluginEntry = translations[lang as keyof typeof translations]
|
|
65
|
+
if (!pluginEntry) {
|
|
66
|
+
continue
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const typedLocale = lang as AcceptedLanguages
|
|
70
|
+
const existing = (config.i18n.translations[typedLocale] ?? {}) as Record<string, unknown>
|
|
71
|
+
config.i18n.translations[typedLocale] = {
|
|
72
|
+
...existing,
|
|
73
|
+
'plugin-mcp': pluginEntry.translations['plugin-mcp'],
|
|
74
|
+
} as PluginDefaultTranslationsObject
|
|
75
|
+
}
|
|
76
|
+
|
|
48
77
|
// Keep the API-keys collection registered even when disabled, so DB schema
|
|
49
78
|
// and generated types don't drift between enabled/disabled environments.
|
|
50
79
|
if (pluginConfig.disabled) {
|
|
@@ -53,10 +82,27 @@ export const mcpPlugin = definePlugin<MCPPluginConfig>({
|
|
|
53
82
|
|
|
54
83
|
return {
|
|
55
84
|
...config,
|
|
85
|
+
admin: {
|
|
86
|
+
...config.admin,
|
|
87
|
+
components: {
|
|
88
|
+
...config.admin?.components,
|
|
89
|
+
userMenuSettingsItems: [
|
|
90
|
+
...(config.admin?.components?.userMenuSettingsItems ?? []),
|
|
91
|
+
'@payloadcms/plugin-mcp/client#MCPSettingsMenu',
|
|
92
|
+
],
|
|
93
|
+
},
|
|
94
|
+
},
|
|
56
95
|
endpoints: [
|
|
57
96
|
...(config.endpoints ?? []),
|
|
58
97
|
// Payload prefixes /api, so the full path is /api/mcp.
|
|
59
98
|
{ handler: mcpEndpoint, method: 'post', path: '/mcp' },
|
|
99
|
+
// Streamable HTTP's optional server=>client GET stream. We don't offer
|
|
100
|
+
// one, so answer 405 per spec-— clients then skip it cleanly
|
|
101
|
+
{
|
|
102
|
+
handler: () => new Response(null, { headers: { Allow: 'POST' }, status: 405 }),
|
|
103
|
+
method: 'get',
|
|
104
|
+
path: '/mcp',
|
|
105
|
+
},
|
|
60
106
|
],
|
|
61
107
|
}
|
|
62
108
|
},
|
|
@@ -1,29 +1,21 @@
|
|
|
1
1
|
import { McpServer, type ServerContext } from '@modelcontextprotocol/server'
|
|
2
|
-
import { APIError,
|
|
2
|
+
import { APIError, type PayloadRequest } from 'payload'
|
|
3
|
+
import { z } from 'zod'
|
|
3
4
|
|
|
4
5
|
import type {
|
|
5
6
|
AuthorizedMCP,
|
|
7
|
+
CollectionMCPItem,
|
|
8
|
+
GlobalMCPItem,
|
|
6
9
|
JsonSchemaType,
|
|
7
10
|
MCPResponseOverride,
|
|
8
11
|
MCPToolResponse,
|
|
9
12
|
SanitizedMCPPluginConfig,
|
|
13
|
+
ToolInputSchema,
|
|
10
14
|
} from '../types.js'
|
|
11
15
|
|
|
12
|
-
import { toCamelCase } from '../utils/camelCase.js'
|
|
13
16
|
import { getLogger } from '../utils/getLogger.js'
|
|
14
|
-
import {
|
|
15
|
-
getCollectionVirtualFieldNames,
|
|
16
|
-
getGlobalVirtualFieldNames,
|
|
17
|
-
} from '../utils/getVirtualFieldNames.js'
|
|
18
|
-
import { removeVirtualFieldsFromSchema } from '../utils/schemaConversion/removeVirtualFieldsFromSchema.js'
|
|
19
17
|
import { toStandardSchema } from '../utils/toStandardSchema.js'
|
|
20
18
|
|
|
21
|
-
/** `findPosts`, `updateSiteSettings` — auto-prefixed wire name for collection/global tools. */
|
|
22
|
-
const wireName = (key: string, slug: string): string => {
|
|
23
|
-
const camel = toCamelCase(slug)
|
|
24
|
-
return `${key}${camel.charAt(0).toUpperCase()}${camel.slice(1)}`
|
|
25
|
-
}
|
|
26
|
-
|
|
27
19
|
/**
|
|
28
20
|
* Transport-agnostic core: registers every authorized MCP item onto a fresh
|
|
29
21
|
* `McpServer` and returns it. The caller is responsible for picking a transport
|
|
@@ -64,96 +56,100 @@ export const buildMcpServer = ({
|
|
|
64
56
|
return rest
|
|
65
57
|
}
|
|
66
58
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
59
|
+
/**
|
|
60
|
+
* Runs a collection/global tool call:
|
|
61
|
+
* - reads `collectionSlug` / `globalSlug` from the input
|
|
62
|
+
* - runs access control: errors if `authorizedMCP.items` has no entry for this tool + slug
|
|
63
|
+
* - runs the tool handler and finalizes its response
|
|
64
|
+
*/
|
|
65
|
+
const callEntityTool = async ({
|
|
66
|
+
input,
|
|
67
|
+
item,
|
|
68
|
+
serverContext,
|
|
69
|
+
}: {
|
|
70
|
+
input: unknown
|
|
71
|
+
item: CollectionMCPItem | GlobalMCPItem
|
|
72
|
+
serverContext: ServerContext
|
|
73
|
+
}): Promise<MCPToolResponse> => {
|
|
74
|
+
const entity = item.type === 'collectionTool' ? 'collection' : 'global'
|
|
75
|
+
const slugKey = item.type === 'collectionTool' ? 'collectionSlug' : 'globalSlug'
|
|
76
|
+
const toolInput = (input ?? {}) as Record<string, unknown>
|
|
77
|
+
const slug = toolInput[slugKey] as string | undefined
|
|
78
|
+
|
|
79
|
+
if (!slug) {
|
|
80
|
+
return {
|
|
81
|
+
content: [
|
|
82
|
+
{
|
|
83
|
+
type: 'text',
|
|
84
|
+
text: `Error: "${item.mcpName}" requires ${slugKey}. Use getConfigInfo to inspect ${entity} slugs.`,
|
|
85
|
+
},
|
|
86
|
+
],
|
|
87
|
+
isError: true,
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const match = authorizedMCP.items.find(
|
|
92
|
+
(candidate): candidate is CollectionMCPItem | GlobalMCPItem =>
|
|
93
|
+
candidate.type === item.type &&
|
|
94
|
+
candidate.mcpName === item.mcpName &&
|
|
95
|
+
(candidate.type === 'collectionTool'
|
|
96
|
+
? candidate.collectionSlug === slug
|
|
97
|
+
: candidate.type === 'globalTool' && candidate.globalSlug === slug),
|
|
98
|
+
)
|
|
99
|
+
|
|
100
|
+
if (!match) {
|
|
101
|
+
return {
|
|
102
|
+
content: [
|
|
103
|
+
{
|
|
104
|
+
type: 'text',
|
|
105
|
+
text: `Error: MCP access to "${item.mcpName}" is not enabled for ${entity} "${slug}"`,
|
|
106
|
+
},
|
|
107
|
+
],
|
|
108
|
+
isError: true,
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const handlerArgs = { authorizedMCP, input: toolInput, req, serverContext }
|
|
113
|
+
const response = await (match.type === 'collectionTool'
|
|
114
|
+
? match.tool.handler({ ...handlerArgs, collectionSlug: slug })
|
|
115
|
+
: match.tool.handler({ ...handlerArgs, globalSlug: slug }))
|
|
116
|
+
|
|
117
|
+
return finalizeToolResponse(response, match.tool.overrideResponse)
|
|
118
|
+
}
|
|
73
119
|
|
|
74
120
|
try {
|
|
121
|
+
const registeredEntityTools = new Set<string>()
|
|
122
|
+
|
|
75
123
|
for (const item of authorizedMCP.items) {
|
|
76
124
|
switch (item.type) {
|
|
77
|
-
case 'collectionTool':
|
|
78
|
-
const tool = item.tool
|
|
79
|
-
const name = wireName(item.key, item.collectionSlug)
|
|
80
|
-
let inputSchema = tool.input
|
|
81
|
-
if (typeof inputSchema === 'function') {
|
|
82
|
-
const raw = configSchema.$defs?.[item.collectionSlug]
|
|
83
|
-
if (!raw) {
|
|
84
|
-
throw new APIError(
|
|
85
|
-
`Collection schema not found for slug: ${item.collectionSlug}`,
|
|
86
|
-
500,
|
|
87
|
-
)
|
|
88
|
-
}
|
|
89
|
-
const collectionSchema = removeVirtualFieldsFromSchema(
|
|
90
|
-
JSON.parse(JSON.stringify(raw)) as JsonSchemaType,
|
|
91
|
-
getCollectionVirtualFieldNames(req.payload.config, item.collectionSlug),
|
|
92
|
-
)
|
|
93
|
-
inputSchema = inputSchema({ collectionSchema })
|
|
94
|
-
}
|
|
95
|
-
server.registerTool(
|
|
96
|
-
name,
|
|
97
|
-
{
|
|
98
|
-
description: tool.description,
|
|
99
|
-
inputSchema: inputSchema ? toStandardSchema(inputSchema) : undefined,
|
|
100
|
-
},
|
|
101
|
-
async (input: unknown, ctx: ServerContext) =>
|
|
102
|
-
finalizeToolResponse(
|
|
103
|
-
await tool.handler({
|
|
104
|
-
authorizedMCP,
|
|
105
|
-
collectionSlug: item.collectionSlug,
|
|
106
|
-
input: (input ?? {}) as Record<string, unknown>,
|
|
107
|
-
req,
|
|
108
|
-
serverContext: ctx,
|
|
109
|
-
}),
|
|
110
|
-
tool.overrideResponse,
|
|
111
|
-
),
|
|
112
|
-
)
|
|
113
|
-
logger.info(`✅ Tool: ${name} Registered.`)
|
|
114
|
-
break
|
|
115
|
-
}
|
|
125
|
+
case 'collectionTool':
|
|
116
126
|
case 'globalTool': {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
let inputSchema = tool.input
|
|
120
|
-
if (typeof inputSchema === 'function') {
|
|
121
|
-
const raw = configSchema.$defs?.[item.globalSlug]
|
|
122
|
-
if (!raw) {
|
|
123
|
-
throw new APIError(`Global schema not found for slug: ${item.globalSlug}`, 500)
|
|
124
|
-
}
|
|
125
|
-
const globalSchema = removeVirtualFieldsFromSchema(
|
|
126
|
-
JSON.parse(JSON.stringify(raw)) as JsonSchemaType,
|
|
127
|
-
getGlobalVirtualFieldNames(req.payload.config, item.globalSlug),
|
|
128
|
-
)
|
|
129
|
-
|
|
130
|
-
inputSchema = inputSchema({ globalSchema })
|
|
127
|
+
if (registeredEntityTools.has(item.mcpName)) {
|
|
128
|
+
break
|
|
131
129
|
}
|
|
130
|
+
registeredEntityTools.add(item.mcpName)
|
|
131
|
+
|
|
132
|
+
const inputSchema = withSlugInput({
|
|
133
|
+
name: item.type === 'collectionTool' ? 'collectionSlug' : 'globalSlug',
|
|
134
|
+
input: item.tool.input,
|
|
135
|
+
})
|
|
136
|
+
|
|
132
137
|
server.registerTool(
|
|
133
|
-
|
|
138
|
+
item.mcpName,
|
|
134
139
|
{
|
|
135
|
-
description: tool.description,
|
|
136
|
-
inputSchema:
|
|
140
|
+
description: item.tool.description,
|
|
141
|
+
inputSchema: toStandardSchema(inputSchema),
|
|
137
142
|
},
|
|
138
143
|
async (input: unknown, ctx: ServerContext) =>
|
|
139
|
-
|
|
140
|
-
await tool.handler({
|
|
141
|
-
authorizedMCP,
|
|
142
|
-
globalSlug: item.globalSlug,
|
|
143
|
-
input: (input ?? {}) as Record<string, unknown>,
|
|
144
|
-
req,
|
|
145
|
-
serverContext: ctx,
|
|
146
|
-
}),
|
|
147
|
-
tool.overrideResponse,
|
|
148
|
-
),
|
|
144
|
+
callEntityTool({ input, item, serverContext: ctx }),
|
|
149
145
|
)
|
|
150
|
-
logger.info(`✅ Tool: ${
|
|
146
|
+
logger.info(`✅ Tool: ${item.mcpName} Registered.`)
|
|
151
147
|
break
|
|
152
148
|
}
|
|
153
149
|
case 'prompt': {
|
|
154
150
|
const prompt = item.prompt
|
|
155
151
|
server.registerPrompt(
|
|
156
|
-
item.
|
|
152
|
+
item.mcpName,
|
|
157
153
|
{
|
|
158
154
|
argsSchema: prompt.argsSchema ? toStandardSchema(prompt.argsSchema) : undefined,
|
|
159
155
|
description: prompt.description,
|
|
@@ -172,7 +168,7 @@ export const buildMcpServer = ({
|
|
|
172
168
|
case 'resource': {
|
|
173
169
|
const resource = item.resource
|
|
174
170
|
server.registerResource(
|
|
175
|
-
item.
|
|
171
|
+
item.mcpName,
|
|
176
172
|
// @ts-expect-error - Overload type ambiguity (string OR ResourceTemplate is valid)
|
|
177
173
|
resource.uri,
|
|
178
174
|
{
|
|
@@ -195,7 +191,7 @@ export const buildMcpServer = ({
|
|
|
195
191
|
case 'tool': {
|
|
196
192
|
const tool = item.tool
|
|
197
193
|
server.registerTool(
|
|
198
|
-
item.
|
|
194
|
+
item.mcpName,
|
|
199
195
|
{
|
|
200
196
|
description: tool.description,
|
|
201
197
|
inputSchema: tool.input ? toStandardSchema(tool.input) : undefined,
|
|
@@ -211,7 +207,7 @@ export const buildMcpServer = ({
|
|
|
211
207
|
tool.overrideResponse,
|
|
212
208
|
),
|
|
213
209
|
)
|
|
214
|
-
logger.info(`✅ Tool: ${item.
|
|
210
|
+
logger.info(`✅ Tool: ${item.mcpName} Registered.`)
|
|
215
211
|
break
|
|
216
212
|
}
|
|
217
213
|
}
|
|
@@ -222,3 +218,40 @@ export const buildMcpServer = ({
|
|
|
222
218
|
|
|
223
219
|
return server
|
|
224
220
|
}
|
|
221
|
+
|
|
222
|
+
const withSlugInput = ({
|
|
223
|
+
name,
|
|
224
|
+
input,
|
|
225
|
+
}: {
|
|
226
|
+
input?: ToolInputSchema
|
|
227
|
+
name: 'collectionSlug' | 'globalSlug'
|
|
228
|
+
}): ToolInputSchema => {
|
|
229
|
+
const description = name === 'collectionSlug' ? 'The collection slug' : 'The global slug'
|
|
230
|
+
const slugSchema = z.string().describe(description)
|
|
231
|
+
|
|
232
|
+
if (!input) {
|
|
233
|
+
return z.object({ [name]: slugSchema })
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
if (input instanceof z.ZodObject) {
|
|
237
|
+
return input.extend({ [name]: slugSchema })
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
const schema = input as {
|
|
241
|
+
properties?: Record<string, JsonSchemaType>
|
|
242
|
+
required?: string[]
|
|
243
|
+
} & JsonSchemaType
|
|
244
|
+
|
|
245
|
+
return {
|
|
246
|
+
...schema,
|
|
247
|
+
type: 'object',
|
|
248
|
+
properties: {
|
|
249
|
+
...schema.properties,
|
|
250
|
+
[name]: {
|
|
251
|
+
type: 'string',
|
|
252
|
+
description,
|
|
253
|
+
},
|
|
254
|
+
},
|
|
255
|
+
required: Array.from(new Set([name, ...(schema.required ?? [])])),
|
|
256
|
+
}
|
|
257
|
+
}
|
|
@@ -9,50 +9,47 @@ import {
|
|
|
9
9
|
stripVirtualFields,
|
|
10
10
|
} from '../../../utils/getVirtualFieldNames.js'
|
|
11
11
|
import { localAPIDefaults } from '../../../utils/localAPIDefaults.js'
|
|
12
|
-
import { prepareCollectionSchema } from '../../../utils/schemaConversion/prepareCollectionSchema.js'
|
|
13
12
|
import { transformPointDataToPayload } from '../../../utils/transformPointDataToPayload.js'
|
|
13
|
+
import { validateCollectionData } from '../validateEntityData.js'
|
|
14
|
+
import { formatCollectionError } from './formatCollectionError.js'
|
|
14
15
|
|
|
15
|
-
const DEFAULT_DESCRIPTION =
|
|
16
|
+
const DEFAULT_DESCRIPTION =
|
|
17
|
+
'Create a document in any collection by passing the collection slug and data.'
|
|
16
18
|
|
|
17
|
-
export const
|
|
19
|
+
export const createDocumentTool = defineCollectionTool({
|
|
18
20
|
description: DEFAULT_DESCRIPTION,
|
|
19
|
-
input: ({
|
|
20
|
-
z.
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
)
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
.describe(
|
|
52
|
-
'Optional: define exactly which fields you\'d like to create (JSON), e.g., \'{"title": "My Post"}\'',
|
|
53
|
-
)
|
|
54
|
-
.optional(),
|
|
55
|
-
}),
|
|
21
|
+
input: z.object({
|
|
22
|
+
data: z.record(z.string(), z.unknown()).describe('The document fields to create'),
|
|
23
|
+
depth: z
|
|
24
|
+
.number()
|
|
25
|
+
.int()
|
|
26
|
+
.min(0)
|
|
27
|
+
.max(10)
|
|
28
|
+
.describe('How many levels deep to populate relationships in response')
|
|
29
|
+
.optional()
|
|
30
|
+
.default(0),
|
|
31
|
+
draft: z
|
|
32
|
+
.boolean()
|
|
33
|
+
.describe('Whether to create the document as a draft')
|
|
34
|
+
.optional()
|
|
35
|
+
.default(false),
|
|
36
|
+
fallbackLocale: z
|
|
37
|
+
.string()
|
|
38
|
+
.describe('Optional: fallback locale code to use when requested locale is not available')
|
|
39
|
+
.optional(),
|
|
40
|
+
locale: z
|
|
41
|
+
.string()
|
|
42
|
+
.describe(
|
|
43
|
+
'Optional: locale code to create the document in (e.g., "en", "es"). Defaults to the default locale',
|
|
44
|
+
)
|
|
45
|
+
.optional(),
|
|
46
|
+
select: z
|
|
47
|
+
.string()
|
|
48
|
+
.describe(
|
|
49
|
+
"Optional: define exactly which fields you'd like to return (JSON), e.g., '{\"title\": true}'",
|
|
50
|
+
)
|
|
51
|
+
.optional(),
|
|
52
|
+
}),
|
|
56
53
|
}).handler(async ({ authorizedMCP, collectionSlug, input, req }) => {
|
|
57
54
|
const payload = req.payload
|
|
58
55
|
const logger = getLogger({ payload })
|
|
@@ -64,9 +61,15 @@ export const createCollectionTool = defineCollectionTool({
|
|
|
64
61
|
)
|
|
65
62
|
|
|
66
63
|
try {
|
|
67
|
-
let parsedData = transformPointDataToPayload(data as Record<string, unknown>)
|
|
68
64
|
const virtualFieldNames = getCollectionVirtualFieldNames(payload.config, collectionSlug)
|
|
69
|
-
|
|
65
|
+
const inputData = stripVirtualFields(data, virtualFieldNames)
|
|
66
|
+
const validationError = validateCollectionData({ collectionSlug, data: inputData, req })
|
|
67
|
+
|
|
68
|
+
if (validationError) {
|
|
69
|
+
return validationError
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const parsedData = transformPointDataToPayload(inputData)
|
|
70
73
|
|
|
71
74
|
let selectClause: SelectType | undefined
|
|
72
75
|
if (select) {
|
|
@@ -104,13 +107,6 @@ export const createCollectionTool = defineCollectionTool({
|
|
|
104
107
|
} catch (error) {
|
|
105
108
|
const errorMessage = error instanceof Error ? error.message : 'Unknown error'
|
|
106
109
|
logger.error(`Error creating document in ${collectionSlug}: ${errorMessage}`)
|
|
107
|
-
return {
|
|
108
|
-
content: [
|
|
109
|
-
{
|
|
110
|
-
type: 'text',
|
|
111
|
-
text: `Error creating document in collection "${collectionSlug}": ${errorMessage}`,
|
|
112
|
-
},
|
|
113
|
-
],
|
|
114
|
-
}
|
|
110
|
+
return formatCollectionError({ action: 'creating', collectionSlug, error, req })
|
|
115
111
|
}
|
|
116
112
|
})
|
|
@@ -3,10 +3,12 @@ import { z } from 'zod'
|
|
|
3
3
|
import { defineCollectionTool } from '../../../defineTool.js'
|
|
4
4
|
import { getLogger } from '../../../utils/getLogger.js'
|
|
5
5
|
import { localAPIDefaults } from '../../../utils/localAPIDefaults.js'
|
|
6
|
+
import { whereSchema } from '../../../utils/whereSchema.js'
|
|
6
7
|
|
|
7
|
-
const DEFAULT_DESCRIPTION =
|
|
8
|
+
const DEFAULT_DESCRIPTION =
|
|
9
|
+
'Delete documents in any collection by passing the collection slug and ID or where clause.'
|
|
8
10
|
|
|
9
|
-
export const
|
|
11
|
+
export const deleteDocumentsTool = defineCollectionTool({
|
|
10
12
|
description: DEFAULT_DESCRIPTION,
|
|
11
13
|
input: z.object({
|
|
12
14
|
id: z
|
|
@@ -31,9 +33,10 @@ export const deleteCollectionTool = defineCollectionTool({
|
|
|
31
33
|
'Optional: locale code for the operation (e.g., "en", "es"). Defaults to the default locale',
|
|
32
34
|
)
|
|
33
35
|
.optional(),
|
|
34
|
-
where:
|
|
35
|
-
.
|
|
36
|
-
|
|
36
|
+
where: whereSchema
|
|
37
|
+
.describe(
|
|
38
|
+
'Optional: where clause to delete multiple documents. Use field names with Payload operators, and/or arrays for grouping. Example: {"title":{"contains":"test"}}',
|
|
39
|
+
)
|
|
37
40
|
.optional(),
|
|
38
41
|
}),
|
|
39
42
|
}).handler(async ({ authorizedMCP, collectionSlug, input, req }) => {
|
|
@@ -53,16 +56,6 @@ export const deleteCollectionTool = defineCollectionTool({
|
|
|
53
56
|
}
|
|
54
57
|
}
|
|
55
58
|
|
|
56
|
-
let whereClause: Record<string, unknown> = {}
|
|
57
|
-
if (where) {
|
|
58
|
-
try {
|
|
59
|
-
whereClause = JSON.parse(where) as Record<string, unknown>
|
|
60
|
-
} catch {
|
|
61
|
-
logger.warn(`Invalid where clause JSON: ${where}`)
|
|
62
|
-
return { content: [{ type: 'text', text: 'Error: Invalid JSON in where clause' }] }
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
59
|
const deleteOptions: Record<string, unknown> = {
|
|
67
60
|
collection: collectionSlug,
|
|
68
61
|
depth,
|
|
@@ -75,7 +68,7 @@ export const deleteCollectionTool = defineCollectionTool({
|
|
|
75
68
|
if (id) {
|
|
76
69
|
deleteOptions.id = id
|
|
77
70
|
} else {
|
|
78
|
-
deleteOptions.where =
|
|
71
|
+
deleteOptions.where = where
|
|
79
72
|
}
|
|
80
73
|
|
|
81
74
|
const result = await payload.delete(deleteOptions as Parameters<typeof payload.delete>[0])
|
|
@@ -5,11 +5,12 @@ import { z } from 'zod'
|
|
|
5
5
|
import { defineCollectionTool } from '../../../defineTool.js'
|
|
6
6
|
import { getLogger } from '../../../utils/getLogger.js'
|
|
7
7
|
import { localAPIDefaults } from '../../../utils/localAPIDefaults.js'
|
|
8
|
+
import { whereSchema } from '../../../utils/whereSchema.js'
|
|
8
9
|
|
|
9
10
|
const DEFAULT_DESCRIPTION =
|
|
10
|
-
'Find documents in
|
|
11
|
+
'Find documents in any collection by passing the collection slug and optional ID or where clause.'
|
|
11
12
|
|
|
12
|
-
export const
|
|
13
|
+
export const findDocumentsTool = defineCollectionTool({
|
|
13
14
|
description: DEFAULT_DESCRIPTION,
|
|
14
15
|
input: z.object({
|
|
15
16
|
id: z
|
|
@@ -67,10 +68,9 @@ export const findCollectionTool = defineCollectionTool({
|
|
|
67
68
|
.string()
|
|
68
69
|
.describe('Field to sort by (e.g., "createdAt", "-updatedAt" for descending)')
|
|
69
70
|
.optional(),
|
|
70
|
-
where:
|
|
71
|
-
.string()
|
|
71
|
+
where: whereSchema
|
|
72
72
|
.describe(
|
|
73
|
-
'Optional
|
|
73
|
+
'Optional: where clause for filtering. Use field names with Payload operators, and/or arrays for grouping. Example: {"title":{"contains":"test"}}',
|
|
74
74
|
)
|
|
75
75
|
.optional(),
|
|
76
76
|
}),
|
|
@@ -85,16 +85,6 @@ export const findCollectionTool = defineCollectionTool({
|
|
|
85
85
|
)
|
|
86
86
|
|
|
87
87
|
try {
|
|
88
|
-
let whereClause: Record<string, unknown> = {}
|
|
89
|
-
if (where) {
|
|
90
|
-
try {
|
|
91
|
-
whereClause = JSON.parse(where) as Record<string, unknown>
|
|
92
|
-
} catch {
|
|
93
|
-
logger.warn(`Invalid where clause JSON: ${where}`)
|
|
94
|
-
return { content: [{ type: 'text', text: 'Error: Invalid JSON in where clause' }] }
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
|
|
98
88
|
let selectClause: SelectType | undefined
|
|
99
89
|
if (select) {
|
|
100
90
|
try {
|
|
@@ -157,8 +147,8 @@ export const findCollectionTool = defineCollectionTool({
|
|
|
157
147
|
if (sort) {
|
|
158
148
|
findOptions.sort = sort
|
|
159
149
|
}
|
|
160
|
-
if (
|
|
161
|
-
findOptions.where =
|
|
150
|
+
if (where) {
|
|
151
|
+
findOptions.where = where
|
|
162
152
|
}
|
|
163
153
|
|
|
164
154
|
const result = await payload.find(findOptions)
|