@payloadcms/plugin-mcp 4.0.0-internal.d28e9fb → 4.0.0-internal.d927017
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/LICENSE.md +1 -1
- package/bin.js +48 -0
- package/dist/bin/index.d.ts +2 -0
- package/dist/bin/index.d.ts.map +1 -0
- package/dist/bin/index.js +12 -0
- package/dist/bin/index.js.map +1 -0
- package/dist/bin/initializeViteHMR.d.ts +8 -0
- package/dist/bin/initializeViteHMR.d.ts.map +1 -0
- package/dist/bin/initializeViteHMR.js +63 -0
- package/dist/bin/initializeViteHMR.js.map +1 -0
- package/dist/bin/viteConfigBoundary.d.ts +6 -0
- package/dist/bin/viteConfigBoundary.d.ts.map +1 -0
- package/dist/bin/viteConfigBoundary.js +25 -0
- package/dist/bin/viteConfigBoundary.js.map +1 -0
- package/dist/defaultAccess.d.ts +3 -0
- package/dist/defaultAccess.d.ts.map +1 -0
- package/dist/defaultAccess.js +3 -0
- package/dist/defaultAccess.js.map +1 -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 +17 -0
- package/dist/endpoint/access.d.ts.map +1 -0
- package/dist/endpoint/access.js +93 -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 +87 -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/exports/internal.d.ts +2 -0
- package/dist/exports/internal.d.ts.map +1 -0
- package/dist/exports/internal.js +3 -0
- package/dist/exports/internal.js.map +1 -0
- package/dist/index.d.ts +6 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +39 -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 +223 -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 +288 -0
- package/dist/mcp/builtin/collections/authTools.js.map +1 -0
- package/dist/mcp/builtin/collections/countTool.d.ts +2 -0
- package/dist/mcp/builtin/collections/countTool.d.ts.map +1 -0
- package/dist/mcp/builtin/collections/countTool.js +68 -0
- package/dist/mcp/builtin/collections/countTool.js.map +1 -0
- package/dist/mcp/builtin/collections/countVersionsTool.d.ts +2 -0
- package/dist/mcp/builtin/collections/countVersionsTool.d.ts.map +1 -0
- package/dist/mcp/builtin/collections/countVersionsTool.js +64 -0
- package/dist/mcp/builtin/collections/countVersionsTool.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 +86 -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 +110 -0
- package/dist/mcp/builtin/collections/deleteTool.js.map +1 -0
- package/dist/mcp/builtin/collections/duplicateTool.d.ts +2 -0
- package/dist/mcp/builtin/collections/duplicateTool.d.ts.map +1 -0
- package/dist/mcp/builtin/collections/duplicateTool.js +96 -0
- package/dist/mcp/builtin/collections/duplicateTool.js.map +1 -0
- package/dist/mcp/builtin/collections/findDistinctTool.d.ts +2 -0
- package/dist/mcp/builtin/collections/findDistinctTool.d.ts.map +1 -0
- package/dist/mcp/builtin/collections/findDistinctTool.js +92 -0
- package/dist/mcp/builtin/collections/findDistinctTool.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 +164 -0
- package/dist/mcp/builtin/collections/findTool.js.map +1 -0
- package/dist/mcp/builtin/collections/findVersionByIDTool.d.ts +2 -0
- package/dist/mcp/builtin/collections/findVersionByIDTool.d.ts.map +1 -0
- package/dist/mcp/builtin/collections/findVersionByIDTool.js +83 -0
- package/dist/mcp/builtin/collections/findVersionByIDTool.js.map +1 -0
- package/dist/mcp/builtin/collections/findVersionsTool.d.ts +2 -0
- package/dist/mcp/builtin/collections/findVersionsTool.d.ts.map +1 -0
- package/dist/mcp/builtin/collections/findVersionsTool.js +98 -0
- package/dist/mcp/builtin/collections/findVersionsTool.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 +65 -0
- package/dist/mcp/builtin/collections/getCollectionSchemaTool.js.map +1 -0
- package/dist/mcp/builtin/collections/restoreVersionTool.d.ts +2 -0
- package/dist/mcp/builtin/collections/restoreVersionTool.d.ts.map +1 -0
- package/dist/mcp/builtin/collections/restoreVersionTool.js +81 -0
- package/dist/mcp/builtin/collections/restoreVersionTool.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 +198 -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 +68 -0
- package/dist/mcp/builtin/getConfigInfoTool.js.map +1 -0
- package/dist/mcp/builtin/globals/countVersionsTool.d.ts +2 -0
- package/dist/mcp/builtin/globals/countVersionsTool.d.ts.map +1 -0
- package/dist/mcp/builtin/globals/countVersionsTool.js +64 -0
- package/dist/mcp/builtin/globals/countVersionsTool.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 +73 -0
- package/dist/mcp/builtin/globals/findTool.js.map +1 -0
- package/dist/mcp/builtin/globals/findVersionByIDTool.d.ts +2 -0
- package/dist/mcp/builtin/globals/findVersionByIDTool.d.ts.map +1 -0
- package/dist/mcp/builtin/globals/findVersionByIDTool.js +79 -0
- package/dist/mcp/builtin/globals/findVersionByIDTool.js.map +1 -0
- package/dist/mcp/builtin/globals/findVersionsTool.d.ts +2 -0
- package/dist/mcp/builtin/globals/findVersionsTool.d.ts.map +1 -0
- package/dist/mcp/builtin/globals/findVersionsTool.js +94 -0
- package/dist/mcp/builtin/globals/findVersionsTool.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 +65 -0
- package/dist/mcp/builtin/globals/getGlobalSchemaTool.js.map +1 -0
- package/dist/mcp/builtin/globals/restoreVersionTool.d.ts +2 -0
- package/dist/mcp/builtin/globals/restoreVersionTool.d.ts.map +1 -0
- package/dist/mcp/builtin/globals/restoreVersionTool.js +77 -0
- package/dist/mcp/builtin/globals/restoreVersionTool.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 +87 -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 +162 -0
- package/dist/mcp/builtinTools.d.ts.map +1 -0
- package/dist/mcp/builtinTools.js +163 -0
- package/dist/mcp/builtinTools.js.map +1 -0
- package/dist/mcp/sanitizeMCPConfig.d.ts +16 -0
- package/dist/mcp/sanitizeMCPConfig.d.ts.map +1 -0
- package/dist/mcp/sanitizeMCPConfig.js +230 -0
- package/dist/mcp/sanitizeMCPConfig.js.map +1 -0
- package/dist/stdio.d.ts +9 -0
- package/dist/stdio.d.ts.map +1 -0
- package/dist/stdio.js +127 -0
- package/dist/stdio.js.map +1 -0
- package/dist/types.d.ts +256 -447
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +4 -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/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/filterFieldsByAccess.d.ts +28 -0
- package/dist/utils/schemaConversion/filterFieldsByAccess.d.ts.map +1 -0
- package/dist/utils/schemaConversion/filterFieldsByAccess.js +71 -0
- package/dist/utils/schemaConversion/filterFieldsByAccess.js.map +1 -0
- package/dist/utils/schemaConversion/getEntityInputSchema.d.ts +13 -0
- package/dist/utils/schemaConversion/getEntityInputSchema.d.ts.map +1 -0
- package/dist/utils/schemaConversion/getEntityInputSchema.js +66 -0
- package/dist/utils/schemaConversion/getEntityInputSchema.js.map +1 -0
- package/dist/utils/schemaConversion/sanitizeEntitySchema.d.ts +10 -0
- package/dist/utils/schemaConversion/sanitizeEntitySchema.d.ts.map +1 -0
- package/dist/utils/schemaConversion/sanitizeEntitySchema.js +384 -0
- package/dist/utils/schemaConversion/sanitizeEntitySchema.js.map +1 -0
- package/dist/utils/schemaConversion/sanitizeEntitySchema.spec.js +133 -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 +43 -10
- package/src/bin/index.ts +16 -0
- package/src/bin/initializeViteHMR.ts +60 -0
- package/src/bin/viteConfigBoundary.ts +39 -0
- package/src/defaultAccess.ts +3 -0
- package/src/defineTool.ts +44 -0
- package/src/endpoint/access.ts +112 -0
- package/src/endpoint/index.ts +77 -0
- package/src/exports/client.ts +3 -0
- package/src/exports/internal.ts +1 -0
- package/src/index.ts +31 -89
- package/src/mcp/buildMcpServer.ts +284 -0
- package/src/mcp/builtin/collections/authTools.ts +269 -0
- package/src/mcp/builtin/collections/countTool.ts +73 -0
- package/src/mcp/builtin/collections/countVersionsTool.ts +69 -0
- package/src/mcp/builtin/collections/createTool.ts +117 -0
- package/src/mcp/builtin/collections/deleteTool.ts +125 -0
- package/src/mcp/builtin/collections/duplicateTool.ts +134 -0
- package/src/mcp/builtin/collections/findDistinctTool.ts +119 -0
- package/src/mcp/builtin/collections/findTool.ts +216 -0
- package/src/mcp/builtin/collections/findVersionByIDTool.ts +109 -0
- package/src/mcp/builtin/collections/findVersionsTool.ts +154 -0
- package/src/mcp/builtin/collections/formatCollectionError.ts +84 -0
- package/src/mcp/builtin/collections/getCollectionSchemaTool.ts +63 -0
- package/src/mcp/builtin/collections/restoreVersionTool.ts +107 -0
- package/src/mcp/builtin/collections/updateTool.ts +225 -0
- package/src/mcp/builtin/getConfigInfoTool.ts +67 -0
- package/src/mcp/builtin/globals/countVersionsTool.ts +68 -0
- package/src/mcp/builtin/globals/findTool.ts +105 -0
- package/src/mcp/builtin/globals/findVersionByIDTool.ts +103 -0
- package/src/mcp/builtin/globals/findVersionsTool.ts +147 -0
- package/src/mcp/builtin/globals/getGlobalSchemaTool.ts +63 -0
- package/src/mcp/builtin/globals/restoreVersionTool.ts +99 -0
- package/src/mcp/builtin/globals/updateTool.ts +115 -0
- package/src/mcp/builtin/validateEntityData.ts +132 -0
- package/src/mcp/builtinTools.ts +154 -0
- package/src/mcp/sanitizeMCPConfig.ts +278 -0
- package/src/stdio.ts +131 -0
- package/src/types.ts +304 -486
- package/src/utils/getLogger.ts +22 -0
- package/src/utils/getPluginConfig.ts +24 -0
- package/src/utils/resolveProjectRoot.ts +17 -0
- package/src/utils/schemaConversion/filterFieldsByAccess.ts +123 -0
- package/src/utils/schemaConversion/getEntityInputSchema.ts +96 -0
- package/src/utils/schemaConversion/sanitizeEntitySchema.spec.ts +96 -0
- package/src/utils/schemaConversion/sanitizeEntitySchema.ts +432 -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/removeVirtualFieldsFromSchema.d.ts +0 -7
- package/dist/utils/schemaConversion/removeVirtualFieldsFromSchema.d.ts.map +0 -1
- package/dist/utils/schemaConversion/removeVirtualFieldsFromSchema.js +0 -20
- package/dist/utils/schemaConversion/removeVirtualFieldsFromSchema.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/removeVirtualFieldsFromSchema.ts +0 -27
- 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,147 @@
|
|
|
1
|
+
import type { PopulateType, SelectType } from 'payload'
|
|
2
|
+
|
|
3
|
+
import { z } from 'zod'
|
|
4
|
+
|
|
5
|
+
import { defaultAccess } from '../../../defaultAccess.js'
|
|
6
|
+
import { defineGlobalTool } from '../../../defineTool.js'
|
|
7
|
+
import { getLogger } from '../../../utils/getLogger.js'
|
|
8
|
+
import { whereSchema } from '../../../utils/whereSchema.js'
|
|
9
|
+
|
|
10
|
+
const DEFAULT_DESCRIPTION =
|
|
11
|
+
'Find global versions in any version-enabled global by passing the global slug and optional where clause.'
|
|
12
|
+
|
|
13
|
+
export const findGlobalVersionsTool = defineGlobalTool({
|
|
14
|
+
access: (args) =>
|
|
15
|
+
defaultAccess(args) && Boolean(args.permissions?.globals?.[args.globalSlug]?.readVersions),
|
|
16
|
+
annotations: {
|
|
17
|
+
destructiveHint: false,
|
|
18
|
+
idempotentHint: true,
|
|
19
|
+
openWorldHint: false,
|
|
20
|
+
readOnlyHint: true,
|
|
21
|
+
title: 'Find Global Versions',
|
|
22
|
+
},
|
|
23
|
+
description: DEFAULT_DESCRIPTION,
|
|
24
|
+
input: z.object({
|
|
25
|
+
depth: z
|
|
26
|
+
.number()
|
|
27
|
+
.int()
|
|
28
|
+
.min(0)
|
|
29
|
+
.max(10)
|
|
30
|
+
.describe('How many levels deep to populate relationships in global version documents')
|
|
31
|
+
.optional()
|
|
32
|
+
.default(0),
|
|
33
|
+
fallbackLocale: z
|
|
34
|
+
.string()
|
|
35
|
+
.describe('Optional: fallback locale code to use when requested locale is not available')
|
|
36
|
+
.optional(),
|
|
37
|
+
limit: z
|
|
38
|
+
.number()
|
|
39
|
+
.int()
|
|
40
|
+
.min(1)
|
|
41
|
+
.max(100)
|
|
42
|
+
.describe('Maximum number of versions to return (default: 10, max: 100)')
|
|
43
|
+
.optional()
|
|
44
|
+
.default(10),
|
|
45
|
+
locale: z
|
|
46
|
+
.string()
|
|
47
|
+
.describe(
|
|
48
|
+
'Optional: locale code to retrieve data in (e.g., "en", "es"). Use "all" to retrieve all locales for localized fields',
|
|
49
|
+
)
|
|
50
|
+
.optional(),
|
|
51
|
+
page: z
|
|
52
|
+
.number()
|
|
53
|
+
.int()
|
|
54
|
+
.min(1)
|
|
55
|
+
.describe('Page number for pagination (default: 1)')
|
|
56
|
+
.optional()
|
|
57
|
+
.default(1),
|
|
58
|
+
pagination: z
|
|
59
|
+
.boolean()
|
|
60
|
+
.describe('Optional: set to false to skip the count query overhead')
|
|
61
|
+
.optional(),
|
|
62
|
+
populate: z
|
|
63
|
+
.record(z.string(), z.unknown())
|
|
64
|
+
.describe(
|
|
65
|
+
'Optional: control which fields to include from populated relationship or upload documents.',
|
|
66
|
+
)
|
|
67
|
+
.optional(),
|
|
68
|
+
select: z
|
|
69
|
+
.record(z.string(), z.unknown())
|
|
70
|
+
.describe(
|
|
71
|
+
'Optional: define exactly which fields you\'d like to return in the response, e.g., {"version.siteName": true}',
|
|
72
|
+
)
|
|
73
|
+
.optional(),
|
|
74
|
+
showHiddenFields: z
|
|
75
|
+
.boolean()
|
|
76
|
+
.describe('Optional: include hidden fields in returned global version documents')
|
|
77
|
+
.optional(),
|
|
78
|
+
sort: z
|
|
79
|
+
.string()
|
|
80
|
+
.describe('Field to sort by (e.g., "-updatedAt", "-version.updatedAt" for descending)')
|
|
81
|
+
.optional(),
|
|
82
|
+
where: whereSchema
|
|
83
|
+
.describe(
|
|
84
|
+
'Optional: where clause for filtering versions. Version document fields are usually under "version". Example: {"version.siteName":{"contains":"test"}}',
|
|
85
|
+
)
|
|
86
|
+
.optional(),
|
|
87
|
+
}),
|
|
88
|
+
}).handler(async ({ authorizedMCP, globalSlug, input, req }) => {
|
|
89
|
+
const payload = req.payload
|
|
90
|
+
const logger = getLogger({ payload })
|
|
91
|
+
const {
|
|
92
|
+
depth,
|
|
93
|
+
fallbackLocale,
|
|
94
|
+
limit,
|
|
95
|
+
locale,
|
|
96
|
+
page,
|
|
97
|
+
pagination,
|
|
98
|
+
populate,
|
|
99
|
+
select,
|
|
100
|
+
showHiddenFields,
|
|
101
|
+
sort,
|
|
102
|
+
where,
|
|
103
|
+
} = input
|
|
104
|
+
|
|
105
|
+
logger.info(`Finding versions for global: ${globalSlug}, limit: ${limit}, page: ${page}`)
|
|
106
|
+
|
|
107
|
+
try {
|
|
108
|
+
const result = await payload.findGlobalVersions({
|
|
109
|
+
slug: globalSlug,
|
|
110
|
+
depth,
|
|
111
|
+
limit,
|
|
112
|
+
overrideAccess: authorizedMCP.overrideAccess,
|
|
113
|
+
page,
|
|
114
|
+
req,
|
|
115
|
+
...(fallbackLocale ? { fallbackLocale } : {}),
|
|
116
|
+
...(locale ? { locale } : {}),
|
|
117
|
+
...(pagination !== undefined ? { pagination } : {}),
|
|
118
|
+
...(populate ? { populate: populate as PopulateType } : {}),
|
|
119
|
+
...(select ? { select: select as SelectType } : {}),
|
|
120
|
+
...(showHiddenFields !== undefined ? { showHiddenFields } : {}),
|
|
121
|
+
...(sort ? { sort } : {}),
|
|
122
|
+
...(where ? { where } : {}),
|
|
123
|
+
})
|
|
124
|
+
|
|
125
|
+
return {
|
|
126
|
+
content: [
|
|
127
|
+
{
|
|
128
|
+
type: 'text',
|
|
129
|
+
text: `Versions for global "${globalSlug}":\n\`\`\`json\n${JSON.stringify(result)}\n\`\`\``,
|
|
130
|
+
},
|
|
131
|
+
],
|
|
132
|
+
doc: result as unknown as Record<string, unknown>,
|
|
133
|
+
}
|
|
134
|
+
} catch (error) {
|
|
135
|
+
const errorMessage = error instanceof Error ? error.message : 'Unknown error'
|
|
136
|
+
logger.error(`Error finding versions for global ${globalSlug}: ${errorMessage}`)
|
|
137
|
+
return {
|
|
138
|
+
content: [
|
|
139
|
+
{
|
|
140
|
+
type: 'text',
|
|
141
|
+
text: `❌ **Error finding versions for global "${globalSlug}":** ${errorMessage}`,
|
|
142
|
+
},
|
|
143
|
+
],
|
|
144
|
+
isError: true,
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
})
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { getAccessResults } from 'payload'
|
|
2
|
+
|
|
3
|
+
import { defaultAccess } from '../../../defaultAccess.js'
|
|
4
|
+
import { defineGlobalTool } from '../../../defineTool.js'
|
|
5
|
+
import { getGlobalInputSchema } from '../../../utils/schemaConversion/getEntityInputSchema.js'
|
|
6
|
+
|
|
7
|
+
export const getGlobalSchemaTool = defineGlobalTool({
|
|
8
|
+
access: (args) => {
|
|
9
|
+
const permissions = args.permissions?.globals?.[args.globalSlug]
|
|
10
|
+
|
|
11
|
+
return defaultAccess(args) && Boolean(permissions?.update)
|
|
12
|
+
},
|
|
13
|
+
annotations: {
|
|
14
|
+
destructiveHint: false,
|
|
15
|
+
idempotentHint: true,
|
|
16
|
+
openWorldHint: false,
|
|
17
|
+
readOnlyHint: true,
|
|
18
|
+
title: 'Get Global Schema',
|
|
19
|
+
},
|
|
20
|
+
description: 'Get the input schema for updating a global.',
|
|
21
|
+
}).handler(async ({ authorizedMCP, globalSlug, req }) => {
|
|
22
|
+
const permissions = authorizedMCP.overrideAccess
|
|
23
|
+
? null
|
|
24
|
+
: (await getAccessResults({ req })).globals?.[globalSlug]
|
|
25
|
+
|
|
26
|
+
if (!authorizedMCP.overrideAccess && !permissions?.update) {
|
|
27
|
+
return {
|
|
28
|
+
content: [
|
|
29
|
+
{
|
|
30
|
+
type: 'text',
|
|
31
|
+
text: `Error: MCP access to "getGlobalSchema" is not enabled for global "${globalSlug}"`,
|
|
32
|
+
},
|
|
33
|
+
],
|
|
34
|
+
isError: true,
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const inputSchema = getGlobalInputSchema({
|
|
39
|
+
globalSlug,
|
|
40
|
+
req,
|
|
41
|
+
...(permissions ? { permissions } : {}),
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
if (!inputSchema) {
|
|
45
|
+
return {
|
|
46
|
+
content: [{ type: 'text', text: `Error: Global "${globalSlug}" not found` }],
|
|
47
|
+
isError: true,
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return {
|
|
52
|
+
content: [
|
|
53
|
+
{
|
|
54
|
+
type: 'text',
|
|
55
|
+
text: `Schema for global "${globalSlug}":\n\`\`\`json\n${JSON.stringify(inputSchema)}\n\`\`\``,
|
|
56
|
+
},
|
|
57
|
+
],
|
|
58
|
+
structuredContent: {
|
|
59
|
+
globalSlug,
|
|
60
|
+
schema: inputSchema,
|
|
61
|
+
},
|
|
62
|
+
}
|
|
63
|
+
})
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import type { PopulateType } from 'payload'
|
|
2
|
+
|
|
3
|
+
import { z } from 'zod'
|
|
4
|
+
|
|
5
|
+
import { defaultAccess } from '../../../defaultAccess.js'
|
|
6
|
+
import { defineGlobalTool } from '../../../defineTool.js'
|
|
7
|
+
import { getLogger } from '../../../utils/getLogger.js'
|
|
8
|
+
|
|
9
|
+
const DEFAULT_DESCRIPTION =
|
|
10
|
+
'Restore a global from a previous version in any version-enabled global.'
|
|
11
|
+
|
|
12
|
+
export const restoreGlobalVersionTool = defineGlobalTool({
|
|
13
|
+
access: (args) =>
|
|
14
|
+
defaultAccess(args) && Boolean(args.permissions?.globals?.[args.globalSlug]?.update),
|
|
15
|
+
annotations: {
|
|
16
|
+
destructiveHint: true,
|
|
17
|
+
idempotentHint: false,
|
|
18
|
+
openWorldHint: false,
|
|
19
|
+
readOnlyHint: false,
|
|
20
|
+
title: 'Restore Global Version',
|
|
21
|
+
},
|
|
22
|
+
description: DEFAULT_DESCRIPTION,
|
|
23
|
+
input: z.object({
|
|
24
|
+
id: z.string().describe('The ID of the global version to restore'),
|
|
25
|
+
depth: z
|
|
26
|
+
.number()
|
|
27
|
+
.int()
|
|
28
|
+
.min(0)
|
|
29
|
+
.max(10)
|
|
30
|
+
.describe('How many levels deep to populate relationships in response')
|
|
31
|
+
.optional()
|
|
32
|
+
.default(0),
|
|
33
|
+
fallbackLocale: z
|
|
34
|
+
.string()
|
|
35
|
+
.describe('Optional: fallback locale code to use when requested locale is not available')
|
|
36
|
+
.optional(),
|
|
37
|
+
locale: z
|
|
38
|
+
.string()
|
|
39
|
+
.describe('Optional: locale code to restore in (e.g., "en", "es")')
|
|
40
|
+
.optional(),
|
|
41
|
+
populate: z
|
|
42
|
+
.record(z.string(), z.unknown())
|
|
43
|
+
.describe(
|
|
44
|
+
'Optional: control which fields to include from populated relationship or upload documents.',
|
|
45
|
+
)
|
|
46
|
+
.optional(),
|
|
47
|
+
showHiddenFields: z
|
|
48
|
+
.boolean()
|
|
49
|
+
.describe('Optional: include hidden fields in the restored global response')
|
|
50
|
+
.optional(),
|
|
51
|
+
}),
|
|
52
|
+
}).handler(async ({ authorizedMCP, globalSlug, input, req }) => {
|
|
53
|
+
const payload = req.payload
|
|
54
|
+
const logger = getLogger({ payload })
|
|
55
|
+
const { id, depth, fallbackLocale, locale, populate, showHiddenFields } = input
|
|
56
|
+
|
|
57
|
+
logger.info(`Restoring version for global: ${globalSlug} with ID: ${id}`)
|
|
58
|
+
|
|
59
|
+
try {
|
|
60
|
+
const result = await payload.restoreGlobalVersion({
|
|
61
|
+
id,
|
|
62
|
+
slug: globalSlug,
|
|
63
|
+
depth,
|
|
64
|
+
overrideAccess: authorizedMCP.overrideAccess,
|
|
65
|
+
req,
|
|
66
|
+
...(fallbackLocale ? { fallbackLocale } : {}),
|
|
67
|
+
...(locale ? { locale } : {}),
|
|
68
|
+
...(populate ? { populate: populate as PopulateType } : {}),
|
|
69
|
+
...(showHiddenFields !== undefined ? { showHiddenFields } : {}),
|
|
70
|
+
})
|
|
71
|
+
const resultObject = result as Record<string, unknown>
|
|
72
|
+
const restoredGlobal =
|
|
73
|
+
resultObject.version && typeof resultObject.version === 'object'
|
|
74
|
+
? (resultObject.version as Record<string, unknown>)
|
|
75
|
+
: resultObject
|
|
76
|
+
|
|
77
|
+
return {
|
|
78
|
+
content: [
|
|
79
|
+
{
|
|
80
|
+
type: 'text',
|
|
81
|
+
text: `Version "${id}" restored successfully for global "${globalSlug}"!\nRestored global:\n\`\`\`json\n${JSON.stringify(restoredGlobal)}\n\`\`\``,
|
|
82
|
+
},
|
|
83
|
+
],
|
|
84
|
+
doc: restoredGlobal,
|
|
85
|
+
}
|
|
86
|
+
} catch (error) {
|
|
87
|
+
const errorMessage = error instanceof Error ? error.message : 'Unknown error'
|
|
88
|
+
logger.error(`Error restoring version ${id} for global ${globalSlug}: ${errorMessage}`)
|
|
89
|
+
return {
|
|
90
|
+
content: [
|
|
91
|
+
{
|
|
92
|
+
type: 'text',
|
|
93
|
+
text: `❌ **Error restoring version "${id}" for global "${globalSlug}":** ${errorMessage}`,
|
|
94
|
+
},
|
|
95
|
+
],
|
|
96
|
+
isError: true,
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
})
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import type { SelectType } from 'payload'
|
|
2
|
+
|
|
3
|
+
import { z } from 'zod'
|
|
4
|
+
|
|
5
|
+
import { defaultAccess } from '../../../defaultAccess.js'
|
|
6
|
+
import { defineGlobalTool } from '../../../defineTool.js'
|
|
7
|
+
import { getLogger } from '../../../utils/getLogger.js'
|
|
8
|
+
import {
|
|
9
|
+
getGlobalVirtualFieldNames,
|
|
10
|
+
stripVirtualFields,
|
|
11
|
+
} from '../../../utils/getVirtualFieldNames.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
|
+
access: (args) =>
|
|
19
|
+
defaultAccess(args) && Boolean(args.permissions?.globals?.[args.globalSlug]?.update),
|
|
20
|
+
annotations: {
|
|
21
|
+
destructiveHint: true,
|
|
22
|
+
idempotentHint: false,
|
|
23
|
+
openWorldHint: false,
|
|
24
|
+
readOnlyHint: false,
|
|
25
|
+
title: 'Update Global',
|
|
26
|
+
},
|
|
27
|
+
description: DEFAULT_DESCRIPTION,
|
|
28
|
+
input: z.object({
|
|
29
|
+
data: z.record(z.string(), z.unknown()).describe('The global fields to update'),
|
|
30
|
+
depth: z
|
|
31
|
+
.number()
|
|
32
|
+
.describe('Optional: Depth of relationships to populate')
|
|
33
|
+
.optional()
|
|
34
|
+
.default(0),
|
|
35
|
+
draft: z
|
|
36
|
+
.boolean()
|
|
37
|
+
.describe('Optional: Whether to save as draft (default: false)')
|
|
38
|
+
.optional()
|
|
39
|
+
.default(false),
|
|
40
|
+
fallbackLocale: z
|
|
41
|
+
.string()
|
|
42
|
+
.describe('Optional: fallback locale code to use when requested locale is not available')
|
|
43
|
+
.optional(),
|
|
44
|
+
locale: z
|
|
45
|
+
.string()
|
|
46
|
+
.describe(
|
|
47
|
+
'Optional: locale code to update data in (e.g., "en", "es"). Use "all" to update all locales for localized fields',
|
|
48
|
+
)
|
|
49
|
+
.optional(),
|
|
50
|
+
select: z
|
|
51
|
+
.record(z.string(), z.unknown())
|
|
52
|
+
.describe(
|
|
53
|
+
'Optional: define exactly which fields you\'d like to return in the response, e.g., {"siteName": true}',
|
|
54
|
+
)
|
|
55
|
+
.optional(),
|
|
56
|
+
}),
|
|
57
|
+
}).handler(async ({ authorizedMCP, globalSlug, input, req }) => {
|
|
58
|
+
const payload = req.payload
|
|
59
|
+
const logger = getLogger({ payload })
|
|
60
|
+
|
|
61
|
+
const { data, depth, draft, fallbackLocale, locale, select } = input
|
|
62
|
+
|
|
63
|
+
logger.info(
|
|
64
|
+
`Updating global: ${globalSlug}, draft: ${draft}${locale ? `, locale: ${locale}` : ''}`,
|
|
65
|
+
)
|
|
66
|
+
|
|
67
|
+
try {
|
|
68
|
+
const virtualFieldNames = getGlobalVirtualFieldNames(payload.config, globalSlug)
|
|
69
|
+
const inputData = stripVirtualFields(data, virtualFieldNames)
|
|
70
|
+
const validationError = validateGlobalData({ data: inputData, globalSlug, req })
|
|
71
|
+
|
|
72
|
+
if (validationError) {
|
|
73
|
+
return validationError
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const parsedData = transformPointDataToPayload(inputData)
|
|
77
|
+
|
|
78
|
+
const updateOptions: Parameters<typeof payload.updateGlobal>[0] = {
|
|
79
|
+
slug: globalSlug,
|
|
80
|
+
data: parsedData,
|
|
81
|
+
depth,
|
|
82
|
+
draft,
|
|
83
|
+
overrideAccess: authorizedMCP.overrideAccess,
|
|
84
|
+
req,
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
if (locale) {
|
|
88
|
+
updateOptions.locale = locale
|
|
89
|
+
}
|
|
90
|
+
if (fallbackLocale) {
|
|
91
|
+
updateOptions.fallbackLocale = fallbackLocale
|
|
92
|
+
}
|
|
93
|
+
if (select) {
|
|
94
|
+
updateOptions.select = select as SelectType
|
|
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/validators/cf-worker'
|
|
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
|
+
}
|