@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,102 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { defineCollectionTool } from '../../../defineTool.js';
|
|
3
|
+
import { getLogger } from '../../../utils/getLogger.js';
|
|
4
|
+
import { localAPIDefaults } from '../../../utils/localAPIDefaults.js';
|
|
5
|
+
import { whereSchema } from '../../../utils/whereSchema.js';
|
|
6
|
+
const DEFAULT_DESCRIPTION = 'Delete documents in any collection by passing the collection slug and ID or where clause.';
|
|
7
|
+
export const deleteDocumentsTool = defineCollectionTool({
|
|
8
|
+
description: DEFAULT_DESCRIPTION,
|
|
9
|
+
input: z.object({
|
|
10
|
+
id: z.union([
|
|
11
|
+
z.string(),
|
|
12
|
+
z.number()
|
|
13
|
+
]).describe('Optional: specific document ID to delete').optional(),
|
|
14
|
+
depth: z.number().int().min(0).max(10).describe('Depth of population for relationships in response').optional().default(0),
|
|
15
|
+
fallbackLocale: z.string().describe('Optional: fallback locale code to use when requested locale is not available').optional(),
|
|
16
|
+
locale: z.string().describe('Optional: locale code for the operation (e.g., "en", "es"). Defaults to the default locale').optional(),
|
|
17
|
+
where: whereSchema.describe('Optional: where clause to delete multiple documents. Use field names with Payload operators, and/or arrays for grouping. Example: {"title":{"contains":"test"}}').optional()
|
|
18
|
+
})
|
|
19
|
+
}).handler(async ({ authorizedMCP, collectionSlug, input, req })=>{
|
|
20
|
+
const payload = req.payload;
|
|
21
|
+
const logger = getLogger({
|
|
22
|
+
payload
|
|
23
|
+
});
|
|
24
|
+
const { id, depth, fallbackLocale, locale, where } = input;
|
|
25
|
+
logger.info(`Deleting document from collection: ${collectionSlug}${id ? ` with ID: ${id}` : ' with where clause'}${locale ? `, locale: ${locale}` : ''}`);
|
|
26
|
+
try {
|
|
27
|
+
if (!id && !where) {
|
|
28
|
+
return {
|
|
29
|
+
content: [
|
|
30
|
+
{
|
|
31
|
+
type: 'text',
|
|
32
|
+
text: 'Error: Either id or where clause must be provided'
|
|
33
|
+
}
|
|
34
|
+
]
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
const deleteOptions = {
|
|
38
|
+
collection: collectionSlug,
|
|
39
|
+
depth,
|
|
40
|
+
req,
|
|
41
|
+
...localAPIDefaults(authorizedMCP),
|
|
42
|
+
...locale && {
|
|
43
|
+
locale
|
|
44
|
+
},
|
|
45
|
+
...fallbackLocale && {
|
|
46
|
+
fallbackLocale
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
if (id) {
|
|
50
|
+
deleteOptions.id = id;
|
|
51
|
+
} else {
|
|
52
|
+
deleteOptions.where = where;
|
|
53
|
+
}
|
|
54
|
+
const result = await payload.delete(deleteOptions);
|
|
55
|
+
if (id) {
|
|
56
|
+
return {
|
|
57
|
+
content: [
|
|
58
|
+
{
|
|
59
|
+
type: 'text',
|
|
60
|
+
text: `Document deleted successfully from collection "${collectionSlug}"!\nDeleted document:\n\`\`\`json\n${JSON.stringify(result)}\n\`\`\``
|
|
61
|
+
}
|
|
62
|
+
],
|
|
63
|
+
doc: result
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
const bulkResult = result;
|
|
67
|
+
const docs = bulkResult.docs || [];
|
|
68
|
+
const errors = bulkResult.errors || [];
|
|
69
|
+
let responseText = `Document deleted successfully from collection "${collectionSlug}"!\nDeleted: ${docs.length} documents\nErrors: ${errors.length}\n---`;
|
|
70
|
+
if (docs.length > 0) {
|
|
71
|
+
responseText += `\n\nDeleted documents:\n\`\`\`json\n${JSON.stringify(docs)}\n\`\`\``;
|
|
72
|
+
}
|
|
73
|
+
if (errors.length > 0) {
|
|
74
|
+
responseText += `\n\nErrors:\n\`\`\`json\n${JSON.stringify(errors)}\n\`\`\``;
|
|
75
|
+
}
|
|
76
|
+
return {
|
|
77
|
+
content: [
|
|
78
|
+
{
|
|
79
|
+
type: 'text',
|
|
80
|
+
text: responseText
|
|
81
|
+
}
|
|
82
|
+
],
|
|
83
|
+
doc: {
|
|
84
|
+
docs,
|
|
85
|
+
errors
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
} catch (error) {
|
|
89
|
+
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
|
|
90
|
+
logger.error(`Error deleting document from ${collectionSlug}: ${errorMessage}`);
|
|
91
|
+
return {
|
|
92
|
+
content: [
|
|
93
|
+
{
|
|
94
|
+
type: 'text',
|
|
95
|
+
text: `Error deleting document from collection "${collectionSlug}": ${errorMessage}`
|
|
96
|
+
}
|
|
97
|
+
]
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
//# sourceMappingURL=deleteTool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/mcp/builtin/collections/deleteTool.ts"],"sourcesContent":["import { z } from 'zod'\n\nimport { defineCollectionTool } from '../../../defineTool.js'\nimport { getLogger } from '../../../utils/getLogger.js'\nimport { localAPIDefaults } from '../../../utils/localAPIDefaults.js'\nimport { whereSchema } from '../../../utils/whereSchema.js'\n\nconst DEFAULT_DESCRIPTION =\n 'Delete documents in any collection by passing the collection slug and ID or where clause.'\n\nexport const deleteDocumentsTool = defineCollectionTool({\n description: DEFAULT_DESCRIPTION,\n input: z.object({\n id: z\n .union([z.string(), z.number()])\n .describe('Optional: specific document ID to delete')\n .optional(),\n depth: z\n .number()\n .int()\n .min(0)\n .max(10)\n .describe('Depth of population for relationships in response')\n .optional()\n .default(0),\n fallbackLocale: z\n .string()\n .describe('Optional: fallback locale code to use when requested locale is not available')\n .optional(),\n locale: z\n .string()\n .describe(\n 'Optional: locale code for the operation (e.g., \"en\", \"es\"). Defaults to the default locale',\n )\n .optional(),\n where: whereSchema\n .describe(\n 'Optional: where clause to delete multiple documents. Use field names with Payload operators, and/or arrays for grouping. Example: {\"title\":{\"contains\":\"test\"}}',\n )\n .optional(),\n }),\n}).handler(async ({ authorizedMCP, collectionSlug, input, req }) => {\n const payload = req.payload\n const logger = getLogger({ payload })\n\n const { id, depth, fallbackLocale, locale, where } = input\n\n logger.info(\n `Deleting document from collection: ${collectionSlug}${id ? ` with ID: ${id}` : ' with where clause'}${locale ? `, locale: ${locale}` : ''}`,\n )\n\n try {\n if (!id && !where) {\n return {\n content: [{ type: 'text', text: 'Error: Either id or where clause must be provided' }],\n }\n }\n\n const deleteOptions: Record<string, unknown> = {\n collection: collectionSlug,\n depth,\n req,\n ...localAPIDefaults(authorizedMCP),\n ...(locale && { locale }),\n ...(fallbackLocale && { fallbackLocale }),\n }\n\n if (id) {\n deleteOptions.id = id\n } else {\n deleteOptions.where = where\n }\n\n const result = await payload.delete(deleteOptions as Parameters<typeof payload.delete>[0])\n\n if (id) {\n return {\n content: [\n {\n type: 'text',\n text: `Document deleted successfully from collection \"${collectionSlug}\"!\\nDeleted document:\\n\\`\\`\\`json\\n${JSON.stringify(result)}\\n\\`\\`\\``,\n },\n ],\n doc: result as Record<string, unknown>,\n }\n }\n\n const bulkResult = result as { docs?: unknown[]; errors?: unknown[] }\n const docs = bulkResult.docs || []\n const errors = bulkResult.errors || []\n\n let responseText = `Document deleted successfully from collection \"${collectionSlug}\"!\\nDeleted: ${docs.length} documents\\nErrors: ${errors.length}\\n---`\n if (docs.length > 0) {\n responseText += `\\n\\nDeleted documents:\\n\\`\\`\\`json\\n${JSON.stringify(docs)}\\n\\`\\`\\``\n }\n if (errors.length > 0) {\n responseText += `\\n\\nErrors:\\n\\`\\`\\`json\\n${JSON.stringify(errors)}\\n\\`\\`\\``\n }\n\n return {\n content: [{ type: 'text', text: responseText }],\n doc: { docs, errors } as unknown as Record<string, unknown>,\n }\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : 'Unknown error'\n logger.error(`Error deleting document from ${collectionSlug}: ${errorMessage}`)\n return {\n content: [\n {\n type: 'text',\n text: `Error deleting document from collection \"${collectionSlug}\": ${errorMessage}`,\n },\n ],\n }\n }\n})\n"],"names":["z","defineCollectionTool","getLogger","localAPIDefaults","whereSchema","DEFAULT_DESCRIPTION","deleteDocumentsTool","description","input","object","id","union","string","number","describe","optional","depth","int","min","max","default","fallbackLocale","locale","where","handler","authorizedMCP","collectionSlug","req","payload","logger","info","content","type","text","deleteOptions","collection","result","delete","JSON","stringify","doc","bulkResult","docs","errors","responseText","length","error","errorMessage","Error","message"],"mappings":"AAAA,SAASA,CAAC,QAAQ,MAAK;AAEvB,SAASC,oBAAoB,QAAQ,yBAAwB;AAC7D,SAASC,SAAS,QAAQ,8BAA6B;AACvD,SAASC,gBAAgB,QAAQ,qCAAoC;AACrE,SAASC,WAAW,QAAQ,gCAA+B;AAE3D,MAAMC,sBACJ;AAEF,OAAO,MAAMC,sBAAsBL,qBAAqB;IACtDM,aAAaF;IACbG,OAAOR,EAAES,MAAM,CAAC;QACdC,IAAIV,EACDW,KAAK,CAAC;YAACX,EAAEY,MAAM;YAAIZ,EAAEa,MAAM;SAAG,EAC9BC,QAAQ,CAAC,4CACTC,QAAQ;QACXC,OAAOhB,EACJa,MAAM,GACNI,GAAG,GACHC,GAAG,CAAC,GACJC,GAAG,CAAC,IACJL,QAAQ,CAAC,qDACTC,QAAQ,GACRK,OAAO,CAAC;QACXC,gBAAgBrB,EACbY,MAAM,GACNE,QAAQ,CAAC,gFACTC,QAAQ;QACXO,QAAQtB,EACLY,MAAM,GACNE,QAAQ,CACP,8FAEDC,QAAQ;QACXQ,OAAOnB,YACJU,QAAQ,CACP,mKAEDC,QAAQ;IACb;AACF,GAAGS,OAAO,CAAC,OAAO,EAAEC,aAAa,EAAEC,cAAc,EAAElB,KAAK,EAAEmB,GAAG,EAAE;IAC7D,MAAMC,UAAUD,IAAIC,OAAO;IAC3B,MAAMC,SAAS3B,UAAU;QAAE0B;IAAQ;IAEnC,MAAM,EAAElB,EAAE,EAAEM,KAAK,EAAEK,cAAc,EAAEC,MAAM,EAAEC,KAAK,EAAE,GAAGf;IAErDqB,OAAOC,IAAI,CACT,CAAC,mCAAmC,EAAEJ,iBAAiBhB,KA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ACLZ,SAAS;gBAAC;oBAAEC,MAAM;oBAAQC,MAAMW;gBAAa;aAAE;YAC/CJ,KAAK;gBAAEE;gBAAMC;YAAO;QACtB;IACF,EAAE,OAAOG,OAAO;QACd,MAAMC,eAAeD,iBAAiBE,QAAQF,MAAMG,OAAO,GAAG;QAC9DpB,OAAOiB,KAAK,CAAC,CAAC,6BAA6B,EAAEpB,eAAe,EAAE,EAAEqB,cAAc;QAC9E,OAAO;YACLhB,SAAS;gBACP;oBACEC,MAAM;oBACNC,MAAM,CAAC,yCAAyC,EAAEP,eAAe,GAAG,EAAEqB,cAAc;gBACtF;aACD;QACH;IACF;AACF,GAAE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"findTool.d.ts","sourceRoot":"","sources":["../../../../src/mcp/builtin/collections/findTool.ts"],"names":[],"mappings":"AAYA,eAAO,MAAM,iBAAiB,4CAoK5B,CAAA"}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { defineCollectionTool } from '../../../defineTool.js';
|
|
3
|
+
import { getLogger } from '../../../utils/getLogger.js';
|
|
4
|
+
import { localAPIDefaults } from '../../../utils/localAPIDefaults.js';
|
|
5
|
+
import { whereSchema } from '../../../utils/whereSchema.js';
|
|
6
|
+
const DEFAULT_DESCRIPTION = 'Find documents in any collection by passing the collection slug and optional ID or where clause.';
|
|
7
|
+
export const findDocumentsTool = defineCollectionTool({
|
|
8
|
+
description: DEFAULT_DESCRIPTION,
|
|
9
|
+
input: z.object({
|
|
10
|
+
id: z.union([
|
|
11
|
+
z.string(),
|
|
12
|
+
z.number()
|
|
13
|
+
]).describe('Optional: specific document ID to retrieve. If not provided, returns all documents').optional(),
|
|
14
|
+
depth: z.number().int().min(0).max(10).describe('How many levels deep to populate relationships (default: 0)').optional().default(0),
|
|
15
|
+
draft: z.boolean().describe('Optional: whether the document should be queried from the versions table/collection or not.').optional(),
|
|
16
|
+
fallbackLocale: z.string().describe('Optional: fallback locale code to use when requested locale is not available').optional(),
|
|
17
|
+
limit: z.number().int().min(1).max(100).describe('Maximum number of documents to return (default: 10, max: 100)').optional().default(10),
|
|
18
|
+
locale: z.string().describe('Optional: locale code to retrieve data in (e.g., "en", "es"). Use "all" to retrieve all locales for localized fields').optional(),
|
|
19
|
+
page: z.number().int().min(1).describe('Page number for pagination (default: 1)').optional().default(1),
|
|
20
|
+
select: z.string().describe("Optional: define exactly which fields you'd like to return in the response (JSON), e.g., '{\"title\": true}'").optional(),
|
|
21
|
+
sort: z.string().describe('Field to sort by (e.g., "createdAt", "-updatedAt" for descending)').optional(),
|
|
22
|
+
where: whereSchema.describe('Optional: where clause for filtering. Use field names with Payload operators, and/or arrays for grouping. Example: {"title":{"contains":"test"}}').optional()
|
|
23
|
+
})
|
|
24
|
+
}).handler(async ({ authorizedMCP, collectionSlug, input, req })=>{
|
|
25
|
+
const payload = req.payload;
|
|
26
|
+
const logger = getLogger({
|
|
27
|
+
payload
|
|
28
|
+
});
|
|
29
|
+
const { id, depth, draft, fallbackLocale, limit, locale, page, select, sort, where } = input;
|
|
30
|
+
logger.info(`Reading document from collection: ${collectionSlug}${id ? ` with ID: ${id}` : ''}, limit: ${limit}, page: ${page}${locale ? `, locale: ${locale}` : ''}`);
|
|
31
|
+
try {
|
|
32
|
+
let selectClause;
|
|
33
|
+
if (select) {
|
|
34
|
+
try {
|
|
35
|
+
selectClause = JSON.parse(select);
|
|
36
|
+
} catch {
|
|
37
|
+
logger.warn(`Invalid select clause JSON: ${select}`);
|
|
38
|
+
return {
|
|
39
|
+
content: [
|
|
40
|
+
{
|
|
41
|
+
type: 'text',
|
|
42
|
+
text: 'Error: Invalid JSON in select clause'
|
|
43
|
+
}
|
|
44
|
+
]
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
if (id) {
|
|
49
|
+
try {
|
|
50
|
+
const doc = await payload.findByID({
|
|
51
|
+
id,
|
|
52
|
+
collection: collectionSlug,
|
|
53
|
+
depth,
|
|
54
|
+
req,
|
|
55
|
+
...localAPIDefaults(authorizedMCP),
|
|
56
|
+
...selectClause && {
|
|
57
|
+
select: selectClause
|
|
58
|
+
},
|
|
59
|
+
...locale && {
|
|
60
|
+
locale
|
|
61
|
+
},
|
|
62
|
+
...fallbackLocale && {
|
|
63
|
+
fallbackLocale
|
|
64
|
+
},
|
|
65
|
+
...draft !== undefined && {
|
|
66
|
+
draft
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
return {
|
|
70
|
+
content: [
|
|
71
|
+
{
|
|
72
|
+
type: 'text',
|
|
73
|
+
text: `Document from collection "${collectionSlug}":\n${JSON.stringify(doc)}`
|
|
74
|
+
}
|
|
75
|
+
],
|
|
76
|
+
doc: doc
|
|
77
|
+
};
|
|
78
|
+
} catch {
|
|
79
|
+
logger.warn(`Document not found with ID: ${id} in collection: ${collectionSlug}`);
|
|
80
|
+
return {
|
|
81
|
+
content: [
|
|
82
|
+
{
|
|
83
|
+
type: 'text',
|
|
84
|
+
text: `Error: Document with ID "${id}" not found in collection "${collectionSlug}"`
|
|
85
|
+
}
|
|
86
|
+
]
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
const findOptions = {
|
|
91
|
+
collection: collectionSlug,
|
|
92
|
+
depth,
|
|
93
|
+
limit,
|
|
94
|
+
page,
|
|
95
|
+
req,
|
|
96
|
+
...localAPIDefaults(authorizedMCP),
|
|
97
|
+
...selectClause && {
|
|
98
|
+
select: selectClause
|
|
99
|
+
},
|
|
100
|
+
...locale && {
|
|
101
|
+
locale
|
|
102
|
+
},
|
|
103
|
+
...fallbackLocale && {
|
|
104
|
+
fallbackLocale
|
|
105
|
+
},
|
|
106
|
+
...draft !== undefined && {
|
|
107
|
+
draft
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
if (sort) {
|
|
111
|
+
findOptions.sort = sort;
|
|
112
|
+
}
|
|
113
|
+
if (where) {
|
|
114
|
+
findOptions.where = where;
|
|
115
|
+
}
|
|
116
|
+
const result = await payload.find(findOptions);
|
|
117
|
+
let responseText = `Collection: "${collectionSlug}"\nTotal: ${result.totalDocs} documents\nPage: ${result.page} of ${result.totalPages}\n`;
|
|
118
|
+
for (const doc of result.docs){
|
|
119
|
+
responseText += `\n\`\`\`json\n${JSON.stringify(doc)}\n\`\`\``;
|
|
120
|
+
}
|
|
121
|
+
return {
|
|
122
|
+
content: [
|
|
123
|
+
{
|
|
124
|
+
type: 'text',
|
|
125
|
+
text: responseText
|
|
126
|
+
}
|
|
127
|
+
],
|
|
128
|
+
doc: result
|
|
129
|
+
};
|
|
130
|
+
} catch (error) {
|
|
131
|
+
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
|
|
132
|
+
logger.error(`Error reading documents from collection ${collectionSlug}: ${errorMessage}`);
|
|
133
|
+
return {
|
|
134
|
+
content: [
|
|
135
|
+
{
|
|
136
|
+
type: 'text',
|
|
137
|
+
text: `❌ **Error reading documents from collection "${collectionSlug}":** ${errorMessage}`
|
|
138
|
+
}
|
|
139
|
+
]
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
//# sourceMappingURL=findTool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/mcp/builtin/collections/findTool.ts"],"sourcesContent":["import type { SelectType } from 'payload'\n\nimport { z } from 'zod'\n\nimport { defineCollectionTool } from '../../../defineTool.js'\nimport { getLogger } from '../../../utils/getLogger.js'\nimport { localAPIDefaults } from '../../../utils/localAPIDefaults.js'\nimport { whereSchema } from '../../../utils/whereSchema.js'\n\nconst DEFAULT_DESCRIPTION =\n 'Find documents in any collection by passing the collection slug and optional ID or where clause.'\n\nexport const findDocumentsTool = defineCollectionTool({\n description: DEFAULT_DESCRIPTION,\n input: z.object({\n id: z\n .union([z.string(), z.number()])\n .describe(\n 'Optional: specific document ID to retrieve. If not provided, returns all documents',\n )\n .optional(),\n depth: z\n .number()\n .int()\n .min(0)\n .max(10)\n .describe('How many levels deep to populate relationships (default: 0)')\n .optional()\n .default(0),\n draft: z\n .boolean()\n .describe(\n 'Optional: whether the document should be queried from the versions table/collection or not.',\n )\n .optional(),\n fallbackLocale: z\n .string()\n .describe('Optional: fallback locale code to use when requested locale is not available')\n .optional(),\n limit: z\n .number()\n .int()\n .min(1)\n .max(100)\n .describe('Maximum number of documents to return (default: 10, max: 100)')\n .optional()\n .default(10),\n locale: z\n .string()\n .describe(\n 'Optional: locale code to retrieve data in (e.g., \"en\", \"es\"). Use \"all\" to retrieve all locales for localized fields',\n )\n .optional(),\n page: z\n .number()\n .int()\n .min(1)\n .describe('Page number for pagination (default: 1)')\n .optional()\n .default(1),\n select: z\n .string()\n .describe(\n \"Optional: define exactly which fields you'd like to return in the response (JSON), e.g., '{\\\"title\\\": true}'\",\n )\n .optional(),\n sort: z\n .string()\n .describe('Field to sort by (e.g., \"createdAt\", \"-updatedAt\" for descending)')\n .optional(),\n where: whereSchema\n .describe(\n 'Optional: where clause for filtering. Use field names with Payload operators, and/or arrays for grouping. Example: {\"title\":{\"contains\":\"test\"}}',\n )\n .optional(),\n }),\n}).handler(async ({ authorizedMCP, collectionSlug, input, req }) => {\n const payload = req.payload\n const logger = getLogger({ payload })\n\n const { id, depth, draft, fallbackLocale, limit, locale, page, select, sort, where } = input\n\n logger.info(\n `Reading document from collection: ${collectionSlug}${id ? ` with ID: ${id}` : ''}, limit: ${limit}, page: ${page}${locale ? `, locale: ${locale}` : ''}`,\n )\n\n try {\n let selectClause: SelectType | undefined\n if (select) {\n try {\n selectClause = JSON.parse(select) as SelectType\n } catch {\n logger.warn(`Invalid select clause JSON: ${select}`)\n return { content: [{ type: 'text', text: 'Error: Invalid JSON in select clause' }] }\n }\n }\n\n if (id) {\n try {\n const doc = await payload.findByID({\n id,\n collection: collectionSlug,\n depth,\n req,\n ...localAPIDefaults(authorizedMCP),\n ...(selectClause && { select: selectClause }),\n ...(locale && { locale }),\n ...(fallbackLocale && { fallbackLocale }),\n ...(draft !== undefined && { draft }),\n })\n\n return {\n content: [\n {\n type: 'text',\n text: `Document from collection \"${collectionSlug}\":\\n${JSON.stringify(doc)}`,\n },\n ],\n doc: doc as Record<string, unknown>,\n }\n } catch {\n logger.warn(`Document not found with ID: ${id} in collection: ${collectionSlug}`)\n return {\n content: [\n {\n type: 'text',\n text: `Error: Document with ID \"${id}\" not found in collection \"${collectionSlug}\"`,\n },\n ],\n }\n }\n }\n\n const findOptions: Parameters<typeof payload.find>[0] = {\n collection: collectionSlug,\n depth,\n limit,\n page,\n req,\n ...localAPIDefaults(authorizedMCP),\n ...(selectClause && { select: selectClause }),\n ...(locale && { locale }),\n ...(fallbackLocale && { fallbackLocale }),\n ...(draft !== undefined && { draft }),\n }\n\n if (sort) {\n findOptions.sort = sort\n }\n if (where) {\n findOptions.where = where\n }\n\n const result = await payload.find(findOptions)\n\n let responseText = `Collection: \"${collectionSlug}\"\\nTotal: ${result.totalDocs} documents\\nPage: ${result.page} of ${result.totalPages}\\n`\n for (const doc of result.docs) {\n responseText += `\\n\\`\\`\\`json\\n${JSON.stringify(doc)}\\n\\`\\`\\``\n }\n\n return {\n content: [{ type: 'text', text: responseText }],\n doc: result as unknown as Record<string, unknown>,\n }\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : 'Unknown error'\n logger.error(`Error reading documents from collection ${collectionSlug}: ${errorMessage}`)\n return {\n content: [\n {\n type: 'text',\n text: `❌ **Error reading documents from collection \"${collectionSlug}\":** ${errorMessage}`,\n },\n ],\n }\n }\n})\n"],"names":["z","defineCollectionTool","getLogger","localAPIDefaults","whereSchema","DEFAULT_DESCRIPTION","findDocumentsTool","description","input","object","id","union","string","number","describe","optional","depth","int","min","max","default","draft","boolean","fallbackLocale","limit","locale","page","select","sort","where","handler","authorizedMCP","collectionSlug","req","payload","logger","info","selectClause","JSON","parse","warn","content","type","text","doc","findByID","collection","undefined","stringify","findOptions","result","find","responseText","totalDocs","totalPages","docs","error","errorM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,MAAM;oBACNC,MAAM,CAAC,6CAA6C,EAAEX,eAAe,KAAK,EAAEyB,cAAc;gBAC5F;aACD;QACH;IACF;AACF,GAAE"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { CollectionSlug, PayloadRequest } from 'payload';
|
|
2
|
+
import type { MCPToolResponse } from '../../../types.js';
|
|
3
|
+
export declare const formatCollectionError: ({ action, collectionSlug, error, req, }: {
|
|
4
|
+
action: "creating" | "updating";
|
|
5
|
+
collectionSlug: CollectionSlug;
|
|
6
|
+
error: unknown;
|
|
7
|
+
req: PayloadRequest;
|
|
8
|
+
}) => MCPToolResponse;
|
|
9
|
+
//# sourceMappingURL=formatCollectionError.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"formatCollectionError.d.ts","sourceRoot":"","sources":["../../../../src/mcp/builtin/collections/formatCollectionError.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAE7D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AAgCxD,eAAO,MAAM,qBAAqB,GAAI,yCAKnC;IACD,MAAM,EAAE,UAAU,GAAG,UAAU,CAAA;IAC/B,cAAc,EAAE,cAAc,CAAA;IAC9B,KAAK,EAAE,OAAO,CAAA;IACd,GAAG,EAAE,cAAc,CAAA;CACpB,KAAG,eAuCH,CAAA"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { getCollectionInputSchema } from '../../../utils/schemaConversion/getEntityInputSchema.js';
|
|
2
|
+
const getValidationErrors = (error)=>{
|
|
3
|
+
if (!error || typeof error !== 'object') {
|
|
4
|
+
return undefined;
|
|
5
|
+
}
|
|
6
|
+
const data = 'data' in error ? error.data : undefined;
|
|
7
|
+
if (!data || typeof data !== 'object' || !('errors' in data) || !Array.isArray(data.errors)) {
|
|
8
|
+
return undefined;
|
|
9
|
+
}
|
|
10
|
+
return data.errors;
|
|
11
|
+
};
|
|
12
|
+
const isSchemaError = (error, message)=>{
|
|
13
|
+
if (getValidationErrors(error)) {
|
|
14
|
+
return true;
|
|
15
|
+
}
|
|
16
|
+
const name = error && typeof error === 'object' && 'name' in error ? error.name : undefined;
|
|
17
|
+
return name === 'CastError' || name === 'ValidationError' || message.includes('Cast to ') || message.includes('validation failed');
|
|
18
|
+
};
|
|
19
|
+
export const formatCollectionError = ({ action, collectionSlug, error, req })=>{
|
|
20
|
+
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
|
|
21
|
+
const errors = getValidationErrors(error) ?? [
|
|
22
|
+
{
|
|
23
|
+
message: errorMessage
|
|
24
|
+
}
|
|
25
|
+
];
|
|
26
|
+
if (!isSchemaError(error, errorMessage)) {
|
|
27
|
+
return {
|
|
28
|
+
content: [
|
|
29
|
+
{
|
|
30
|
+
type: 'text',
|
|
31
|
+
text: `Error ${action} document in collection "${collectionSlug}": ${errorMessage}`
|
|
32
|
+
}
|
|
33
|
+
],
|
|
34
|
+
isError: true
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
const schema = getCollectionInputSchema({
|
|
38
|
+
collectionSlug,
|
|
39
|
+
req
|
|
40
|
+
});
|
|
41
|
+
const schemaText = schema ? `\n\nUse this schema for data:\n\`\`\`json\n${JSON.stringify(schema)}\n\`\`\`` : '';
|
|
42
|
+
return {
|
|
43
|
+
content: [
|
|
44
|
+
{
|
|
45
|
+
type: 'text',
|
|
46
|
+
text: `Error ${action} document in collection "${collectionSlug}": ${errorMessage}${schemaText}`
|
|
47
|
+
}
|
|
48
|
+
],
|
|
49
|
+
isError: true,
|
|
50
|
+
...schema ? {
|
|
51
|
+
structuredContent: {
|
|
52
|
+
collectionSlug,
|
|
53
|
+
errors,
|
|
54
|
+
schema
|
|
55
|
+
}
|
|
56
|
+
} : {}
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
//# sourceMappingURL=formatCollectionError.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/mcp/builtin/collections/formatCollectionError.ts"],"sourcesContent":["import type { CollectionSlug, PayloadRequest } from 'payload'\n\nimport type { MCPToolResponse } from '../../../types.js'\n\nimport { getCollectionInputSchema } from '../../../utils/schemaConversion/getEntityInputSchema.js'\n\nconst getValidationErrors = (error: unknown): undefined | unknown[] => {\n if (!error || typeof error !== 'object') {\n return undefined\n }\n\n const data = 'data' in error ? error.data : undefined\n if (!data || typeof data !== 'object' || !('errors' in data) || !Array.isArray(data.errors)) {\n return undefined\n }\n\n return data.errors\n}\n\nconst isSchemaError = (error: unknown, message: string): boolean => {\n if (getValidationErrors(error)) {\n return true\n }\n\n const name = error && typeof error === 'object' && 'name' in error ? error.name : undefined\n\n return (\n name === 'CastError' ||\n name === 'ValidationError' ||\n message.includes('Cast to ') ||\n message.includes('validation failed')\n )\n}\n\nexport const formatCollectionError = ({\n action,\n collectionSlug,\n error,\n req,\n}: {\n action: 'creating' | 'updating'\n collectionSlug: CollectionSlug\n error: unknown\n req: PayloadRequest\n}): MCPToolResponse => {\n const errorMessage = error instanceof Error ? error.message : 'Unknown error'\n const errors = getValidationErrors(error) ?? [{ message: errorMessage }]\n\n if (!isSchemaError(error, errorMessage)) {\n return {\n content: [\n {\n type: 'text',\n text: `Error ${action} document in collection \"${collectionSlug}\": ${errorMessage}`,\n },\n ],\n isError: true,\n }\n }\n\n const schema = getCollectionInputSchema({ collectionSlug, req })\n const schemaText = schema\n ? `\\n\\nUse this schema for data:\\n\\`\\`\\`json\\n${JSON.stringify(schema)}\\n\\`\\`\\``\n : ''\n\n return {\n content: [\n {\n type: 'text',\n text: `Error ${action} document in collection \"${collectionSlug}\": ${errorMessage}${schemaText}`,\n },\n ],\n isError: true,\n ...(schema\n ? {\n structuredContent: {\n collectionSlug,\n errors,\n schema,\n },\n }\n : {}),\n }\n}\n"],"names":["getCollectionInputSchema","getValidationErrors","error","undefined","data","Array","isArray","errors","isSchemaError","message","name","includes","formatCollectionError","action","collectionSlug","req","errorMessage","Error","content","type","text","isError","schema","schemaText","JSON","stringify","structuredContent"],"mappings":"AAIA,SAASA,wBAAwB,QAAQ,0DAAyD;AAElG,MAAMC,sBAAsB,CAACC;IAC3B,IAAI,CAACA,SAAS,OAAOA,UAAU,UAAU;QACvC,OAAOC;IACT;IAEA,MAAMC,OAAO,UAAUF,QAAQA,MAAME,IAAI,GAAGD;IAC5C,IAAI,CAACC,QAAQ,OAAOA,SAAS,YAAY,CAAE,CAAA,YAAYA,IAAG,KAAM,CAACC,MAAMC,OAAO,CAACF,KAAKG,MAAM,GAAG;QAC3F,OAAOJ;IACT;IAEA,OAAOC,KAAKG,MAAM;AACpB;AAEA,MAAMC,gBAAgB,CAACN,OAAgBO;IACrC,IAAIR,oBAAoBC,QAAQ;QAC9B,OAAO;IACT;IAEA,MAAMQ,OAAOR,SAAS,OAAOA,UAAU,YAAY,UAAUA,QAAQA,MAAMQ,IAAI,GAAGP;IAElF,OACEO,SAAS,eACTA,SAAS,qBACTD,QAAQE,QAAQ,CAAC,eACjBF,QAAQE,QAAQ,CAAC;AAErB;AAEA,OAAO,MAAMC,wBAAwB,CAAC,EACpCC,MAAM,EACNC,cAAc,EACdZ,KAAK,EACLa,GAAG,EAMJ;IACC,MAAMC,eAAed,iBAAiBe,QAAQf,MAAMO,OAAO,GAAG;IAC9D,MAAMF,SAASN,oBAAoBC,UAAU;QAAC;YAAEO,SAASO;QAAa;KAAE;IAExE,IAAI,CAACR,cAAcN,OAAOc,eAAe;QACvC,OAAO;YACLE,SAAS;gBACP;oBACEC,MAAM;oBACNC,MAAM,CAAC,MAAM,EAAEP,OAAO,yBAAyB,EAAEC,eAAe,GAAG,EAAEE,cAAc;gBACrF;aACD;YACDK,SAAS;QACX;IACF;IAEA,MAAMC,SAAStB,yBAAyB;QAAEc;QAAgBC;IAAI;IAC9D,MAAMQ,aAAaD,SACf,CAAC,2CAA2C,EAAEE,KAAKC,SAAS,CAACH,QAAQ,QAAQ,CAAC,GAC9E;IAEJ,OAAO;QACLJ,SAAS;YACP;gBACEC,MAAM;gBACNC,MAAM,CAAC,MAAM,EAAEP,OAAO,yBAAyB,EAAEC,eAAe,GAAG,EAAEE,eAAeO,YAAY;YAClG;SACD;QACDF,SAAS;QACT,GAAIC,SACA;YACEI,mBAAmB;gBACjBZ;gBACAP;gBACAe;YACF;QACF,IACA,CAAC,CAAC;IACR;AACF,EAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getCollectionSchemaTool.d.ts","sourceRoot":"","sources":["../../../../src/mcp/builtin/collections/getCollectionSchemaTool.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,uBAAuB,4CAwBlC,CAAA"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { defineCollectionTool } from '../../../defineTool.js';
|
|
2
|
+
import { getCollectionInputSchema } from '../../../utils/schemaConversion/getEntityInputSchema.js';
|
|
3
|
+
export const getCollectionSchemaTool = defineCollectionTool({
|
|
4
|
+
description: 'Get the input schema for creating or updating documents in a collection.'
|
|
5
|
+
}).handler(({ collectionSlug, req })=>{
|
|
6
|
+
const inputSchema = getCollectionInputSchema({
|
|
7
|
+
collectionSlug,
|
|
8
|
+
req
|
|
9
|
+
});
|
|
10
|
+
if (!inputSchema) {
|
|
11
|
+
return {
|
|
12
|
+
content: [
|
|
13
|
+
{
|
|
14
|
+
type: 'text',
|
|
15
|
+
text: `Error: Collection "${collectionSlug}" not found`
|
|
16
|
+
}
|
|
17
|
+
],
|
|
18
|
+
isError: true
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
return {
|
|
22
|
+
content: [
|
|
23
|
+
{
|
|
24
|
+
type: 'text',
|
|
25
|
+
text: `Schema for collection "${collectionSlug}":\n\`\`\`json\n${JSON.stringify(inputSchema)}\n\`\`\``
|
|
26
|
+
}
|
|
27
|
+
],
|
|
28
|
+
structuredContent: {
|
|
29
|
+
collectionSlug,
|
|
30
|
+
schema: inputSchema
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
//# sourceMappingURL=getCollectionSchemaTool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/mcp/builtin/collections/getCollectionSchemaTool.ts"],"sourcesContent":["import { defineCollectionTool } from '../../../defineTool.js'\nimport { getCollectionInputSchema } from '../../../utils/schemaConversion/getEntityInputSchema.js'\n\nexport const getCollectionSchemaTool = defineCollectionTool({\n description: 'Get the input schema for creating or updating documents in a collection.',\n}).handler(({ collectionSlug, req }) => {\n const inputSchema = getCollectionInputSchema({ collectionSlug, req })\n\n if (!inputSchema) {\n return {\n content: [{ type: 'text', text: `Error: Collection \"${collectionSlug}\" not found` }],\n isError: true,\n }\n }\n\n return {\n content: [\n {\n type: 'text',\n text: `Schema for collection \"${collectionSlug}\":\\n\\`\\`\\`json\\n${JSON.stringify(inputSchema)}\\n\\`\\`\\``,\n },\n ],\n structuredContent: {\n collectionSlug,\n schema: inputSchema,\n },\n }\n})\n"],"names":["defineCollectionTool","getCollectionInputSchema","getCollectionSchemaTool","description","handler","collectionSlug","req","inputSchema","content","type","text","isError","JSON","stringify","structuredContent","schema"],"mappings":"AAAA,SAASA,oBAAoB,QAAQ,yBAAwB;AAC7D,SAASC,wBAAwB,QAAQ,0DAAyD;AAElG,OAAO,MAAMC,0BAA0BF,qBAAqB;IAC1DG,aAAa;AACf,GAAGC,OAAO,CAAC,CAAC,EAAEC,cAAc,EAAEC,GAAG,EAAE;IACjC,MAAMC,cAAcN,yBAAyB;QAAEI;QAAgBC;IAAI;IAEnE,IAAI,CAACC,aAAa;QAChB,OAAO;YACLC,SAAS;gBAAC;oBAAEC,MAAM;oBAAQC,MAAM,CAAC,mBAAmB,EAAEL,eAAe,WAAW,CAAC;gBAAC;aAAE;YACpFM,SAAS;QACX;IACF;IAEA,OAAO;QACLH,SAAS;YACP;gBACEC,MAAM;gBACNC,MAAM,CAAC,uBAAuB,EAAEL,eAAe,gBAAgB,EAAEO,KAAKC,SAAS,CAACN,aAAa,QAAQ,CAAC;YACxG;SACD;QACDO,mBAAmB;YACjBT;YACAU,QAAQR;QACV;IACF;AACF,GAAE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"updateTool.d.ts","sourceRoot":"","sources":["../../../../src/mcp/builtin/collections/updateTool.ts"],"names":[],"mappings":"AAoBA,eAAO,MAAM,kBAAkB,4CA8L7B,CAAA"}
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { defineCollectionTool } from '../../../defineTool.js';
|
|
3
|
+
import { getLogger } from '../../../utils/getLogger.js';
|
|
4
|
+
import { getCollectionVirtualFieldNames, stripVirtualFields } from '../../../utils/getVirtualFieldNames.js';
|
|
5
|
+
import { localAPIDefaults } from '../../../utils/localAPIDefaults.js';
|
|
6
|
+
import { getCollectionInputSchema } from '../../../utils/schemaConversion/getEntityInputSchema.js';
|
|
7
|
+
import { transformPointDataToPayload } from '../../../utils/transformPointDataToPayload.js';
|
|
8
|
+
import { whereSchema } from '../../../utils/whereSchema.js';
|
|
9
|
+
import { validateCollectionData } from '../validateEntityData.js';
|
|
10
|
+
import { formatCollectionError } from './formatCollectionError.js';
|
|
11
|
+
const DEFAULT_DESCRIPTION = 'Update documents in any collection by passing the collection slug and data.';
|
|
12
|
+
export const updateDocumentTool = defineCollectionTool({
|
|
13
|
+
description: DEFAULT_DESCRIPTION,
|
|
14
|
+
input: z.object({
|
|
15
|
+
id: z.union([
|
|
16
|
+
z.string(),
|
|
17
|
+
z.number()
|
|
18
|
+
]).describe('The ID of the document to update').optional(),
|
|
19
|
+
data: z.record(z.string(), z.unknown()).describe('The fields to update'),
|
|
20
|
+
depth: z.number().describe('How many levels deep to populate relationships').optional().default(0),
|
|
21
|
+
draft: z.boolean().describe('Whether to update the document as a draft').optional().default(false),
|
|
22
|
+
fallbackLocale: z.string().describe('Optional: fallback locale code to use when requested locale is not available').optional(),
|
|
23
|
+
filePath: z.string().describe('File path for file uploads').optional(),
|
|
24
|
+
locale: z.string().describe('Optional: locale code to update the document in (e.g., "en", "es"). Defaults to the default locale').optional(),
|
|
25
|
+
overrideLock: z.boolean().describe('Whether to override document locks').optional().default(true),
|
|
26
|
+
overwriteExistingFiles: z.boolean().describe('Whether to overwrite existing files').optional().default(false),
|
|
27
|
+
select: z.string().describe("Optional: define exactly which fields you'd like to return in the response (JSON), e.g., '{\"title\": true}'").optional(),
|
|
28
|
+
where: whereSchema.describe('Where clause to update multiple documents. Use field names with Payload operators, and/or arrays for grouping. Example: {"title":{"contains":"test"}}').optional()
|
|
29
|
+
})
|
|
30
|
+
}).handler(async ({ authorizedMCP, collectionSlug, input, req })=>{
|
|
31
|
+
const payload = req.payload;
|
|
32
|
+
const logger = getLogger({
|
|
33
|
+
payload
|
|
34
|
+
});
|
|
35
|
+
const { id, data, depth, draft, fallbackLocale, filePath, locale, overrideLock, overwriteExistingFiles, select, where } = input;
|
|
36
|
+
logger.info(`Updating document in collection: ${collectionSlug}${id ? ` with ID: ${id}` : ' with where clause'}, draft: ${draft}${locale ? `, locale: ${locale}` : ''}`);
|
|
37
|
+
try {
|
|
38
|
+
if (!id && !where) {
|
|
39
|
+
return {
|
|
40
|
+
content: [
|
|
41
|
+
{
|
|
42
|
+
type: 'text',
|
|
43
|
+
text: 'Error: Either id or where clause must be provided'
|
|
44
|
+
}
|
|
45
|
+
]
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
const virtualFieldNames = getCollectionVirtualFieldNames(payload.config, collectionSlug);
|
|
49
|
+
const inputData = stripVirtualFields(data, virtualFieldNames);
|
|
50
|
+
const validationError = validateCollectionData({
|
|
51
|
+
collectionSlug,
|
|
52
|
+
data: inputData,
|
|
53
|
+
partial: true,
|
|
54
|
+
req
|
|
55
|
+
});
|
|
56
|
+
if (validationError) {
|
|
57
|
+
return validationError;
|
|
58
|
+
}
|
|
59
|
+
const parsedData = transformPointDataToPayload(inputData);
|
|
60
|
+
const whereClause = where ?? {};
|
|
61
|
+
let selectClause;
|
|
62
|
+
if (select) {
|
|
63
|
+
try {
|
|
64
|
+
selectClause = JSON.parse(select);
|
|
65
|
+
} catch {
|
|
66
|
+
logger.warn(`Invalid select clause JSON: ${select}`);
|
|
67
|
+
return {
|
|
68
|
+
content: [
|
|
69
|
+
{
|
|
70
|
+
type: 'text',
|
|
71
|
+
text: 'Error: Invalid JSON in select clause'
|
|
72
|
+
}
|
|
73
|
+
]
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
if (id) {
|
|
78
|
+
const result = await payload.update({
|
|
79
|
+
id,
|
|
80
|
+
collection: collectionSlug,
|
|
81
|
+
data: parsedData,
|
|
82
|
+
depth,
|
|
83
|
+
draft,
|
|
84
|
+
overrideLock,
|
|
85
|
+
req,
|
|
86
|
+
...localAPIDefaults(authorizedMCP),
|
|
87
|
+
...filePath ? {
|
|
88
|
+
filePath
|
|
89
|
+
} : {},
|
|
90
|
+
...overwriteExistingFiles ? {
|
|
91
|
+
overwriteExistingFiles
|
|
92
|
+
} : {},
|
|
93
|
+
...locale ? {
|
|
94
|
+
locale
|
|
95
|
+
} : {},
|
|
96
|
+
...fallbackLocale ? {
|
|
97
|
+
fallbackLocale
|
|
98
|
+
} : {},
|
|
99
|
+
...selectClause ? {
|
|
100
|
+
select: selectClause
|
|
101
|
+
} : {}
|
|
102
|
+
});
|
|
103
|
+
return {
|
|
104
|
+
content: [
|
|
105
|
+
{
|
|
106
|
+
type: 'text',
|
|
107
|
+
text: `Document updated successfully in collection "${collectionSlug}"!\nUpdated document:\n\`\`\`json\n${JSON.stringify(result)}\n\`\`\``
|
|
108
|
+
}
|
|
109
|
+
],
|
|
110
|
+
doc: result
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
const result = await payload.update({
|
|
114
|
+
collection: collectionSlug,
|
|
115
|
+
data: parsedData,
|
|
116
|
+
depth,
|
|
117
|
+
draft,
|
|
118
|
+
overrideLock,
|
|
119
|
+
req,
|
|
120
|
+
where: whereClause,
|
|
121
|
+
...localAPIDefaults(authorizedMCP),
|
|
122
|
+
...filePath ? {
|
|
123
|
+
filePath
|
|
124
|
+
} : {},
|
|
125
|
+
...overwriteExistingFiles ? {
|
|
126
|
+
overwriteExistingFiles
|
|
127
|
+
} : {},
|
|
128
|
+
...locale ? {
|
|
129
|
+
locale
|
|
130
|
+
} : {},
|
|
131
|
+
...fallbackLocale ? {
|
|
132
|
+
fallbackLocale
|
|
133
|
+
} : {},
|
|
134
|
+
...selectClause ? {
|
|
135
|
+
select: selectClause
|
|
136
|
+
} : {}
|
|
137
|
+
});
|
|
138
|
+
const docs = result.docs || [];
|
|
139
|
+
const errors = result.errors || [];
|
|
140
|
+
let responseText = `Multiple documents updated in collection "${collectionSlug}"!\nUpdated: ${docs.length} documents\nErrors: ${errors.length}\n---`;
|
|
141
|
+
if (docs.length > 0) {
|
|
142
|
+
responseText += `\n\nUpdated documents:\n\`\`\`json\n${JSON.stringify(docs)}\n\`\`\``;
|
|
143
|
+
}
|
|
144
|
+
if (errors.length > 0) {
|
|
145
|
+
responseText += `\n\nErrors:\n\`\`\`json\n${JSON.stringify(errors)}\n\`\`\``;
|
|
146
|
+
const errorSchema = getCollectionInputSchema({
|
|
147
|
+
collectionSlug,
|
|
148
|
+
req
|
|
149
|
+
});
|
|
150
|
+
if (errorSchema) {
|
|
151
|
+
responseText += `\n\nUse this schema for data:\n\`\`\`json\n${JSON.stringify(errorSchema)}\n\`\`\``;
|
|
152
|
+
}
|
|
153
|
+
return {
|
|
154
|
+
content: [
|
|
155
|
+
{
|
|
156
|
+
type: 'text',
|
|
157
|
+
text: responseText
|
|
158
|
+
}
|
|
159
|
+
],
|
|
160
|
+
doc: {
|
|
161
|
+
docs,
|
|
162
|
+
errors
|
|
163
|
+
},
|
|
164
|
+
isError: true,
|
|
165
|
+
...errorSchema ? {
|
|
166
|
+
structuredContent: {
|
|
167
|
+
collectionSlug,
|
|
168
|
+
docs,
|
|
169
|
+
errors,
|
|
170
|
+
schema: errorSchema
|
|
171
|
+
}
|
|
172
|
+
} : {}
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
return {
|
|
176
|
+
content: [
|
|
177
|
+
{
|
|
178
|
+
type: 'text',
|
|
179
|
+
text: responseText
|
|
180
|
+
}
|
|
181
|
+
],
|
|
182
|
+
doc: {
|
|
183
|
+
docs,
|
|
184
|
+
errors
|
|
185
|
+
}
|
|
186
|
+
};
|
|
187
|
+
} catch (error) {
|
|
188
|
+
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
|
|
189
|
+
logger.error(`Error updating document in ${collectionSlug}: ${errorMessage}`);
|
|
190
|
+
return formatCollectionError({
|
|
191
|
+
action: 'updating',
|
|
192
|
+
collectionSlug,
|
|
193
|
+
error,
|
|
194
|
+
req
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
//# sourceMappingURL=updateTool.js.map
|