@payloadcms/plugin-mcp 4.0.0-internal.d28e9fb → 4.0.0-internal.d3909a9
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 +93 -0
- package/dist/endpoint/access.js.map +1 -0
- package/dist/endpoint/index.d.ts +3 -0
- package/dist/endpoint/index.d.ts.map +1 -0
- package/dist/endpoint/index.js +116 -0
- package/dist/endpoint/index.js.map +1 -0
- package/dist/exports/client.d.ts +2 -0
- package/dist/exports/client.d.ts.map +1 -0
- package/dist/exports/client.js +4 -0
- package/dist/exports/client.js.map +1 -0
- package/dist/exports/internal.d.ts +2 -0
- package/dist/exports/internal.d.ts.map +1 -0
- package/dist/exports/internal.js +3 -0
- package/dist/exports/internal.js.map +1 -0
- package/dist/index.d.ts +6 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +39 -67
- package/dist/index.js.map +1 -1
- package/dist/mcp/buildMcpServer.d.ts +19 -0
- package/dist/mcp/buildMcpServer.d.ts.map +1 -0
- package/dist/mcp/buildMcpServer.js +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 +233 -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 +263 -447
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +4 -1
- package/dist/types.js.map +1 -1
- package/dist/utils/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 +111 -0
- package/src/endpoint/index.ts +107 -0
- package/src/exports/client.ts +3 -0
- package/src/exports/internal.ts +1 -0
- package/src/index.ts +31 -89
- package/src/mcp/buildMcpServer.ts +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 +281 -0
- package/src/stdio.ts +131 -0
- package/src/types.ts +312 -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
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import { definePlugin } from 'payload'\n\nimport type {
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import { definePlugin } from 'payload'\n\nimport type { AuthorizedMCP, MCPPluginConfig, SanitizedMCPPluginConfig } from './types.js'\n\nimport { mcpEndpoint } from './endpoint/index.js'\nimport { sanitizeMCPConfig } from './mcp/sanitizeMCPConfig.js'\n\ndeclare module 'payload' {\n export interface PayloadRequestAPI {\n MCP: true\n }\n interface RegisteredPlugins {\n /** After the plugin's `plugin` callback runs, `options` holds the sanitized config. */\n '@payloadcms/plugin-mcp': MCPPluginConfig\n }\n}\n\nexport type { AuthorizedMCP, MCPPluginConfig, SanitizedMCPPluginConfig }\n\nexport { defineCollectionTool, defineGlobalTool, definePrompt, defineTool } from './defineTool.js'\n\nexport const mcpPlugin = definePlugin<MCPPluginConfig>({\n slug: '@payloadcms/plugin-mcp',\n order: 10,\n plugin: ({ config, options, plugins }) => {\n const pluginConfig = sanitizeMCPConfig({ config, pluginConfig: options })\n\n // Stash the sanitized config on plugin options so `getPluginConfig()` reads it.\n const registered = plugins['@payloadcms/plugin-mcp']\n if (registered) {\n // @ts-expect-error\n registered.sanitizedOptions = pluginConfig\n }\n\n if (pluginConfig.disabled) {\n return config\n }\n\n return {\n ...config,\n endpoints: [\n ...(config.endpoints ?? []),\n // Payload prefixes /api, so the full path is /api/mcp.\n { handler: mcpEndpoint, method: 'post', path: '/mcp' },\n // Streamable HTTP's optional server=>client GET stream. We don't offer\n // one, so answer 405 per spec-— clients then skip it cleanly\n {\n handler: () => new Response(null, { headers: { Allow: 'POST' }, status: 405 }),\n method: 'get',\n path: '/mcp',\n },\n ],\n }\n },\n})\n"],"names":["definePlugin","mcpEndpoint","sanitizeMCPConfig","defineCollectionTool","defineGlobalTool","definePrompt","defineTool","mcpPlugin","slug","order","plugin","config","options","plugins","pluginConfig","registered","sanitizedOptions","disabled","endpoints","handler","method","path","Response","headers","Allow","status"],"mappings":"AAAA,SAASA,YAAY,QAAQ,UAAS;AAItC,SAASC,WAAW,QAAQ,sBAAqB;AACjD,SAASC,iBAAiB,QAAQ,6BAA4B;AAc9D,SAASC,oBAAoB,EAAEC,gBAAgB,EAAEC,YAAY,EAAEC,UAAU,QAAQ,kBAAiB;AAElG,OAAO,MAAMC,YAAYP,aAA8B;IACrDQ,MAAM;IACNC,OAAO;IACPC,QAAQ,CAAC,EAAEC,MAAM,EAAEC,OAAO,EAAEC,OAAO,EAAE;QACnC,MAAMC,eAAeZ,kBAAkB;YAAES;YAAQG,cAAcF;QAAQ;QAEvE,gFAAgF;QAChF,MAAMG,aAAaF,OAAO,CAAC,yBAAyB;QACpD,IAAIE,YAAY;YACd,mBAAmB;YACnBA,WAAWC,gBAAgB,GAAGF;QAChC;QAEA,IAAIA,aAAaG,QAAQ,EAAE;YACzB,OAAON;QACT;QAEA,OAAO;YACL,GAAGA,MAAM;YACTO,WAAW;mBACLP,OAAOO,SAAS,IAAI,EAAE;gBAC1B,uDAAuD;gBACvD;oBAAEC,SAASlB;oBAAamB,QAAQ;oBAAQC,MAAM;gBAAO;gBACrD,uEAAuE;gBACvE,6DAA6D;gBAC7D;oBACEF,SAAS,IAAM,IAAIG,SAAS,MAAM;4BAAEC,SAAS;gCAAEC,OAAO;4BAAO;4BAAGC,QAAQ;wBAAI;oBAC5EL,QAAQ;oBACRC,MAAM;gBACR;aACD;QACH;IACF;AACF,GAAE"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { PayloadRequest } from 'payload';
|
|
2
|
+
import { McpServer } from '@modelcontextprotocol/server';
|
|
3
|
+
import type { AuthorizedMCP, SanitizedMCPPluginConfig } from '../types.js';
|
|
4
|
+
/**
|
|
5
|
+
* Serving-entry-agnostic core: registers every authorized MCP item onto a fresh
|
|
6
|
+
* `McpServer` and returns it. The HTTP and stdio entry point callers provide fresh
|
|
7
|
+
* instances from this builder while they own the transport and protocol-era
|
|
8
|
+
* decision.
|
|
9
|
+
*
|
|
10
|
+
* `req` is the request context handlers see. For HTTP it's the live
|
|
11
|
+
* `PayloadRequest` derived from the incoming HTTP request; for stdio it's a
|
|
12
|
+
* synthesized one built via `createPayloadRequest`.
|
|
13
|
+
*/
|
|
14
|
+
export declare const buildMcpServer: ({ authorizedMCP, pluginConfig, req, }: {
|
|
15
|
+
authorizedMCP: AuthorizedMCP;
|
|
16
|
+
pluginConfig: SanitizedMCPPluginConfig;
|
|
17
|
+
req: PayloadRequest;
|
|
18
|
+
}) => McpServer;
|
|
19
|
+
//# sourceMappingURL=buildMcpServer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"buildMcpServer.d.ts","sourceRoot":"","sources":["../../src/mcp/buildMcpServer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAE7C,OAAO,EAAE,SAAS,EAAsB,MAAM,8BAA8B,CAAA;AAG5E,OAAO,KAAK,EACV,aAAa,EAMb,wBAAwB,EAEzB,MAAM,aAAa,CAAA;AAKpB;;;;;;;;;GASG;AACH,eAAO,MAAM,cAAc,0CAIxB;IACD,aAAa,EAAE,aAAa,CAAA;IAC5B,YAAY,EAAE,wBAAwB,CAAA;IACtC,GAAG,EAAE,cAAc,CAAA;CACpB,KAAG,SAgNH,CAAA"}
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
import { McpServer } from '@modelcontextprotocol/server';
|
|
2
|
+
import { APIError, strictObject, z } from 'payload';
|
|
3
|
+
import { getLogger } from '../utils/getLogger.js';
|
|
4
|
+
import { toStandardSchema } from '../utils/toStandardSchema.js';
|
|
5
|
+
/**
|
|
6
|
+
* Serving-entry-agnostic core: registers every authorized MCP item onto a fresh
|
|
7
|
+
* `McpServer` and returns it. The HTTP and stdio entry point callers provide fresh
|
|
8
|
+
* instances from this builder while they own the transport and protocol-era
|
|
9
|
+
* decision.
|
|
10
|
+
*
|
|
11
|
+
* `req` is the request context handlers see. For HTTP it's the live
|
|
12
|
+
* `PayloadRequest` derived from the incoming HTTP request; for stdio it's a
|
|
13
|
+
* synthesized one built via `createPayloadRequest`.
|
|
14
|
+
*/ export const buildMcpServer = ({ authorizedMCP, pluginConfig, req })=>{
|
|
15
|
+
z.config(z.locales.en());
|
|
16
|
+
const serverOptions = pluginConfig.mcp?.serverOptions || {};
|
|
17
|
+
const server = new McpServer({
|
|
18
|
+
name: 'Payload MCP Server',
|
|
19
|
+
version: '1.0.0',
|
|
20
|
+
...serverOptions.serverInfo
|
|
21
|
+
}, serverOptions.options);
|
|
22
|
+
const logger = getLogger({
|
|
23
|
+
payload: req.payload
|
|
24
|
+
});
|
|
25
|
+
/**
|
|
26
|
+
* Wrap a tool handler's response with the tool's `overrideResponse`, then
|
|
27
|
+
* strip the internal `doc` field so it doesn't leak onto the wire.
|
|
28
|
+
*/ const finalizeToolResponse = async ({ input, overrideResponse, response, toolName })=>{
|
|
29
|
+
let overridden = overrideResponse?.(response, response.doc ?? {}, req) ?? response;
|
|
30
|
+
for (const hook of pluginConfig.hooks?.afterToolCall ?? []){
|
|
31
|
+
overridden = await hook({
|
|
32
|
+
input,
|
|
33
|
+
req,
|
|
34
|
+
response: overridden,
|
|
35
|
+
toolName
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
const { doc: _doc, ...rest } = overridden;
|
|
39
|
+
return rest;
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* Runs a collection/global tool call:
|
|
43
|
+
* - reads `slug` from the input
|
|
44
|
+
* - runs access control: errors if `authorizedMCP.items` has no entry for this tool + slug
|
|
45
|
+
* - runs the tool handler and finalizes its response
|
|
46
|
+
*/ const callEntityTool = async ({ input, item, serverContext })=>{
|
|
47
|
+
const entity = item.type === 'collectionTool' ? 'collection' : 'global';
|
|
48
|
+
const toolInput = input ?? {};
|
|
49
|
+
const slug = toolInput.slug;
|
|
50
|
+
if (!slug) {
|
|
51
|
+
return {
|
|
52
|
+
content: [
|
|
53
|
+
{
|
|
54
|
+
type: 'text',
|
|
55
|
+
text: `Error: "${item.mcpName}" requires slug. Use getConfigInfo to inspect ${entity} slugs.`
|
|
56
|
+
}
|
|
57
|
+
],
|
|
58
|
+
isError: true
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
const match = authorizedMCP.items.find((candidate)=>candidate.type === item.type && candidate.mcpName === item.mcpName && (candidate.type === 'collectionTool' ? candidate.collectionSlug === slug : candidate.type === 'globalTool' && candidate.globalSlug === slug));
|
|
62
|
+
if (!match) {
|
|
63
|
+
return {
|
|
64
|
+
content: [
|
|
65
|
+
{
|
|
66
|
+
type: 'text',
|
|
67
|
+
text: `Error: MCP access to "${item.mcpName}" is not enabled for ${entity} "${slug}"`
|
|
68
|
+
}
|
|
69
|
+
],
|
|
70
|
+
isError: true
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
const handlerArgs = {
|
|
74
|
+
authorizedMCP,
|
|
75
|
+
input: toolInput,
|
|
76
|
+
req,
|
|
77
|
+
serverContext
|
|
78
|
+
};
|
|
79
|
+
const response = await (match.type === 'collectionTool' ? match.tool.handler({
|
|
80
|
+
...handlerArgs,
|
|
81
|
+
slug
|
|
82
|
+
}) : match.tool.handler({
|
|
83
|
+
...handlerArgs,
|
|
84
|
+
slug
|
|
85
|
+
}));
|
|
86
|
+
return finalizeToolResponse({
|
|
87
|
+
input: toolInput,
|
|
88
|
+
overrideResponse: match.tool.overrideResponse,
|
|
89
|
+
response,
|
|
90
|
+
toolName: match.mcpName
|
|
91
|
+
});
|
|
92
|
+
};
|
|
93
|
+
try {
|
|
94
|
+
const registeredEntityTools = new Set();
|
|
95
|
+
for (const item of authorizedMCP.items){
|
|
96
|
+
switch(item.type){
|
|
97
|
+
case 'collectionTool':
|
|
98
|
+
case 'globalTool':
|
|
99
|
+
{
|
|
100
|
+
if (registeredEntityTools.has(item.mcpName)) {
|
|
101
|
+
break;
|
|
102
|
+
}
|
|
103
|
+
registeredEntityTools.add(item.mcpName);
|
|
104
|
+
const inputSchema = withSlugInput({
|
|
105
|
+
input: item.tool.input
|
|
106
|
+
});
|
|
107
|
+
server.registerTool(item.mcpName, {
|
|
108
|
+
annotations: item.tool.annotations,
|
|
109
|
+
description: item.tool.description,
|
|
110
|
+
inputSchema: toStandardSchema(inputSchema)
|
|
111
|
+
}, async (input, ctx)=>callEntityTool({
|
|
112
|
+
input,
|
|
113
|
+
item,
|
|
114
|
+
serverContext: ctx
|
|
115
|
+
}));
|
|
116
|
+
logger.info(`✅ Tool: ${item.mcpName} Registered.`);
|
|
117
|
+
break;
|
|
118
|
+
}
|
|
119
|
+
case 'prompt':
|
|
120
|
+
{
|
|
121
|
+
const prompt = item.prompt;
|
|
122
|
+
server.registerPrompt(item.mcpName, {
|
|
123
|
+
argsSchema: prompt.argsSchema ? toStandardSchema(prompt.argsSchema) : undefined,
|
|
124
|
+
description: prompt.description,
|
|
125
|
+
title: prompt.title
|
|
126
|
+
}, async (input, ctx)=>prompt.handler({
|
|
127
|
+
input: input ?? {},
|
|
128
|
+
req,
|
|
129
|
+
serverContext: ctx
|
|
130
|
+
}));
|
|
131
|
+
logger.info(`✅ Prompt: ${prompt.title} Registered.`);
|
|
132
|
+
break;
|
|
133
|
+
}
|
|
134
|
+
case 'resource':
|
|
135
|
+
{
|
|
136
|
+
const resource = item.resource;
|
|
137
|
+
server.registerResource(item.mcpName, // @ts-expect-error - Overload type ambiguity (string OR ResourceTemplate is valid)
|
|
138
|
+
resource.uri, {
|
|
139
|
+
description: resource.description,
|
|
140
|
+
mimeType: resource.mimeType,
|
|
141
|
+
title: resource.title
|
|
142
|
+
}, // Static URIs call (uri, ctx); ResourceTemplates call (uri, params, ctx).
|
|
143
|
+
// The rest-params shape lets us collect either signature uniformly.
|
|
144
|
+
async (...sdkArgs)=>{
|
|
145
|
+
const ctx = sdkArgs[sdkArgs.length - 1];
|
|
146
|
+
const uri = sdkArgs[0];
|
|
147
|
+
const params = sdkArgs.length > 2 ? sdkArgs[1] : {};
|
|
148
|
+
return resource.handler({
|
|
149
|
+
params,
|
|
150
|
+
req,
|
|
151
|
+
serverContext: ctx,
|
|
152
|
+
uri
|
|
153
|
+
});
|
|
154
|
+
});
|
|
155
|
+
logger.info(`✅ Resource: ${resource.title} Registered.`);
|
|
156
|
+
break;
|
|
157
|
+
}
|
|
158
|
+
case 'tool':
|
|
159
|
+
{
|
|
160
|
+
const tool = item.tool;
|
|
161
|
+
server.registerTool(item.mcpName, {
|
|
162
|
+
annotations: tool.annotations,
|
|
163
|
+
description: tool.description,
|
|
164
|
+
inputSchema: tool.input ? toStandardSchema(tool.input) : undefined
|
|
165
|
+
}, async (input, ctx)=>{
|
|
166
|
+
const toolInput = input ?? {};
|
|
167
|
+
const response = await tool.handler({
|
|
168
|
+
authorizedMCP,
|
|
169
|
+
input: toolInput,
|
|
170
|
+
req,
|
|
171
|
+
serverContext: ctx
|
|
172
|
+
});
|
|
173
|
+
return finalizeToolResponse({
|
|
174
|
+
input: toolInput,
|
|
175
|
+
overrideResponse: tool.overrideResponse,
|
|
176
|
+
response,
|
|
177
|
+
toolName: item.mcpName
|
|
178
|
+
});
|
|
179
|
+
});
|
|
180
|
+
logger.info(`✅ Tool: ${item.mcpName} Registered.`);
|
|
181
|
+
break;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
} catch (error) {
|
|
186
|
+
throw new APIError(`Error initializing MCP handler: ${String(error)}`, 500);
|
|
187
|
+
}
|
|
188
|
+
return server;
|
|
189
|
+
};
|
|
190
|
+
const withSlugInput = ({ input })=>{
|
|
191
|
+
const description = 'The target slug.';
|
|
192
|
+
const slugSchema = z.string().check(z.describe(description));
|
|
193
|
+
if (!input) {
|
|
194
|
+
return strictObject({
|
|
195
|
+
slug: slugSchema
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
if (typeof input === 'object' && input !== null && '~standard' in input) {
|
|
199
|
+
const schema = input['~standard'].jsonSchema.input({
|
|
200
|
+
target: 'draft-2020-12'
|
|
201
|
+
});
|
|
202
|
+
const properties = schema.properties;
|
|
203
|
+
if (properties?.slug) {
|
|
204
|
+
return input;
|
|
205
|
+
}
|
|
206
|
+
return addSlugToJSONSchema({
|
|
207
|
+
description,
|
|
208
|
+
schema
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
return addSlugToJSONSchema({
|
|
212
|
+
description,
|
|
213
|
+
schema: input
|
|
214
|
+
});
|
|
215
|
+
};
|
|
216
|
+
const addSlugToJSONSchema = ({ description, schema })=>{
|
|
217
|
+
const objectSchema = schema;
|
|
218
|
+
return {
|
|
219
|
+
...objectSchema,
|
|
220
|
+
type: 'object',
|
|
221
|
+
properties: {
|
|
222
|
+
...objectSchema.properties,
|
|
223
|
+
slug: {
|
|
224
|
+
type: 'string',
|
|
225
|
+
description
|
|
226
|
+
}
|
|
227
|
+
},
|
|
228
|
+
required: Array.from(new Set([
|
|
229
|
+
'slug',
|
|
230
|
+
...objectSchema.required ?? []
|
|
231
|
+
]))
|
|
232
|
+
};
|
|
233
|
+
};
|
|
234
|
+
|
|
235
|
+
//# sourceMappingURL=buildMcpServer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/mcp/buildMcpServer.ts"],"sourcesContent":["import type { PayloadRequest } from 'payload'\n\nimport { McpServer, type ServerContext } from '@modelcontextprotocol/server'\nimport { APIError, strictObject, z } from 'payload'\n\nimport type {\n AuthorizedMCP,\n CollectionMCPItem,\n GlobalMCPItem,\n JsonSchemaType,\n MCPResponseOverride,\n MCPToolResponse,\n SanitizedMCPPluginConfig,\n ToolInputSchema,\n} from '../types.js'\n\nimport { getLogger } from '../utils/getLogger.js'\nimport { toStandardSchema } from '../utils/toStandardSchema.js'\n\n/**\n * Serving-entry-agnostic core: registers every authorized MCP item onto a fresh\n * `McpServer` and returns it. The HTTP and stdio entry point callers provide fresh\n * instances from this builder while they own the transport and protocol-era\n * decision.\n *\n * `req` is the request context handlers see. For HTTP it's the live\n * `PayloadRequest` derived from the incoming HTTP request; for stdio it's a\n * synthesized one built via `createPayloadRequest`.\n */\nexport const buildMcpServer = ({\n authorizedMCP,\n pluginConfig,\n req,\n}: {\n authorizedMCP: AuthorizedMCP\n pluginConfig: SanitizedMCPPluginConfig\n req: PayloadRequest\n}): McpServer => {\n z.config(z.locales.en())\n\n const serverOptions = pluginConfig.mcp?.serverOptions || {}\n const server = new McpServer(\n { name: 'Payload MCP Server', version: '1.0.0', ...serverOptions.serverInfo },\n serverOptions.options,\n )\n\n const logger = getLogger({ payload: req.payload })\n\n /**\n * Wrap a tool handler's response with the tool's `overrideResponse`, then\n * strip the internal `doc` field so it doesn't leak onto the wire.\n */\n const finalizeToolResponse = async ({\n input,\n overrideResponse,\n response,\n toolName,\n }: {\n input: unknown\n overrideResponse?: MCPResponseOverride\n response: MCPToolResponse\n toolName: string\n }): Promise<MCPToolResponse> => {\n let overridden = overrideResponse?.(response, response.doc ?? {}, req) ?? response\n for (const hook of pluginConfig.hooks?.afterToolCall ?? []) {\n overridden = await hook({ input, req, response: overridden, toolName })\n }\n const { doc: _doc, ...rest } = overridden\n return rest\n }\n\n /**\n * Runs a collection/global tool call:\n * - reads `slug` from the input\n * - runs access control: errors if `authorizedMCP.items` has no entry for this tool + slug\n * - runs the tool handler and finalizes its response\n */\n const callEntityTool = async ({\n input,\n item,\n serverContext,\n }: {\n input: unknown\n item: CollectionMCPItem | GlobalMCPItem\n serverContext: ServerContext\n }): Promise<MCPToolResponse> => {\n const entity = item.type === 'collectionTool' ? 'collection' : 'global'\n const toolInput = (input ?? {}) as Record<string, unknown>\n const slug = toolInput.slug as string | undefined\n\n if (!slug) {\n return {\n content: [\n {\n type: 'text',\n text: `Error: \"${item.mcpName}\" requires slug. Use getConfigInfo to inspect ${entity} slugs.`,\n },\n ],\n isError: true,\n }\n }\n\n const match = authorizedMCP.items.find(\n (candidate): candidate is CollectionMCPItem | GlobalMCPItem =>\n candidate.type === item.type &&\n candidate.mcpName === item.mcpName &&\n (candidate.type === 'collectionTool'\n ? candidate.collectionSlug === slug\n : candidate.type === 'globalTool' && candidate.globalSlug === slug),\n )\n\n if (!match) {\n return {\n content: [\n {\n type: 'text',\n text: `Error: MCP access to \"${item.mcpName}\" is not enabled for ${entity} \"${slug}\"`,\n },\n ],\n isError: true,\n }\n }\n\n const handlerArgs = {\n authorizedMCP,\n input: toolInput,\n req,\n serverContext,\n }\n const response = await (match.type === 'collectionTool'\n ? match.tool.handler({ ...handlerArgs, slug })\n : match.tool.handler({ ...handlerArgs, slug }))\n\n return finalizeToolResponse({\n input: toolInput,\n overrideResponse: match.tool.overrideResponse,\n response,\n toolName: match.mcpName,\n })\n }\n\n try {\n const registeredEntityTools = new Set<string>()\n\n for (const item of authorizedMCP.items) {\n switch (item.type) {\n case 'collectionTool':\n case 'globalTool': {\n if (registeredEntityTools.has(item.mcpName)) {\n break\n }\n registeredEntityTools.add(item.mcpName)\n\n const inputSchema = withSlugInput({ input: item.tool.input })\n\n server.registerTool(\n item.mcpName,\n {\n annotations: item.tool.annotations,\n description: item.tool.description,\n inputSchema: toStandardSchema(inputSchema),\n },\n async (input: unknown, ctx: ServerContext) =>\n callEntityTool({ input, item, serverContext: ctx }),\n )\n logger.info(`✅ Tool: ${item.mcpName} Registered.`)\n break\n }\n case 'prompt': {\n const prompt = item.prompt\n server.registerPrompt(\n item.mcpName,\n {\n argsSchema: prompt.argsSchema ? toStandardSchema(prompt.argsSchema) : undefined,\n description: prompt.description,\n title: prompt.title,\n },\n async (input: unknown, ctx: ServerContext) =>\n prompt.handler({\n input: (input ?? {}) as Record<string, unknown>,\n req,\n serverContext: ctx,\n }),\n )\n logger.info(`✅ Prompt: ${prompt.title} Registered.`)\n break\n }\n case 'resource': {\n const resource = item.resource\n server.registerResource(\n item.mcpName,\n // @ts-expect-error - Overload type ambiguity (string OR ResourceTemplate is valid)\n resource.uri,\n {\n description: resource.description,\n mimeType: resource.mimeType,\n title: resource.title,\n },\n // Static URIs call (uri, ctx); ResourceTemplates call (uri, params, ctx).\n // The rest-params shape lets us collect either signature uniformly.\n async (...sdkArgs: unknown[]) => {\n const ctx = sdkArgs[sdkArgs.length - 1] as ServerContext\n const uri = sdkArgs[0] as URL\n const params = (sdkArgs.length > 2 ? sdkArgs[1] : {}) as Record<string, string>\n return resource.handler({ params, req, serverContext: ctx, uri })\n },\n )\n logger.info(`✅ Resource: ${resource.title} Registered.`)\n break\n }\n case 'tool': {\n const tool = item.tool\n server.registerTool(\n item.mcpName,\n {\n annotations: tool.annotations,\n description: tool.description,\n inputSchema: tool.input ? toStandardSchema(tool.input) : undefined,\n },\n async (input: unknown, ctx: ServerContext) => {\n const toolInput = (input ?? {}) as Record<string, unknown>\n const response = await tool.handler({\n authorizedMCP,\n input: toolInput,\n req,\n serverContext: ctx,\n })\n return finalizeToolResponse({\n input: toolInput,\n overrideResponse: tool.overrideResponse,\n response,\n toolName: item.mcpName,\n })\n },\n )\n logger.info(`✅ Tool: ${item.mcpName} Registered.`)\n break\n }\n }\n }\n } catch (error) {\n throw new APIError(`Error initializing MCP handler: ${String(error)}`, 500)\n }\n\n return server\n}\n\nconst withSlugInput = ({ input }: { input?: ToolInputSchema }): ToolInputSchema => {\n const description = 'The target slug.'\n const slugSchema = z.string().check(z.describe(description))\n\n if (!input) {\n return strictObject({ slug: slugSchema })\n }\n\n if (typeof input === 'object' && input !== null && '~standard' in input) {\n const schema = input['~standard'].jsonSchema.input({ target: 'draft-2020-12' })\n const properties = schema.properties as Record<string, unknown> | undefined\n\n if (properties?.slug) {\n return input\n }\n\n return addSlugToJSONSchema({ description, schema })\n }\n\n return addSlugToJSONSchema({ description, schema: input })\n}\n\nconst addSlugToJSONSchema = ({\n description,\n schema,\n}: {\n description: string\n schema: JsonSchemaType\n}): JsonSchemaType => {\n const objectSchema = schema as {\n properties?: Record<string, JsonSchemaType>\n required?: string[]\n } & JsonSchemaType\n\n return {\n ...objectSchema,\n type: 'object',\n properties: {\n ...objectSchema.properties,\n slug: {\n type: 'string',\n description,\n },\n },\n required: Array.from(new Set(['slug', ...(objectSchema.required ?? [])])),\n }\n}\n"],"names":["McpServer","APIError","strictObject","z","getLogger","toStandardSchema","buildMcpServer","authorizedMCP","pluginConfig","req","config","locales","en","serverOptions","mcp","server","name","version","serverInfo","options","logger","payload","finalizeToolResponse","input","overrideResponse","response","toolName","overridden","doc","hook","hooks","afterToolCall","_doc","rest","callEntityTool","item","serverContext","entity","type","toolInput","slug","content","text","mcpName","isError","match","items","find","candidate","collectionSlug","globalSlug","handlerArgs","tool","handler","registeredEntityTools","Set","has","add","inputSchema","withSlugInput","registerTool","annotations","description","ctx","info","prompt","registerPrompt","argsSchema","undefined","title","resource","registerResource","uri","mimeType","sdkArgs","length","params","error","String","slugSchema","string","check","describe","schema","jsonSchema","target","properties","addSlugToJSONSchema","objectSchema","required","Array","from"],"mappings":"AAEA,SAASA,SAAS,QAA4B,+BAA8B;AAC5E,SAASC,QAAQ,EAAEC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IAAI,CAACvC,OAAO;QACV,OAAOrB,aAAa;YAAEsC,MAAMuC;QAAW;IACzC;IAEA,IAAI,OAAOxD,UAAU,YAAYA,UAAU,QAAQ,eAAeA,OAAO;QACvE,MAAM4D,SAAS5D,KAAK,CAAC,YAAY,CAAC6D,UAAU,CAAC7D,KAAK,CAAC;YAAE8D,QAAQ;QAAgB;QAC7E,MAAMC,aAAaH,OAAOG,UAAU;QAEpC,IAAIA,YAAY9C,MAAM;YACpB,OAAOjB;QACT;QAEA,OAAOgE,oBAAoB;YAAEzB;YAAaqB;QAAO;IACnD;IAEA,OAAOI,oBAAoB;QAAEzB;QAAaqB,QAAQ5D;IAAM;AAC1D;AAEA,MAAMgE,sBAAsB,CAAC,EAC3BzB,WAAW,EACXqB,MAAM,EAIP;IACC,MAAMK,eAAeL;IAKrB,OAAO;QACL,GAAGK,YAAY;QACflD,MAAM;QACNgD,YAAY;YACV,GAAGE,aAAaF,UAAU;YAC1B9C,MAAM;gBACJF,MAAM;gBACNwB;YACF;QACF;QACA2B,UAAUC,MAAMC,IAAI,CAAC,IAAIpC,IAAI;YAAC;eAAYiC,aAAaC,QAAQ,IAAI,EAAE;SAAE;IACzE;AACF"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare const authCollectionTool: import("../../../types.js").CollectionTool;
|
|
2
|
+
export declare const forgotPasswordCollectionTool: import("../../../types.js").CollectionTool;
|
|
3
|
+
export declare const loginCollectionTool: import("../../../types.js").CollectionTool;
|
|
4
|
+
export declare const resetPasswordCollectionTool: import("../../../types.js").CollectionTool;
|
|
5
|
+
export declare const unlockCollectionTool: import("../../../types.js").CollectionTool;
|
|
6
|
+
export declare const verifyCollectionTool: import("../../../types.js").CollectionTool;
|
|
7
|
+
//# sourceMappingURL=authTools.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authTools.d.ts","sourceRoot":"","sources":["../../../../src/mcp/builtin/collections/authTools.ts"],"names":[],"mappings":"AAkCA,eAAO,MAAM,kBAAkB,4CA0D7B,CAAA;AAEF,eAAO,MAAM,4BAA4B,4CAmCvC,CAAA;AAEF,eAAO,MAAM,mBAAmB,4CAuC9B,CAAA;AAEF,eAAO,MAAM,2BAA2B,4CAmCtC,CAAA;AAEF,eAAO,MAAM,oBAAoB,4CAmC/B,CAAA;AAEF,eAAO,MAAM,oBAAoB,4CAiC/B,CAAA"}
|
|
@@ -0,0 +1,312 @@
|
|
|
1
|
+
import { createPayloadRequest, strictObject, z } from 'payload';
|
|
2
|
+
import { defaultAccess } from '../../../defaultAccess.js';
|
|
3
|
+
import { defineCollectionTool } from '../../../defineTool.js';
|
|
4
|
+
import { getLogger } from '../../../utils/getLogger.js';
|
|
5
|
+
/**
|
|
6
|
+
* Auth tools surfaced under `collections.<auth-collection>.tools`. Opt-in: they
|
|
7
|
+
* default off (an LLM with `login` access can probe passwords; not something
|
|
8
|
+
* to expose by default). Enable in plugin config via `tools: { login: true }`
|
|
9
|
+
* (or `{ description: '...' }`).
|
|
10
|
+
*
|
|
11
|
+
* `auth` (check current token) doesn't actually depend on the collection at
|
|
12
|
+
* runtime — `payload.auth({ headers })` is global — but it's grouped under the
|
|
13
|
+
* users collection so all auth-shaped tools live in one place.
|
|
14
|
+
*/ const emailSchema = z.email().check(z.describe('The user email address.'));
|
|
15
|
+
const wrapError = (name)=>({ slug, message })=>{
|
|
16
|
+
return {
|
|
17
|
+
content: [
|
|
18
|
+
{
|
|
19
|
+
type: 'text',
|
|
20
|
+
text: `❌ **Error in ${name}** on ${slug}: ${message}`
|
|
21
|
+
}
|
|
22
|
+
]
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
export const authCollectionTool = defineCollectionTool({
|
|
26
|
+
annotations: {
|
|
27
|
+
destructiveHint: false,
|
|
28
|
+
idempotentHint: true,
|
|
29
|
+
openWorldHint: false,
|
|
30
|
+
readOnlyHint: true,
|
|
31
|
+
title: 'Check Auth Status'
|
|
32
|
+
},
|
|
33
|
+
description: 'Checks authentication status for the current user.',
|
|
34
|
+
input: strictObject({
|
|
35
|
+
headers: z.optional(z.record(z.string(), z.string())).check(z.describe('Custom headers to send with the authentication request.'))
|
|
36
|
+
})
|
|
37
|
+
}).handler(async ({ slug, authorizedMCP, input, req })=>{
|
|
38
|
+
const logger = getLogger({
|
|
39
|
+
payload: req.payload
|
|
40
|
+
});
|
|
41
|
+
try {
|
|
42
|
+
let authHeaders = new Headers();
|
|
43
|
+
if (input.headers) {
|
|
44
|
+
authHeaders = new Headers(input.headers);
|
|
45
|
+
}
|
|
46
|
+
const authReq = await createPayloadRequest({
|
|
47
|
+
payload: req.payload,
|
|
48
|
+
req: {
|
|
49
|
+
headers: authHeaders
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
const result = await req.payload.auth({
|
|
53
|
+
headers: authHeaders,
|
|
54
|
+
req: authReq
|
|
55
|
+
});
|
|
56
|
+
if (result.user) {
|
|
57
|
+
const authenticatedUser = result.user;
|
|
58
|
+
// Auth strategies read users with trusted Local API access. Re-read the user with the MCP
|
|
59
|
+
// caller's access level before returning it to the client.
|
|
60
|
+
const user = await req.payload.findByID({
|
|
61
|
+
id: authenticatedUser.id,
|
|
62
|
+
collection: authenticatedUser.collection,
|
|
63
|
+
overrideAccess: authorizedMCP.overrideAccess,
|
|
64
|
+
req: authReq
|
|
65
|
+
});
|
|
66
|
+
result.user = {
|
|
67
|
+
...user,
|
|
68
|
+
_sid: authenticatedUser._sid,
|
|
69
|
+
_strategy: authenticatedUser._strategy,
|
|
70
|
+
collection: authenticatedUser.collection
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
return {
|
|
74
|
+
content: [
|
|
75
|
+
{
|
|
76
|
+
type: 'text',
|
|
77
|
+
text: `# Authentication Status\n\n\`\`\`json\n${JSON.stringify(result)}\n\`\`\``
|
|
78
|
+
}
|
|
79
|
+
],
|
|
80
|
+
doc: result
|
|
81
|
+
};
|
|
82
|
+
} catch (error) {
|
|
83
|
+
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
|
|
84
|
+
logger.error(`Error in auth tool on ${slug}: ${errorMessage}`);
|
|
85
|
+
return wrapError('auth')({
|
|
86
|
+
slug,
|
|
87
|
+
message: errorMessage
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
export const forgotPasswordCollectionTool = defineCollectionTool({
|
|
92
|
+
annotations: {
|
|
93
|
+
destructiveHint: false,
|
|
94
|
+
idempotentHint: false,
|
|
95
|
+
openWorldHint: true,
|
|
96
|
+
readOnlyHint: false,
|
|
97
|
+
title: 'Forgot Password'
|
|
98
|
+
},
|
|
99
|
+
description: 'Sends a password reset email to a user.',
|
|
100
|
+
input: strictObject({
|
|
101
|
+
email: emailSchema
|
|
102
|
+
})
|
|
103
|
+
}).handler(async ({ slug, input, req })=>{
|
|
104
|
+
const logger = getLogger({
|
|
105
|
+
payload: req.payload
|
|
106
|
+
});
|
|
107
|
+
try {
|
|
108
|
+
await req.payload.forgotPassword({
|
|
109
|
+
collection: slug,
|
|
110
|
+
data: {
|
|
111
|
+
email: input.email
|
|
112
|
+
},
|
|
113
|
+
disableEmail: false,
|
|
114
|
+
overrideAccess: false,
|
|
115
|
+
req
|
|
116
|
+
});
|
|
117
|
+
return {
|
|
118
|
+
content: [
|
|
119
|
+
{
|
|
120
|
+
type: 'text',
|
|
121
|
+
text: 'If an account matches that email, password reset instructions have been sent.'
|
|
122
|
+
}
|
|
123
|
+
]
|
|
124
|
+
};
|
|
125
|
+
} catch (error) {
|
|
126
|
+
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
|
|
127
|
+
logger.error(`Error in forgotPassword tool on ${slug}: ${errorMessage}`);
|
|
128
|
+
return wrapError('forgotPassword')({
|
|
129
|
+
slug,
|
|
130
|
+
message: errorMessage
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
export const loginCollectionTool = defineCollectionTool({
|
|
135
|
+
annotations: {
|
|
136
|
+
destructiveHint: false,
|
|
137
|
+
idempotentHint: false,
|
|
138
|
+
openWorldHint: false,
|
|
139
|
+
readOnlyHint: false,
|
|
140
|
+
title: 'User Login'
|
|
141
|
+
},
|
|
142
|
+
description: 'Authenticates a user with email and password.',
|
|
143
|
+
input: strictObject({
|
|
144
|
+
depth: z._default(z.int().check(z.minimum(0), z.maximum(10)), 0).check(z.describe('Depth of population for relationships.')),
|
|
145
|
+
email: emailSchema,
|
|
146
|
+
password: z.string().check(z.describe('The user password.'))
|
|
147
|
+
})
|
|
148
|
+
}).handler(async ({ slug, authorizedMCP, input, req })=>{
|
|
149
|
+
const logger = getLogger({
|
|
150
|
+
payload: req.payload
|
|
151
|
+
});
|
|
152
|
+
try {
|
|
153
|
+
const result = await req.payload.login({
|
|
154
|
+
collection: slug,
|
|
155
|
+
data: {
|
|
156
|
+
email: input.email,
|
|
157
|
+
password: input.password
|
|
158
|
+
},
|
|
159
|
+
depth: input.depth,
|
|
160
|
+
overrideAccess: authorizedMCP.overrideAccess
|
|
161
|
+
});
|
|
162
|
+
return {
|
|
163
|
+
content: [
|
|
164
|
+
{
|
|
165
|
+
type: 'text',
|
|
166
|
+
text: `# Login Successful\n\n**User:** ${input.email}\n**Collection:** ${slug}\n\n\`\`\`json\n${JSON.stringify(result)}\n\`\`\``
|
|
167
|
+
}
|
|
168
|
+
],
|
|
169
|
+
doc: result
|
|
170
|
+
};
|
|
171
|
+
} catch (error) {
|
|
172
|
+
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
|
|
173
|
+
logger.error(`Error in login tool on ${slug}: ${errorMessage}`);
|
|
174
|
+
return wrapError('login')({
|
|
175
|
+
slug,
|
|
176
|
+
message: errorMessage
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
});
|
|
180
|
+
export const resetPasswordCollectionTool = defineCollectionTool({
|
|
181
|
+
annotations: {
|
|
182
|
+
destructiveHint: false,
|
|
183
|
+
idempotentHint: false,
|
|
184
|
+
openWorldHint: false,
|
|
185
|
+
readOnlyHint: false,
|
|
186
|
+
title: 'Reset Password'
|
|
187
|
+
},
|
|
188
|
+
description: 'Resets a user password with a reset token.',
|
|
189
|
+
input: strictObject({
|
|
190
|
+
password: z.string().check(z.describe('The new password for the user.')),
|
|
191
|
+
token: z.string().check(z.describe('The password reset token sent to the user email.'))
|
|
192
|
+
})
|
|
193
|
+
}).handler(async ({ slug, authorizedMCP, input, req })=>{
|
|
194
|
+
const logger = getLogger({
|
|
195
|
+
payload: req.payload
|
|
196
|
+
});
|
|
197
|
+
try {
|
|
198
|
+
const result = await req.payload.resetPassword({
|
|
199
|
+
collection: slug,
|
|
200
|
+
data: {
|
|
201
|
+
password: input.password,
|
|
202
|
+
token: input.token
|
|
203
|
+
},
|
|
204
|
+
overrideAccess: authorizedMCP.overrideAccess
|
|
205
|
+
});
|
|
206
|
+
return {
|
|
207
|
+
content: [
|
|
208
|
+
{
|
|
209
|
+
type: 'text',
|
|
210
|
+
text: `# Password Reset Successful\n\n**Collection:** ${slug}\n\n\`\`\`json\n${JSON.stringify(result)}\n\`\`\``
|
|
211
|
+
}
|
|
212
|
+
],
|
|
213
|
+
doc: result
|
|
214
|
+
};
|
|
215
|
+
} catch (error) {
|
|
216
|
+
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
|
|
217
|
+
logger.error(`Error in resetPassword tool on ${slug}: ${errorMessage}`);
|
|
218
|
+
return wrapError('resetPassword')({
|
|
219
|
+
slug,
|
|
220
|
+
message: errorMessage
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
});
|
|
224
|
+
export const unlockCollectionTool = defineCollectionTool({
|
|
225
|
+
access: (args)=>defaultAccess(args) && Boolean(args.permissions?.collections?.[args.slug]?.unlock),
|
|
226
|
+
annotations: {
|
|
227
|
+
destructiveHint: false,
|
|
228
|
+
idempotentHint: true,
|
|
229
|
+
openWorldHint: false,
|
|
230
|
+
readOnlyHint: false,
|
|
231
|
+
title: 'Unlock Account'
|
|
232
|
+
},
|
|
233
|
+
description: 'Unlocks a user account that has been locked due to failed login attempts.',
|
|
234
|
+
input: strictObject({
|
|
235
|
+
email: emailSchema
|
|
236
|
+
})
|
|
237
|
+
}).handler(async ({ slug, authorizedMCP, input, req })=>{
|
|
238
|
+
const logger = getLogger({
|
|
239
|
+
payload: req.payload
|
|
240
|
+
});
|
|
241
|
+
try {
|
|
242
|
+
const result = await req.payload.unlock({
|
|
243
|
+
collection: slug,
|
|
244
|
+
data: {
|
|
245
|
+
email: input.email
|
|
246
|
+
},
|
|
247
|
+
overrideAccess: authorizedMCP.overrideAccess,
|
|
248
|
+
req
|
|
249
|
+
});
|
|
250
|
+
return {
|
|
251
|
+
content: [
|
|
252
|
+
{
|
|
253
|
+
type: 'text',
|
|
254
|
+
text: `# Account Unlocked\n\n**Collection:** ${slug}\n**Email:** ${input.email}\n**Result:** ${result ? 'Success' : 'Failed'}`
|
|
255
|
+
}
|
|
256
|
+
],
|
|
257
|
+
doc: {
|
|
258
|
+
result
|
|
259
|
+
}
|
|
260
|
+
};
|
|
261
|
+
} catch (error) {
|
|
262
|
+
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
|
|
263
|
+
logger.error(`Error in unlock tool on ${slug}: ${errorMessage}`);
|
|
264
|
+
return wrapError('unlock')({
|
|
265
|
+
slug,
|
|
266
|
+
message: errorMessage
|
|
267
|
+
});
|
|
268
|
+
}
|
|
269
|
+
});
|
|
270
|
+
export const verifyCollectionTool = defineCollectionTool({
|
|
271
|
+
annotations: {
|
|
272
|
+
destructiveHint: false,
|
|
273
|
+
idempotentHint: false,
|
|
274
|
+
openWorldHint: false,
|
|
275
|
+
readOnlyHint: false,
|
|
276
|
+
title: 'Email Verification'
|
|
277
|
+
},
|
|
278
|
+
description: 'Verifies a user email with a verification token.',
|
|
279
|
+
input: strictObject({
|
|
280
|
+
token: z.string().check(z.describe('The verification token sent to the user email.'))
|
|
281
|
+
})
|
|
282
|
+
}).handler(async ({ slug, input, req })=>{
|
|
283
|
+
const logger = getLogger({
|
|
284
|
+
payload: req.payload
|
|
285
|
+
});
|
|
286
|
+
try {
|
|
287
|
+
const result = await req.payload.verifyEmail({
|
|
288
|
+
collection: slug,
|
|
289
|
+
token: input.token
|
|
290
|
+
});
|
|
291
|
+
return {
|
|
292
|
+
content: [
|
|
293
|
+
{
|
|
294
|
+
type: 'text',
|
|
295
|
+
text: `# Email Verification Successful\n\n**Collection:** ${slug}\n**Result:** ${result ? 'Success' : 'Failed'}`
|
|
296
|
+
}
|
|
297
|
+
],
|
|
298
|
+
doc: {
|
|
299
|
+
result
|
|
300
|
+
}
|
|
301
|
+
};
|
|
302
|
+
} catch (error) {
|
|
303
|
+
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
|
|
304
|
+
logger.error(`Error in verify tool on ${slug}: ${errorMessage}`);
|
|
305
|
+
return wrapError('verify')({
|
|
306
|
+
slug,
|
|
307
|
+
message: errorMessage
|
|
308
|
+
});
|
|
309
|
+
}
|
|
310
|
+
});
|
|
311
|
+
|
|
312
|
+
//# sourceMappingURL=authTools.js.map
|