@payloadcms/plugin-mcp 4.0.0-internal.d28e9fb → 4.0.0-internal.d7d662c
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 +17 -0
- package/dist/endpoint/access.d.ts.map +1 -0
- package/dist/endpoint/access.js +105 -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 +129 -0
- package/dist/endpoint/index.js.map +1 -0
- package/dist/endpoint/oauth.d.ts +35 -0
- package/dist/endpoint/oauth.d.ts.map +1 -0
- package/dist/endpoint/oauth.js +87 -0
- package/dist/endpoint/oauth.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 +14 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +50 -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 +235 -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 +312 -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 +63 -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 +60 -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 +137 -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 +90 -0
- package/dist/mcp/builtin/collections/duplicateTool.js.map +1 -0
- package/dist/mcp/builtin/collections/fileInput.d.ts +28 -0
- package/dist/mcp/builtin/collections/fileInput.d.ts.map +1 -0
- package/dist/mcp/builtin/collections/fileInput.js +88 -0
- package/dist/mcp/builtin/collections/fileInput.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 +77 -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 +146 -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 +74 -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 +84 -0
- package/dist/mcp/builtin/collections/findVersionsTool.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 +103 -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 +69 -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 +172 -0
- package/dist/mcp/builtin/collections/updateTool.js.map +1 -0
- package/dist/mcp/builtin/collections/uploadInstructionsTool.d.ts +2 -0
- package/dist/mcp/builtin/collections/uploadInstructionsTool.d.ts.map +1 -0
- package/dist/mcp/builtin/collections/uploadInstructionsTool.js +55 -0
- package/dist/mcp/builtin/collections/uploadInstructionsTool.js.map +1 -0
- package/dist/mcp/builtin/formatEntityError.d.ts +16 -0
- package/dist/mcp/builtin/formatEntityError.d.ts.map +1 -0
- package/dist/mcp/builtin/formatEntityError.js +55 -0
- package/dist/mcp/builtin/formatEntityError.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 +69 -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 +60 -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 +67 -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 +68 -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 +78 -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 +81 -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 +70 -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 +78 -0
- package/dist/mcp/builtin/globals/updateTool.js.map +1 -0
- package/dist/mcp/builtinTools.d.ts +168 -0
- package/dist/mcp/builtinTools.d.ts.map +1 -0
- package/dist/mcp/builtinTools.js +169 -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 +234 -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 +128 -0
- package/dist/stdio.js.map +1 -0
- package/dist/types.d.ts +298 -446
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +4 -1
- package/dist/types.js.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/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/package.json +41 -26
- package/src/defaultAccess.ts +3 -0
- package/src/defineTool.ts +44 -0
- package/src/endpoint/access.ts +120 -0
- package/src/endpoint/index.ts +115 -0
- package/src/endpoint/oauth.ts +90 -0
- package/src/exports/client.ts +3 -0
- package/src/exports/internal.ts +1 -0
- package/src/index.ts +47 -88
- package/src/mcp/buildMcpServer.ts +294 -0
- package/src/mcp/builtin/collections/authTools.ts +280 -0
- package/src/mcp/builtin/collections/countTool.ts +61 -0
- package/src/mcp/builtin/collections/countVersionsTool.ts +60 -0
- package/src/mcp/builtin/collections/createTool.ts +143 -0
- package/src/mcp/builtin/collections/deleteTool.ts +97 -0
- package/src/mcp/builtin/collections/duplicateTool.ts +84 -0
- package/src/mcp/builtin/collections/fileInput.spec.ts +93 -0
- package/src/mcp/builtin/collections/fileInput.ts +127 -0
- package/src/mcp/builtin/collections/findDistinctTool.ts +67 -0
- package/src/mcp/builtin/collections/findTool.ts +134 -0
- package/src/mcp/builtin/collections/findVersionByIDTool.ts +66 -0
- package/src/mcp/builtin/collections/findVersionsTool.ts +83 -0
- package/src/mcp/builtin/collections/getCollectionSchemaTool.ts +91 -0
- package/src/mcp/builtin/collections/restoreVersionTool.ts +65 -0
- package/src/mcp/builtin/collections/updateTool.ts +173 -0
- package/src/mcp/builtin/collections/uploadInstructionsTool.ts +64 -0
- package/src/mcp/builtin/formatEntityError.ts +77 -0
- package/src/mcp/builtin/getConfigInfoTool.ts +68 -0
- package/src/mcp/builtin/globals/countVersionsTool.ts +60 -0
- package/src/mcp/builtin/globals/findTool.ts +66 -0
- package/src/mcp/builtin/globals/findVersionByIDTool.ts +64 -0
- package/src/mcp/builtin/globals/findVersionsTool.ts +69 -0
- package/src/mcp/builtin/globals/getGlobalSchemaTool.ts +73 -0
- package/src/mcp/builtin/globals/restoreVersionTool.ts +68 -0
- package/src/mcp/builtin/globals/updateTool.ts +92 -0
- package/src/mcp/builtinTools.ts +161 -0
- package/src/mcp/sanitizeMCPConfig.ts +282 -0
- package/src/stdio.ts +131 -0
- package/src/types.ts +346 -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/toStandardSchema.ts +9 -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/getVirtualFieldNames.d.ts +0 -14
- package/dist/utils/getVirtualFieldNames.d.ts.map +0 -1
- package/dist/utils/getVirtualFieldNames.js +0 -35
- package/dist/utils/getVirtualFieldNames.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/dist/utils/transformPointDataToPayload.d.ts +0 -7
- package/dist/utils/transformPointDataToPayload.d.ts.map +0 -1
- package/dist/utils/transformPointDataToPayload.js +0 -28
- package/dist/utils/transformPointDataToPayload.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/getVirtualFieldNames.ts +0 -53
- 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
- package/src/utils/transformPointDataToPayload.ts +0 -40
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { getAccessResults, getCollectionInputSchema, getCollectionSchemaInputSchema } from 'payload'
|
|
2
|
+
import { getLLMInstructions } from 'payload/internal'
|
|
3
|
+
|
|
4
|
+
import { defaultAccess } from '../../../defaultAccess.js'
|
|
5
|
+
import { defineCollectionTool } from '../../../defineTool.js'
|
|
6
|
+
|
|
7
|
+
export const getCollectionSchemaTool = defineCollectionTool({
|
|
8
|
+
access: (args) => {
|
|
9
|
+
const permissions = args.permissions?.collections?.[args.slug]
|
|
10
|
+
|
|
11
|
+
return defaultAccess(args) && Boolean(permissions?.create || permissions?.update)
|
|
12
|
+
},
|
|
13
|
+
annotations: {
|
|
14
|
+
destructiveHint: false,
|
|
15
|
+
idempotentHint: true,
|
|
16
|
+
openWorldHint: false,
|
|
17
|
+
readOnlyHint: true,
|
|
18
|
+
title: 'Get Collection Schema',
|
|
19
|
+
},
|
|
20
|
+
description:
|
|
21
|
+
'Get the input schema and LLM instructions before creating or updating documents in a collection.',
|
|
22
|
+
input: getCollectionSchemaInputSchema,
|
|
23
|
+
}).handler(async ({ slug, authorizedMCP, req }) => {
|
|
24
|
+
const permissions = authorizedMCP.overrideAccess
|
|
25
|
+
? null
|
|
26
|
+
: (await getAccessResults({ req })).collections?.[slug]
|
|
27
|
+
|
|
28
|
+
if (!authorizedMCP.overrideAccess && !permissions?.create && !permissions?.update) {
|
|
29
|
+
return {
|
|
30
|
+
content: [
|
|
31
|
+
{
|
|
32
|
+
type: 'text',
|
|
33
|
+
text: `Error: MCP access to "getCollectionSchema" is not enabled for collection "${slug}"`,
|
|
34
|
+
},
|
|
35
|
+
],
|
|
36
|
+
isError: true,
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const inputSchema = getCollectionInputSchema({
|
|
41
|
+
collectionSlug: slug,
|
|
42
|
+
req,
|
|
43
|
+
...(permissions ? { permissions } : {}),
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
if (!inputSchema) {
|
|
47
|
+
return {
|
|
48
|
+
content: [{ type: 'text', text: `Error: Collection "${slug}" not found` }],
|
|
49
|
+
isError: true,
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const uploadConfig = req.payload.collections[slug]?.config.upload
|
|
54
|
+
const maxFileSize = req.payload.config.upload.limits?.fileSize
|
|
55
|
+
const upload = uploadConfig
|
|
56
|
+
? {
|
|
57
|
+
enabled: true,
|
|
58
|
+
filesRequiredOnCreate: uploadConfig.filesRequiredOnCreate !== false,
|
|
59
|
+
mimeTypes: uploadConfig.mimeTypes ?? ['*/*'],
|
|
60
|
+
sources: [
|
|
61
|
+
...(uploadConfig.pasteURL !== false ? ['externalURL'] : []),
|
|
62
|
+
'base64',
|
|
63
|
+
'uploadReference',
|
|
64
|
+
],
|
|
65
|
+
...(typeof maxFileSize === 'number' && Number.isFinite(maxFileSize) ? { maxFileSize } : {}),
|
|
66
|
+
}
|
|
67
|
+
: { enabled: false }
|
|
68
|
+
|
|
69
|
+
const instructions = await getLLMInstructions({
|
|
70
|
+
slug,
|
|
71
|
+
type: 'collection',
|
|
72
|
+
overrideAccess: authorizedMCP.overrideAccess,
|
|
73
|
+
req,
|
|
74
|
+
})
|
|
75
|
+
|
|
76
|
+
return {
|
|
77
|
+
content: [
|
|
78
|
+
{
|
|
79
|
+
type: 'text',
|
|
80
|
+
text: `Schema for collection "${slug}":\n\`\`\`json\n${JSON.stringify(inputSchema)}\n\`\`\`\nUpload configuration:\n\`\`\`json\n${JSON.stringify(upload)}\n\`\`\``,
|
|
81
|
+
},
|
|
82
|
+
...(instructions ? [{ type: 'text' as const, text: instructions }] : []),
|
|
83
|
+
],
|
|
84
|
+
structuredContent: {
|
|
85
|
+
slug,
|
|
86
|
+
schema: inputSchema,
|
|
87
|
+
upload,
|
|
88
|
+
...(instructions ? { instructions } : {}),
|
|
89
|
+
},
|
|
90
|
+
}
|
|
91
|
+
})
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { restoreVersionInputSchema } from 'payload'
|
|
2
|
+
|
|
3
|
+
import { defaultAccess } from '../../../defaultAccess.js'
|
|
4
|
+
import { defineCollectionTool } from '../../../defineTool.js'
|
|
5
|
+
import { getLogger } from '../../../utils/getLogger.js'
|
|
6
|
+
|
|
7
|
+
const DEFAULT_DESCRIPTION =
|
|
8
|
+
'Restore a document from a previous version in any version-enabled collection.'
|
|
9
|
+
|
|
10
|
+
export const restoreVersionTool = defineCollectionTool({
|
|
11
|
+
access: (args) =>
|
|
12
|
+
defaultAccess(args) && Boolean(args.permissions?.collections?.[args.slug]?.update),
|
|
13
|
+
annotations: {
|
|
14
|
+
destructiveHint: true,
|
|
15
|
+
idempotentHint: false,
|
|
16
|
+
openWorldHint: false,
|
|
17
|
+
readOnlyHint: false,
|
|
18
|
+
title: 'Restore Version',
|
|
19
|
+
},
|
|
20
|
+
description: DEFAULT_DESCRIPTION,
|
|
21
|
+
input: restoreVersionInputSchema,
|
|
22
|
+
}).handler(async ({ slug, authorizedMCP, input, req }) => {
|
|
23
|
+
const payload = req.payload
|
|
24
|
+
const logger = getLogger({ payload })
|
|
25
|
+
const { id, depth, draft, fallbackLocale, locale, populate, select } = input
|
|
26
|
+
|
|
27
|
+
logger.info(`Restoring version in collection: ${slug} with ID: ${id}`)
|
|
28
|
+
|
|
29
|
+
try {
|
|
30
|
+
const result = await payload.restoreVersion({
|
|
31
|
+
id: String(id),
|
|
32
|
+
collection: slug,
|
|
33
|
+
depth,
|
|
34
|
+
draft,
|
|
35
|
+
overrideAccess: authorizedMCP.overrideAccess,
|
|
36
|
+
req,
|
|
37
|
+
...(fallbackLocale !== undefined ? { fallbackLocale } : {}),
|
|
38
|
+
...(locale ? { locale } : {}),
|
|
39
|
+
...(populate ? { populate } : {}),
|
|
40
|
+
...(select ? { select } : {}),
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
return {
|
|
44
|
+
content: [
|
|
45
|
+
{
|
|
46
|
+
type: 'text',
|
|
47
|
+
text: `Version "${id}" restored successfully in collection "${slug}"!\nRestored document:\n\`\`\`json\n${JSON.stringify(result)}\n\`\`\``,
|
|
48
|
+
},
|
|
49
|
+
],
|
|
50
|
+
doc: result,
|
|
51
|
+
}
|
|
52
|
+
} catch (error) {
|
|
53
|
+
const errorMessage = error instanceof Error ? error.message : 'Unknown error'
|
|
54
|
+
logger.error(`Error restoring version ${id} in ${slug}: ${errorMessage}`)
|
|
55
|
+
return {
|
|
56
|
+
content: [
|
|
57
|
+
{
|
|
58
|
+
type: 'text',
|
|
59
|
+
text: `❌ **Error restoring version "${id}" in collection "${slug}":** ${errorMessage}`,
|
|
60
|
+
},
|
|
61
|
+
],
|
|
62
|
+
isError: true,
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
})
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import type { Where } from 'payload'
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
getCollectionInputSchema,
|
|
5
|
+
getCollectionVirtualFieldNames,
|
|
6
|
+
parseDocumentID,
|
|
7
|
+
stripVirtualFields,
|
|
8
|
+
transformPointDataToPayload,
|
|
9
|
+
updateDocumentInputSchema,
|
|
10
|
+
validateCollectionData,
|
|
11
|
+
} from 'payload'
|
|
12
|
+
|
|
13
|
+
import { defaultAccess } from '../../../defaultAccess.js'
|
|
14
|
+
import { defineCollectionTool } from '../../../defineTool.js'
|
|
15
|
+
import { getLogger } from '../../../utils/getLogger.js'
|
|
16
|
+
import { formatEntityError } from '../formatEntityError.js'
|
|
17
|
+
import { fileInputSchema, resolveFile } from './fileInput.js'
|
|
18
|
+
|
|
19
|
+
const DEFAULT_DESCRIPTION =
|
|
20
|
+
'Update documents. Prefer uploadReference after upload, externalURL for URLs, or base64 for small local files.'
|
|
21
|
+
|
|
22
|
+
export const updateDocumentTool = defineCollectionTool({
|
|
23
|
+
access: (args) =>
|
|
24
|
+
defaultAccess(args) && Boolean(args.permissions?.collections?.[args.slug]?.update),
|
|
25
|
+
annotations: {
|
|
26
|
+
destructiveHint: true,
|
|
27
|
+
idempotentHint: false,
|
|
28
|
+
openWorldHint: false,
|
|
29
|
+
readOnlyHint: false,
|
|
30
|
+
title: 'Update Document',
|
|
31
|
+
},
|
|
32
|
+
description: DEFAULT_DESCRIPTION,
|
|
33
|
+
input: updateDocumentInputSchema({ file: fileInputSchema }),
|
|
34
|
+
}).handler(async ({ slug, authorizedMCP, input, req }) => {
|
|
35
|
+
const payload = req.payload
|
|
36
|
+
const logger = getLogger({ payload })
|
|
37
|
+
|
|
38
|
+
const {
|
|
39
|
+
id,
|
|
40
|
+
data,
|
|
41
|
+
depth,
|
|
42
|
+
draft,
|
|
43
|
+
fallbackLocale,
|
|
44
|
+
file: fileInput,
|
|
45
|
+
limit,
|
|
46
|
+
locale,
|
|
47
|
+
overrideLock,
|
|
48
|
+
populate,
|
|
49
|
+
publishAllLocales,
|
|
50
|
+
returning,
|
|
51
|
+
select,
|
|
52
|
+
sort,
|
|
53
|
+
trash,
|
|
54
|
+
unpublishAllLocales,
|
|
55
|
+
where,
|
|
56
|
+
} = input
|
|
57
|
+
|
|
58
|
+
logger.info(
|
|
59
|
+
`Updating document in collection: ${slug}${id ? ` with ID: ${id}` : ' with where clause'}, draft: ${draft}${locale ? `, locale: ${locale}` : ''}`,
|
|
60
|
+
)
|
|
61
|
+
|
|
62
|
+
try {
|
|
63
|
+
const virtualFieldNames = getCollectionVirtualFieldNames(payload.config, slug)
|
|
64
|
+
const inputData = stripVirtualFields(data, virtualFieldNames)
|
|
65
|
+
validateCollectionData({
|
|
66
|
+
slug,
|
|
67
|
+
data: inputData,
|
|
68
|
+
partial: true,
|
|
69
|
+
req,
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
const parsedData = transformPointDataToPayload(inputData)
|
|
73
|
+
const file = await resolveFile({ slug, input: fileInput, req })
|
|
74
|
+
|
|
75
|
+
const whereClause: Where = where ?? {}
|
|
76
|
+
|
|
77
|
+
if (id !== undefined) {
|
|
78
|
+
const result = await payload.update({
|
|
79
|
+
id: parseDocumentID({ id, collectionSlug: slug, payload }),
|
|
80
|
+
collection: slug,
|
|
81
|
+
data: parsedData,
|
|
82
|
+
depth,
|
|
83
|
+
draft,
|
|
84
|
+
fallbackLocale,
|
|
85
|
+
locale,
|
|
86
|
+
overrideAccess: authorizedMCP.overrideAccess,
|
|
87
|
+
overrideLock,
|
|
88
|
+
populate,
|
|
89
|
+
publishAllLocales,
|
|
90
|
+
req,
|
|
91
|
+
select: returning ? select : { id: true },
|
|
92
|
+
trash,
|
|
93
|
+
unpublishAllLocales,
|
|
94
|
+
...(file ? { file } : {}),
|
|
95
|
+
})
|
|
96
|
+
|
|
97
|
+
const responseResult = returning ? result : { id: result.id }
|
|
98
|
+
|
|
99
|
+
return {
|
|
100
|
+
content: [
|
|
101
|
+
{
|
|
102
|
+
type: 'text',
|
|
103
|
+
text: `Document updated successfully in collection "${slug}"!\nResult:\n\`\`\`json\n${JSON.stringify(responseResult)}\n\`\`\``,
|
|
104
|
+
},
|
|
105
|
+
],
|
|
106
|
+
doc: responseResult,
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
const result = await payload.update({
|
|
111
|
+
collection: slug,
|
|
112
|
+
data: parsedData,
|
|
113
|
+
depth,
|
|
114
|
+
draft,
|
|
115
|
+
fallbackLocale,
|
|
116
|
+
limit,
|
|
117
|
+
locale,
|
|
118
|
+
overrideAccess: authorizedMCP.overrideAccess,
|
|
119
|
+
overrideLock,
|
|
120
|
+
populate,
|
|
121
|
+
publishAllLocales,
|
|
122
|
+
req,
|
|
123
|
+
select: returning ? select : { id: true },
|
|
124
|
+
sort,
|
|
125
|
+
trash,
|
|
126
|
+
unpublishAllLocales,
|
|
127
|
+
where: whereClause,
|
|
128
|
+
...(file ? { file } : {}),
|
|
129
|
+
})
|
|
130
|
+
|
|
131
|
+
const docs = returning ? result.docs : result.docs.map(({ id }) => ({ id }))
|
|
132
|
+
const errors = result.errors || []
|
|
133
|
+
|
|
134
|
+
let responseText = `Multiple documents updated in collection "${slug}"!\nUpdated: ${docs.length} documents\nErrors: ${errors.length}\n---`
|
|
135
|
+
if (docs.length > 0) {
|
|
136
|
+
responseText += `\n\nUpdated documents:\n\`\`\`json\n${JSON.stringify(docs)}\n\`\`\``
|
|
137
|
+
}
|
|
138
|
+
if (errors.length > 0) {
|
|
139
|
+
responseText += `\n\nErrors:\n\`\`\`json\n${JSON.stringify(errors)}\n\`\`\``
|
|
140
|
+
|
|
141
|
+
const errorSchema = getCollectionInputSchema({ collectionSlug: slug, req })
|
|
142
|
+
|
|
143
|
+
if (errorSchema) {
|
|
144
|
+
responseText += `\n\nUse this schema for data:\n\`\`\`json\n${JSON.stringify(errorSchema)}\n\`\`\``
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
return {
|
|
148
|
+
content: [{ type: 'text', text: responseText }],
|
|
149
|
+
doc: { docs, errors } as unknown as Record<string, unknown>,
|
|
150
|
+
isError: true,
|
|
151
|
+
...(errorSchema
|
|
152
|
+
? {
|
|
153
|
+
structuredContent: {
|
|
154
|
+
slug,
|
|
155
|
+
docs,
|
|
156
|
+
errors,
|
|
157
|
+
schema: errorSchema,
|
|
158
|
+
},
|
|
159
|
+
}
|
|
160
|
+
: {}),
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
return {
|
|
165
|
+
content: [{ type: 'text', text: responseText }],
|
|
166
|
+
doc: { docs, errors } as unknown as Record<string, unknown>,
|
|
167
|
+
}
|
|
168
|
+
} catch (error) {
|
|
169
|
+
const errorMessage = error instanceof Error ? error.message : 'Unknown error'
|
|
170
|
+
logger.error(`Error updating document in ${slug}: ${errorMessage}`)
|
|
171
|
+
return formatEntityError({ slug, action: 'updating', entity: 'collection', error, req })
|
|
172
|
+
}
|
|
173
|
+
})
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { strictObject, z } from 'payload'
|
|
2
|
+
import { getUploadInstructions as getPayloadUploadInstructions } from 'payload/internal'
|
|
3
|
+
|
|
4
|
+
import { defaultAccess } from '../../../defaultAccess.js'
|
|
5
|
+
import { defineCollectionTool } from '../../../defineTool.js'
|
|
6
|
+
|
|
7
|
+
export const getUploadInstructionsTool = defineCollectionTool({
|
|
8
|
+
access: (args) =>
|
|
9
|
+
defaultAccess(args) &&
|
|
10
|
+
Boolean(
|
|
11
|
+
args.permissions?.collections?.[args.slug]?.create ||
|
|
12
|
+
args.permissions?.collections?.[args.slug]?.update,
|
|
13
|
+
),
|
|
14
|
+
annotations: {
|
|
15
|
+
destructiveHint: false,
|
|
16
|
+
idempotentHint: false,
|
|
17
|
+
openWorldHint: true,
|
|
18
|
+
readOnlyHint: false,
|
|
19
|
+
title: 'Get Upload Instructions',
|
|
20
|
+
},
|
|
21
|
+
description:
|
|
22
|
+
'Prepare uploads for createDocuments or updateDocument. This does not upload bytes; finish the returned action before use.',
|
|
23
|
+
input: strictObject({
|
|
24
|
+
docPrefix: z.optional(z.string()).check(z.describe('Document folder or prefix.')),
|
|
25
|
+
filename: z.string().check(z.describe('The original file name.')),
|
|
26
|
+
filesize: z.int().check(z.nonnegative(), z.describe('The file size in bytes.')),
|
|
27
|
+
mimeType: z.string().check(z.describe('The file MIME type.')),
|
|
28
|
+
}),
|
|
29
|
+
}).handler(async ({ slug, authorizedMCP, input, req }) => {
|
|
30
|
+
try {
|
|
31
|
+
const instructions = await getPayloadUploadInstructions({
|
|
32
|
+
...input,
|
|
33
|
+
collectionSlug: slug,
|
|
34
|
+
overrideAccess: authorizedMCP.overrideAccess,
|
|
35
|
+
req,
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
const nextStep =
|
|
39
|
+
instructions.type === 'http'
|
|
40
|
+
? 'Upload bytes with instructions.request. After success, pass { source: "uploadReference", file: instructions.file }.'
|
|
41
|
+
: `Call "${instructions.name}" with file and data. After success, pass { source: "uploadReference", file: instructions.file }.`
|
|
42
|
+
|
|
43
|
+
return {
|
|
44
|
+
content: [
|
|
45
|
+
{
|
|
46
|
+
type: 'text',
|
|
47
|
+
text: `Upload instructions for collection "${slug}":\n\`\`\`json\n${JSON.stringify(instructions)}\n\`\`\`\n${nextStep}`,
|
|
48
|
+
},
|
|
49
|
+
],
|
|
50
|
+
structuredContent: { instructions },
|
|
51
|
+
}
|
|
52
|
+
} catch (error) {
|
|
53
|
+
const message = error instanceof Error ? error.message : 'Unknown error'
|
|
54
|
+
return {
|
|
55
|
+
content: [
|
|
56
|
+
{
|
|
57
|
+
type: 'text',
|
|
58
|
+
text: `Error getting upload instructions for collection "${slug}": ${message}`,
|
|
59
|
+
},
|
|
60
|
+
],
|
|
61
|
+
isError: true,
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
})
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import type { CollectionSlug, GlobalSlug, PayloadRequest } from 'payload'
|
|
2
|
+
|
|
3
|
+
import { getCollectionInputSchema, getGlobalInputSchema, ValidationError } from 'payload'
|
|
4
|
+
|
|
5
|
+
import type { MCPToolResponse } from '../../types.js'
|
|
6
|
+
|
|
7
|
+
export const formatEntityError = ({
|
|
8
|
+
slug,
|
|
9
|
+
action,
|
|
10
|
+
entity,
|
|
11
|
+
error,
|
|
12
|
+
req,
|
|
13
|
+
}:
|
|
14
|
+
| {
|
|
15
|
+
action: 'creating' | 'duplicating' | 'updating'
|
|
16
|
+
entity: 'collection'
|
|
17
|
+
error: unknown
|
|
18
|
+
req: PayloadRequest
|
|
19
|
+
slug: CollectionSlug
|
|
20
|
+
}
|
|
21
|
+
| {
|
|
22
|
+
action: 'updating'
|
|
23
|
+
entity: 'global'
|
|
24
|
+
error: unknown
|
|
25
|
+
req: PayloadRequest
|
|
26
|
+
slug: GlobalSlug
|
|
27
|
+
}): MCPToolResponse => {
|
|
28
|
+
const message = error instanceof Error ? error.message : 'Unknown error'
|
|
29
|
+
const target = entity === 'collection' ? `document in collection "${slug}"` : `global "${slug}"`
|
|
30
|
+
|
|
31
|
+
if (!isValidationError(error, message)) {
|
|
32
|
+
return {
|
|
33
|
+
content: [{ type: 'text', text: `Error ${action} ${target}: ${message}` }],
|
|
34
|
+
isError: true,
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const schema =
|
|
39
|
+
entity === 'collection'
|
|
40
|
+
? getCollectionInputSchema({ collectionSlug: slug, req })
|
|
41
|
+
: getGlobalInputSchema({ globalSlug: slug, req })
|
|
42
|
+
const errors = error instanceof ValidationError ? error.data.errors : [{ message }]
|
|
43
|
+
const validationMessage = errors
|
|
44
|
+
.map((issue) => `${'path' in issue ? `${issue.path}: ` : ''}${issue.message}`)
|
|
45
|
+
.join('\n')
|
|
46
|
+
const schemaText = schema
|
|
47
|
+
? `\n\nUse this schema for data:\n\`\`\`json\n${JSON.stringify(schema)}\n\`\`\``
|
|
48
|
+
: ''
|
|
49
|
+
|
|
50
|
+
return {
|
|
51
|
+
content: [
|
|
52
|
+
{ type: 'text', text: `Error ${action} ${target}: ${validationMessage}${schemaText}` },
|
|
53
|
+
],
|
|
54
|
+
isError: true,
|
|
55
|
+
...(schema
|
|
56
|
+
? {
|
|
57
|
+
structuredContent: {
|
|
58
|
+
slug,
|
|
59
|
+
errors,
|
|
60
|
+
schema,
|
|
61
|
+
},
|
|
62
|
+
}
|
|
63
|
+
: {}),
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const isValidationError = (error: unknown, message: string): boolean => {
|
|
68
|
+
if (error instanceof ValidationError) {
|
|
69
|
+
return true
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const name = error && typeof error === 'object' && 'name' in error ? error.name : undefined
|
|
73
|
+
|
|
74
|
+
return (
|
|
75
|
+
name === 'CastError' || message.includes('Cast to ') || message.includes('validation failed')
|
|
76
|
+
)
|
|
77
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { getAccessResults, getConfigInfoInputSchema, isEntityHidden } from 'payload'
|
|
2
|
+
|
|
3
|
+
import { defineTool } from '../../defineTool.js'
|
|
4
|
+
|
|
5
|
+
export const getConfigInfoTool = defineTool({
|
|
6
|
+
annotations: {
|
|
7
|
+
destructiveHint: false,
|
|
8
|
+
idempotentHint: true,
|
|
9
|
+
openWorldHint: false,
|
|
10
|
+
readOnlyHint: true,
|
|
11
|
+
title: 'Config Info',
|
|
12
|
+
},
|
|
13
|
+
description: 'List the Payload collection and global slugs visible to this MCP client.',
|
|
14
|
+
input: getConfigInfoInputSchema,
|
|
15
|
+
}).handler(async ({ authorizedMCP, req }) => {
|
|
16
|
+
const user = req.user
|
|
17
|
+
const permissions = authorizedMCP.overrideAccess ? null : await getAccessResults({ req })
|
|
18
|
+
const authorizedCollectionSlugs = new Set<string>()
|
|
19
|
+
const authorizedGlobalSlugs = new Set<string>()
|
|
20
|
+
|
|
21
|
+
for (const item of authorizedMCP.items) {
|
|
22
|
+
if (item.type === 'collectionTool') {
|
|
23
|
+
authorizedCollectionSlugs.add(item.collectionSlug)
|
|
24
|
+
} else if (item.type === 'globalTool') {
|
|
25
|
+
authorizedGlobalSlugs.add(item.globalSlug)
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const collections: string[] = []
|
|
30
|
+
const globals: string[] = []
|
|
31
|
+
|
|
32
|
+
for (const collection of req.payload.config.collections) {
|
|
33
|
+
if (!authorizedCollectionSlugs.has(collection.slug)) {
|
|
34
|
+
continue
|
|
35
|
+
}
|
|
36
|
+
if (user && isEntityHidden({ hidden: collection.admin.hidden, user })) {
|
|
37
|
+
continue
|
|
38
|
+
}
|
|
39
|
+
if (!authorizedMCP.overrideAccess && !permissions?.collections?.[collection.slug]?.read) {
|
|
40
|
+
continue
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
collections.push(collection.slug)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
for (const global of req.payload.config.globals) {
|
|
47
|
+
if (!authorizedGlobalSlugs.has(global.slug)) {
|
|
48
|
+
continue
|
|
49
|
+
}
|
|
50
|
+
if (user && isEntityHidden({ hidden: global.admin.hidden, user })) {
|
|
51
|
+
continue
|
|
52
|
+
}
|
|
53
|
+
if (!authorizedMCP.overrideAccess && !permissions?.globals?.[global.slug]?.read) {
|
|
54
|
+
continue
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
globals.push(global.slug)
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return {
|
|
61
|
+
content: [
|
|
62
|
+
{
|
|
63
|
+
type: 'text',
|
|
64
|
+
text: `Collections: ${collections.join(', ') || 'none'}\nGlobals: ${globals.join(', ') || 'none'}`,
|
|
65
|
+
},
|
|
66
|
+
],
|
|
67
|
+
}
|
|
68
|
+
})
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { countGlobalVersionsInputSchema } from 'payload'
|
|
2
|
+
|
|
3
|
+
import { defaultAccess } from '../../../defaultAccess.js'
|
|
4
|
+
import { defineGlobalTool } from '../../../defineTool.js'
|
|
5
|
+
import { getLogger } from '../../../utils/getLogger.js'
|
|
6
|
+
|
|
7
|
+
const DEFAULT_DESCRIPTION =
|
|
8
|
+
'Count global versions in any version-enabled global by passing the global slug and optional where clause.'
|
|
9
|
+
|
|
10
|
+
export const countGlobalVersionsTool = defineGlobalTool({
|
|
11
|
+
access: (args) =>
|
|
12
|
+
defaultAccess(args) && Boolean(args.permissions?.globals?.[args.slug]?.readVersions),
|
|
13
|
+
annotations: {
|
|
14
|
+
destructiveHint: false,
|
|
15
|
+
idempotentHint: true,
|
|
16
|
+
openWorldHint: false,
|
|
17
|
+
readOnlyHint: true,
|
|
18
|
+
title: 'Count Global Versions',
|
|
19
|
+
},
|
|
20
|
+
description: DEFAULT_DESCRIPTION,
|
|
21
|
+
input: countGlobalVersionsInputSchema,
|
|
22
|
+
}).handler(async ({ slug, authorizedMCP, input, req }) => {
|
|
23
|
+
const payload = req.payload
|
|
24
|
+
const logger = getLogger({ payload })
|
|
25
|
+
const { locale, where } = input
|
|
26
|
+
|
|
27
|
+
logger.info(`Counting versions for global: ${slug}`)
|
|
28
|
+
|
|
29
|
+
try {
|
|
30
|
+
const result = await payload.countGlobalVersions({
|
|
31
|
+
global: slug,
|
|
32
|
+
overrideAccess: authorizedMCP.overrideAccess,
|
|
33
|
+
req,
|
|
34
|
+
...(locale ? { locale } : {}),
|
|
35
|
+
...(where ? { where } : {}),
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
return {
|
|
39
|
+
content: [
|
|
40
|
+
{
|
|
41
|
+
type: 'text',
|
|
42
|
+
text: `Global "${slug}" contains ${result.totalDocs} matching versions.\n\`\`\`json\n${JSON.stringify(result)}\n\`\`\``,
|
|
43
|
+
},
|
|
44
|
+
],
|
|
45
|
+
doc: result,
|
|
46
|
+
}
|
|
47
|
+
} catch (error) {
|
|
48
|
+
const errorMessage = error instanceof Error ? error.message : 'Unknown error'
|
|
49
|
+
logger.error(`Error counting versions for global ${slug}: ${errorMessage}`)
|
|
50
|
+
return {
|
|
51
|
+
content: [
|
|
52
|
+
{
|
|
53
|
+
type: 'text',
|
|
54
|
+
text: `❌ **Error counting versions for global "${slug}":** ${errorMessage}`,
|
|
55
|
+
},
|
|
56
|
+
],
|
|
57
|
+
isError: true,
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
})
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { findGlobalInputSchema } from 'payload'
|
|
2
|
+
|
|
3
|
+
import { defaultAccess } from '../../../defaultAccess.js'
|
|
4
|
+
import { defineGlobalTool } from '../../../defineTool.js'
|
|
5
|
+
import { getLogger } from '../../../utils/getLogger.js'
|
|
6
|
+
|
|
7
|
+
const DEFAULT_DESCRIPTION = 'Find any Payload global by passing the global slug.'
|
|
8
|
+
|
|
9
|
+
export const findGlobalTool = defineGlobalTool({
|
|
10
|
+
access: (args) => defaultAccess(args) && Boolean(args.permissions?.globals?.[args.slug]?.read),
|
|
11
|
+
annotations: {
|
|
12
|
+
destructiveHint: false,
|
|
13
|
+
idempotentHint: true,
|
|
14
|
+
openWorldHint: false,
|
|
15
|
+
readOnlyHint: true,
|
|
16
|
+
title: 'Find Global',
|
|
17
|
+
},
|
|
18
|
+
description: DEFAULT_DESCRIPTION,
|
|
19
|
+
input: findGlobalInputSchema,
|
|
20
|
+
}).handler(async ({ slug, authorizedMCP, input, req }) => {
|
|
21
|
+
const payload = req.payload
|
|
22
|
+
const logger = getLogger({ payload })
|
|
23
|
+
|
|
24
|
+
const { depth, fallbackLocale, locale, populate, select } = input
|
|
25
|
+
|
|
26
|
+
logger.info(`Reading global: ${slug}, depth: ${depth}${locale ? `, locale: ${locale}` : ''}`)
|
|
27
|
+
|
|
28
|
+
try {
|
|
29
|
+
const findOptions: Parameters<typeof payload.findGlobal>[0] = {
|
|
30
|
+
slug,
|
|
31
|
+
depth,
|
|
32
|
+
overrideAccess: authorizedMCP.overrideAccess,
|
|
33
|
+
req,
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (locale) {
|
|
37
|
+
findOptions.locale = locale
|
|
38
|
+
}
|
|
39
|
+
if (fallbackLocale !== undefined) {
|
|
40
|
+
findOptions.fallbackLocale = fallbackLocale
|
|
41
|
+
}
|
|
42
|
+
if (select) {
|
|
43
|
+
findOptions.select = select
|
|
44
|
+
}
|
|
45
|
+
if (populate) {
|
|
46
|
+
findOptions.populate = populate
|
|
47
|
+
}
|
|
48
|
+
const result = await payload.findGlobal(findOptions)
|
|
49
|
+
|
|
50
|
+
return {
|
|
51
|
+
content: [
|
|
52
|
+
{
|
|
53
|
+
type: 'text',
|
|
54
|
+
text: `Global "${slug}":\n\`\`\`json\n${JSON.stringify(result)}\n\`\`\``,
|
|
55
|
+
},
|
|
56
|
+
],
|
|
57
|
+
doc: result,
|
|
58
|
+
}
|
|
59
|
+
} catch (error) {
|
|
60
|
+
const errorMessage = error instanceof Error ? error.message : 'Unknown error'
|
|
61
|
+
logger.error(`Error reading global ${slug}: ${errorMessage}`)
|
|
62
|
+
return {
|
|
63
|
+
content: [{ type: 'text', text: `❌ **Error reading global "${slug}":** ${errorMessage}` }],
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
})
|