@payloadcms/plugin-mcp 3.86.0-internal.ac46214 → 4.0.0-canary.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/bin.js +39 -0
- package/dist/collection/getAccessField.d.ts +12 -0
- package/dist/collection/getAccessField.d.ts.map +1 -0
- package/dist/collection/getAccessField.js +57 -0
- package/dist/collection/getAccessField.js.map +1 -0
- package/dist/collection/index.d.ts +6 -0
- package/dist/collection/index.d.ts.map +1 -0
- package/dist/collection/index.js +60 -0
- package/dist/collection/index.js.map +1 -0
- package/dist/components/AccessField/index.client.d.ts +10 -0
- package/dist/components/AccessField/index.client.d.ts.map +1 -0
- package/dist/components/AccessField/index.client.js +305 -0
- package/dist/components/AccessField/index.client.js.map +1 -0
- package/dist/components/AccessField/index.css +93 -0
- package/dist/defineTool.d.ts +26 -0
- package/dist/defineTool.d.ts.map +1 -0
- package/dist/defineTool.js +37 -0
- package/dist/defineTool.js.map +1 -0
- package/dist/endpoint/access.d.ts +10 -0
- package/dist/endpoint/access.d.ts.map +1 -0
- package/dist/endpoint/access.js +106 -0
- package/dist/endpoint/access.js.map +1 -0
- package/dist/endpoint/index.d.ts +3 -0
- package/dist/endpoint/index.d.ts.map +1 -0
- package/dist/endpoint/index.js +36 -0
- package/dist/endpoint/index.js.map +1 -0
- package/dist/exports/client.d.ts +2 -0
- package/dist/exports/client.d.ts.map +1 -0
- package/dist/exports/client.js +4 -0
- package/dist/exports/client.js.map +1 -0
- package/dist/index.d.ts +4 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +44 -67
- package/dist/index.js.map +1 -1
- package/dist/mcp/buildMcpServer.d.ts +19 -0
- package/dist/mcp/buildMcpServer.d.ts.map +1 -0
- package/dist/mcp/buildMcpServer.js +199 -0
- package/dist/mcp/buildMcpServer.js.map +1 -0
- package/dist/mcp/builtin/collections/authTools.d.ts +7 -0
- package/dist/mcp/builtin/collections/authTools.d.ts.map +1 -0
- package/dist/mcp/builtin/collections/authTools.js +250 -0
- package/dist/mcp/builtin/collections/authTools.js.map +1 -0
- package/dist/mcp/builtin/collections/createTool.d.ts +2 -0
- package/dist/mcp/builtin/collections/createTool.d.ts.map +1 -0
- package/dist/mcp/builtin/collections/createTool.js +94 -0
- package/dist/mcp/builtin/collections/createTool.js.map +1 -0
- package/dist/mcp/builtin/collections/deleteTool.d.ts +2 -0
- package/dist/mcp/builtin/collections/deleteTool.d.ts.map +1 -0
- package/dist/mcp/builtin/collections/deleteTool.js +102 -0
- package/dist/mcp/builtin/collections/deleteTool.js.map +1 -0
- package/dist/mcp/builtin/collections/findTool.d.ts +2 -0
- package/dist/mcp/builtin/collections/findTool.d.ts.map +1 -0
- package/dist/mcp/builtin/collections/findTool.js +144 -0
- package/dist/mcp/builtin/collections/findTool.js.map +1 -0
- 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 +2 -0
- package/dist/mcp/builtin/collections/updateTool.d.ts.map +1 -0
- package/dist/mcp/builtin/collections/updateTool.js +199 -0
- package/dist/mcp/builtin/collections/updateTool.js.map +1 -0
- 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.d.ts +2 -0
- package/dist/mcp/builtin/globals/findTool.d.ts.map +1 -0
- package/dist/mcp/builtin/globals/findTool.js +76 -0
- package/dist/mcp/builtin/globals/findTool.js.map +1 -0
- 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 +2 -0
- package/dist/mcp/builtin/globals/updateTool.d.ts.map +1 -0
- package/dist/mcp/builtin/globals/updateTool.js +94 -0
- package/dist/mcp/builtin/globals/updateTool.js.map +1 -0
- 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 +105 -0
- package/dist/mcp/builtinTools.d.ts.map +1 -0
- package/dist/mcp/builtinTools.js +107 -0
- package/dist/mcp/builtinTools.js.map +1 -0
- package/dist/mcp/sanitizeMCPConfig.d.ts +17 -0
- package/dist/mcp/sanitizeMCPConfig.d.ts.map +1 -0
- package/dist/mcp/sanitizeMCPConfig.js +188 -0
- package/dist/mcp/sanitizeMCPConfig.js.map +1 -0
- package/dist/stdio.d.ts +8 -0
- package/dist/stdio.d.ts.map +1 -0
- package/dist/stdio.js +89 -0
- package/dist/stdio.js.map +1 -0
- package/dist/types.d.ts +251 -455
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +6 -1
- package/dist/types.js.map +1 -1
- package/dist/utils/camelCase.d.ts.map +1 -1
- package/dist/utils/getLogger.d.ts +10 -0
- package/dist/utils/getLogger.d.ts.map +1 -0
- package/dist/utils/getLogger.js +22 -0
- package/dist/utils/getLogger.js.map +1 -0
- package/dist/utils/getPluginConfig.d.ts +12 -0
- package/dist/utils/getPluginConfig.d.ts.map +1 -0
- package/dist/utils/getPluginConfig.js +15 -0
- package/dist/utils/getPluginConfig.js.map +1 -0
- package/dist/utils/localAPIDefaults.d.ts +20 -0
- package/dist/utils/localAPIDefaults.d.ts.map +1 -0
- package/dist/utils/localAPIDefaults.js +19 -0
- package/dist/utils/localAPIDefaults.js.map +1 -0
- package/dist/utils/resolveProjectRoot.d.ts +7 -0
- package/dist/utils/resolveProjectRoot.d.ts.map +1 -0
- package/dist/utils/resolveProjectRoot.js +15 -0
- package/dist/utils/resolveProjectRoot.js.map +1 -0
- 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/removeVirtualFieldsFromSchema.d.ts +2 -2
- package/dist/utils/schemaConversion/removeVirtualFieldsFromSchema.d.ts.map +1 -1
- package/dist/utils/schemaConversion/removeVirtualFieldsFromSchema.js.map +1 -1
- 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/toStandardSchema.d.ts +5 -0
- package/dist/utils/toStandardSchema.d.ts.map +1 -0
- package/dist/utils/toStandardSchema.js +4 -0
- package/dist/utils/toStandardSchema.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 +35 -10
- package/src/collection/getAccessField.ts +64 -0
- package/src/collection/index.ts +64 -0
- package/src/components/AccessField/index.client.tsx +347 -0
- package/src/components/AccessField/index.css +93 -0
- package/src/defineTool.ts +44 -0
- package/src/endpoint/access.ts +132 -0
- package/src/endpoint/index.ts +35 -0
- package/src/exports/client.ts +2 -0
- package/src/index.ts +35 -85
- package/src/mcp/buildMcpServer.ts +257 -0
- package/src/mcp/builtin/collections/authTools.ts +233 -0
- package/src/mcp/builtin/collections/createTool.ts +112 -0
- package/src/mcp/builtin/collections/deleteTool.ts +116 -0
- package/src/mcp/builtin/collections/findTool.ts +177 -0
- 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 +211 -0
- package/src/mcp/builtin/getConfigInfoTool.ts +44 -0
- package/src/mcp/builtin/globals/findTool.ts +96 -0
- package/src/mcp/builtin/globals/getGlobalSchemaTool.ts +28 -0
- package/src/mcp/builtin/globals/updateTool.ts +115 -0
- package/src/mcp/builtin/validateEntityData.ts +132 -0
- package/src/mcp/builtinTools.ts +98 -0
- package/src/mcp/sanitizeMCPConfig.ts +260 -0
- package/src/stdio.ts +98 -0
- package/src/types.ts +290 -490
- package/src/utils/getLogger.ts +22 -0
- package/src/utils/getPluginConfig.ts +24 -0
- package/src/utils/localAPIDefaults.ts +22 -0
- package/src/utils/resolveProjectRoot.ts +17 -0
- package/src/utils/schemaConversion/getEntityInputSchema.ts +78 -0
- package/src/utils/schemaConversion/removeVirtualFieldsFromSchema.ts +3 -3
- package/src/utils/schemaConversion/sanitizeEntitySchema.spec.ts +103 -0
- package/src/utils/schemaConversion/sanitizeEntitySchema.ts +529 -0
- package/src/utils/toStandardSchema.ts +9 -0
- package/src/utils/whereSchema.ts +24 -0
- package/dist/collections/createApiKeysCollection.d.ts +0 -7
- package/dist/collections/createApiKeysCollection.d.ts.map +0 -1
- package/dist/collections/createApiKeysCollection.js +0 -317
- package/dist/collections/createApiKeysCollection.js.map +0 -1
- package/dist/defaults.d.ts +0 -4
- package/dist/defaults.d.ts.map +0 -1
- package/dist/defaults.js +0 -5
- package/dist/defaults.js.map +0 -1
- package/dist/endpoints/mcp.d.ts +0 -4
- package/dist/endpoints/mcp.d.ts.map +0 -1
- package/dist/endpoints/mcp.js +0 -71
- package/dist/endpoints/mcp.js.map +0 -1
- package/dist/mcp/createRequest.d.ts +0 -3
- package/dist/mcp/createRequest.d.ts.map +0 -1
- package/dist/mcp/createRequest.js +0 -14
- package/dist/mcp/createRequest.js.map +0 -1
- package/dist/mcp/getMcpHandler.d.ts +0 -4
- package/dist/mcp/getMcpHandler.d.ts.map +0 -1
- package/dist/mcp/getMcpHandler.js +0 -231
- package/dist/mcp/getMcpHandler.js.map +0 -1
- package/dist/mcp/helpers/config.d.ts +0 -22
- package/dist/mcp/helpers/config.d.ts.map +0 -1
- package/dist/mcp/helpers/config.js +0 -153
- package/dist/mcp/helpers/config.js.map +0 -1
- package/dist/mcp/helpers/fields.d.ts +0 -19
- package/dist/mcp/helpers/fields.d.ts.map +0 -1
- package/dist/mcp/helpers/fields.js +0 -102
- package/dist/mcp/helpers/fields.js.map +0 -1
- package/dist/mcp/helpers/fileValidation.d.ts +0 -67
- package/dist/mcp/helpers/fileValidation.d.ts.map +0 -1
- package/dist/mcp/helpers/fileValidation.js +0 -267
- package/dist/mcp/helpers/fileValidation.js.map +0 -1
- package/dist/mcp/registerTool.d.ts +0 -6
- package/dist/mcp/registerTool.d.ts.map +0 -1
- package/dist/mcp/registerTool.js +0 -18
- package/dist/mcp/registerTool.js.map +0 -1
- package/dist/mcp/tools/auth/auth.d.ts +0 -4
- package/dist/mcp/tools/auth/auth.d.ts.map +0 -1
- package/dist/mcp/tools/auth/auth.js +0 -57
- package/dist/mcp/tools/auth/auth.js.map +0 -1
- package/dist/mcp/tools/auth/forgotPassword.d.ts +0 -4
- package/dist/mcp/tools/auth/forgotPassword.d.ts.map +0 -1
- package/dist/mcp/tools/auth/forgotPassword.js +0 -48
- package/dist/mcp/tools/auth/forgotPassword.js.map +0 -1
- package/dist/mcp/tools/auth/login.d.ts +0 -4
- package/dist/mcp/tools/auth/login.d.ts.map +0 -1
- package/dist/mcp/tools/auth/login.js +0 -51
- package/dist/mcp/tools/auth/login.js.map +0 -1
- package/dist/mcp/tools/auth/resetPassword.d.ts +0 -4
- package/dist/mcp/tools/auth/resetPassword.d.ts.map +0 -1
- package/dist/mcp/tools/auth/resetPassword.js +0 -49
- package/dist/mcp/tools/auth/resetPassword.js.map +0 -1
- package/dist/mcp/tools/auth/unlock.d.ts +0 -4
- package/dist/mcp/tools/auth/unlock.d.ts.map +0 -1
- package/dist/mcp/tools/auth/unlock.js +0 -48
- package/dist/mcp/tools/auth/unlock.js.map +0 -1
- package/dist/mcp/tools/auth/verify.d.ts +0 -4
- package/dist/mcp/tools/auth/verify.d.ts.map +0 -1
- package/dist/mcp/tools/auth/verify.js +0 -45
- package/dist/mcp/tools/auth/verify.js.map +0 -1
- package/dist/mcp/tools/collection/create.d.ts +0 -10
- package/dist/mcp/tools/collection/create.d.ts.map +0 -1
- package/dist/mcp/tools/collection/create.js +0 -139
- package/dist/mcp/tools/collection/create.js.map +0 -1
- package/dist/mcp/tools/collection/delete.d.ts +0 -10
- package/dist/mcp/tools/collection/delete.d.ts.map +0 -1
- package/dist/mcp/tools/collection/delete.js +0 -154
- package/dist/mcp/tools/collection/delete.js.map +0 -1
- package/dist/mcp/tools/collection/find.d.ts +0 -10
- package/dist/mcp/tools/collection/find.d.ts.map +0 -1
- package/dist/mcp/tools/collection/find.js +0 -165
- package/dist/mcp/tools/collection/find.js.map +0 -1
- package/dist/mcp/tools/collection/update.d.ts +0 -10
- package/dist/mcp/tools/collection/update.d.ts.map +0 -1
- package/dist/mcp/tools/collection/update.js +0 -209
- package/dist/mcp/tools/collection/update.js.map +0 -1
- package/dist/mcp/tools/config/find.d.ts +0 -10
- package/dist/mcp/tools/config/find.d.ts.map +0 -1
- package/dist/mcp/tools/config/find.js +0 -97
- package/dist/mcp/tools/config/find.js.map +0 -1
- package/dist/mcp/tools/config/update.d.ts +0 -10
- package/dist/mcp/tools/config/update.d.ts.map +0 -1
- package/dist/mcp/tools/config/update.js +0 -215
- package/dist/mcp/tools/config/update.js.map +0 -1
- package/dist/mcp/tools/global/find.d.ts +0 -5
- package/dist/mcp/tools/global/find.d.ts.map +0 -1
- package/dist/mcp/tools/global/find.js +0 -82
- package/dist/mcp/tools/global/find.js.map +0 -1
- package/dist/mcp/tools/global/update.d.ts +0 -6
- package/dist/mcp/tools/global/update.d.ts.map +0 -1
- package/dist/mcp/tools/global/update.js +0 -124
- package/dist/mcp/tools/global/update.js.map +0 -1
- package/dist/mcp/tools/job/create.d.ts +0 -10
- package/dist/mcp/tools/job/create.d.ts.map +0 -1
- package/dist/mcp/tools/job/create.js +0 -293
- package/dist/mcp/tools/job/create.js.map +0 -1
- package/dist/mcp/tools/job/run.d.ts +0 -10
- package/dist/mcp/tools/job/run.d.ts.map +0 -1
- package/dist/mcp/tools/job/run.js +0 -129
- package/dist/mcp/tools/job/run.js.map +0 -1
- package/dist/mcp/tools/job/update.d.ts +0 -11
- package/dist/mcp/tools/job/update.d.ts.map +0 -1
- package/dist/mcp/tools/job/update.js +0 -186
- package/dist/mcp/tools/job/update.js.map +0 -1
- package/dist/mcp/tools/resource/create.d.ts +0 -6
- package/dist/mcp/tools/resource/create.d.ts.map +0 -1
- package/dist/mcp/tools/resource/create.js +0 -124
- package/dist/mcp/tools/resource/create.js.map +0 -1
- package/dist/mcp/tools/resource/delete.d.ts +0 -5
- package/dist/mcp/tools/resource/delete.d.ts.map +0 -1
- package/dist/mcp/tools/resource/delete.js +0 -151
- package/dist/mcp/tools/resource/delete.js.map +0 -1
- package/dist/mcp/tools/resource/find.d.ts +0 -5
- package/dist/mcp/tools/resource/find.d.ts.map +0 -1
- package/dist/mcp/tools/resource/find.js +0 -170
- package/dist/mcp/tools/resource/find.js.map +0 -1
- package/dist/mcp/tools/resource/update.d.ts +0 -6
- package/dist/mcp/tools/resource/update.d.ts.map +0 -1
- package/dist/mcp/tools/resource/update.js +0 -256
- package/dist/mcp/tools/resource/update.js.map +0 -1
- package/dist/mcp/tools/schemas.d.ts +0 -457
- package/dist/mcp/tools/schemas.d.ts.map +0 -1
- package/dist/mcp/tools/schemas.js +0 -243
- package/dist/mcp/tools/schemas.js.map +0 -1
- package/dist/utils/adminEntitySettings.d.ts +0 -17
- package/dist/utils/adminEntitySettings.d.ts.map +0 -1
- package/dist/utils/adminEntitySettings.js +0 -41
- package/dist/utils/adminEntitySettings.js.map +0 -1
- package/dist/utils/createApiKeyFields.d.ts +0 -15
- package/dist/utils/createApiKeyFields.d.ts.map +0 -1
- package/dist/utils/createApiKeyFields.js +0 -57
- package/dist/utils/createApiKeyFields.js.map +0 -1
- package/dist/utils/getEnabledSlugs.d.ts +0 -13
- package/dist/utils/getEnabledSlugs.d.ts.map +0 -1
- package/dist/utils/getEnabledSlugs.js +0 -32
- package/dist/utils/getEnabledSlugs.js.map +0 -1
- package/dist/utils/schemaConversion/convertCollectionSchemaToZod.d.ts +0 -3
- package/dist/utils/schemaConversion/convertCollectionSchemaToZod.d.ts.map +0 -1
- package/dist/utils/schemaConversion/convertCollectionSchemaToZod.js +0 -43
- package/dist/utils/schemaConversion/convertCollectionSchemaToZod.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 -53
- 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 -51
- package/dist/utils/schemaConversion/transformPointFields.js.map +0 -1
- package/src/collections/createApiKeysCollection.ts +0 -373
- package/src/defaults.ts +0 -3
- package/src/endpoints/mcp.ts +0 -91
- package/src/mcp/createRequest.ts +0 -13
- package/src/mcp/getMcpHandler.ts +0 -545
- package/src/mcp/helpers/config.ts +0 -213
- package/src/mcp/helpers/fields.ts +0 -154
- package/src/mcp/helpers/fileValidation.ts +0 -362
- package/src/mcp/registerTool.ts +0 -22
- package/src/mcp/tools/auth/auth.ts +0 -71
- package/src/mcp/tools/auth/forgotPassword.ts +0 -70
- package/src/mcp/tools/auth/login.ts +0 -72
- package/src/mcp/tools/auth/resetPassword.ts +0 -61
- package/src/mcp/tools/auth/unlock.ts +0 -64
- package/src/mcp/tools/auth/verify.ts +0 -57
- package/src/mcp/tools/collection/create.ts +0 -210
- package/src/mcp/tools/collection/delete.ts +0 -211
- package/src/mcp/tools/collection/find.ts +0 -224
- package/src/mcp/tools/collection/update.ts +0 -290
- package/src/mcp/tools/config/find.ts +0 -128
- package/src/mcp/tools/config/update.ts +0 -280
- package/src/mcp/tools/global/find.ts +0 -128
- package/src/mcp/tools/global/update.ts +0 -207
- package/src/mcp/tools/job/create.ts +0 -416
- package/src/mcp/tools/job/run.ts +0 -167
- package/src/mcp/tools/job/update.ts +0 -274
- package/src/mcp/tools/resource/create.ts +0 -211
- package/src/mcp/tools/resource/delete.ts +0 -218
- package/src/mcp/tools/resource/find.ts +0 -246
- package/src/mcp/tools/resource/update.ts +0 -383
- package/src/mcp/tools/schemas.ts +0 -520
- package/src/utils/adminEntitySettings.ts +0 -40
- package/src/utils/createApiKeyFields.ts +0 -72
- package/src/utils/getEnabledSlugs.ts +0 -42
- package/src/utils/schemaConversion/convertCollectionSchemaToZod.ts +0 -52
- package/src/utils/schemaConversion/sanitizeJsonSchema.ts +0 -62
- package/src/utils/schemaConversion/simplifyRelationshipFields.ts +0 -65
- package/src/utils/schemaConversion/transformPointFields.ts +0 -55
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
import type { SelectType, Where } from 'payload'
|
|
2
|
+
|
|
3
|
+
import { z } from 'zod'
|
|
4
|
+
|
|
5
|
+
import { defineCollectionTool } from '../../../defineTool.js'
|
|
6
|
+
import { getLogger } from '../../../utils/getLogger.js'
|
|
7
|
+
import {
|
|
8
|
+
getCollectionVirtualFieldNames,
|
|
9
|
+
stripVirtualFields,
|
|
10
|
+
} from '../../../utils/getVirtualFieldNames.js'
|
|
11
|
+
import { localAPIDefaults } from '../../../utils/localAPIDefaults.js'
|
|
12
|
+
import { getCollectionInputSchema } from '../../../utils/schemaConversion/getEntityInputSchema.js'
|
|
13
|
+
import { transformPointDataToPayload } from '../../../utils/transformPointDataToPayload.js'
|
|
14
|
+
import { whereSchema } from '../../../utils/whereSchema.js'
|
|
15
|
+
import { validateCollectionData } from '../validateEntityData.js'
|
|
16
|
+
import { formatCollectionError } from './formatCollectionError.js'
|
|
17
|
+
|
|
18
|
+
const DEFAULT_DESCRIPTION =
|
|
19
|
+
'Update documents in any collection by passing the collection slug and data.'
|
|
20
|
+
|
|
21
|
+
export const updateDocumentTool = defineCollectionTool({
|
|
22
|
+
description: DEFAULT_DESCRIPTION,
|
|
23
|
+
input: z.object({
|
|
24
|
+
id: z.union([z.string(), z.number()]).describe('The ID of the document to update').optional(),
|
|
25
|
+
data: z.record(z.string(), z.unknown()).describe('The fields to update'),
|
|
26
|
+
depth: z
|
|
27
|
+
.number()
|
|
28
|
+
.describe('How many levels deep to populate relationships')
|
|
29
|
+
.optional()
|
|
30
|
+
.default(0),
|
|
31
|
+
draft: z
|
|
32
|
+
.boolean()
|
|
33
|
+
.describe('Whether to update 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
|
+
filePath: z.string().describe('File path for file uploads').optional(),
|
|
41
|
+
locale: z
|
|
42
|
+
.string()
|
|
43
|
+
.describe(
|
|
44
|
+
'Optional: locale code to update the document in (e.g., "en", "es"). Defaults to the default locale',
|
|
45
|
+
)
|
|
46
|
+
.optional(),
|
|
47
|
+
overrideLock: z
|
|
48
|
+
.boolean()
|
|
49
|
+
.describe('Whether to override document locks')
|
|
50
|
+
.optional()
|
|
51
|
+
.default(true),
|
|
52
|
+
overwriteExistingFiles: z
|
|
53
|
+
.boolean()
|
|
54
|
+
.describe('Whether to overwrite existing files')
|
|
55
|
+
.optional()
|
|
56
|
+
.default(false),
|
|
57
|
+
select: z
|
|
58
|
+
.string()
|
|
59
|
+
.describe(
|
|
60
|
+
"Optional: define exactly which fields you'd like to return in the response (JSON), e.g., '{\"title\": true}'",
|
|
61
|
+
)
|
|
62
|
+
.optional(),
|
|
63
|
+
where: whereSchema
|
|
64
|
+
.describe(
|
|
65
|
+
'Where clause to update multiple documents. Use field names with Payload operators, and/or arrays for grouping. Example: {"title":{"contains":"test"}}',
|
|
66
|
+
)
|
|
67
|
+
.optional(),
|
|
68
|
+
}),
|
|
69
|
+
}).handler(async ({ authorizedMCP, collectionSlug, input, req }) => {
|
|
70
|
+
const payload = req.payload
|
|
71
|
+
const logger = getLogger({ payload })
|
|
72
|
+
|
|
73
|
+
const {
|
|
74
|
+
id,
|
|
75
|
+
data,
|
|
76
|
+
depth,
|
|
77
|
+
draft,
|
|
78
|
+
fallbackLocale,
|
|
79
|
+
filePath,
|
|
80
|
+
locale,
|
|
81
|
+
overrideLock,
|
|
82
|
+
overwriteExistingFiles,
|
|
83
|
+
select,
|
|
84
|
+
where,
|
|
85
|
+
} = input
|
|
86
|
+
|
|
87
|
+
logger.info(
|
|
88
|
+
`Updating document in collection: ${collectionSlug}${id ? ` with ID: ${id}` : ' with where clause'}, draft: ${draft}${locale ? `, locale: ${locale}` : ''}`,
|
|
89
|
+
)
|
|
90
|
+
|
|
91
|
+
try {
|
|
92
|
+
if (!id && !where) {
|
|
93
|
+
return {
|
|
94
|
+
content: [{ type: 'text', text: 'Error: Either id or where clause must be provided' }],
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const virtualFieldNames = getCollectionVirtualFieldNames(payload.config, collectionSlug)
|
|
99
|
+
const inputData = stripVirtualFields(data, virtualFieldNames)
|
|
100
|
+
const validationError = validateCollectionData({
|
|
101
|
+
collectionSlug,
|
|
102
|
+
data: inputData,
|
|
103
|
+
partial: true,
|
|
104
|
+
req,
|
|
105
|
+
})
|
|
106
|
+
|
|
107
|
+
if (validationError) {
|
|
108
|
+
return validationError
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const parsedData = transformPointDataToPayload(inputData)
|
|
112
|
+
|
|
113
|
+
const whereClause: Where = where ?? {}
|
|
114
|
+
|
|
115
|
+
let selectClause: SelectType | undefined
|
|
116
|
+
if (select) {
|
|
117
|
+
try {
|
|
118
|
+
selectClause = JSON.parse(select) as SelectType
|
|
119
|
+
} catch {
|
|
120
|
+
logger.warn(`Invalid select clause JSON: ${select}`)
|
|
121
|
+
return { content: [{ type: 'text', text: 'Error: Invalid JSON in select clause' }] }
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
if (id) {
|
|
126
|
+
const result = await payload.update({
|
|
127
|
+
id,
|
|
128
|
+
collection: collectionSlug,
|
|
129
|
+
data: parsedData,
|
|
130
|
+
depth,
|
|
131
|
+
draft,
|
|
132
|
+
overrideLock,
|
|
133
|
+
req,
|
|
134
|
+
...localAPIDefaults(authorizedMCP),
|
|
135
|
+
...(filePath ? { filePath } : {}),
|
|
136
|
+
...(overwriteExistingFiles ? { overwriteExistingFiles } : {}),
|
|
137
|
+
...(locale ? { locale } : {}),
|
|
138
|
+
...(fallbackLocale ? { fallbackLocale } : {}),
|
|
139
|
+
...(selectClause ? { select: selectClause } : {}),
|
|
140
|
+
})
|
|
141
|
+
|
|
142
|
+
return {
|
|
143
|
+
content: [
|
|
144
|
+
{
|
|
145
|
+
type: 'text',
|
|
146
|
+
text: `Document updated successfully in collection "${collectionSlug}"!\nUpdated document:\n\`\`\`json\n${JSON.stringify(result)}\n\`\`\``,
|
|
147
|
+
},
|
|
148
|
+
],
|
|
149
|
+
doc: result as Record<string, unknown>,
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
const result = await payload.update({
|
|
154
|
+
collection: collectionSlug,
|
|
155
|
+
data: parsedData,
|
|
156
|
+
depth,
|
|
157
|
+
draft,
|
|
158
|
+
overrideLock,
|
|
159
|
+
req,
|
|
160
|
+
where: whereClause,
|
|
161
|
+
...localAPIDefaults(authorizedMCP),
|
|
162
|
+
...(filePath ? { filePath } : {}),
|
|
163
|
+
...(overwriteExistingFiles ? { overwriteExistingFiles } : {}),
|
|
164
|
+
...(locale ? { locale } : {}),
|
|
165
|
+
...(fallbackLocale ? { fallbackLocale } : {}),
|
|
166
|
+
...(selectClause ? { select: selectClause } : {}),
|
|
167
|
+
})
|
|
168
|
+
|
|
169
|
+
const docs = result.docs || []
|
|
170
|
+
const errors = result.errors || []
|
|
171
|
+
|
|
172
|
+
let responseText = `Multiple documents updated in collection "${collectionSlug}"!\nUpdated: ${docs.length} documents\nErrors: ${errors.length}\n---`
|
|
173
|
+
if (docs.length > 0) {
|
|
174
|
+
responseText += `\n\nUpdated documents:\n\`\`\`json\n${JSON.stringify(docs)}\n\`\`\``
|
|
175
|
+
}
|
|
176
|
+
if (errors.length > 0) {
|
|
177
|
+
responseText += `\n\nErrors:\n\`\`\`json\n${JSON.stringify(errors)}\n\`\`\``
|
|
178
|
+
|
|
179
|
+
const errorSchema = getCollectionInputSchema({ collectionSlug, req })
|
|
180
|
+
|
|
181
|
+
if (errorSchema) {
|
|
182
|
+
responseText += `\n\nUse this schema for data:\n\`\`\`json\n${JSON.stringify(errorSchema)}\n\`\`\``
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
return {
|
|
186
|
+
content: [{ type: 'text', text: responseText }],
|
|
187
|
+
doc: { docs, errors } as unknown as Record<string, unknown>,
|
|
188
|
+
isError: true,
|
|
189
|
+
...(errorSchema
|
|
190
|
+
? {
|
|
191
|
+
structuredContent: {
|
|
192
|
+
collectionSlug,
|
|
193
|
+
docs,
|
|
194
|
+
errors,
|
|
195
|
+
schema: errorSchema,
|
|
196
|
+
},
|
|
197
|
+
}
|
|
198
|
+
: {}),
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
return {
|
|
203
|
+
content: [{ type: 'text', text: responseText }],
|
|
204
|
+
doc: { docs, errors } as unknown as Record<string, unknown>,
|
|
205
|
+
}
|
|
206
|
+
} catch (error) {
|
|
207
|
+
const errorMessage = error instanceof Error ? error.message : 'Unknown error'
|
|
208
|
+
logger.error(`Error updating document in ${collectionSlug}: ${errorMessage}`)
|
|
209
|
+
return formatCollectionError({ action: 'updating', collectionSlug, error, req })
|
|
210
|
+
}
|
|
211
|
+
})
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { getAccessResults, isEntityHidden } from 'payload'
|
|
2
|
+
|
|
3
|
+
import { defineTool } from '../../defineTool.js'
|
|
4
|
+
|
|
5
|
+
export const getConfigInfoTool = defineTool({
|
|
6
|
+
description: 'List the Payload collection and global slugs visible to this MCP client.',
|
|
7
|
+
}).handler(async ({ authorizedMCP, req }) => {
|
|
8
|
+
const user = authorizedMCP.user ?? req.user ?? null
|
|
9
|
+
const permissions = user ? await getAccessResults({ req: { ...req, user } }) : null
|
|
10
|
+
|
|
11
|
+
const collections: string[] = []
|
|
12
|
+
const globals: string[] = []
|
|
13
|
+
|
|
14
|
+
for (const collection of req.payload.config.collections) {
|
|
15
|
+
if (user && isEntityHidden({ hidden: collection.admin.hidden, user })) {
|
|
16
|
+
continue
|
|
17
|
+
}
|
|
18
|
+
if (user && !permissions?.collections?.[collection.slug]?.read) {
|
|
19
|
+
continue
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
collections.push(collection.slug)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
for (const global of req.payload.config.globals) {
|
|
26
|
+
if (user && isEntityHidden({ hidden: global.admin.hidden, user })) {
|
|
27
|
+
continue
|
|
28
|
+
}
|
|
29
|
+
if (user && !permissions?.globals?.[global.slug]?.read) {
|
|
30
|
+
continue
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
globals.push(global.slug)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return {
|
|
37
|
+
content: [
|
|
38
|
+
{
|
|
39
|
+
type: 'text',
|
|
40
|
+
text: `Collections: ${collections.join(', ') || 'none'}\nGlobals: ${globals.join(', ') || 'none'}`,
|
|
41
|
+
},
|
|
42
|
+
],
|
|
43
|
+
}
|
|
44
|
+
})
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import type { SelectType } from 'payload'
|
|
2
|
+
|
|
3
|
+
import { z } from 'zod'
|
|
4
|
+
|
|
5
|
+
import { defineGlobalTool } from '../../../defineTool.js'
|
|
6
|
+
import { getLogger } from '../../../utils/getLogger.js'
|
|
7
|
+
import { localAPIDefaults } from '../../../utils/localAPIDefaults.js'
|
|
8
|
+
|
|
9
|
+
const DEFAULT_DESCRIPTION = 'Find any Payload global by passing the global slug.'
|
|
10
|
+
|
|
11
|
+
export const findGlobalTool = defineGlobalTool({
|
|
12
|
+
description: DEFAULT_DESCRIPTION,
|
|
13
|
+
input: z.object({
|
|
14
|
+
depth: z
|
|
15
|
+
.number()
|
|
16
|
+
.int()
|
|
17
|
+
.min(0)
|
|
18
|
+
.max(10)
|
|
19
|
+
.describe('Depth of population for relationships')
|
|
20
|
+
.optional()
|
|
21
|
+
.default(0),
|
|
22
|
+
fallbackLocale: z
|
|
23
|
+
.string()
|
|
24
|
+
.describe('Optional: fallback locale code to use when requested locale is not available')
|
|
25
|
+
.optional(),
|
|
26
|
+
locale: z
|
|
27
|
+
.string()
|
|
28
|
+
.describe(
|
|
29
|
+
'Optional: locale code to retrieve data in (e.g., "en", "es"). Use "all" to retrieve all locales for localized fields',
|
|
30
|
+
)
|
|
31
|
+
.optional(),
|
|
32
|
+
select: z
|
|
33
|
+
.string()
|
|
34
|
+
.describe(
|
|
35
|
+
"Optional: define exactly which fields you'd like to return in the response (JSON), e.g., '{\"title\": true}'",
|
|
36
|
+
)
|
|
37
|
+
.optional(),
|
|
38
|
+
}),
|
|
39
|
+
}).handler(async ({ authorizedMCP, globalSlug, input, req }) => {
|
|
40
|
+
const payload = req.payload
|
|
41
|
+
const logger = getLogger({ payload })
|
|
42
|
+
|
|
43
|
+
const { depth, fallbackLocale, locale, select } = input
|
|
44
|
+
|
|
45
|
+
logger.info(
|
|
46
|
+
`Reading global: ${globalSlug}, depth: ${depth}${locale ? `, locale: ${locale}` : ''}`,
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
try {
|
|
50
|
+
const findOptions: Parameters<typeof payload.findGlobal>[0] = {
|
|
51
|
+
slug: globalSlug,
|
|
52
|
+
depth,
|
|
53
|
+
...localAPIDefaults(authorizedMCP),
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
let selectClause: SelectType | undefined
|
|
57
|
+
if (select) {
|
|
58
|
+
try {
|
|
59
|
+
selectClause = JSON.parse(select) as SelectType
|
|
60
|
+
} catch {
|
|
61
|
+
logger.warn(`Invalid select clause JSON for global: ${select}`)
|
|
62
|
+
return { content: [{ type: 'text', text: 'Error: Invalid JSON in select clause' }] }
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (locale) {
|
|
67
|
+
findOptions.locale = locale
|
|
68
|
+
}
|
|
69
|
+
if (fallbackLocale) {
|
|
70
|
+
findOptions.fallbackLocale = fallbackLocale
|
|
71
|
+
}
|
|
72
|
+
if (selectClause) {
|
|
73
|
+
findOptions.select = selectClause
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const result = await payload.findGlobal(findOptions)
|
|
77
|
+
|
|
78
|
+
return {
|
|
79
|
+
content: [
|
|
80
|
+
{
|
|
81
|
+
type: 'text',
|
|
82
|
+
text: `Global "${globalSlug}":\n\`\`\`json\n${JSON.stringify(result)}\n\`\`\``,
|
|
83
|
+
},
|
|
84
|
+
],
|
|
85
|
+
doc: result as Record<string, unknown>,
|
|
86
|
+
}
|
|
87
|
+
} catch (error) {
|
|
88
|
+
const errorMessage = error instanceof Error ? error.message : 'Unknown error'
|
|
89
|
+
logger.error(`Error reading global ${globalSlug}: ${errorMessage}`)
|
|
90
|
+
return {
|
|
91
|
+
content: [
|
|
92
|
+
{ type: 'text', text: `❌ **Error reading global "${globalSlug}":** ${errorMessage}` },
|
|
93
|
+
],
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
})
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { defineGlobalTool } from '../../../defineTool.js'
|
|
2
|
+
import { getGlobalInputSchema } from '../../../utils/schemaConversion/getEntityInputSchema.js'
|
|
3
|
+
|
|
4
|
+
export const getGlobalSchemaTool = defineGlobalTool({
|
|
5
|
+
description: 'Get the input schema for updating a global.',
|
|
6
|
+
}).handler(({ globalSlug, req }) => {
|
|
7
|
+
const inputSchema = getGlobalInputSchema({ globalSlug, req })
|
|
8
|
+
|
|
9
|
+
if (!inputSchema) {
|
|
10
|
+
return {
|
|
11
|
+
content: [{ type: 'text', text: `Error: Global "${globalSlug}" not found` }],
|
|
12
|
+
isError: true,
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
return {
|
|
17
|
+
content: [
|
|
18
|
+
{
|
|
19
|
+
type: 'text',
|
|
20
|
+
text: `Schema for global "${globalSlug}":\n\`\`\`json\n${JSON.stringify(inputSchema)}\n\`\`\``,
|
|
21
|
+
},
|
|
22
|
+
],
|
|
23
|
+
structuredContent: {
|
|
24
|
+
globalSlug,
|
|
25
|
+
schema: inputSchema,
|
|
26
|
+
},
|
|
27
|
+
}
|
|
28
|
+
})
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import type { SelectType } from 'payload'
|
|
2
|
+
|
|
3
|
+
import { z } from 'zod'
|
|
4
|
+
|
|
5
|
+
import { defineGlobalTool } from '../../../defineTool.js'
|
|
6
|
+
import { getLogger } from '../../../utils/getLogger.js'
|
|
7
|
+
import {
|
|
8
|
+
getGlobalVirtualFieldNames,
|
|
9
|
+
stripVirtualFields,
|
|
10
|
+
} from '../../../utils/getVirtualFieldNames.js'
|
|
11
|
+
import { localAPIDefaults } from '../../../utils/localAPIDefaults.js'
|
|
12
|
+
import { transformPointDataToPayload } from '../../../utils/transformPointDataToPayload.js'
|
|
13
|
+
import { validateGlobalData } from '../validateEntityData.js'
|
|
14
|
+
|
|
15
|
+
const DEFAULT_DESCRIPTION = 'Update any Payload global by passing the global slug and data.'
|
|
16
|
+
|
|
17
|
+
export const updateGlobalTool = defineGlobalTool({
|
|
18
|
+
description: DEFAULT_DESCRIPTION,
|
|
19
|
+
input: z.object({
|
|
20
|
+
data: z.record(z.string(), z.unknown()).describe('The global fields to update'),
|
|
21
|
+
depth: z
|
|
22
|
+
.number()
|
|
23
|
+
.describe('Optional: Depth of relationships to populate')
|
|
24
|
+
.optional()
|
|
25
|
+
.default(0),
|
|
26
|
+
draft: z
|
|
27
|
+
.boolean()
|
|
28
|
+
.describe('Optional: Whether to save as draft (default: false)')
|
|
29
|
+
.optional()
|
|
30
|
+
.default(false),
|
|
31
|
+
fallbackLocale: z
|
|
32
|
+
.string()
|
|
33
|
+
.describe('Optional: fallback locale code to use when requested locale is not available')
|
|
34
|
+
.optional(),
|
|
35
|
+
locale: z
|
|
36
|
+
.string()
|
|
37
|
+
.describe(
|
|
38
|
+
'Optional: locale code to update data in (e.g., "en", "es"). Use "all" to update all locales for localized fields',
|
|
39
|
+
)
|
|
40
|
+
.optional(),
|
|
41
|
+
select: z
|
|
42
|
+
.string()
|
|
43
|
+
.describe(
|
|
44
|
+
"Optional: define exactly which fields you'd like to return in the response (JSON), e.g., '{\"siteName\": true}'",
|
|
45
|
+
)
|
|
46
|
+
.optional(),
|
|
47
|
+
}),
|
|
48
|
+
}).handler(async ({ authorizedMCP, globalSlug, input, req }) => {
|
|
49
|
+
const payload = req.payload
|
|
50
|
+
const logger = getLogger({ payload })
|
|
51
|
+
|
|
52
|
+
const { data, depth, draft, fallbackLocale, locale, select } = input
|
|
53
|
+
|
|
54
|
+
logger.info(
|
|
55
|
+
`Updating global: ${globalSlug}, draft: ${draft}${locale ? `, locale: ${locale}` : ''}`,
|
|
56
|
+
)
|
|
57
|
+
|
|
58
|
+
try {
|
|
59
|
+
const virtualFieldNames = getGlobalVirtualFieldNames(payload.config, globalSlug)
|
|
60
|
+
const inputData = stripVirtualFields(data, virtualFieldNames)
|
|
61
|
+
const validationError = validateGlobalData({ data: inputData, globalSlug, req })
|
|
62
|
+
|
|
63
|
+
if (validationError) {
|
|
64
|
+
return validationError
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const parsedData = transformPointDataToPayload(inputData)
|
|
68
|
+
|
|
69
|
+
let selectClause: SelectType | undefined
|
|
70
|
+
if (select) {
|
|
71
|
+
try {
|
|
72
|
+
selectClause = JSON.parse(select) as SelectType
|
|
73
|
+
} catch {
|
|
74
|
+
logger.warn(`Invalid select clause JSON for global: ${select}`)
|
|
75
|
+
return { content: [{ type: 'text', text: 'Error: Invalid JSON in select clause' }] }
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const updateOptions: Parameters<typeof payload.updateGlobal>[0] = {
|
|
80
|
+
slug: globalSlug,
|
|
81
|
+
data: parsedData,
|
|
82
|
+
depth,
|
|
83
|
+
draft,
|
|
84
|
+
...localAPIDefaults(authorizedMCP),
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
if (locale) {
|
|
88
|
+
updateOptions.locale = locale
|
|
89
|
+
}
|
|
90
|
+
if (fallbackLocale) {
|
|
91
|
+
updateOptions.fallbackLocale = fallbackLocale
|
|
92
|
+
}
|
|
93
|
+
if (selectClause) {
|
|
94
|
+
updateOptions.select = selectClause
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const result = await payload.updateGlobal(updateOptions)
|
|
98
|
+
|
|
99
|
+
return {
|
|
100
|
+
content: [
|
|
101
|
+
{
|
|
102
|
+
type: 'text',
|
|
103
|
+
text: `Global "${globalSlug}" updated successfully!\n\`\`\`json\n${JSON.stringify(result)}\n\`\`\``,
|
|
104
|
+
},
|
|
105
|
+
],
|
|
106
|
+
doc: result as Record<string, unknown>,
|
|
107
|
+
}
|
|
108
|
+
} catch (error) {
|
|
109
|
+
const errorMessage = error instanceof Error ? error.message : 'Unknown error'
|
|
110
|
+
logger.error(`Error updating global ${globalSlug}: ${errorMessage}`)
|
|
111
|
+
return {
|
|
112
|
+
content: [{ type: 'text', text: `Error updating global "${globalSlug}": ${errorMessage}` }],
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
})
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import type { CollectionSlug, GlobalSlug, PayloadRequest, SanitizedConfig } from 'payload'
|
|
2
|
+
|
|
3
|
+
import { CfWorkerJsonSchemaValidator } from '@modelcontextprotocol/server'
|
|
4
|
+
|
|
5
|
+
import type { JsonSchemaType, MCPToolResponse } from '../../types.js'
|
|
6
|
+
|
|
7
|
+
import {
|
|
8
|
+
getCollectionInputSchema,
|
|
9
|
+
getGlobalInputSchema,
|
|
10
|
+
} from '../../utils/schemaConversion/getEntityInputSchema.js'
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Keep the default `shortcircuit: true` - `false` makes validating nested rich text exponentially slow.
|
|
14
|
+
*/
|
|
15
|
+
const validator = new CfWorkerJsonSchemaValidator({ shortcircuit: true })
|
|
16
|
+
|
|
17
|
+
type EntityValidator = {
|
|
18
|
+
schema: JsonSchemaType
|
|
19
|
+
validate: ReturnType<(typeof validator)['getValidator']>
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* - Caches each entity's schema and validator, so both are only built on the first request.
|
|
24
|
+
* - Keyed by payload config, then by entity type, slug, partial and language.
|
|
25
|
+
*/
|
|
26
|
+
const validatorCache = new WeakMap<SanitizedConfig, Map<string, EntityValidator>>()
|
|
27
|
+
|
|
28
|
+
export const validateCollectionData = ({
|
|
29
|
+
collectionSlug,
|
|
30
|
+
data,
|
|
31
|
+
partial,
|
|
32
|
+
req,
|
|
33
|
+
}: {
|
|
34
|
+
collectionSlug: CollectionSlug
|
|
35
|
+
data: Record<string, unknown>
|
|
36
|
+
partial?: boolean
|
|
37
|
+
req: PayloadRequest
|
|
38
|
+
}): MCPToolResponse | null =>
|
|
39
|
+
validateData({
|
|
40
|
+
slug: collectionSlug,
|
|
41
|
+
buildSchema: () => getCollectionInputSchema({ collectionSlug, req }),
|
|
42
|
+
data,
|
|
43
|
+
entity: 'collection',
|
|
44
|
+
partial,
|
|
45
|
+
req,
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
export const validateGlobalData = ({
|
|
49
|
+
data,
|
|
50
|
+
globalSlug,
|
|
51
|
+
req,
|
|
52
|
+
}: {
|
|
53
|
+
data: Record<string, unknown>
|
|
54
|
+
globalSlug: GlobalSlug
|
|
55
|
+
req: PayloadRequest
|
|
56
|
+
}): MCPToolResponse | null =>
|
|
57
|
+
validateData({
|
|
58
|
+
slug: globalSlug,
|
|
59
|
+
buildSchema: () => getGlobalInputSchema({ globalSlug, req }),
|
|
60
|
+
data,
|
|
61
|
+
entity: 'global',
|
|
62
|
+
partial: true,
|
|
63
|
+
req,
|
|
64
|
+
})
|
|
65
|
+
|
|
66
|
+
const validateData = ({
|
|
67
|
+
slug,
|
|
68
|
+
buildSchema,
|
|
69
|
+
data,
|
|
70
|
+
entity,
|
|
71
|
+
partial,
|
|
72
|
+
req,
|
|
73
|
+
}: {
|
|
74
|
+
buildSchema: () => JsonSchemaType | null
|
|
75
|
+
data: Record<string, unknown>
|
|
76
|
+
entity: 'collection' | 'global'
|
|
77
|
+
partial?: boolean
|
|
78
|
+
req: PayloadRequest
|
|
79
|
+
slug: string
|
|
80
|
+
}): MCPToolResponse | null => {
|
|
81
|
+
let cache = validatorCache.get(req.payload.config)
|
|
82
|
+
if (!cache) {
|
|
83
|
+
cache = new Map()
|
|
84
|
+
validatorCache.set(req.payload.config, cache)
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const cacheKey = `${entity}:${slug}:${partial ? 'partial' : 'full'}:${req.i18n.language}`
|
|
88
|
+
let entityValidator = cache.get(cacheKey)
|
|
89
|
+
|
|
90
|
+
if (!entityValidator) {
|
|
91
|
+
const schema = buildSchema()
|
|
92
|
+
|
|
93
|
+
if (!schema) {
|
|
94
|
+
return null
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
entityValidator = {
|
|
98
|
+
schema,
|
|
99
|
+
validate: validator.getValidator(partial ? withoutRequired(schema) : schema),
|
|
100
|
+
}
|
|
101
|
+
cache.set(cacheKey, entityValidator)
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const result = entityValidator.validate(data)
|
|
105
|
+
|
|
106
|
+
if (result.valid) {
|
|
107
|
+
return null
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
const { schema } = entityValidator
|
|
111
|
+
|
|
112
|
+
return {
|
|
113
|
+
content: [
|
|
114
|
+
{
|
|
115
|
+
type: 'text',
|
|
116
|
+
text: `Invalid data for ${entity} "${slug}": ${result.errorMessage}\n\nUse this schema for data:\n\`\`\`json\n${JSON.stringify(schema)}\n\`\`\``,
|
|
117
|
+
},
|
|
118
|
+
],
|
|
119
|
+
isError: true,
|
|
120
|
+
structuredContent: {
|
|
121
|
+
[`${entity}Slug`]: slug,
|
|
122
|
+
errors: [{ message: result.errorMessage }],
|
|
123
|
+
schema,
|
|
124
|
+
},
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/** Updates are partial — drop the schema's top-level `required` before validating. */
|
|
129
|
+
const withoutRequired = (schema: JsonSchemaType): JsonSchemaType => {
|
|
130
|
+
const { required: _required, ...rest } = schema
|
|
131
|
+
return rest
|
|
132
|
+
}
|