@payloadcms/plugin-mcp 4.0.0-internal.e16cf59 → 4.0.0-internal.fa345ef
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 +39 -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 +22 -0
- package/dist/endpoint/access.d.ts.map +1 -0
- package/dist/endpoint/access.js +100 -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 +69 -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 +65 -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 +87 -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 +111 -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 +97 -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 +93 -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 +165 -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 +84 -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 +99 -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 +47 -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 +82 -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 +192 -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 +71 -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 +65 -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 +80 -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 +95 -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 +47 -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 +78 -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 +8 -0
- package/dist/stdio.d.ts.map +1 -0
- package/dist/stdio.js +126 -0
- package/dist/stdio.js.map +1 -0
- package/dist/types.d.ts +235 -463
- 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 +32 -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 +30 -10
- package/src/defaultAccess.ts +3 -0
- package/src/defineTool.ts +44 -0
- package/src/endpoint/access.ts +119 -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 +74 -0
- package/src/mcp/builtin/collections/countVersionsTool.ts +73 -0
- package/src/mcp/builtin/collections/createTool.ts +112 -0
- package/src/mcp/builtin/collections/deleteTool.ts +126 -0
- package/src/mcp/builtin/collections/duplicateTool.ts +135 -0
- package/src/mcp/builtin/collections/findDistinctTool.ts +119 -0
- package/src/mcp/builtin/collections/findTool.ts +217 -0
- package/src/mcp/builtin/collections/findVersionByIDTool.ts +110 -0
- package/src/mcp/builtin/collections/findVersionsTool.ts +155 -0
- package/src/mcp/builtin/collections/formatCollectionError.ts +84 -0
- package/src/mcp/builtin/collections/getCollectionSchemaTool.ts +46 -0
- package/src/mcp/builtin/collections/restoreVersionTool.ts +108 -0
- package/src/mcp/builtin/collections/updateTool.ts +211 -0
- package/src/mcp/builtin/getConfigInfoTool.ts +69 -0
- package/src/mcp/builtin/globals/countVersionsTool.ts +72 -0
- package/src/mcp/builtin/globals/findTool.ts +105 -0
- package/src/mcp/builtin/globals/findVersionByIDTool.ts +104 -0
- package/src/mcp/builtin/globals/findVersionsTool.ts +148 -0
- package/src/mcp/builtin/globals/getGlobalSchemaTool.ts +41 -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 +130 -0
- package/src/types.ts +276 -494
- 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 +62 -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 @@
|
|
|
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' | 'duplicating' | '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,OA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@
|
|
|
1
|
+
{"version":3,"file":"getCollectionSchemaTool.d.ts","sourceRoot":"","sources":["../../../../src/mcp/builtin/collections/getCollectionSchemaTool.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,uBAAuB,4CAyClC,CAAA"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { defaultAccess } from '../../../defaultAccess.js';
|
|
2
|
+
import { defineCollectionTool } from '../../../defineTool.js';
|
|
3
|
+
import { getCollectionInputSchema } from '../../../utils/schemaConversion/getEntityInputSchema.js';
|
|
4
|
+
export const getCollectionSchemaTool = defineCollectionTool({
|
|
5
|
+
access: (args)=>{
|
|
6
|
+
const permissions = args.permissions?.collections?.[args.collectionSlug];
|
|
7
|
+
return defaultAccess(args) && Boolean(permissions?.create || permissions?.delete || permissions?.read || permissions?.update);
|
|
8
|
+
},
|
|
9
|
+
annotations: {
|
|
10
|
+
destructiveHint: false,
|
|
11
|
+
idempotentHint: true,
|
|
12
|
+
openWorldHint: false,
|
|
13
|
+
readOnlyHint: true,
|
|
14
|
+
title: 'Get Collection Schema'
|
|
15
|
+
},
|
|
16
|
+
description: 'Get the input schema for creating or updating documents in a collection.'
|
|
17
|
+
}).handler(({ collectionSlug, req })=>{
|
|
18
|
+
const inputSchema = getCollectionInputSchema({
|
|
19
|
+
collectionSlug,
|
|
20
|
+
req
|
|
21
|
+
});
|
|
22
|
+
if (!inputSchema) {
|
|
23
|
+
return {
|
|
24
|
+
content: [
|
|
25
|
+
{
|
|
26
|
+
type: 'text',
|
|
27
|
+
text: `Error: Collection "${collectionSlug}" not found`
|
|
28
|
+
}
|
|
29
|
+
],
|
|
30
|
+
isError: true
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
return {
|
|
34
|
+
content: [
|
|
35
|
+
{
|
|
36
|
+
type: 'text',
|
|
37
|
+
text: `Schema for collection "${collectionSlug}":\n\`\`\`json\n${JSON.stringify(inputSchema)}\n\`\`\``
|
|
38
|
+
}
|
|
39
|
+
],
|
|
40
|
+
structuredContent: {
|
|
41
|
+
collectionSlug,
|
|
42
|
+
schema: inputSchema
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
//# sourceMappingURL=getCollectionSchemaTool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/mcp/builtin/collections/getCollectionSchemaTool.ts"],"sourcesContent":["import { defaultAccess } from '../../../defaultAccess.js'\nimport { defineCollectionTool } from '../../../defineTool.js'\nimport { getCollectionInputSchema } from '../../../utils/schemaConversion/getEntityInputSchema.js'\n\nexport const getCollectionSchemaTool = defineCollectionTool({\n access: (args) => {\n const permissions = args.permissions?.collections?.[args.collectionSlug]\n\n return (\n defaultAccess(args) &&\n Boolean(\n permissions?.create || permissions?.delete || permissions?.read || permissions?.update,\n )\n )\n },\n annotations: {\n destructiveHint: false,\n idempotentHint: true,\n openWorldHint: false,\n readOnlyHint: true,\n title: 'Get Collection Schema',\n },\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":["defaultAccess","defineCollectionTool","getCollectionInputSchema","getCollectionSchemaTool","access","args","permissions","collections","collectionSlug","Boolean","create","delete","read","update","annotations","destructiveHint","idempotentHint","openWorldHint","readOnlyHint","title","description","handler","req","inputSchema","content","type","text","isError","JSON","stringify","structuredContent","schema"],"mappings":"AAAA,SAASA,aAAa,QAAQ,4BAA2B;AACzD,SAASC,oBAAoB,QAAQ,yBAAwB;AAC7D,SAASC,wBAAwB,QAAQ,0DAAyD;AAElG,OAAO,MAAMC,0BAA0BF,qBAAqB;IAC1DG,QAAQ,CAACC;QACP,MAAMC,cAAcD,KAAKC,WAAW,EAAEC,aAAa,CAACF,KAAKG,cAAc,CAAC;QAExE,OACER,cAAcK,SACdI,QACEH,aAAaI,UAAUJ,aAAaK,UAAUL,aAAaM,QAAQN,aAAaO;IAGtF;IACAC,aAAa;QACXC,iBAAiB;QACjBC,gBAAgB;QAChBC,eAAe;QACfC,cAAc;QACdC,OAAO;IACT;IACAC,aAAa;AACf,GAAGC,OAAO,CAAC,CAAC,EAAEb,cAAc,EAAEc,GAAG,EAAE;IACjC,MAAMC,cAAcrB,yBAAyB;QAAEM;QAAgBc;IAAI;IAEnE,IAAI,CAACC,aAAa;QAChB,OAAO;YACLC,SAAS;gBAAC;oBAAEC,MAAM;oBAAQC,MAAM,CAAC,mBAAmB,EAAElB,eAAe,WAAW,CAAC;gBAAC;aAAE;YACpFmB,SAAS;QACX;IACF;IAEA,OAAO;QACLH,SAAS;YACP;gBACEC,MAAM;gBACNC,MAAM,CAAC,uBAAuB,EAAElB,eAAe,gBAAgB,EAAEoB,KAAKC,SAAS,CAACN,aAAa,QAAQ,CAAC;YACxG;SACD;QACDO,mBAAmB;YACjBtB;YACAuB,QAAQR;QACV;IACF;AACF,GAAE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"restoreVersionTool.d.ts","sourceRoot":"","sources":["../../../../src/mcp/builtin/collections/restoreVersionTool.ts"],"names":[],"mappings":"AAYA,eAAO,MAAM,kBAAkB,4CA+F7B,CAAA"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { defaultAccess } from '../../../defaultAccess.js';
|
|
3
|
+
import { defineCollectionTool } from '../../../defineTool.js';
|
|
4
|
+
import { getLogger } from '../../../utils/getLogger.js';
|
|
5
|
+
import { localAPIDefaults } from '../../../utils/localAPIDefaults.js';
|
|
6
|
+
const DEFAULT_DESCRIPTION = 'Restore a document from a previous version in any version-enabled collection.';
|
|
7
|
+
export const restoreVersionTool = defineCollectionTool({
|
|
8
|
+
access: (args)=>defaultAccess(args) && Boolean(args.permissions?.collections?.[args.collectionSlug]?.update),
|
|
9
|
+
annotations: {
|
|
10
|
+
destructiveHint: true,
|
|
11
|
+
idempotentHint: false,
|
|
12
|
+
openWorldHint: false,
|
|
13
|
+
readOnlyHint: false,
|
|
14
|
+
title: 'Restore Version'
|
|
15
|
+
},
|
|
16
|
+
description: DEFAULT_DESCRIPTION,
|
|
17
|
+
input: z.object({
|
|
18
|
+
id: z.string().describe('The ID of the version to restore'),
|
|
19
|
+
depth: z.number().int().min(0).max(10).describe('How many levels deep to populate relationships in response').optional().default(0),
|
|
20
|
+
draft: z.boolean().describe('Whether to restore the version as a draft').optional().default(false),
|
|
21
|
+
fallbackLocale: z.string().describe('Optional: fallback locale code to use when requested locale is not available').optional(),
|
|
22
|
+
locale: z.string().describe('Optional: locale code to restore in (e.g., "en", "es")').optional(),
|
|
23
|
+
populate: z.record(z.string(), z.unknown()).describe('Optional: control which fields to include from populated relationship or upload documents.').optional(),
|
|
24
|
+
select: z.record(z.string(), z.unknown()).describe('Optional: define exactly which fields you\'d like to return in the response, e.g., {"title": true}').optional(),
|
|
25
|
+
showHiddenFields: z.boolean().describe('Optional: include hidden fields in the restored document response').optional()
|
|
26
|
+
})
|
|
27
|
+
}).handler(async ({ authorizedMCP, collectionSlug, input, req })=>{
|
|
28
|
+
const payload = req.payload;
|
|
29
|
+
const logger = getLogger({
|
|
30
|
+
payload
|
|
31
|
+
});
|
|
32
|
+
const { id, depth, draft, fallbackLocale, locale, populate, select, showHiddenFields } = input;
|
|
33
|
+
logger.info(`Restoring version in collection: ${collectionSlug} with ID: ${id}`);
|
|
34
|
+
try {
|
|
35
|
+
const result = await payload.restoreVersion({
|
|
36
|
+
id,
|
|
37
|
+
collection: collectionSlug,
|
|
38
|
+
depth,
|
|
39
|
+
draft,
|
|
40
|
+
req,
|
|
41
|
+
...localAPIDefaults(authorizedMCP),
|
|
42
|
+
...fallbackLocale ? {
|
|
43
|
+
fallbackLocale
|
|
44
|
+
} : {},
|
|
45
|
+
...locale ? {
|
|
46
|
+
locale
|
|
47
|
+
} : {},
|
|
48
|
+
...populate ? {
|
|
49
|
+
populate: populate
|
|
50
|
+
} : {},
|
|
51
|
+
...select ? {
|
|
52
|
+
select: select
|
|
53
|
+
} : {},
|
|
54
|
+
...showHiddenFields !== undefined ? {
|
|
55
|
+
showHiddenFields
|
|
56
|
+
} : {}
|
|
57
|
+
});
|
|
58
|
+
return {
|
|
59
|
+
content: [
|
|
60
|
+
{
|
|
61
|
+
type: 'text',
|
|
62
|
+
text: `Version "${id}" restored successfully in collection "${collectionSlug}"!\nRestored document:\n\`\`\`json\n${JSON.stringify(result)}\n\`\`\``
|
|
63
|
+
}
|
|
64
|
+
],
|
|
65
|
+
doc: result
|
|
66
|
+
};
|
|
67
|
+
} catch (error) {
|
|
68
|
+
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
|
|
69
|
+
logger.error(`Error restoring version ${id} in ${collectionSlug}: ${errorMessage}`);
|
|
70
|
+
return {
|
|
71
|
+
content: [
|
|
72
|
+
{
|
|
73
|
+
type: 'text',
|
|
74
|
+
text: `❌ **Error restoring version "${id}" in collection "${collectionSlug}":** ${errorMessage}`
|
|
75
|
+
}
|
|
76
|
+
],
|
|
77
|
+
isError: true
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
//# sourceMappingURL=restoreVersionTool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/mcp/builtin/collections/restoreVersionTool.ts"],"sourcesContent":["import type { PopulateType, SelectType } from 'payload'\n\nimport { z } from 'zod'\n\nimport { defaultAccess } from '../../../defaultAccess.js'\nimport { defineCollectionTool } from '../../../defineTool.js'\nimport { getLogger } from '../../../utils/getLogger.js'\nimport { localAPIDefaults } from '../../../utils/localAPIDefaults.js'\n\nconst DEFAULT_DESCRIPTION =\n 'Restore a document from a previous version in any version-enabled collection.'\n\nexport const restoreVersionTool = defineCollectionTool({\n access: (args) =>\n defaultAccess(args) && Boolean(args.permissions?.collections?.[args.collectionSlug]?.update),\n annotations: {\n destructiveHint: true,\n idempotentHint: false,\n openWorldHint: false,\n readOnlyHint: false,\n title: 'Restore Version',\n },\n description: DEFAULT_DESCRIPTION,\n input: z.object({\n id: z.string().describe('The ID of the version to restore'),\n depth: z\n .number()\n .int()\n .min(0)\n .max(10)\n .describe('How many levels deep to populate relationships in response')\n .optional()\n .default(0),\n draft: z\n .boolean()\n .describe('Whether to restore the version as a draft')\n .optional()\n .default(false),\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('Optional: locale code to restore in (e.g., \"en\", \"es\")')\n .optional(),\n populate: z\n .record(z.string(), z.unknown())\n .describe(\n 'Optional: control which fields to include from populated relationship or upload documents.',\n )\n .optional(),\n select: z\n .record(z.string(), z.unknown())\n .describe(\n 'Optional: define exactly which fields you\\'d like to return in the response, e.g., {\"title\": true}',\n )\n .optional(),\n showHiddenFields: z\n .boolean()\n .describe('Optional: include hidden fields in the restored document response')\n .optional(),\n }),\n}).handler(async ({ authorizedMCP, collectionSlug, input, req }) => {\n const payload = req.payload\n const logger = getLogger({ payload })\n const { id, depth, draft, fallbackLocale, locale, populate, select, showHiddenFields } = input\n\n logger.info(`Restoring version in collection: ${collectionSlug} with ID: ${id}`)\n\n try {\n const result = await payload.restoreVersion({\n id,\n collection: collectionSlug,\n depth,\n draft,\n req,\n ...localAPIDefaults(authorizedMCP),\n ...(fallbackLocale ? { fallbackLocale } : {}),\n ...(locale ? { locale } : {}),\n ...(populate ? { populate: populate as PopulateType } : {}),\n ...(select ? { select: select as SelectType } : {}),\n ...(showHiddenFields !== undefined ? { showHiddenFields } : {}),\n })\n\n return {\n content: [\n {\n type: 'text',\n text: `Version \"${id}\" restored successfully in collection \"${collectionSlug}\"!\\nRestored document:\\n\\`\\`\\`json\\n${JSON.stringify(result)}\\n\\`\\`\\``,\n },\n ],\n doc: result as Record<string, unknown>,\n }\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : 'Unknown error'\n logger.error(`Error restoring version ${id} in ${collectionSlug}: ${errorMessage}`)\n return {\n content: [\n {\n type: 'text',\n text: `❌ **Error restoring version \"${id}\" in collection \"${collectionSlug}\":** ${errorMessage}`,\n },\n ],\n isError: true,\n }\n }\n})\n"],"names":["z","defaultAccess","defineCollectionTool","getLogger","localAPIDefaults","DEFAULT_DESCRIPTION","restoreVersionTool","access","args","Boolean","permissions","collections","collectionSlug","update","annotations","destructiveHint","idempotentHint","openWorldHint","readOnlyHint","title","description","input","object","id","string","describe","depth","number","int","min","max","optional","default","draft","boolean","fallbackLocale","locale","populate","record","unknown","select","showHiddenFields","handler","authorizedMCP","req","payload","logger","info","result","restoreVersion","collection","undefined","content","type","text","JSON","stringify","doc","error","errorMessage","Error","message","isError"],"mappings":"AAEA,SAASA,CAAC,QAAQ,MAAK;AAEvB,SAASC,aAAa,QAAQ,4BAA2B;AACzD,SAASC,oBAAoB,QAAQ,yBAAwB;AAC7D,SAASC,SAAS,QAAQ,8BAA6B;AACvD,SAASC,gBAAgB,QAAQ,qCAAoC;AAErE,MAAMC,sBACJ;AAEF,OAAO,MAAMC,qBAAqBJ,qBAAqB;IACrDK,QAAQ,CAACC,OACPP,cAAcO,SAASC,QAAQD,KAAKE,WAAW,EAAEC,aAAa,CAACH,KAAKI,cAAc,CAAC,EAAEC;IACvFC,aAAa;QACXC,iBAAiB;QACjBC,gBAAgB;QAChBC,eAAe;QACfC,cAAc;QACdC,OAAO;IACT;IACAC,aAAaf;IACbgB,OAAOrB,EAAEsB,MAAM,CAAC;QACdC,IAAIvB,EAAEwB,MAAM,GAAGC,QAAQ,CAAC;QACxBC,OAAO1B,EACJ2B,MAAM,GACNC,GAAG,GACHC,GAA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AyB,IAAI,CAAC,CAAC;YAC1D,GAAIG,SAAS;gBAAEA,QAAQA;YAAqB,IAAI,CAAC,CAAC;YAClD,GAAIC,qBAAqBU,YAAY;gBAAEV;YAAiB,IAAI,CAAC,CAAC;QAChE;QAEA,OAAO;YACLW,SAAS;gBACP;oBACEC,MAAM;oBACNC,MAAM,CAAC,SAAS,EAAE/B,GAAG,uCAAuC,EAAEX,eAAe,oCAAoC,EAAE2C,KAAKC,SAAS,CAACR,QAAQ,QAAQ,CAAC;gBACrJ;aACD;YACDS,KAAKT;QACP;IACF,EAAE,OAAOU,OAAO;QACd,MAAMC,eAAeD,iBAAiBE,QAAQF,MAAMG,OAAO,GAAG;QAC9Df,OAAOY,KAAK,CAAC,CAAC,wBAAwB,EAAEnC,GAAG,IAAI,EAAEX,eAAe,EAAE,EAAE+C,cAAc;QAClF,OAAO;YACLP,SAAS;gBACP;oBACEC,MAAM;oBACNC,MAAM,CAAC,6BAA6B,EAAE/B,GAAG,iBAAiB,EAAEX,eAAe,KAAK,EAAE+C,cAAc;gBAClG;aACD;YACDG,SAAS;QACX;IACF;AACF,GAAE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"updateTool.d.ts","sourceRoot":"","sources":["../../../../src/mcp/builtin/collections/updateTool.ts"],"names":[],"mappings":"AAqBA,eAAO,MAAM,kBAAkB,4CA6L7B,CAAA"}
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { defaultAccess } from '../../../defaultAccess.js';
|
|
3
|
+
import { defineCollectionTool } from '../../../defineTool.js';
|
|
4
|
+
import { getLogger } from '../../../utils/getLogger.js';
|
|
5
|
+
import { getCollectionVirtualFieldNames, stripVirtualFields } from '../../../utils/getVirtualFieldNames.js';
|
|
6
|
+
import { localAPIDefaults } from '../../../utils/localAPIDefaults.js';
|
|
7
|
+
import { getCollectionInputSchema } from '../../../utils/schemaConversion/getEntityInputSchema.js';
|
|
8
|
+
import { transformPointDataToPayload } from '../../../utils/transformPointDataToPayload.js';
|
|
9
|
+
import { whereSchema } from '../../../utils/whereSchema.js';
|
|
10
|
+
import { validateCollectionData } from '../validateEntityData.js';
|
|
11
|
+
import { formatCollectionError } from './formatCollectionError.js';
|
|
12
|
+
const DEFAULT_DESCRIPTION = 'Update documents in any collection by passing the collection slug and data.';
|
|
13
|
+
export const updateDocumentTool = defineCollectionTool({
|
|
14
|
+
access: (args)=>defaultAccess(args) && Boolean(args.permissions?.collections?.[args.collectionSlug]?.update),
|
|
15
|
+
annotations: {
|
|
16
|
+
destructiveHint: true,
|
|
17
|
+
idempotentHint: false,
|
|
18
|
+
openWorldHint: false,
|
|
19
|
+
readOnlyHint: false,
|
|
20
|
+
title: 'Update Document'
|
|
21
|
+
},
|
|
22
|
+
description: DEFAULT_DESCRIPTION,
|
|
23
|
+
input: z.object({
|
|
24
|
+
id: z.union([
|
|
25
|
+
z.string(),
|
|
26
|
+
z.number()
|
|
27
|
+
]).describe('The ID of the document to update').optional(),
|
|
28
|
+
data: z.record(z.string(), z.unknown()).describe('The fields to update'),
|
|
29
|
+
depth: z.number().describe('How many levels deep to populate relationships').optional().default(0),
|
|
30
|
+
draft: z.boolean().describe('Whether to update the document as a draft').optional().default(false),
|
|
31
|
+
fallbackLocale: z.string().describe('Optional: fallback locale code to use when requested locale is not available').optional(),
|
|
32
|
+
filePath: z.string().describe('File path for file uploads').optional(),
|
|
33
|
+
locale: z.string().describe('Optional: locale code to update the document in (e.g., "en", "es"). Defaults to the default locale').optional(),
|
|
34
|
+
overrideLock: z.boolean().describe('Whether to override document locks').optional().default(true),
|
|
35
|
+
overwriteExistingFiles: z.boolean().describe('Whether to overwrite existing files').optional().default(false),
|
|
36
|
+
select: z.record(z.string(), z.unknown()).describe('Optional: define exactly which fields you\'d like to return in the response, e.g., {"title": true}').optional(),
|
|
37
|
+
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()
|
|
38
|
+
})
|
|
39
|
+
}).handler(async ({ authorizedMCP, collectionSlug, input, req })=>{
|
|
40
|
+
const payload = req.payload;
|
|
41
|
+
const logger = getLogger({
|
|
42
|
+
payload
|
|
43
|
+
});
|
|
44
|
+
const { id, data, depth, draft, fallbackLocale, filePath, locale, overrideLock, overwriteExistingFiles, select, where } = input;
|
|
45
|
+
logger.info(`Updating document in collection: ${collectionSlug}${id ? ` with ID: ${id}` : ' with where clause'}, draft: ${draft}${locale ? `, locale: ${locale}` : ''}`);
|
|
46
|
+
try {
|
|
47
|
+
if (!id && !where) {
|
|
48
|
+
return {
|
|
49
|
+
content: [
|
|
50
|
+
{
|
|
51
|
+
type: 'text',
|
|
52
|
+
text: 'Error: Either id or where clause must be provided'
|
|
53
|
+
}
|
|
54
|
+
]
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
const virtualFieldNames = getCollectionVirtualFieldNames(payload.config, collectionSlug);
|
|
58
|
+
const inputData = stripVirtualFields(data, virtualFieldNames);
|
|
59
|
+
const validationError = validateCollectionData({
|
|
60
|
+
collectionSlug,
|
|
61
|
+
data: inputData,
|
|
62
|
+
partial: true,
|
|
63
|
+
req
|
|
64
|
+
});
|
|
65
|
+
if (validationError) {
|
|
66
|
+
return validationError;
|
|
67
|
+
}
|
|
68
|
+
const parsedData = transformPointDataToPayload(inputData);
|
|
69
|
+
const whereClause = where ?? {};
|
|
70
|
+
if (id) {
|
|
71
|
+
const result = await payload.update({
|
|
72
|
+
id,
|
|
73
|
+
collection: collectionSlug,
|
|
74
|
+
data: parsedData,
|
|
75
|
+
depth,
|
|
76
|
+
draft,
|
|
77
|
+
overrideLock,
|
|
78
|
+
req,
|
|
79
|
+
...localAPIDefaults(authorizedMCP),
|
|
80
|
+
...filePath ? {
|
|
81
|
+
filePath
|
|
82
|
+
} : {},
|
|
83
|
+
...overwriteExistingFiles ? {
|
|
84
|
+
overwriteExistingFiles
|
|
85
|
+
} : {},
|
|
86
|
+
...locale ? {
|
|
87
|
+
locale
|
|
88
|
+
} : {},
|
|
89
|
+
...fallbackLocale ? {
|
|
90
|
+
fallbackLocale
|
|
91
|
+
} : {},
|
|
92
|
+
...select ? {
|
|
93
|
+
select: select
|
|
94
|
+
} : {}
|
|
95
|
+
});
|
|
96
|
+
return {
|
|
97
|
+
content: [
|
|
98
|
+
{
|
|
99
|
+
type: 'text',
|
|
100
|
+
text: `Document updated successfully in collection "${collectionSlug}"!\nUpdated document:\n\`\`\`json\n${JSON.stringify(result)}\n\`\`\``
|
|
101
|
+
}
|
|
102
|
+
],
|
|
103
|
+
doc: result
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
const result = await payload.update({
|
|
107
|
+
collection: collectionSlug,
|
|
108
|
+
data: parsedData,
|
|
109
|
+
depth,
|
|
110
|
+
draft,
|
|
111
|
+
overrideLock,
|
|
112
|
+
req,
|
|
113
|
+
where: whereClause,
|
|
114
|
+
...localAPIDefaults(authorizedMCP),
|
|
115
|
+
...filePath ? {
|
|
116
|
+
filePath
|
|
117
|
+
} : {},
|
|
118
|
+
...overwriteExistingFiles ? {
|
|
119
|
+
overwriteExistingFiles
|
|
120
|
+
} : {},
|
|
121
|
+
...locale ? {
|
|
122
|
+
locale
|
|
123
|
+
} : {},
|
|
124
|
+
...fallbackLocale ? {
|
|
125
|
+
fallbackLocale
|
|
126
|
+
} : {},
|
|
127
|
+
...select ? {
|
|
128
|
+
select: select
|
|
129
|
+
} : {}
|
|
130
|
+
});
|
|
131
|
+
const docs = result.docs || [];
|
|
132
|
+
const errors = result.errors || [];
|
|
133
|
+
let responseText = `Multiple documents updated in collection "${collectionSlug}"!\nUpdated: ${docs.length} documents\nErrors: ${errors.length}\n---`;
|
|
134
|
+
if (docs.length > 0) {
|
|
135
|
+
responseText += `\n\nUpdated documents:\n\`\`\`json\n${JSON.stringify(docs)}\n\`\`\``;
|
|
136
|
+
}
|
|
137
|
+
if (errors.length > 0) {
|
|
138
|
+
responseText += `\n\nErrors:\n\`\`\`json\n${JSON.stringify(errors)}\n\`\`\``;
|
|
139
|
+
const errorSchema = getCollectionInputSchema({
|
|
140
|
+
collectionSlug,
|
|
141
|
+
req
|
|
142
|
+
});
|
|
143
|
+
if (errorSchema) {
|
|
144
|
+
responseText += `\n\nUse this schema for data:\n\`\`\`json\n${JSON.stringify(errorSchema)}\n\`\`\``;
|
|
145
|
+
}
|
|
146
|
+
return {
|
|
147
|
+
content: [
|
|
148
|
+
{
|
|
149
|
+
type: 'text',
|
|
150
|
+
text: responseText
|
|
151
|
+
}
|
|
152
|
+
],
|
|
153
|
+
doc: {
|
|
154
|
+
docs,
|
|
155
|
+
errors
|
|
156
|
+
},
|
|
157
|
+
isError: true,
|
|
158
|
+
...errorSchema ? {
|
|
159
|
+
structuredContent: {
|
|
160
|
+
collectionSlug,
|
|
161
|
+
docs,
|
|
162
|
+
errors,
|
|
163
|
+
schema: errorSchema
|
|
164
|
+
}
|
|
165
|
+
} : {}
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
return {
|
|
169
|
+
content: [
|
|
170
|
+
{
|
|
171
|
+
type: 'text',
|
|
172
|
+
text: responseText
|
|
173
|
+
}
|
|
174
|
+
],
|
|
175
|
+
doc: {
|
|
176
|
+
docs,
|
|
177
|
+
errors
|
|
178
|
+
}
|
|
179
|
+
};
|
|
180
|
+
} catch (error) {
|
|
181
|
+
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
|
|
182
|
+
logger.error(`Error updating document in ${collectionSlug}: ${errorMessage}`);
|
|
183
|
+
return formatCollectionError({
|
|
184
|
+
action: 'updating',
|
|
185
|
+
collectionSlug,
|
|
186
|
+
error,
|
|
187
|
+
req
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
//# sourceMappingURL=updateTool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/mcp/builtin/collections/updateTool.ts"],"sourcesContent":["import type { SelectType, Where } from 'payload'\n\nimport { z } from 'zod'\n\nimport { defaultAccess } from '../../../defaultAccess.js'\nimport { defineCollectionTool } from '../../../defineTool.js'\nimport { getLogger } from '../../../utils/getLogger.js'\nimport {\n getCollectionVirtualFieldNames,\n stripVirtualFields,\n} from '../../../utils/getVirtualFieldNames.js'\nimport { localAPIDefaults } from '../../../utils/localAPIDefaults.js'\nimport { getCollectionInputSchema } from '../../../utils/schemaConversion/getEntityInputSchema.js'\nimport { transformPointDataToPayload } from '../../../utils/transformPointDataToPayload.js'\nimport { whereSchema } from '../../../utils/whereSchema.js'\nimport { validateCollectionData } from '../validateEntityData.js'\nimport { formatCollectionError } from './formatCollectionError.js'\n\nconst DEFAULT_DESCRIPTION =\n 'Update documents in any collection by passing the collection slug and data.'\n\nexport const updateDocumentTool = defineCollectionTool({\n access: (args) =>\n defaultAccess(args) && Boolean(args.permissions?.collections?.[args.collectionSlug]?.update),\n annotations: {\n destructiveHint: true,\n idempotentHint: false,\n openWorldHint: false,\n readOnlyHint: false,\n title: 'Update Document',\n },\n description: DEFAULT_DESCRIPTION,\n input: z.object({\n id: z.union([z.string(), z.number()]).describe('The ID of the document to update').optional(),\n data: z.record(z.string(), z.unknown()).describe('The fields to update'),\n depth: z\n .number()\n .describe('How many levels deep to populate relationships')\n .optional()\n .default(0),\n draft: z\n .boolean()\n .describe('Whether to update the document as a draft')\n .optional()\n .default(false),\n fallbackLocale: z\n .string()\n .describe('Optional: fallback locale code to use when requested locale is not available')\n .optional(),\n filePath: z.string().describe('File path for file uploads').optional(),\n locale: z\n .string()\n .describe(\n 'Optional: locale code to update the document in (e.g., \"en\", \"es\"). Defaults to the default locale',\n )\n .optional(),\n overrideLock: z\n .boolean()\n .describe('Whether to override document locks')\n .optional()\n .default(true),\n overwriteExistingFiles: z\n .boolean()\n .describe('Whether to overwrite existing files')\n .optional()\n .default(false),\n select: z\n .record(z.string(), z.unknown())\n .describe(\n 'Optional: define exactly which fields you\\'d like to return in the response, e.g., {\"title\": true}',\n )\n .optional(),\n where: whereSchema\n .describe(\n 'Where clause to update 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 {\n id,\n data,\n depth,\n draft,\n fallbackLocale,\n filePath,\n locale,\n overrideLock,\n overwriteExistingFiles,\n select,\n where,\n } = input\n\n logger.info(\n `Updating document in collection: ${collectionSlug}${id ? ` with ID: ${id}` : ' with where clause'}, draft: ${draft}${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 virtualFieldNames = getCollectionVirtualFieldNames(payload.config, collectionSlug)\n const inputData = stripVirtualFields(data, virtualFieldNames)\n const validationError = validateCollectionData({\n collectionSlug,\n data: inputData,\n partial: true,\n req,\n })\n\n if (validationError) {\n return validationError\n }\n\n const parsedData = transformPointDataToPayload(inputData)\n\n const whereClause: Where = where ?? {}\n\n if (id) {\n const result = await payload.update({\n id,\n collection: collectionSlug,\n data: parsedData,\n depth,\n draft,\n overrideLock,\n req,\n ...localAPIDefaults(authorizedMCP),\n ...(filePath ? { filePath } : {}),\n ...(overwriteExistingFiles ? { overwriteExistingFiles } : {}),\n ...(locale ? { locale } : {}),\n ...(fallbackLocale ? { fallbackLocale } : {}),\n ...(select ? { select: select as SelectType } : {}),\n })\n\n return {\n content: [\n {\n type: 'text',\n text: `Document updated successfully in collection \"${collectionSlug}\"!\\nUpdated document:\\n\\`\\`\\`json\\n${JSON.stringify(result)}\\n\\`\\`\\``,\n },\n ],\n doc: result as Record<string, unknown>,\n }\n }\n\n const result = await payload.update({\n collection: collectionSlug,\n data: parsedData,\n depth,\n draft,\n overrideLock,\n req,\n where: whereClause,\n ...localAPIDefaults(authorizedMCP),\n ...(filePath ? { filePath } : {}),\n ...(overwriteExistingFiles ? { overwriteExistingFiles } : {}),\n ...(locale ? { locale } : {}),\n ...(fallbackLocale ? { fallbackLocale } : {}),\n ...(select ? { select: select as SelectType } : {}),\n })\n\n const docs = result.docs || []\n const errors = result.errors || []\n\n let responseText = `Multiple documents updated in collection \"${collectionSlug}\"!\\nUpdated: ${docs.length} documents\\nErrors: ${errors.length}\\n---`\n if (docs.length > 0) {\n responseText += `\\n\\nUpdated 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 const errorSchema = getCollectionInputSchema({ collectionSlug, req })\n\n if (errorSchema) {\n responseText += `\\n\\nUse this schema for data:\\n\\`\\`\\`json\\n${JSON.stringify(errorSchema)}\\n\\`\\`\\``\n }\n\n return {\n content: [{ type: 'text', text: responseText }],\n doc: { docs, errors } as unknown as Record<string, unknown>,\n isError: true,\n ...(errorSchema\n ? {\n structuredContent: {\n collectionSlug,\n docs,\n errors,\n schema: errorSchema,\n },\n }\n : {}),\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 updating document in ${collectionSlug}: ${errorMessage}`)\n return formatCollectionError({ action: 'updating', collectionSlug, error, req })\n }\n})\n"],"names":["z","defaultAccess","defineCollectionTool","getLogger","getCollectionVirtualFieldNames","stripVirtualFields","localAPIDefaults","getCollectionInputSchema","transformPointDataToPayload","whereSchema","validateCollectionData","formatCollectionError","DEFAULT_DESCRIPTION","updateDocumentTool","access","args","Boolean","permissions","collections","collectionSlug","update","annotations","destructiveHint","idempotentHint","openWorldHint","readOnlyHint","title","description","input","object","id","union","string","number","describe","optional","data","record","unknown","depth","default","draft","boolean","fallbackLocale","filePath","locale","overrideLock","overwriteExistingFiles","select","where","handler","authorizedMCP","req","payload","logger","info","content","type","text","virtualFieldNames","config","inputData","validationError","partial","parsedData","whereClause","result","collection","JSON","stringify","doc","docs","errors","responseText","length","errorSchema","isError","structuredContent","schema","error","errorMessage","Error","message","action"],"mappings":"AAEA,SAASA,CAAC,QAAQ,MAAK;AAEvB,SAASC,aAAa,QAAQ,4BAA2B;AACzD,SAASC,oBAAoB,QAAQ,yBAAwB;AAC7D,SAASC,SAAS,QAAQ,8BAA6B;AACvD,SACEC,8BAA8B,EAC9BC,kBAAkB,QACb,yCAAwC;AAC/C,SAASC,gBAAgB,QAAQ,qCAAoC;AACrE,SAASC,wBAAwB,QAAQ,0DAAyD;AAClG,SAASC,2BAA2B,QAAQ,gDAA+C;AAC3F,SAASC,WAAW,QAAQ,gCAA+B;AAC3D,SAASC,sBAAsB,QAAQ,2BAA0B;AACjE,SAASC,qBAAqB,QAAQ,6BAA4B;AAElE,MAAMC,sBACJ;AAEF,OAAO,MAAMC,qBAAqBX,qBAAqB;IACrDY,QAAQ,CAACC,OACPd,cAAcc,SAASC,QAAQD,KAAKE,WAAW,EAAEC,aAAa,CAACH,KAAKI,cAAc,CAAC,EAAEC;IACvFC,aAAa;QACXC,iBAAiB;QACjBC,gBAAgB;QAChBC,eAAe;QACfC,cAAc;QACdC,OAAO;IACT;IACAC,aAAaf;IACbgB,OAAO5B,EAAE6B,MAAM,CAAC;QACdC,IAAI9B,EAAE+B,KAAK,CAAC;YAAC/B,EAAEgC,MAAM;YAAIhC,EAAEiC,MAAM;SAAG,EAAEC,QAAQ,CAAC,oCAAoCC,QAAQ;QAC3FC,MAAMpC,EAAEqC,MAAM,CAACrC,EAAEgC,MAAM,IAAIhC,EAAEsC,OAAO,IAAIJ,QAAQ,CAAC;QACjDK,OAAOvC,EACJiC,MAAM,GACNC,QAAQ,CAAC,kDACTC,QAAQ,GACRK,OAAO,CAAC;QACXC,OAAOzC,EACJ0C,OAAO,GACPR,QAAQ,CAAC,6CACTC,QAAQ,GACRK,OAAO,CAAC;QACXG,gBAAgB3C,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E;YAAgB4D;YAAO3B;QAAI;IAChF;AACF,GAAE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getConfigInfoTool.d.ts","sourceRoot":"","sources":["../../../src/mcp/builtin/getConfigInfoTool.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,iBAAiB,+BAgE5B,CAAA"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { getAccessResults, isEntityHidden } from 'payload';
|
|
2
|
+
import { defineTool } from '../../defineTool.js';
|
|
3
|
+
export const getConfigInfoTool = defineTool({
|
|
4
|
+
annotations: {
|
|
5
|
+
destructiveHint: false,
|
|
6
|
+
idempotentHint: true,
|
|
7
|
+
openWorldHint: false,
|
|
8
|
+
readOnlyHint: true,
|
|
9
|
+
title: 'Config Info'
|
|
10
|
+
},
|
|
11
|
+
description: 'List the Payload collection and global slugs visible to this MCP client.'
|
|
12
|
+
}).handler(async ({ authorizedMCP, req })=>{
|
|
13
|
+
const user = authorizedMCP.user;
|
|
14
|
+
const permissions = authorizedMCP.overrideAccess ? null : await getAccessResults({
|
|
15
|
+
req: {
|
|
16
|
+
...req,
|
|
17
|
+
user
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
const authorizedCollectionSlugs = new Set();
|
|
21
|
+
const authorizedGlobalSlugs = new Set();
|
|
22
|
+
for (const item of authorizedMCP.items){
|
|
23
|
+
if (item.type === 'collectionTool') {
|
|
24
|
+
authorizedCollectionSlugs.add(item.collectionSlug);
|
|
25
|
+
} else if (item.type === 'globalTool') {
|
|
26
|
+
authorizedGlobalSlugs.add(item.globalSlug);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
const collections = [];
|
|
30
|
+
const globals = [];
|
|
31
|
+
for (const collection of req.payload.config.collections){
|
|
32
|
+
if (!authorizedCollectionSlugs.has(collection.slug)) {
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
if (user && isEntityHidden({
|
|
36
|
+
hidden: collection.admin.hidden,
|
|
37
|
+
user
|
|
38
|
+
})) {
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
if (!authorizedMCP.overrideAccess && !permissions?.collections?.[collection.slug]?.read) {
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
collections.push(collection.slug);
|
|
45
|
+
}
|
|
46
|
+
for (const global of req.payload.config.globals){
|
|
47
|
+
if (!authorizedGlobalSlugs.has(global.slug)) {
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
if (user && isEntityHidden({
|
|
51
|
+
hidden: global.admin.hidden,
|
|
52
|
+
user
|
|
53
|
+
})) {
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
if (!authorizedMCP.overrideAccess && !permissions?.globals?.[global.slug]?.read) {
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
globals.push(global.slug);
|
|
60
|
+
}
|
|
61
|
+
return {
|
|
62
|
+
content: [
|
|
63
|
+
{
|
|
64
|
+
type: 'text',
|
|
65
|
+
text: `Collections: ${collections.join(', ') || 'none'}\nGlobals: ${globals.join(', ') || 'none'}`
|
|
66
|
+
}
|
|
67
|
+
]
|
|
68
|
+
};
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
//# sourceMappingURL=getConfigInfoTool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/mcp/builtin/getConfigInfoTool.ts"],"sourcesContent":["import { getAccessResults, isEntityHidden } from 'payload'\n\nimport { defineTool } from '../../defineTool.js'\n\nexport const getConfigInfoTool = defineTool({\n annotations: {\n destructiveHint: false,\n idempotentHint: true,\n openWorldHint: false,\n readOnlyHint: true,\n title: 'Config Info',\n },\n description: 'List the Payload collection and global slugs visible to this MCP client.',\n}).handler(async ({ authorizedMCP, req }) => {\n const user = authorizedMCP.user\n const permissions = authorizedMCP.overrideAccess\n ? null\n : await getAccessResults({ req: { ...req, user } })\n const authorizedCollectionSlugs = new Set<string>()\n const authorizedGlobalSlugs = new Set<string>()\n\n for (const item of authorizedMCP.items) {\n if (item.type === 'collectionTool') {\n authorizedCollectionSlugs.add(item.collectionSlug)\n } else if (item.type === 'globalTool') {\n authorizedGlobalSlugs.add(item.globalSlug)\n }\n }\n\n const collections: string[] = []\n const globals: string[] = []\n\n for (const collection of req.payload.config.collections) {\n if (!authorizedCollectionSlugs.has(collection.slug)) {\n continue\n }\n if (user && isEntityHidden({ hidden: collection.admin.hidden, user })) {\n continue\n }\n if (!authorizedMCP.overrideAccess && !permissions?.collections?.[collection.slug]?.read) {\n continue\n }\n\n collections.push(collection.slug)\n }\n\n for (const global of req.payload.config.globals) {\n if (!authorizedGlobalSlugs.has(global.slug)) {\n continue\n }\n if (user && isEntityHidden({ hidden: global.admin.hidden, user })) {\n continue\n }\n if (!authorizedMCP.overrideAccess && !permissions?.globals?.[global.slug]?.read) {\n continue\n }\n\n globals.push(global.slug)\n }\n\n return {\n content: [\n {\n type: 'text',\n text: `Collections: ${collections.join(', ') || 'none'}\\nGlobals: ${globals.join(', ') || 'none'}`,\n },\n ],\n }\n})\n"],"names":["getAccessResults","isEntityHidden","defineTool","getConfigInfoTool","annotations","destructiveHint","idempotentHint","openWorldHint","readOnlyHint","title","description","handler","authorizedMCP","req","user","permissions","overrideAccess","authorizedCollectionSlugs","Set","authorizedGlobalSlugs","item","items","type","add","collectionSlug","globalSlug","collections","globals","collection","payload","config","has","slug","hidden","admin","read","push","global","content","text","join"],"mappings":"AAAA,SAASA,gBAAgB,EAAEC,cAAc,QAAQ,UAAS;AAE1D,SAASC,UAAU,QAAQ,sBAAqB;AAEhD,OAAO,MAAMC,oBAAoBD,WAAW;IAC1CE,aAAa;QACXC,iBAAiB;QACjBC,gBAAgB;QAChBC,eAAe;QACfC,cAAc;QACdC,OAAO;IACT;IACAC,aAAa;AACf,GAAGC,OAAO,CAAC,OAAO,EAAEC,aAAa,EAAEC,GAAG,EAAE;IACtC,MAAMC,OAAOF,cAAcE,IAAI;IAC/B,MAAMC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,OAAO;QACLM,SAAS;YACP;gBACEhB,MAAM;gBACNiB,MAAM,CAAC,aAAa,EAAEb,YAAYc,IAAI,CAAC,SAAS,OAAO,WAAW,EAAEb,QAAQa,IAAI,CAAC,SAAS,QAAQ;YACpG;SACD;IACH;AACF,GAAE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"countVersionsTool.d.ts","sourceRoot":"","sources":["../../../../src/mcp/builtin/globals/countVersionsTool.ts"],"names":[],"mappings":"AAWA,eAAO,MAAM,uBAAuB,wCA4DlC,CAAA"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { defaultAccess } from '../../../defaultAccess.js';
|
|
3
|
+
import { defineGlobalTool } from '../../../defineTool.js';
|
|
4
|
+
import { getLogger } from '../../../utils/getLogger.js';
|
|
5
|
+
import { localAPIDefaults } from '../../../utils/localAPIDefaults.js';
|
|
6
|
+
import { whereSchema } from '../../../utils/whereSchema.js';
|
|
7
|
+
const DEFAULT_DESCRIPTION = 'Count global versions in any version-enabled global by passing the global slug and optional where clause.';
|
|
8
|
+
export const countGlobalVersionsTool = defineGlobalTool({
|
|
9
|
+
access: (args)=>defaultAccess(args) && Boolean(args.permissions?.globals?.[args.globalSlug]?.readVersions),
|
|
10
|
+
annotations: {
|
|
11
|
+
destructiveHint: false,
|
|
12
|
+
idempotentHint: true,
|
|
13
|
+
openWorldHint: false,
|
|
14
|
+
readOnlyHint: true,
|
|
15
|
+
title: 'Count Global Versions'
|
|
16
|
+
},
|
|
17
|
+
description: DEFAULT_DESCRIPTION,
|
|
18
|
+
input: z.object({
|
|
19
|
+
locale: z.string().describe('Optional: locale code to count versions in').optional(),
|
|
20
|
+
where: whereSchema.describe('Optional: where clause for filtering versions. Version document fields are usually under "version". Example: {"version.siteName":{"contains":"test"}}').optional()
|
|
21
|
+
})
|
|
22
|
+
}).handler(async ({ authorizedMCP, globalSlug, input, req })=>{
|
|
23
|
+
const payload = req.payload;
|
|
24
|
+
const logger = getLogger({
|
|
25
|
+
payload
|
|
26
|
+
});
|
|
27
|
+
const { locale, where } = input;
|
|
28
|
+
logger.info(`Counting versions for global: ${globalSlug}`);
|
|
29
|
+
try {
|
|
30
|
+
const result = await payload.countGlobalVersions({
|
|
31
|
+
global: globalSlug,
|
|
32
|
+
req,
|
|
33
|
+
...localAPIDefaults(authorizedMCP),
|
|
34
|
+
...locale ? {
|
|
35
|
+
locale
|
|
36
|
+
} : {},
|
|
37
|
+
...where ? {
|
|
38
|
+
where
|
|
39
|
+
} : {}
|
|
40
|
+
});
|
|
41
|
+
return {
|
|
42
|
+
content: [
|
|
43
|
+
{
|
|
44
|
+
type: 'text',
|
|
45
|
+
text: `Global "${globalSlug}" contains ${result.totalDocs} matching versions.\n\`\`\`json\n${JSON.stringify(result)}\n\`\`\``
|
|
46
|
+
}
|
|
47
|
+
],
|
|
48
|
+
doc: result
|
|
49
|
+
};
|
|
50
|
+
} catch (error) {
|
|
51
|
+
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
|
|
52
|
+
logger.error(`Error counting versions for global ${globalSlug}: ${errorMessage}`);
|
|
53
|
+
return {
|
|
54
|
+
content: [
|
|
55
|
+
{
|
|
56
|
+
type: 'text',
|
|
57
|
+
text: `❌ **Error counting versions for global "${globalSlug}":** ${errorMessage}`
|
|
58
|
+
}
|
|
59
|
+
],
|
|
60
|
+
isError: true
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
//# sourceMappingURL=countVersionsTool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/mcp/builtin/globals/countVersionsTool.ts"],"sourcesContent":["import { z } from 'zod'\n\nimport { defaultAccess } from '../../../defaultAccess.js'\nimport { defineGlobalTool } 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 'Count global versions in any version-enabled global by passing the global slug and optional where clause.'\n\nexport const countGlobalVersionsTool = defineGlobalTool({\n access: (args) =>\n defaultAccess(args) && Boolean(args.permissions?.globals?.[args.globalSlug]?.readVersions),\n annotations: {\n destructiveHint: false,\n idempotentHint: true,\n openWorldHint: false,\n readOnlyHint: true,\n title: 'Count Global Versions',\n },\n description: DEFAULT_DESCRIPTION,\n input: z.object({\n locale: z\n .string()\n .describe('Optional: locale code to count versions in')\n .optional(),\n where: whereSchema\n .describe(\n 'Optional: where clause for filtering versions. Version document fields are usually under \"version\". Example: {\"version.siteName\":{\"contains\":\"test\"}}',\n )\n .optional(),\n }),\n}).handler(async ({ authorizedMCP, globalSlug, input, req }) => {\n const payload = req.payload\n const logger = getLogger({ payload })\n const { locale, where } = input\n\n logger.info(`Counting versions for global: ${globalSlug}`)\n\n try {\n const result = await payload.countGlobalVersions({\n global: globalSlug,\n req,\n ...localAPIDefaults(authorizedMCP),\n ...(locale ? { locale } : {}),\n ...(where ? { where } : {}),\n })\n\n return {\n content: [\n {\n type: 'text',\n text: `Global \"${globalSlug}\" contains ${result.totalDocs} matching versions.\\n\\`\\`\\`json\\n${JSON.stringify(result)}\\n\\`\\`\\``,\n },\n ],\n doc: result,\n }\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : 'Unknown error'\n logger.error(`Error counting versions for global ${globalSlug}: ${errorMessage}`)\n return {\n content: [\n {\n type: 'text',\n text: `❌ **Error counting versions for global \"${globalSlug}\":** ${errorMessage}`,\n },\n ],\n isError: true,\n }\n }\n})\n"],"names":["z","defaultAccess","defineGlobalTool","getLogger","localAPIDefaults","whereSchema","DEFAULT_DESCRIPTION","countGlobalVersionsTool","access","args","Boolean","permissions","globals","globalSlug","readVersions","annotations","destructiveHint","idempotentHint","openWorldHint","readOnlyHint","title","description","input","object","locale","string","describe","optional","where","handler","authorizedMCP","req","payload","logger","info","result","countGlobalVersions","global","content","type","text","totalD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