@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,84 @@
|
|
|
1
|
+
import {
|
|
2
|
+
duplicateDocumentInputSchema,
|
|
3
|
+
getCollectionVirtualFieldNames,
|
|
4
|
+
parseDocumentID,
|
|
5
|
+
stripVirtualFields,
|
|
6
|
+
transformPointDataToPayload,
|
|
7
|
+
validateCollectionData,
|
|
8
|
+
} from 'payload'
|
|
9
|
+
|
|
10
|
+
import { defaultAccess } from '../../../defaultAccess.js'
|
|
11
|
+
import { defineCollectionTool } from '../../../defineTool.js'
|
|
12
|
+
import { getLogger } from '../../../utils/getLogger.js'
|
|
13
|
+
import { formatEntityError } from '../formatEntityError.js'
|
|
14
|
+
|
|
15
|
+
const DEFAULT_DESCRIPTION =
|
|
16
|
+
'Duplicate a document in any collection by passing the collection slug and source document ID.'
|
|
17
|
+
|
|
18
|
+
export const duplicateDocumentTool = defineCollectionTool({
|
|
19
|
+
access: (args) =>
|
|
20
|
+
defaultAccess(args) && Boolean(args.permissions?.collections?.[args.slug]?.create),
|
|
21
|
+
annotations: {
|
|
22
|
+
destructiveHint: false,
|
|
23
|
+
idempotentHint: false,
|
|
24
|
+
openWorldHint: false,
|
|
25
|
+
readOnlyHint: false,
|
|
26
|
+
title: 'Duplicate Document',
|
|
27
|
+
},
|
|
28
|
+
description: DEFAULT_DESCRIPTION,
|
|
29
|
+
input: duplicateDocumentInputSchema,
|
|
30
|
+
}).handler(async ({ slug, authorizedMCP, input, req }) => {
|
|
31
|
+
const payload = req.payload
|
|
32
|
+
const logger = getLogger({ payload })
|
|
33
|
+
const { id, data, depth, draft, fallbackLocale, locale, populate, select, selectedLocales } =
|
|
34
|
+
input
|
|
35
|
+
|
|
36
|
+
logger.info(`Duplicating document in collection: ${slug} with ID: ${id}`)
|
|
37
|
+
|
|
38
|
+
try {
|
|
39
|
+
const virtualFieldNames = getCollectionVirtualFieldNames(payload.config, slug)
|
|
40
|
+
const inputData = data ? stripVirtualFields(data, virtualFieldNames) : undefined
|
|
41
|
+
|
|
42
|
+
if (inputData) {
|
|
43
|
+
validateCollectionData({
|
|
44
|
+
slug,
|
|
45
|
+
data: inputData,
|
|
46
|
+
partial: true,
|
|
47
|
+
req,
|
|
48
|
+
})
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const parsedData = inputData ? transformPointDataToPayload(inputData) : undefined
|
|
52
|
+
|
|
53
|
+
const result = await payload.duplicate({
|
|
54
|
+
id: parseDocumentID({ id, collectionSlug: slug, payload }),
|
|
55
|
+
collection: slug,
|
|
56
|
+
depth,
|
|
57
|
+
draft,
|
|
58
|
+
overrideAccess: authorizedMCP.overrideAccess,
|
|
59
|
+
req,
|
|
60
|
+
...(parsedData ? { data: parsedData } : {}),
|
|
61
|
+
...(locale ? { locale } : {}),
|
|
62
|
+
...(fallbackLocale !== undefined ? { fallbackLocale } : {}),
|
|
63
|
+
...(populate ? { populate } : {}),
|
|
64
|
+
...(select ? { select } : {}),
|
|
65
|
+
...(selectedLocales ? { selectedLocales } : {}),
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
logger.info(`Successfully duplicated document in ${slug} from ID: ${id}`)
|
|
69
|
+
|
|
70
|
+
return {
|
|
71
|
+
content: [
|
|
72
|
+
{
|
|
73
|
+
type: 'text',
|
|
74
|
+
text: `Document duplicated successfully in collection "${slug}"!\nDuplicated document:\n\`\`\`json\n${JSON.stringify(result)}\n\`\`\``,
|
|
75
|
+
},
|
|
76
|
+
],
|
|
77
|
+
doc: result,
|
|
78
|
+
}
|
|
79
|
+
} catch (error) {
|
|
80
|
+
const errorMessage = error instanceof Error ? error.message : 'Unknown error'
|
|
81
|
+
logger.error(`Error duplicating document in ${slug}: ${errorMessage}`)
|
|
82
|
+
return formatEntityError({ slug, action: 'duplicating', entity: 'collection', error, req })
|
|
83
|
+
}
|
|
84
|
+
})
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import type { PayloadRequest } from 'payload'
|
|
2
|
+
|
|
3
|
+
import { describe, expect, it } from 'vitest'
|
|
4
|
+
|
|
5
|
+
import { fileInputSchema, resolveFile } from './fileInput.js'
|
|
6
|
+
|
|
7
|
+
describe('MCP file input', () => {
|
|
8
|
+
it('should reject malformed MIME types', () => {
|
|
9
|
+
const result = fileInputSchema.safeParse({
|
|
10
|
+
data: 'aGVsbG8=',
|
|
11
|
+
mimeType: 'text/plain\r\nx-test: value',
|
|
12
|
+
name: 'hello.txt',
|
|
13
|
+
source: 'base64',
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
expect(result.success).toBe(false)
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
it('should accept a prepared upload', () => {
|
|
20
|
+
const result = fileInputSchema.safeParse({
|
|
21
|
+
file: {
|
|
22
|
+
filename: 'image.png',
|
|
23
|
+
mimeType: 'image/png',
|
|
24
|
+
size: 123,
|
|
25
|
+
uploadReference: { uploadId: 'upload-id' },
|
|
26
|
+
},
|
|
27
|
+
source: 'uploadReference',
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
expect(result.success).toBe(true)
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
it('should reject oversized base64 files', async () => {
|
|
34
|
+
const req = createRequest({ maxFileSize: 4 })
|
|
35
|
+
|
|
36
|
+
await expect(
|
|
37
|
+
resolveFile({
|
|
38
|
+
slug: 'media',
|
|
39
|
+
input: {
|
|
40
|
+
data: Buffer.from('hello').toString('base64'),
|
|
41
|
+
mimeType: 'text/plain',
|
|
42
|
+
name: 'hello.txt',
|
|
43
|
+
source: 'base64',
|
|
44
|
+
},
|
|
45
|
+
req,
|
|
46
|
+
}),
|
|
47
|
+
).rejects.toThrow('File exceeds the 4 byte upload limit.')
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
it('should reject URLs outside the collection allowlist', async () => {
|
|
51
|
+
const req = createRequest({
|
|
52
|
+
allowList: [{ hostname: 'assets.example.com', protocol: 'https' }],
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
await expect(
|
|
56
|
+
resolveFile({
|
|
57
|
+
slug: 'media',
|
|
58
|
+
input: {
|
|
59
|
+
source: 'externalURL',
|
|
60
|
+
url: 'https://example.com/image.png',
|
|
61
|
+
},
|
|
62
|
+
req,
|
|
63
|
+
}),
|
|
64
|
+
).rejects.toThrow('The provided file URL is not allowed.')
|
|
65
|
+
})
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
function createRequest({
|
|
69
|
+
allowList,
|
|
70
|
+
maxFileSize,
|
|
71
|
+
}: {
|
|
72
|
+
allowList?: Array<{ hostname: string; protocol: 'http' | 'https' }>
|
|
73
|
+
maxFileSize?: number
|
|
74
|
+
}): PayloadRequest {
|
|
75
|
+
return {
|
|
76
|
+
payload: {
|
|
77
|
+
collections: {
|
|
78
|
+
media: {
|
|
79
|
+
config: {
|
|
80
|
+
upload: allowList ? { pasteURL: { allowList } } : {},
|
|
81
|
+
},
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
config: {
|
|
85
|
+
upload: {
|
|
86
|
+
limits: {
|
|
87
|
+
fileSize: maxFileSize,
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
},
|
|
91
|
+
},
|
|
92
|
+
} as unknown as PayloadRequest
|
|
93
|
+
}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import type { CollectionSlug, File, PayloadRequest } from 'payload'
|
|
2
|
+
|
|
3
|
+
import { APIError, z } from 'payload'
|
|
4
|
+
import {
|
|
5
|
+
externalURLInputSchema,
|
|
6
|
+
getFileFromUploadInstructions,
|
|
7
|
+
resolveURLUploadInput,
|
|
8
|
+
} from 'payload/internal'
|
|
9
|
+
import { sanitizeFilename } from 'payload/shared'
|
|
10
|
+
|
|
11
|
+
const mimeTypeSchema = z
|
|
12
|
+
.string()
|
|
13
|
+
.check(
|
|
14
|
+
z.regex(
|
|
15
|
+
/^[!#$%&'*+.^`|~\w-]+\/[!#$%&'*+.^`|~\w-]+$/,
|
|
16
|
+
'MIME type must use the type/subtype format',
|
|
17
|
+
),
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
const uploadFileSchema = z.strictObject({
|
|
21
|
+
filename: z.string(),
|
|
22
|
+
mimeType: z.string(),
|
|
23
|
+
size: z.int().check(z.nonnegative()),
|
|
24
|
+
uploadReference: z.record(z.string(), z.unknown()),
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
export const fileInputSchema = z
|
|
28
|
+
.discriminatedUnion('source', [
|
|
29
|
+
z.strictObject({
|
|
30
|
+
name: z.string().check(z.minLength(1), z.describe('The file name, including its extension.')),
|
|
31
|
+
data: z
|
|
32
|
+
.string()
|
|
33
|
+
.check(z.describe('The base64-encoded file bytes, without a data URL prefix.')),
|
|
34
|
+
mimeType: mimeTypeSchema.check(z.describe('The file MIME type, for example image/png.')),
|
|
35
|
+
source: z.literal('base64'),
|
|
36
|
+
}),
|
|
37
|
+
externalURLInputSchema,
|
|
38
|
+
z.strictObject({
|
|
39
|
+
file: uploadFileSchema.check(z.describe('getUploadInstructions file field post-upload.')),
|
|
40
|
+
source: z.literal('uploadReference'),
|
|
41
|
+
}),
|
|
42
|
+
])
|
|
43
|
+
.check(
|
|
44
|
+
z.describe(
|
|
45
|
+
'A file for an upload collection. Prefer uploadReference after its upload succeeds; use base64 only for small local files or externalURL for an online file.',
|
|
46
|
+
),
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
type FileInput = z.infer<typeof fileInputSchema>
|
|
50
|
+
|
|
51
|
+
export async function resolveFile({
|
|
52
|
+
slug,
|
|
53
|
+
input,
|
|
54
|
+
req,
|
|
55
|
+
}: {
|
|
56
|
+
input?: FileInput
|
|
57
|
+
req: PayloadRequest
|
|
58
|
+
slug: CollectionSlug
|
|
59
|
+
}): Promise<File | undefined> {
|
|
60
|
+
if (!input) {
|
|
61
|
+
return undefined
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (input.source === 'uploadReference') {
|
|
65
|
+
try {
|
|
66
|
+
return await getFileFromUploadInstructions({ collectionSlug: slug, file: input.file, req })
|
|
67
|
+
} catch (error) {
|
|
68
|
+
if (error instanceof Error && error.message === 'Staged upload was not found.') {
|
|
69
|
+
throw new APIError(
|
|
70
|
+
'Staged upload not found. Complete the upload action first, or use base64 for small local files.',
|
|
71
|
+
400,
|
|
72
|
+
)
|
|
73
|
+
}
|
|
74
|
+
throw error
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (input.source === 'externalURL') {
|
|
79
|
+
return resolveURLUploadInput({ slug, input, req })
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const uploadConfig = req.payload.collections[slug]?.config.upload
|
|
83
|
+
|
|
84
|
+
if (!uploadConfig) {
|
|
85
|
+
throw new APIError(`Collection "${slug}" does not support file uploads.`, 400)
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const maxFileSize = req.payload.config.upload.limits?.fileSize
|
|
89
|
+
const data = decodeBase64({ maxFileSize, value: input.data })
|
|
90
|
+
const file: File = {
|
|
91
|
+
name: sanitizeFilename(input.name),
|
|
92
|
+
data,
|
|
93
|
+
mimetype: input.mimeType,
|
|
94
|
+
size: data.length,
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
if (maxFileSize !== undefined && Number.isFinite(maxFileSize) && file.size > maxFileSize) {
|
|
98
|
+
throw new APIError(`File exceeds the ${maxFileSize} byte upload limit.`, 400)
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
return file
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function decodeBase64({ maxFileSize, value }: { maxFileSize?: number; value: string }): Buffer {
|
|
105
|
+
const normalized = value.replace(/\s/g, '')
|
|
106
|
+
|
|
107
|
+
if (!/^[a-z0-9+/]*={0,2}$/i.test(normalized) || normalized.length % 4 === 1) {
|
|
108
|
+
throw new APIError('File data must be valid base64.', 400)
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
if (maxFileSize !== undefined && Number.isFinite(maxFileSize)) {
|
|
112
|
+
const paddingLength = normalized.endsWith('==') ? 2 : normalized.endsWith('=') ? 1 : 0
|
|
113
|
+
const decodedSize = Math.floor((normalized.length * 3) / 4) - paddingLength
|
|
114
|
+
|
|
115
|
+
if (decodedSize > maxFileSize) {
|
|
116
|
+
throw new APIError(`File exceeds the ${maxFileSize} byte upload limit.`, 400)
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
const data = Buffer.from(normalized, 'base64')
|
|
121
|
+
|
|
122
|
+
if (data.toString('base64').replace(/=+$/, '') !== normalized.replace(/=+$/, '')) {
|
|
123
|
+
throw new APIError('File data must be valid base64.', 400)
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
return data
|
|
127
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { findDistinctInputSchema } 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
|
+
'Find distinct values for a field in any collection by passing the collection slug and field path.'
|
|
9
|
+
|
|
10
|
+
export const findDistinctTool = defineCollectionTool({
|
|
11
|
+
access: (args) =>
|
|
12
|
+
defaultAccess(args) && Boolean(args.permissions?.collections?.[args.slug]?.read),
|
|
13
|
+
annotations: {
|
|
14
|
+
destructiveHint: false,
|
|
15
|
+
idempotentHint: true,
|
|
16
|
+
openWorldHint: false,
|
|
17
|
+
readOnlyHint: true,
|
|
18
|
+
title: 'Find Distinct',
|
|
19
|
+
},
|
|
20
|
+
description: DEFAULT_DESCRIPTION,
|
|
21
|
+
input: findDistinctInputSchema,
|
|
22
|
+
}).handler(async ({ slug, authorizedMCP, input, req }) => {
|
|
23
|
+
const payload = req.payload
|
|
24
|
+
const logger = getLogger({ payload })
|
|
25
|
+
const { depth, field, limit, locale, page, populate, sort, trash, where } = input
|
|
26
|
+
|
|
27
|
+
logger.info(`Finding distinct values in collection: ${slug}, field: ${field}`)
|
|
28
|
+
|
|
29
|
+
try {
|
|
30
|
+
const result = await payload.findDistinct({
|
|
31
|
+
collection: slug,
|
|
32
|
+
depth,
|
|
33
|
+
field,
|
|
34
|
+
overrideAccess: authorizedMCP.overrideAccess,
|
|
35
|
+
req,
|
|
36
|
+
...(limit ? { limit } : {}),
|
|
37
|
+
...(locale ? { locale } : {}),
|
|
38
|
+
...(page ? { page } : {}),
|
|
39
|
+
...(populate ? { populate } : {}),
|
|
40
|
+
...(sort ? { sort } : {}),
|
|
41
|
+
...(trash !== undefined ? { trash } : {}),
|
|
42
|
+
...(where ? { where } : {}),
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
return {
|
|
46
|
+
content: [
|
|
47
|
+
{
|
|
48
|
+
type: 'text',
|
|
49
|
+
text: `Distinct values for "${field}" in collection "${slug}":\n\`\`\`json\n${JSON.stringify(result)}\n\`\`\``,
|
|
50
|
+
},
|
|
51
|
+
],
|
|
52
|
+
doc: result as unknown as Record<string, unknown>,
|
|
53
|
+
}
|
|
54
|
+
} catch (error) {
|
|
55
|
+
const errorMessage = error instanceof Error ? error.message : 'Unknown error'
|
|
56
|
+
logger.error(`Error finding distinct values in ${slug}: ${errorMessage}`)
|
|
57
|
+
return {
|
|
58
|
+
content: [
|
|
59
|
+
{
|
|
60
|
+
type: 'text',
|
|
61
|
+
text: `❌ **Error finding distinct values in collection "${slug}":** ${errorMessage}`,
|
|
62
|
+
},
|
|
63
|
+
],
|
|
64
|
+
isError: true,
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
})
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { findDocumentsInputSchema, parseDocumentID } 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
|
+
'Find documents in any collection by passing the collection slug and optional ID or where clause.'
|
|
9
|
+
|
|
10
|
+
export const findDocumentsTool = defineCollectionTool({
|
|
11
|
+
access: (args) =>
|
|
12
|
+
defaultAccess(args) && Boolean(args.permissions?.collections?.[args.slug]?.read),
|
|
13
|
+
annotations: {
|
|
14
|
+
destructiveHint: false,
|
|
15
|
+
idempotentHint: true,
|
|
16
|
+
openWorldHint: false,
|
|
17
|
+
readOnlyHint: true,
|
|
18
|
+
title: 'Find Documents',
|
|
19
|
+
},
|
|
20
|
+
description: DEFAULT_DESCRIPTION,
|
|
21
|
+
input: findDocumentsInputSchema,
|
|
22
|
+
}).handler(async ({ slug, authorizedMCP, input, req }) => {
|
|
23
|
+
const payload = req.payload
|
|
24
|
+
const logger = getLogger({ payload })
|
|
25
|
+
|
|
26
|
+
const {
|
|
27
|
+
id,
|
|
28
|
+
depth,
|
|
29
|
+
draft,
|
|
30
|
+
fallbackLocale,
|
|
31
|
+
joins,
|
|
32
|
+
limit,
|
|
33
|
+
locale,
|
|
34
|
+
page,
|
|
35
|
+
pagination,
|
|
36
|
+
populate,
|
|
37
|
+
select,
|
|
38
|
+
sort,
|
|
39
|
+
trash,
|
|
40
|
+
where,
|
|
41
|
+
} = input
|
|
42
|
+
|
|
43
|
+
logger.info(
|
|
44
|
+
`Reading document from collection: ${slug}${id ? ` with ID: ${id}` : ''}, limit: ${limit}, page: ${page}${locale ? `, locale: ${locale}` : ''}`,
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
try {
|
|
48
|
+
if (id !== undefined) {
|
|
49
|
+
try {
|
|
50
|
+
const doc = await payload.findByID({
|
|
51
|
+
id: parseDocumentID({ id, collectionSlug: slug, payload }),
|
|
52
|
+
collection: slug,
|
|
53
|
+
depth,
|
|
54
|
+
overrideAccess: authorizedMCP.overrideAccess,
|
|
55
|
+
req,
|
|
56
|
+
...(select && { select }),
|
|
57
|
+
...(populate && { populate }),
|
|
58
|
+
...(joins !== undefined && { joins }),
|
|
59
|
+
...(locale && { locale }),
|
|
60
|
+
...(fallbackLocale !== undefined && { fallbackLocale }),
|
|
61
|
+
...(draft !== undefined && { draft }),
|
|
62
|
+
...(trash !== undefined && { trash }),
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
return {
|
|
66
|
+
content: [
|
|
67
|
+
{
|
|
68
|
+
type: 'text',
|
|
69
|
+
text: `Document from collection "${slug}":\n${JSON.stringify(doc)}`,
|
|
70
|
+
},
|
|
71
|
+
],
|
|
72
|
+
doc,
|
|
73
|
+
}
|
|
74
|
+
} catch {
|
|
75
|
+
logger.warn(`Document not found with ID: ${id} in collection: ${slug}`)
|
|
76
|
+
return {
|
|
77
|
+
content: [
|
|
78
|
+
{
|
|
79
|
+
type: 'text',
|
|
80
|
+
text: `Error: Document with ID "${id}" not found in collection "${slug}"`,
|
|
81
|
+
},
|
|
82
|
+
],
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const findOptions: Parameters<typeof payload.find>[0] = {
|
|
88
|
+
collection: slug,
|
|
89
|
+
depth,
|
|
90
|
+
limit,
|
|
91
|
+
overrideAccess: authorizedMCP.overrideAccess,
|
|
92
|
+
page,
|
|
93
|
+
req,
|
|
94
|
+
...(select && { select }),
|
|
95
|
+
...(populate && { populate }),
|
|
96
|
+
...(joins !== undefined && { joins }),
|
|
97
|
+
...(locale && { locale }),
|
|
98
|
+
...(fallbackLocale !== undefined && { fallbackLocale }),
|
|
99
|
+
...(draft !== undefined && { draft }),
|
|
100
|
+
...(pagination !== undefined && { pagination }),
|
|
101
|
+
...(trash !== undefined && { trash }),
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
if (sort) {
|
|
105
|
+
findOptions.sort = sort
|
|
106
|
+
}
|
|
107
|
+
if (where) {
|
|
108
|
+
findOptions.where = where
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const result = await payload.find(findOptions)
|
|
112
|
+
|
|
113
|
+
let responseText = `Collection: "${slug}"\nTotal: ${result.totalDocs} documents\nPage: ${result.page} of ${result.totalPages}\n`
|
|
114
|
+
for (const doc of result.docs) {
|
|
115
|
+
responseText += `\n\`\`\`json\n${JSON.stringify(doc)}\n\`\`\``
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
return {
|
|
119
|
+
content: [{ type: 'text', text: responseText }],
|
|
120
|
+
doc: result as unknown as Record<string, unknown>,
|
|
121
|
+
}
|
|
122
|
+
} catch (error) {
|
|
123
|
+
const errorMessage = error instanceof Error ? error.message : 'Unknown error'
|
|
124
|
+
logger.error(`Error reading documents from collection ${slug}: ${errorMessage}`)
|
|
125
|
+
return {
|
|
126
|
+
content: [
|
|
127
|
+
{
|
|
128
|
+
type: 'text',
|
|
129
|
+
text: `❌ **Error reading documents from collection "${slug}":** ${errorMessage}`,
|
|
130
|
+
},
|
|
131
|
+
],
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
})
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { findVersionByIDInputSchema } 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
|
+
'Find a specific document version in any version-enabled collection by passing the collection slug and version ID.'
|
|
9
|
+
|
|
10
|
+
export const findVersionByIDTool = defineCollectionTool({
|
|
11
|
+
access: (args) =>
|
|
12
|
+
defaultAccess(args) && Boolean(args.permissions?.collections?.[args.slug]?.readVersions),
|
|
13
|
+
annotations: {
|
|
14
|
+
destructiveHint: false,
|
|
15
|
+
idempotentHint: true,
|
|
16
|
+
openWorldHint: false,
|
|
17
|
+
readOnlyHint: true,
|
|
18
|
+
title: 'Find Version By ID',
|
|
19
|
+
},
|
|
20
|
+
description: DEFAULT_DESCRIPTION,
|
|
21
|
+
input: findVersionByIDInputSchema,
|
|
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, trash } = input
|
|
26
|
+
|
|
27
|
+
logger.info(`Finding version in collection: ${slug} with ID: ${id}`)
|
|
28
|
+
|
|
29
|
+
try {
|
|
30
|
+
const result = await payload.findVersionByID({
|
|
31
|
+
id: String(id),
|
|
32
|
+
collection: slug,
|
|
33
|
+
depth,
|
|
34
|
+
overrideAccess: authorizedMCP.overrideAccess,
|
|
35
|
+
req,
|
|
36
|
+
...(draft !== undefined ? { draft } : {}),
|
|
37
|
+
...(fallbackLocale !== undefined ? { fallbackLocale } : {}),
|
|
38
|
+
...(locale ? { locale } : {}),
|
|
39
|
+
...(populate ? { populate } : {}),
|
|
40
|
+
...(select ? { select } : {}),
|
|
41
|
+
...(trash !== undefined ? { trash } : {}),
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
return {
|
|
45
|
+
content: [
|
|
46
|
+
{
|
|
47
|
+
type: 'text',
|
|
48
|
+
text: `Version "${id}" from collection "${slug}":\n\`\`\`json\n${JSON.stringify(result)}\n\`\`\``,
|
|
49
|
+
},
|
|
50
|
+
],
|
|
51
|
+
doc: result as unknown as Record<string, unknown>,
|
|
52
|
+
}
|
|
53
|
+
} catch (error) {
|
|
54
|
+
const errorMessage = error instanceof Error ? error.message : 'Unknown error'
|
|
55
|
+
logger.error(`Error finding version ${id} in ${slug}: ${errorMessage}`)
|
|
56
|
+
return {
|
|
57
|
+
content: [
|
|
58
|
+
{
|
|
59
|
+
type: 'text',
|
|
60
|
+
text: `❌ **Error finding version "${id}" in collection "${slug}":** ${errorMessage}`,
|
|
61
|
+
},
|
|
62
|
+
],
|
|
63
|
+
isError: true,
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
})
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { findVersionsInputSchema } 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
|
+
'Find document versions in any version-enabled collection by passing the collection slug and optional where clause.'
|
|
9
|
+
|
|
10
|
+
export const findVersionsTool = defineCollectionTool({
|
|
11
|
+
access: (args) =>
|
|
12
|
+
defaultAccess(args) && Boolean(args.permissions?.collections?.[args.slug]?.readVersions),
|
|
13
|
+
annotations: {
|
|
14
|
+
destructiveHint: false,
|
|
15
|
+
idempotentHint: true,
|
|
16
|
+
openWorldHint: false,
|
|
17
|
+
readOnlyHint: true,
|
|
18
|
+
title: 'Find Versions',
|
|
19
|
+
},
|
|
20
|
+
description: DEFAULT_DESCRIPTION,
|
|
21
|
+
input: findVersionsInputSchema,
|
|
22
|
+
}).handler(async ({ slug, authorizedMCP, input, req }) => {
|
|
23
|
+
const payload = req.payload
|
|
24
|
+
const logger = getLogger({ payload })
|
|
25
|
+
const {
|
|
26
|
+
depth,
|
|
27
|
+
draft,
|
|
28
|
+
fallbackLocale,
|
|
29
|
+
limit,
|
|
30
|
+
locale,
|
|
31
|
+
page,
|
|
32
|
+
pagination,
|
|
33
|
+
populate,
|
|
34
|
+
select,
|
|
35
|
+
sort,
|
|
36
|
+
trash,
|
|
37
|
+
where,
|
|
38
|
+
} = input
|
|
39
|
+
|
|
40
|
+
logger.info(`Finding versions in collection: ${slug}, limit: ${limit}, page: ${page}`)
|
|
41
|
+
|
|
42
|
+
try {
|
|
43
|
+
const result = await payload.findVersions({
|
|
44
|
+
collection: slug,
|
|
45
|
+
depth,
|
|
46
|
+
limit,
|
|
47
|
+
overrideAccess: authorizedMCP.overrideAccess,
|
|
48
|
+
page,
|
|
49
|
+
req,
|
|
50
|
+
...(draft !== undefined ? { draft } : {}),
|
|
51
|
+
...(fallbackLocale !== undefined ? { fallbackLocale } : {}),
|
|
52
|
+
...(locale ? { locale } : {}),
|
|
53
|
+
...(pagination !== undefined ? { pagination } : {}),
|
|
54
|
+
...(populate ? { populate } : {}),
|
|
55
|
+
...(select ? { select } : {}),
|
|
56
|
+
...(sort ? { sort } : {}),
|
|
57
|
+
...(trash !== undefined ? { trash } : {}),
|
|
58
|
+
...(where ? { where } : {}),
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
return {
|
|
62
|
+
content: [
|
|
63
|
+
{
|
|
64
|
+
type: 'text',
|
|
65
|
+
text: `Versions for collection "${slug}":\n\`\`\`json\n${JSON.stringify(result)}\n\`\`\``,
|
|
66
|
+
},
|
|
67
|
+
],
|
|
68
|
+
doc: result as unknown as Record<string, unknown>,
|
|
69
|
+
}
|
|
70
|
+
} catch (error) {
|
|
71
|
+
const errorMessage = error instanceof Error ? error.message : 'Unknown error'
|
|
72
|
+
logger.error(`Error finding versions in ${slug}: ${errorMessage}`)
|
|
73
|
+
return {
|
|
74
|
+
content: [
|
|
75
|
+
{
|
|
76
|
+
type: 'text',
|
|
77
|
+
text: `❌ **Error finding versions in collection "${slug}":** ${errorMessage}`,
|
|
78
|
+
},
|
|
79
|
+
],
|
|
80
|
+
isError: true,
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
})
|