@payloadcms/plugin-mcp 4.0.0-internal.e16cf59 → 4.0.0-internal.e387174
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 +46 -0
- package/dist/defaultAccess.d.ts +3 -0
- package/dist/defaultAccess.d.ts.map +1 -0
- package/dist/defaultAccess.js +3 -0
- package/dist/defaultAccess.js.map +1 -0
- package/dist/defineTool.d.ts +26 -0
- package/dist/defineTool.d.ts.map +1 -0
- package/dist/defineTool.js +37 -0
- package/dist/defineTool.js.map +1 -0
- package/dist/endpoint/access.d.ts +17 -0
- package/dist/endpoint/access.d.ts.map +1 -0
- package/dist/endpoint/access.js +93 -0
- package/dist/endpoint/access.js.map +1 -0
- package/dist/endpoint/index.d.ts +3 -0
- package/dist/endpoint/index.d.ts.map +1 -0
- package/dist/endpoint/index.js +87 -0
- package/dist/endpoint/index.js.map +1 -0
- package/dist/exports/client.d.ts +2 -0
- package/dist/exports/client.d.ts.map +1 -0
- package/dist/exports/client.js +4 -0
- package/dist/exports/client.js.map +1 -0
- package/dist/exports/internal.d.ts +2 -0
- package/dist/exports/internal.d.ts.map +1 -0
- package/dist/exports/internal.js +3 -0
- package/dist/exports/internal.js.map +1 -0
- package/dist/index.d.ts +6 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +39 -67
- package/dist/index.js.map +1 -1
- package/dist/mcp/buildMcpServer.d.ts +19 -0
- package/dist/mcp/buildMcpServer.d.ts.map +1 -0
- package/dist/mcp/buildMcpServer.js +223 -0
- package/dist/mcp/buildMcpServer.js.map +1 -0
- package/dist/mcp/builtin/collections/authTools.d.ts +7 -0
- package/dist/mcp/builtin/collections/authTools.d.ts.map +1 -0
- package/dist/mcp/builtin/collections/authTools.js +288 -0
- package/dist/mcp/builtin/collections/authTools.js.map +1 -0
- package/dist/mcp/builtin/collections/countTool.d.ts +2 -0
- package/dist/mcp/builtin/collections/countTool.d.ts.map +1 -0
- package/dist/mcp/builtin/collections/countTool.js +68 -0
- package/dist/mcp/builtin/collections/countTool.js.map +1 -0
- package/dist/mcp/builtin/collections/countVersionsTool.d.ts +2 -0
- package/dist/mcp/builtin/collections/countVersionsTool.d.ts.map +1 -0
- package/dist/mcp/builtin/collections/countVersionsTool.js +64 -0
- package/dist/mcp/builtin/collections/countVersionsTool.js.map +1 -0
- package/dist/mcp/builtin/collections/createTool.d.ts +2 -0
- package/dist/mcp/builtin/collections/createTool.d.ts.map +1 -0
- package/dist/mcp/builtin/collections/createTool.js +86 -0
- package/dist/mcp/builtin/collections/createTool.js.map +1 -0
- package/dist/mcp/builtin/collections/deleteTool.d.ts +2 -0
- package/dist/mcp/builtin/collections/deleteTool.d.ts.map +1 -0
- package/dist/mcp/builtin/collections/deleteTool.js +110 -0
- package/dist/mcp/builtin/collections/deleteTool.js.map +1 -0
- package/dist/mcp/builtin/collections/duplicateTool.d.ts +2 -0
- package/dist/mcp/builtin/collections/duplicateTool.d.ts.map +1 -0
- package/dist/mcp/builtin/collections/duplicateTool.js +96 -0
- package/dist/mcp/builtin/collections/duplicateTool.js.map +1 -0
- package/dist/mcp/builtin/collections/findDistinctTool.d.ts +2 -0
- package/dist/mcp/builtin/collections/findDistinctTool.d.ts.map +1 -0
- package/dist/mcp/builtin/collections/findDistinctTool.js +92 -0
- package/dist/mcp/builtin/collections/findDistinctTool.js.map +1 -0
- package/dist/mcp/builtin/collections/findTool.d.ts +2 -0
- package/dist/mcp/builtin/collections/findTool.d.ts.map +1 -0
- package/dist/mcp/builtin/collections/findTool.js +164 -0
- package/dist/mcp/builtin/collections/findTool.js.map +1 -0
- package/dist/mcp/builtin/collections/findVersionByIDTool.d.ts +2 -0
- package/dist/mcp/builtin/collections/findVersionByIDTool.d.ts.map +1 -0
- package/dist/mcp/builtin/collections/findVersionByIDTool.js +83 -0
- package/dist/mcp/builtin/collections/findVersionByIDTool.js.map +1 -0
- package/dist/mcp/builtin/collections/findVersionsTool.d.ts +2 -0
- package/dist/mcp/builtin/collections/findVersionsTool.d.ts.map +1 -0
- package/dist/mcp/builtin/collections/findVersionsTool.js +98 -0
- package/dist/mcp/builtin/collections/findVersionsTool.js.map +1 -0
- package/dist/mcp/builtin/collections/formatCollectionError.d.ts +9 -0
- package/dist/mcp/builtin/collections/formatCollectionError.d.ts.map +1 -0
- package/dist/mcp/builtin/collections/formatCollectionError.js +60 -0
- package/dist/mcp/builtin/collections/formatCollectionError.js.map +1 -0
- package/dist/mcp/builtin/collections/getCollectionSchemaTool.d.ts +2 -0
- package/dist/mcp/builtin/collections/getCollectionSchemaTool.d.ts.map +1 -0
- package/dist/mcp/builtin/collections/getCollectionSchemaTool.js +65 -0
- package/dist/mcp/builtin/collections/getCollectionSchemaTool.js.map +1 -0
- package/dist/mcp/builtin/collections/restoreVersionTool.d.ts +2 -0
- package/dist/mcp/builtin/collections/restoreVersionTool.d.ts.map +1 -0
- package/dist/mcp/builtin/collections/restoreVersionTool.js +81 -0
- package/dist/mcp/builtin/collections/restoreVersionTool.js.map +1 -0
- package/dist/mcp/builtin/collections/updateTool.d.ts +2 -0
- package/dist/mcp/builtin/collections/updateTool.d.ts.map +1 -0
- package/dist/mcp/builtin/collections/updateTool.js +198 -0
- package/dist/mcp/builtin/collections/updateTool.js.map +1 -0
- package/dist/mcp/builtin/getConfigInfoTool.d.ts +2 -0
- package/dist/mcp/builtin/getConfigInfoTool.d.ts.map +1 -0
- package/dist/mcp/builtin/getConfigInfoTool.js +68 -0
- package/dist/mcp/builtin/getConfigInfoTool.js.map +1 -0
- package/dist/mcp/builtin/globals/countVersionsTool.d.ts +2 -0
- package/dist/mcp/builtin/globals/countVersionsTool.d.ts.map +1 -0
- package/dist/mcp/builtin/globals/countVersionsTool.js +64 -0
- package/dist/mcp/builtin/globals/countVersionsTool.js.map +1 -0
- package/dist/mcp/builtin/globals/findTool.d.ts +2 -0
- package/dist/mcp/builtin/globals/findTool.d.ts.map +1 -0
- package/dist/mcp/builtin/globals/findTool.js +73 -0
- package/dist/mcp/builtin/globals/findTool.js.map +1 -0
- package/dist/mcp/builtin/globals/findVersionByIDTool.d.ts +2 -0
- package/dist/mcp/builtin/globals/findVersionByIDTool.d.ts.map +1 -0
- package/dist/mcp/builtin/globals/findVersionByIDTool.js +79 -0
- package/dist/mcp/builtin/globals/findVersionByIDTool.js.map +1 -0
- package/dist/mcp/builtin/globals/findVersionsTool.d.ts +2 -0
- package/dist/mcp/builtin/globals/findVersionsTool.d.ts.map +1 -0
- package/dist/mcp/builtin/globals/findVersionsTool.js +94 -0
- package/dist/mcp/builtin/globals/findVersionsTool.js.map +1 -0
- package/dist/mcp/builtin/globals/getGlobalSchemaTool.d.ts +2 -0
- package/dist/mcp/builtin/globals/getGlobalSchemaTool.d.ts.map +1 -0
- package/dist/mcp/builtin/globals/getGlobalSchemaTool.js +65 -0
- package/dist/mcp/builtin/globals/getGlobalSchemaTool.js.map +1 -0
- package/dist/mcp/builtin/globals/restoreVersionTool.d.ts +2 -0
- package/dist/mcp/builtin/globals/restoreVersionTool.d.ts.map +1 -0
- package/dist/mcp/builtin/globals/restoreVersionTool.js +77 -0
- package/dist/mcp/builtin/globals/restoreVersionTool.js.map +1 -0
- package/dist/mcp/builtin/globals/updateTool.d.ts +2 -0
- package/dist/mcp/builtin/globals/updateTool.d.ts.map +1 -0
- package/dist/mcp/builtin/globals/updateTool.js +87 -0
- package/dist/mcp/builtin/globals/updateTool.js.map +1 -0
- package/dist/mcp/builtin/validateEntityData.d.ts +14 -0
- package/dist/mcp/builtin/validateEntityData.d.ts.map +1 -0
- package/dist/mcp/builtin/validateEntityData.js +82 -0
- package/dist/mcp/builtin/validateEntityData.js.map +1 -0
- package/dist/mcp/builtinTools.d.ts +162 -0
- package/dist/mcp/builtinTools.d.ts.map +1 -0
- package/dist/mcp/builtinTools.js +163 -0
- package/dist/mcp/builtinTools.js.map +1 -0
- package/dist/mcp/sanitizeMCPConfig.d.ts +16 -0
- package/dist/mcp/sanitizeMCPConfig.d.ts.map +1 -0
- package/dist/mcp/sanitizeMCPConfig.js +230 -0
- package/dist/mcp/sanitizeMCPConfig.js.map +1 -0
- package/dist/stdio.d.ts +8 -0
- package/dist/stdio.d.ts.map +1 -0
- package/dist/stdio.js +126 -0
- package/dist/stdio.js.map +1 -0
- package/dist/types.d.ts +256 -447
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +4 -1
- package/dist/types.js.map +1 -1
- package/dist/utils/camelCase.d.ts.map +1 -1
- package/dist/utils/getLogger.d.ts +10 -0
- package/dist/utils/getLogger.d.ts.map +1 -0
- package/dist/utils/getLogger.js +22 -0
- package/dist/utils/getLogger.js.map +1 -0
- package/dist/utils/getPluginConfig.d.ts +12 -0
- package/dist/utils/getPluginConfig.d.ts.map +1 -0
- package/dist/utils/getPluginConfig.js +15 -0
- package/dist/utils/getPluginConfig.js.map +1 -0
- package/dist/utils/resolveProjectRoot.d.ts +7 -0
- package/dist/utils/resolveProjectRoot.d.ts.map +1 -0
- package/dist/utils/resolveProjectRoot.js +15 -0
- package/dist/utils/resolveProjectRoot.js.map +1 -0
- package/dist/utils/schemaConversion/filterFieldsByAccess.d.ts +28 -0
- package/dist/utils/schemaConversion/filterFieldsByAccess.d.ts.map +1 -0
- package/dist/utils/schemaConversion/filterFieldsByAccess.js +71 -0
- package/dist/utils/schemaConversion/filterFieldsByAccess.js.map +1 -0
- package/dist/utils/schemaConversion/getEntityInputSchema.d.ts +13 -0
- package/dist/utils/schemaConversion/getEntityInputSchema.d.ts.map +1 -0
- package/dist/utils/schemaConversion/getEntityInputSchema.js +66 -0
- package/dist/utils/schemaConversion/getEntityInputSchema.js.map +1 -0
- package/dist/utils/schemaConversion/sanitizeEntitySchema.d.ts +10 -0
- package/dist/utils/schemaConversion/sanitizeEntitySchema.d.ts.map +1 -0
- package/dist/utils/schemaConversion/sanitizeEntitySchema.js +384 -0
- package/dist/utils/schemaConversion/sanitizeEntitySchema.js.map +1 -0
- package/dist/utils/schemaConversion/sanitizeEntitySchema.spec.js +133 -0
- package/dist/utils/schemaConversion/sanitizeEntitySchema.spec.js.map +1 -0
- package/dist/utils/toStandardSchema.d.ts +5 -0
- package/dist/utils/toStandardSchema.d.ts.map +1 -0
- package/dist/utils/toStandardSchema.js +4 -0
- package/dist/utils/toStandardSchema.js.map +1 -0
- package/dist/utils/whereSchema.d.ts +9 -0
- package/dist/utils/whereSchema.d.ts.map +1 -0
- package/dist/utils/whereSchema.js +13 -0
- package/dist/utils/whereSchema.js.map +1 -0
- package/package.json +30 -10
- package/src/defaultAccess.ts +3 -0
- package/src/defineTool.ts +44 -0
- package/src/endpoint/access.ts +112 -0
- package/src/endpoint/index.ts +77 -0
- package/src/exports/client.ts +3 -0
- package/src/exports/internal.ts +1 -0
- package/src/index.ts +31 -89
- package/src/mcp/buildMcpServer.ts +284 -0
- package/src/mcp/builtin/collections/authTools.ts +269 -0
- package/src/mcp/builtin/collections/countTool.ts +73 -0
- package/src/mcp/builtin/collections/countVersionsTool.ts +69 -0
- package/src/mcp/builtin/collections/createTool.ts +117 -0
- package/src/mcp/builtin/collections/deleteTool.ts +125 -0
- package/src/mcp/builtin/collections/duplicateTool.ts +134 -0
- package/src/mcp/builtin/collections/findDistinctTool.ts +119 -0
- package/src/mcp/builtin/collections/findTool.ts +216 -0
- package/src/mcp/builtin/collections/findVersionByIDTool.ts +109 -0
- package/src/mcp/builtin/collections/findVersionsTool.ts +154 -0
- package/src/mcp/builtin/collections/formatCollectionError.ts +84 -0
- package/src/mcp/builtin/collections/getCollectionSchemaTool.ts +63 -0
- package/src/mcp/builtin/collections/restoreVersionTool.ts +107 -0
- package/src/mcp/builtin/collections/updateTool.ts +225 -0
- package/src/mcp/builtin/getConfigInfoTool.ts +67 -0
- package/src/mcp/builtin/globals/countVersionsTool.ts +68 -0
- package/src/mcp/builtin/globals/findTool.ts +105 -0
- package/src/mcp/builtin/globals/findVersionByIDTool.ts +103 -0
- package/src/mcp/builtin/globals/findVersionsTool.ts +147 -0
- package/src/mcp/builtin/globals/getGlobalSchemaTool.ts +63 -0
- package/src/mcp/builtin/globals/restoreVersionTool.ts +99 -0
- package/src/mcp/builtin/globals/updateTool.ts +115 -0
- package/src/mcp/builtin/validateEntityData.ts +132 -0
- package/src/mcp/builtinTools.ts +154 -0
- package/src/mcp/sanitizeMCPConfig.ts +278 -0
- package/src/stdio.ts +130 -0
- package/src/types.ts +304 -486
- package/src/utils/getLogger.ts +22 -0
- package/src/utils/getPluginConfig.ts +24 -0
- package/src/utils/resolveProjectRoot.ts +17 -0
- package/src/utils/schemaConversion/filterFieldsByAccess.ts +123 -0
- package/src/utils/schemaConversion/getEntityInputSchema.ts +96 -0
- package/src/utils/schemaConversion/sanitizeEntitySchema.spec.ts +96 -0
- package/src/utils/schemaConversion/sanitizeEntitySchema.ts +432 -0
- package/src/utils/toStandardSchema.ts +9 -0
- package/src/utils/whereSchema.ts +24 -0
- package/dist/collections/createApiKeysCollection.d.ts +0 -7
- package/dist/collections/createApiKeysCollection.d.ts.map +0 -1
- package/dist/collections/createApiKeysCollection.js +0 -317
- package/dist/collections/createApiKeysCollection.js.map +0 -1
- package/dist/defaults.d.ts +0 -4
- package/dist/defaults.d.ts.map +0 -1
- package/dist/defaults.js +0 -5
- package/dist/defaults.js.map +0 -1
- package/dist/endpoints/mcp.d.ts +0 -4
- package/dist/endpoints/mcp.d.ts.map +0 -1
- package/dist/endpoints/mcp.js +0 -71
- package/dist/endpoints/mcp.js.map +0 -1
- package/dist/mcp/createRequest.d.ts +0 -3
- package/dist/mcp/createRequest.d.ts.map +0 -1
- package/dist/mcp/createRequest.js +0 -14
- package/dist/mcp/createRequest.js.map +0 -1
- package/dist/mcp/getMcpHandler.d.ts +0 -4
- package/dist/mcp/getMcpHandler.d.ts.map +0 -1
- package/dist/mcp/getMcpHandler.js +0 -231
- package/dist/mcp/getMcpHandler.js.map +0 -1
- package/dist/mcp/helpers/config.d.ts +0 -22
- package/dist/mcp/helpers/config.d.ts.map +0 -1
- package/dist/mcp/helpers/config.js +0 -153
- package/dist/mcp/helpers/config.js.map +0 -1
- package/dist/mcp/helpers/fields.d.ts +0 -19
- package/dist/mcp/helpers/fields.d.ts.map +0 -1
- package/dist/mcp/helpers/fields.js +0 -102
- package/dist/mcp/helpers/fields.js.map +0 -1
- package/dist/mcp/helpers/fileValidation.d.ts +0 -67
- package/dist/mcp/helpers/fileValidation.d.ts.map +0 -1
- package/dist/mcp/helpers/fileValidation.js +0 -267
- package/dist/mcp/helpers/fileValidation.js.map +0 -1
- package/dist/mcp/registerTool.d.ts +0 -6
- package/dist/mcp/registerTool.d.ts.map +0 -1
- package/dist/mcp/registerTool.js +0 -18
- package/dist/mcp/registerTool.js.map +0 -1
- package/dist/mcp/tools/auth/auth.d.ts +0 -4
- package/dist/mcp/tools/auth/auth.d.ts.map +0 -1
- package/dist/mcp/tools/auth/auth.js +0 -57
- package/dist/mcp/tools/auth/auth.js.map +0 -1
- package/dist/mcp/tools/auth/forgotPassword.d.ts +0 -4
- package/dist/mcp/tools/auth/forgotPassword.d.ts.map +0 -1
- package/dist/mcp/tools/auth/forgotPassword.js +0 -48
- package/dist/mcp/tools/auth/forgotPassword.js.map +0 -1
- package/dist/mcp/tools/auth/login.d.ts +0 -4
- package/dist/mcp/tools/auth/login.d.ts.map +0 -1
- package/dist/mcp/tools/auth/login.js +0 -51
- package/dist/mcp/tools/auth/login.js.map +0 -1
- package/dist/mcp/tools/auth/resetPassword.d.ts +0 -4
- package/dist/mcp/tools/auth/resetPassword.d.ts.map +0 -1
- package/dist/mcp/tools/auth/resetPassword.js +0 -49
- package/dist/mcp/tools/auth/resetPassword.js.map +0 -1
- package/dist/mcp/tools/auth/unlock.d.ts +0 -4
- package/dist/mcp/tools/auth/unlock.d.ts.map +0 -1
- package/dist/mcp/tools/auth/unlock.js +0 -48
- package/dist/mcp/tools/auth/unlock.js.map +0 -1
- package/dist/mcp/tools/auth/verify.d.ts +0 -4
- package/dist/mcp/tools/auth/verify.d.ts.map +0 -1
- package/dist/mcp/tools/auth/verify.js +0 -45
- package/dist/mcp/tools/auth/verify.js.map +0 -1
- package/dist/mcp/tools/collection/create.d.ts +0 -10
- package/dist/mcp/tools/collection/create.d.ts.map +0 -1
- package/dist/mcp/tools/collection/create.js +0 -139
- package/dist/mcp/tools/collection/create.js.map +0 -1
- package/dist/mcp/tools/collection/delete.d.ts +0 -10
- package/dist/mcp/tools/collection/delete.d.ts.map +0 -1
- package/dist/mcp/tools/collection/delete.js +0 -154
- package/dist/mcp/tools/collection/delete.js.map +0 -1
- package/dist/mcp/tools/collection/find.d.ts +0 -10
- package/dist/mcp/tools/collection/find.d.ts.map +0 -1
- package/dist/mcp/tools/collection/find.js +0 -165
- package/dist/mcp/tools/collection/find.js.map +0 -1
- package/dist/mcp/tools/collection/update.d.ts +0 -10
- package/dist/mcp/tools/collection/update.d.ts.map +0 -1
- package/dist/mcp/tools/collection/update.js +0 -209
- package/dist/mcp/tools/collection/update.js.map +0 -1
- package/dist/mcp/tools/config/find.d.ts +0 -10
- package/dist/mcp/tools/config/find.d.ts.map +0 -1
- package/dist/mcp/tools/config/find.js +0 -97
- package/dist/mcp/tools/config/find.js.map +0 -1
- package/dist/mcp/tools/config/update.d.ts +0 -10
- package/dist/mcp/tools/config/update.d.ts.map +0 -1
- package/dist/mcp/tools/config/update.js +0 -215
- package/dist/mcp/tools/config/update.js.map +0 -1
- package/dist/mcp/tools/global/find.d.ts +0 -5
- package/dist/mcp/tools/global/find.d.ts.map +0 -1
- package/dist/mcp/tools/global/find.js +0 -82
- package/dist/mcp/tools/global/find.js.map +0 -1
- package/dist/mcp/tools/global/update.d.ts +0 -6
- package/dist/mcp/tools/global/update.d.ts.map +0 -1
- package/dist/mcp/tools/global/update.js +0 -124
- package/dist/mcp/tools/global/update.js.map +0 -1
- package/dist/mcp/tools/job/create.d.ts +0 -10
- package/dist/mcp/tools/job/create.d.ts.map +0 -1
- package/dist/mcp/tools/job/create.js +0 -293
- package/dist/mcp/tools/job/create.js.map +0 -1
- package/dist/mcp/tools/job/run.d.ts +0 -10
- package/dist/mcp/tools/job/run.d.ts.map +0 -1
- package/dist/mcp/tools/job/run.js +0 -129
- package/dist/mcp/tools/job/run.js.map +0 -1
- package/dist/mcp/tools/job/update.d.ts +0 -11
- package/dist/mcp/tools/job/update.d.ts.map +0 -1
- package/dist/mcp/tools/job/update.js +0 -186
- package/dist/mcp/tools/job/update.js.map +0 -1
- package/dist/mcp/tools/resource/create.d.ts +0 -6
- package/dist/mcp/tools/resource/create.d.ts.map +0 -1
- package/dist/mcp/tools/resource/create.js +0 -124
- package/dist/mcp/tools/resource/create.js.map +0 -1
- package/dist/mcp/tools/resource/delete.d.ts +0 -5
- package/dist/mcp/tools/resource/delete.d.ts.map +0 -1
- package/dist/mcp/tools/resource/delete.js +0 -151
- package/dist/mcp/tools/resource/delete.js.map +0 -1
- package/dist/mcp/tools/resource/find.d.ts +0 -5
- package/dist/mcp/tools/resource/find.d.ts.map +0 -1
- package/dist/mcp/tools/resource/find.js +0 -170
- package/dist/mcp/tools/resource/find.js.map +0 -1
- package/dist/mcp/tools/resource/update.d.ts +0 -6
- package/dist/mcp/tools/resource/update.d.ts.map +0 -1
- package/dist/mcp/tools/resource/update.js +0 -256
- package/dist/mcp/tools/resource/update.js.map +0 -1
- package/dist/mcp/tools/schemas.d.ts +0 -457
- package/dist/mcp/tools/schemas.d.ts.map +0 -1
- package/dist/mcp/tools/schemas.js +0 -243
- package/dist/mcp/tools/schemas.js.map +0 -1
- package/dist/utils/adminEntitySettings.d.ts +0 -17
- package/dist/utils/adminEntitySettings.d.ts.map +0 -1
- package/dist/utils/adminEntitySettings.js +0 -41
- package/dist/utils/adminEntitySettings.js.map +0 -1
- package/dist/utils/createApiKeyFields.d.ts +0 -15
- package/dist/utils/createApiKeyFields.d.ts.map +0 -1
- package/dist/utils/createApiKeyFields.js +0 -57
- package/dist/utils/createApiKeyFields.js.map +0 -1
- package/dist/utils/getEnabledSlugs.d.ts +0 -13
- package/dist/utils/getEnabledSlugs.d.ts.map +0 -1
- package/dist/utils/getEnabledSlugs.js +0 -32
- package/dist/utils/getEnabledSlugs.js.map +0 -1
- package/dist/utils/schemaConversion/convertCollectionSchemaToZod.d.ts +0 -3
- package/dist/utils/schemaConversion/convertCollectionSchemaToZod.d.ts.map +0 -1
- package/dist/utils/schemaConversion/convertCollectionSchemaToZod.js +0 -43
- package/dist/utils/schemaConversion/convertCollectionSchemaToZod.js.map +0 -1
- package/dist/utils/schemaConversion/removeVirtualFieldsFromSchema.d.ts +0 -7
- package/dist/utils/schemaConversion/removeVirtualFieldsFromSchema.d.ts.map +0 -1
- package/dist/utils/schemaConversion/removeVirtualFieldsFromSchema.js +0 -20
- package/dist/utils/schemaConversion/removeVirtualFieldsFromSchema.js.map +0 -1
- package/dist/utils/schemaConversion/sanitizeJsonSchema.d.ts +0 -13
- package/dist/utils/schemaConversion/sanitizeJsonSchema.d.ts.map +0 -1
- package/dist/utils/schemaConversion/sanitizeJsonSchema.js +0 -56
- package/dist/utils/schemaConversion/sanitizeJsonSchema.js.map +0 -1
- package/dist/utils/schemaConversion/simplifyRelationshipFields.d.ts +0 -20
- package/dist/utils/schemaConversion/simplifyRelationshipFields.d.ts.map +0 -1
- package/dist/utils/schemaConversion/simplifyRelationshipFields.js +0 -53
- package/dist/utils/schemaConversion/simplifyRelationshipFields.js.map +0 -1
- package/dist/utils/schemaConversion/transformPointFields.d.ts +0 -3
- package/dist/utils/schemaConversion/transformPointFields.d.ts.map +0 -1
- package/dist/utils/schemaConversion/transformPointFields.js +0 -51
- package/dist/utils/schemaConversion/transformPointFields.js.map +0 -1
- package/src/collections/createApiKeysCollection.ts +0 -373
- package/src/defaults.ts +0 -3
- package/src/endpoints/mcp.ts +0 -91
- package/src/mcp/createRequest.ts +0 -13
- package/src/mcp/getMcpHandler.ts +0 -545
- package/src/mcp/helpers/config.ts +0 -213
- package/src/mcp/helpers/fields.ts +0 -154
- package/src/mcp/helpers/fileValidation.ts +0 -362
- package/src/mcp/registerTool.ts +0 -22
- package/src/mcp/tools/auth/auth.ts +0 -71
- package/src/mcp/tools/auth/forgotPassword.ts +0 -70
- package/src/mcp/tools/auth/login.ts +0 -72
- package/src/mcp/tools/auth/resetPassword.ts +0 -61
- package/src/mcp/tools/auth/unlock.ts +0 -64
- package/src/mcp/tools/auth/verify.ts +0 -57
- package/src/mcp/tools/collection/create.ts +0 -210
- package/src/mcp/tools/collection/delete.ts +0 -211
- package/src/mcp/tools/collection/find.ts +0 -224
- package/src/mcp/tools/collection/update.ts +0 -290
- package/src/mcp/tools/config/find.ts +0 -128
- package/src/mcp/tools/config/update.ts +0 -280
- package/src/mcp/tools/global/find.ts +0 -128
- package/src/mcp/tools/global/update.ts +0 -207
- package/src/mcp/tools/job/create.ts +0 -416
- package/src/mcp/tools/job/run.ts +0 -167
- package/src/mcp/tools/job/update.ts +0 -274
- package/src/mcp/tools/resource/create.ts +0 -211
- package/src/mcp/tools/resource/delete.ts +0 -218
- package/src/mcp/tools/resource/find.ts +0 -246
- package/src/mcp/tools/resource/update.ts +0 -383
- package/src/mcp/tools/schemas.ts +0 -520
- package/src/utils/adminEntitySettings.ts +0 -40
- package/src/utils/createApiKeyFields.ts +0 -72
- package/src/utils/getEnabledSlugs.ts +0 -42
- package/src/utils/schemaConversion/convertCollectionSchemaToZod.ts +0 -52
- package/src/utils/schemaConversion/removeVirtualFieldsFromSchema.ts +0 -27
- package/src/utils/schemaConversion/sanitizeJsonSchema.ts +0 -62
- package/src/utils/schemaConversion/simplifyRelationshipFields.ts +0 -65
- package/src/utils/schemaConversion/transformPointFields.ts +0 -55
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import type { CollectionTool, GlobalTool, Tool } from '../types.js'
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
authCollectionTool,
|
|
5
|
+
forgotPasswordCollectionTool,
|
|
6
|
+
loginCollectionTool,
|
|
7
|
+
resetPasswordCollectionTool,
|
|
8
|
+
unlockCollectionTool,
|
|
9
|
+
verifyCollectionTool,
|
|
10
|
+
} from './builtin/collections/authTools.js'
|
|
11
|
+
import { countDocumentsTool } from './builtin/collections/countTool.js'
|
|
12
|
+
import { countVersionsTool } from './builtin/collections/countVersionsTool.js'
|
|
13
|
+
import { createDocumentTool } from './builtin/collections/createTool.js'
|
|
14
|
+
import { deleteDocumentsTool } from './builtin/collections/deleteTool.js'
|
|
15
|
+
import { duplicateDocumentTool } from './builtin/collections/duplicateTool.js'
|
|
16
|
+
import { findDistinctTool } from './builtin/collections/findDistinctTool.js'
|
|
17
|
+
import { findDocumentsTool } from './builtin/collections/findTool.js'
|
|
18
|
+
import { findVersionByIDTool } from './builtin/collections/findVersionByIDTool.js'
|
|
19
|
+
import { findVersionsTool } from './builtin/collections/findVersionsTool.js'
|
|
20
|
+
import { getCollectionSchemaTool } from './builtin/collections/getCollectionSchemaTool.js'
|
|
21
|
+
import { restoreVersionTool } from './builtin/collections/restoreVersionTool.js'
|
|
22
|
+
import { updateDocumentTool } from './builtin/collections/updateTool.js'
|
|
23
|
+
import { getConfigInfoTool } from './builtin/getConfigInfoTool.js'
|
|
24
|
+
import { countGlobalVersionsTool } from './builtin/globals/countVersionsTool.js'
|
|
25
|
+
import { findGlobalTool } from './builtin/globals/findTool.js'
|
|
26
|
+
import { findGlobalVersionByIDTool } from './builtin/globals/findVersionByIDTool.js'
|
|
27
|
+
import { findGlobalVersionsTool } from './builtin/globals/findVersionsTool.js'
|
|
28
|
+
import { getGlobalSchemaTool } from './builtin/globals/getGlobalSchemaTool.js'
|
|
29
|
+
import { restoreGlobalVersionTool } from './builtin/globals/restoreVersionTool.js'
|
|
30
|
+
import { updateGlobalTool } from './builtin/globals/updateTool.js'
|
|
31
|
+
|
|
32
|
+
type CollectionBuiltin = {
|
|
33
|
+
mcpName: string
|
|
34
|
+
requiresDuplicateEnabled?: boolean
|
|
35
|
+
requiresVersions?: boolean
|
|
36
|
+
tool: CollectionTool
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
type GlobalBuiltin = {
|
|
40
|
+
mcpName: string
|
|
41
|
+
requiresVersions?: boolean
|
|
42
|
+
tool: GlobalTool
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export const TOOL_BUILTINS = {
|
|
46
|
+
getConfigInfo: { mcpName: 'getConfigInfo', tool: getConfigInfoTool },
|
|
47
|
+
} satisfies Record<string, { mcpName: string; tool: Tool }>
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* The static built-in collection CRUD tools. Keys here are the source of truth
|
|
51
|
+
* for `MCPCollectionBuiltinName` — adding/removing an entry updates the type
|
|
52
|
+
* automatically.
|
|
53
|
+
*/
|
|
54
|
+
export const COLLECTION_BUILTINS = {
|
|
55
|
+
count: { mcpName: 'countDocuments', tool: countDocumentsTool },
|
|
56
|
+
countVersions: { mcpName: 'countVersions', requiresVersions: true, tool: countVersionsTool },
|
|
57
|
+
create: { mcpName: 'createDocument', tool: createDocumentTool },
|
|
58
|
+
delete: { mcpName: 'deleteDocuments', tool: deleteDocumentsTool },
|
|
59
|
+
duplicate: {
|
|
60
|
+
mcpName: 'duplicateDocument',
|
|
61
|
+
requiresDuplicateEnabled: true,
|
|
62
|
+
tool: duplicateDocumentTool,
|
|
63
|
+
},
|
|
64
|
+
find: { mcpName: 'findDocuments', tool: findDocumentsTool },
|
|
65
|
+
findDistinct: { mcpName: 'findDistinct', tool: findDistinctTool },
|
|
66
|
+
findVersionByID: {
|
|
67
|
+
mcpName: 'findVersionByID',
|
|
68
|
+
requiresVersions: true,
|
|
69
|
+
tool: findVersionByIDTool,
|
|
70
|
+
},
|
|
71
|
+
findVersions: { mcpName: 'findVersions', requiresVersions: true, tool: findVersionsTool },
|
|
72
|
+
getCollectionSchema: { mcpName: 'getCollectionSchema', tool: getCollectionSchemaTool },
|
|
73
|
+
restoreVersion: { mcpName: 'restoreVersion', requiresVersions: true, tool: restoreVersionTool },
|
|
74
|
+
update: { mcpName: 'updateDocument', tool: updateDocumentTool },
|
|
75
|
+
} satisfies Record<string, CollectionBuiltin>
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* The static auth tools surfaced under auth-enabled collections. Keys are the
|
|
79
|
+
* source of truth for `MCPCollectionAuthToolName`.
|
|
80
|
+
*/
|
|
81
|
+
export const COLLECTION_AUTH_BUILTINS = {
|
|
82
|
+
auth: { mcpName: 'auth', tool: authCollectionTool },
|
|
83
|
+
forgotPassword: {
|
|
84
|
+
mcpName: 'forgotPassword',
|
|
85
|
+
tool: forgotPasswordCollectionTool,
|
|
86
|
+
},
|
|
87
|
+
login: { mcpName: 'login', tool: loginCollectionTool },
|
|
88
|
+
resetPassword: {
|
|
89
|
+
mcpName: 'resetPassword',
|
|
90
|
+
tool: resetPasswordCollectionTool,
|
|
91
|
+
},
|
|
92
|
+
unlock: { mcpName: 'unlock', tool: unlockCollectionTool },
|
|
93
|
+
verify: { mcpName: 'verify', tool: verifyCollectionTool },
|
|
94
|
+
} satisfies Record<string, { mcpName: string; tool: CollectionTool }>
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* The static built-in global tools. Keys are the source of truth for
|
|
98
|
+
* `MCPGlobalBuiltinName`.
|
|
99
|
+
*/
|
|
100
|
+
export const GLOBAL_BUILTINS = {
|
|
101
|
+
countGlobalVersions: {
|
|
102
|
+
mcpName: 'countGlobalVersions',
|
|
103
|
+
requiresVersions: true,
|
|
104
|
+
tool: countGlobalVersionsTool,
|
|
105
|
+
},
|
|
106
|
+
find: { mcpName: 'findGlobal', tool: findGlobalTool },
|
|
107
|
+
findGlobalVersionByID: {
|
|
108
|
+
mcpName: 'findGlobalVersionByID',
|
|
109
|
+
requiresVersions: true,
|
|
110
|
+
tool: findGlobalVersionByIDTool,
|
|
111
|
+
},
|
|
112
|
+
findGlobalVersions: {
|
|
113
|
+
mcpName: 'findGlobalVersions',
|
|
114
|
+
requiresVersions: true,
|
|
115
|
+
tool: findGlobalVersionsTool,
|
|
116
|
+
},
|
|
117
|
+
getGlobalSchema: { mcpName: 'getGlobalSchema', tool: getGlobalSchemaTool },
|
|
118
|
+
restoreGlobalVersion: {
|
|
119
|
+
mcpName: 'restoreGlobalVersion',
|
|
120
|
+
requiresVersions: true,
|
|
121
|
+
tool: restoreGlobalVersionTool,
|
|
122
|
+
},
|
|
123
|
+
update: { mcpName: 'updateGlobal', tool: updateGlobalTool },
|
|
124
|
+
} satisfies Record<string, GlobalBuiltin>
|
|
125
|
+
|
|
126
|
+
export type MCPCollectionBuiltinName = keyof typeof COLLECTION_BUILTINS
|
|
127
|
+
|
|
128
|
+
export type MCPCollectionAuthToolName = keyof typeof COLLECTION_AUTH_BUILTINS
|
|
129
|
+
|
|
130
|
+
export type MCPGlobalBuiltinName = keyof typeof GLOBAL_BUILTINS
|
|
131
|
+
|
|
132
|
+
export type MCPTopLevelBuiltinName = keyof typeof TOOL_BUILTINS
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Pre-typed `Object.entries` for each registry. The cast from `string` to the
|
|
136
|
+
* literal key union lives here once so consumers can iterate without their own
|
|
137
|
+
* cast — TypeScript's `Object.entries` always widens keys to `string`, which
|
|
138
|
+
* defeats the narrow type lookups on `MCPCollectionToolsMap`.
|
|
139
|
+
*/
|
|
140
|
+
export const TOOL_BUILTIN_ENTRIES = Object.entries(TOOL_BUILTINS) as Array<
|
|
141
|
+
[MCPTopLevelBuiltinName, (typeof TOOL_BUILTINS)[MCPTopLevelBuiltinName]]
|
|
142
|
+
>
|
|
143
|
+
|
|
144
|
+
export const COLLECTION_BUILTIN_ENTRIES = Object.entries(COLLECTION_BUILTINS) as Array<
|
|
145
|
+
[MCPCollectionBuiltinName, CollectionBuiltin]
|
|
146
|
+
>
|
|
147
|
+
|
|
148
|
+
export const COLLECTION_AUTH_BUILTIN_ENTRIES = Object.entries(COLLECTION_AUTH_BUILTINS) as Array<
|
|
149
|
+
[MCPCollectionAuthToolName, (typeof COLLECTION_AUTH_BUILTINS)[MCPCollectionAuthToolName]]
|
|
150
|
+
>
|
|
151
|
+
|
|
152
|
+
export const GLOBAL_BUILTIN_ENTRIES = Object.entries(GLOBAL_BUILTINS) as Array<
|
|
153
|
+
[MCPGlobalBuiltinName, GlobalBuiltin]
|
|
154
|
+
>
|
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
CollectionConfig,
|
|
3
|
+
Config,
|
|
4
|
+
GlobalConfig,
|
|
5
|
+
SanitizedCollectionConfig,
|
|
6
|
+
SanitizedConfig,
|
|
7
|
+
SanitizedGlobalConfig,
|
|
8
|
+
} from 'payload'
|
|
9
|
+
|
|
10
|
+
import type {
|
|
11
|
+
CollectionMCPItem,
|
|
12
|
+
CollectionTool,
|
|
13
|
+
GlobalMCPItem,
|
|
14
|
+
GlobalTool,
|
|
15
|
+
MCPItem,
|
|
16
|
+
MCPPluginConfig,
|
|
17
|
+
SanitizedMCPPluginConfig,
|
|
18
|
+
} from '../types.js'
|
|
19
|
+
|
|
20
|
+
import { defaultAccess } from '../defaultAccess.js'
|
|
21
|
+
import {
|
|
22
|
+
COLLECTION_AUTH_BUILTIN_ENTRIES,
|
|
23
|
+
COLLECTION_AUTH_BUILTINS,
|
|
24
|
+
COLLECTION_BUILTIN_ENTRIES,
|
|
25
|
+
COLLECTION_BUILTINS,
|
|
26
|
+
GLOBAL_BUILTIN_ENTRIES,
|
|
27
|
+
GLOBAL_BUILTINS,
|
|
28
|
+
TOOL_BUILTIN_ENTRIES,
|
|
29
|
+
TOOL_BUILTINS,
|
|
30
|
+
} from './builtinTools.js'
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Converts the user-configured `MCPPluginConfig` into a `SanitizedMCPPluginConfig`:
|
|
34
|
+
* - Flattens `tools` / `prompts` / `resources` / per-collection / per-global
|
|
35
|
+
* tool maps into a single `items` array.
|
|
36
|
+
* - Applies built-in tools for collections and globals, respecting opt-out user overrides.
|
|
37
|
+
*
|
|
38
|
+
* Called once during plugin init. After that, `plugins['@payloadcms/plugin-mcp']
|
|
39
|
+
* ?.options` holds the sanitized result
|
|
40
|
+
*/
|
|
41
|
+
export const sanitizeMCPConfig = ({
|
|
42
|
+
config,
|
|
43
|
+
pluginConfig,
|
|
44
|
+
}: {
|
|
45
|
+
config: Config | SanitizedConfig
|
|
46
|
+
pluginConfig: MCPPluginConfig
|
|
47
|
+
}): SanitizedMCPPluginConfig => {
|
|
48
|
+
const items: MCPItem[] = []
|
|
49
|
+
|
|
50
|
+
for (const collection of config.collections ?? []) {
|
|
51
|
+
items.push(...sanitizeCollectionConfig({ collection, pluginConfig }))
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
for (const global of config.globals ?? []) {
|
|
55
|
+
items.push(...sanitizeGlobalConfig({ global, pluginConfig }))
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
for (const [configKey, { mcpName, tool }] of TOOL_BUILTIN_ENTRIES) {
|
|
59
|
+
items.push({
|
|
60
|
+
type: 'tool',
|
|
61
|
+
configKey,
|
|
62
|
+
label: tool.annotations?.title ?? configKey,
|
|
63
|
+
mcpName,
|
|
64
|
+
tool: { ...tool, access: tool.access ?? defaultAccess },
|
|
65
|
+
})
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
for (const [configKey, tool] of Object.entries(pluginConfig.tools ?? {})) {
|
|
69
|
+
if (configKey in TOOL_BUILTINS) {
|
|
70
|
+
continue
|
|
71
|
+
}
|
|
72
|
+
items.push({
|
|
73
|
+
type: 'tool',
|
|
74
|
+
configKey,
|
|
75
|
+
label: tool.annotations?.title ?? configKey,
|
|
76
|
+
mcpName: configKey,
|
|
77
|
+
tool: { ...tool, access: tool.access ?? defaultAccess },
|
|
78
|
+
})
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
for (const [configKey, prompt] of Object.entries(pluginConfig.prompts ?? {})) {
|
|
82
|
+
items.push({
|
|
83
|
+
type: 'prompt',
|
|
84
|
+
configKey,
|
|
85
|
+
label: prompt.title ?? configKey,
|
|
86
|
+
mcpName: configKey,
|
|
87
|
+
prompt: { ...prompt, access: prompt.access ?? defaultAccess },
|
|
88
|
+
})
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
for (const [configKey, resource] of Object.entries(pluginConfig.resources ?? {})) {
|
|
92
|
+
items.push({
|
|
93
|
+
type: 'resource',
|
|
94
|
+
configKey,
|
|
95
|
+
label: resource.title ?? configKey,
|
|
96
|
+
mcpName: configKey,
|
|
97
|
+
resource: { ...resource, access: resource.access ?? defaultAccess },
|
|
98
|
+
})
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
return {
|
|
102
|
+
disabled: pluginConfig.disabled,
|
|
103
|
+
hooks: pluginConfig.hooks,
|
|
104
|
+
items,
|
|
105
|
+
mcp: pluginConfig.mcp,
|
|
106
|
+
overrideGetAuthorizedMCP: pluginConfig.overrideGetAuthorizedMCP,
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
const sanitizeCollectionConfig = ({
|
|
111
|
+
collection,
|
|
112
|
+
pluginConfig,
|
|
113
|
+
}: {
|
|
114
|
+
collection: CollectionConfig | SanitizedCollectionConfig
|
|
115
|
+
pluginConfig: MCPPluginConfig
|
|
116
|
+
}): CollectionMCPItem[] => {
|
|
117
|
+
const slug = collection.slug
|
|
118
|
+
const collectionPluginConfig = pluginConfig.collections?.[slug]
|
|
119
|
+
const items: CollectionMCPItem[] = []
|
|
120
|
+
/**
|
|
121
|
+
* Payload disables duplicate for auth collections by default unless the
|
|
122
|
+
* collection explicitly opts back in with `disableDuplicate: false`.
|
|
123
|
+
*/
|
|
124
|
+
const isDuplicateDisabled =
|
|
125
|
+
collection.disableDuplicate === true ||
|
|
126
|
+
(Boolean(collection.auth) && collection.disableDuplicate !== false)
|
|
127
|
+
|
|
128
|
+
for (const [
|
|
129
|
+
toolKey,
|
|
130
|
+
{ mcpName, requiresDuplicateEnabled, requiresVersions, tool },
|
|
131
|
+
] of COLLECTION_BUILTIN_ENTRIES) {
|
|
132
|
+
if (requiresVersions && !collection.versions) {
|
|
133
|
+
continue
|
|
134
|
+
}
|
|
135
|
+
if (requiresDuplicateEnabled && isDuplicateDisabled) {
|
|
136
|
+
continue
|
|
137
|
+
}
|
|
138
|
+
const matchedConfigEntry = collectionPluginConfig?.tools?.[toolKey]
|
|
139
|
+
if (matchedConfigEntry === false) {
|
|
140
|
+
continue
|
|
141
|
+
}
|
|
142
|
+
const override = typeof matchedConfigEntry === 'object' ? matchedConfigEntry : undefined
|
|
143
|
+
const annotations = { ...tool.annotations, ...override?.annotations }
|
|
144
|
+
items.push({
|
|
145
|
+
type: 'collectionTool',
|
|
146
|
+
collectionSlug: slug,
|
|
147
|
+
configKey: toolKey,
|
|
148
|
+
label: annotations.title ?? toolKey,
|
|
149
|
+
mcpName,
|
|
150
|
+
tool: {
|
|
151
|
+
...tool,
|
|
152
|
+
access: override?.access ?? tool.access ?? defaultAccess,
|
|
153
|
+
annotations,
|
|
154
|
+
description: override?.description ?? tool.description,
|
|
155
|
+
overrideResponse:
|
|
156
|
+
override?.overrideResponse ??
|
|
157
|
+
collectionPluginConfig?.overrideResponse ??
|
|
158
|
+
tool.overrideResponse,
|
|
159
|
+
},
|
|
160
|
+
})
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
if (collection.auth) {
|
|
164
|
+
for (const [authToolKey, { mcpName, tool }] of COLLECTION_AUTH_BUILTIN_ENTRIES) {
|
|
165
|
+
const matchedConfigEntry = collectionPluginConfig?.tools?.[authToolKey]
|
|
166
|
+
if (!matchedConfigEntry) {
|
|
167
|
+
continue
|
|
168
|
+
}
|
|
169
|
+
// `true` means "enable, no override"; only the object form carries fields.
|
|
170
|
+
const override = typeof matchedConfigEntry === 'object' ? matchedConfigEntry : undefined
|
|
171
|
+
const annotations = { ...tool.annotations, ...override?.annotations }
|
|
172
|
+
items.push({
|
|
173
|
+
type: 'collectionTool',
|
|
174
|
+
collectionSlug: slug,
|
|
175
|
+
configKey: authToolKey,
|
|
176
|
+
label: annotations.title ?? authToolKey,
|
|
177
|
+
mcpName,
|
|
178
|
+
tool: {
|
|
179
|
+
...tool,
|
|
180
|
+
access: override?.access ?? tool.access ?? defaultAccess,
|
|
181
|
+
annotations,
|
|
182
|
+
description: override?.description ?? tool.description,
|
|
183
|
+
overrideResponse:
|
|
184
|
+
override?.overrideResponse ??
|
|
185
|
+
collectionPluginConfig?.overrideResponse ??
|
|
186
|
+
tool.overrideResponse,
|
|
187
|
+
},
|
|
188
|
+
})
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
// Cast: builtin keys are filtered out below, so the remaining values are
|
|
193
|
+
// always custom tools (`CollectionTool`) or undefined
|
|
194
|
+
const customEntries = Object.entries(collectionPluginConfig?.tools ?? {}) as Array<
|
|
195
|
+
[string, CollectionTool | undefined]
|
|
196
|
+
>
|
|
197
|
+
for (const [configKey, customTool] of customEntries) {
|
|
198
|
+
if (configKey in COLLECTION_BUILTINS || configKey in COLLECTION_AUTH_BUILTINS) {
|
|
199
|
+
continue
|
|
200
|
+
}
|
|
201
|
+
if (!customTool) {
|
|
202
|
+
continue
|
|
203
|
+
}
|
|
204
|
+
items.push({
|
|
205
|
+
type: 'collectionTool',
|
|
206
|
+
collectionSlug: slug,
|
|
207
|
+
configKey,
|
|
208
|
+
label: customTool.annotations?.title ?? configKey,
|
|
209
|
+
mcpName: configKey,
|
|
210
|
+
tool: { ...customTool, access: customTool.access ?? defaultAccess },
|
|
211
|
+
})
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
return items
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
const sanitizeGlobalConfig = ({
|
|
218
|
+
global,
|
|
219
|
+
pluginConfig,
|
|
220
|
+
}: {
|
|
221
|
+
global: GlobalConfig | SanitizedGlobalConfig
|
|
222
|
+
pluginConfig: MCPPluginConfig
|
|
223
|
+
}): GlobalMCPItem[] => {
|
|
224
|
+
const slug = global.slug
|
|
225
|
+
const globalPluginConfig = pluginConfig.globals?.[slug]
|
|
226
|
+
const items: GlobalMCPItem[] = []
|
|
227
|
+
|
|
228
|
+
for (const [toolKey, { mcpName, requiresVersions, tool }] of GLOBAL_BUILTIN_ENTRIES) {
|
|
229
|
+
if (requiresVersions && !global.versions) {
|
|
230
|
+
continue
|
|
231
|
+
}
|
|
232
|
+
const matchedConfigEntry = globalPluginConfig?.tools?.[toolKey]
|
|
233
|
+
if (matchedConfigEntry === false) {
|
|
234
|
+
continue
|
|
235
|
+
}
|
|
236
|
+
const override = typeof matchedConfigEntry === 'object' ? matchedConfigEntry : undefined
|
|
237
|
+
const annotations = { ...tool.annotations, ...override?.annotations }
|
|
238
|
+
items.push({
|
|
239
|
+
type: 'globalTool',
|
|
240
|
+
configKey: toolKey,
|
|
241
|
+
globalSlug: slug,
|
|
242
|
+
label: annotations.title ?? toolKey,
|
|
243
|
+
mcpName,
|
|
244
|
+
tool: {
|
|
245
|
+
...tool,
|
|
246
|
+
access: override?.access ?? tool.access ?? defaultAccess,
|
|
247
|
+
annotations,
|
|
248
|
+
description: override?.description ?? tool.description,
|
|
249
|
+
overrideResponse:
|
|
250
|
+
override?.overrideResponse ??
|
|
251
|
+
globalPluginConfig?.overrideResponse ??
|
|
252
|
+
tool.overrideResponse,
|
|
253
|
+
},
|
|
254
|
+
})
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
const customEntries = Object.entries(globalPluginConfig?.tools ?? {}) as Array<
|
|
258
|
+
[string, GlobalTool | undefined]
|
|
259
|
+
>
|
|
260
|
+
for (const [configKey, customTool] of customEntries) {
|
|
261
|
+
if (configKey in GLOBAL_BUILTINS) {
|
|
262
|
+
continue
|
|
263
|
+
}
|
|
264
|
+
if (!customTool) {
|
|
265
|
+
continue
|
|
266
|
+
}
|
|
267
|
+
items.push({
|
|
268
|
+
type: 'globalTool',
|
|
269
|
+
configKey,
|
|
270
|
+
globalSlug: slug,
|
|
271
|
+
label: customTool.annotations?.title ?? configKey,
|
|
272
|
+
mcpName: configKey,
|
|
273
|
+
tool: { ...customTool, access: customTool.access ?? defaultAccess },
|
|
274
|
+
})
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
return items
|
|
278
|
+
}
|
package/src/stdio.ts
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import type { Config, Plugin, SanitizedConfig } from 'payload'
|
|
2
|
+
|
|
3
|
+
/* eslint-disable no-console */
|
|
4
|
+
import { serveStdio } from '@modelcontextprotocol/server/stdio'
|
|
5
|
+
import { fileURLToPath, pathToFileURL } from 'node:url'
|
|
6
|
+
import { createLocalReq, getPayload } from 'payload'
|
|
7
|
+
import { findConfig } from 'payload/node'
|
|
8
|
+
|
|
9
|
+
import type { SanitizedMCPPluginConfig } from './types.js'
|
|
10
|
+
|
|
11
|
+
import { getAuthorizedMCP } from './endpoint/access.js'
|
|
12
|
+
import { buildMcpServer } from './mcp/buildMcpServer.js'
|
|
13
|
+
import { sanitizeMCPConfig } from './mcp/sanitizeMCPConfig.js'
|
|
14
|
+
import { getPluginConfig } from './utils/getPluginConfig.js'
|
|
15
|
+
import { resolveProjectRoot } from './utils/resolveProjectRoot.js'
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Starts Payload's MCP server over stdin and stdout.
|
|
19
|
+
*
|
|
20
|
+
* Set `PAYLOAD_MCP_AUTHORIZATION` to authenticate. In development,
|
|
21
|
+
* `PAYLOAD_MCP_OVERRIDE_ACCESS=true` skips access checks.
|
|
22
|
+
*/
|
|
23
|
+
export const runMcpStdio = async (): Promise<void> => {
|
|
24
|
+
// MCP clients may start this command from another folder. Move to the Payload
|
|
25
|
+
// project so findConfig() can find the config.
|
|
26
|
+
const projectRoot = resolveProjectRoot(fileURLToPath(import.meta.url))
|
|
27
|
+
if (projectRoot) {
|
|
28
|
+
process.chdir(projectRoot)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const configPath = findConfig()
|
|
32
|
+
const configModule = await import(pathToFileURL(configPath).toString())
|
|
33
|
+
const config = (await (configModule.default ?? configModule)) as SanitizedConfig
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* stdout is only for MCP messages. The spec says the server must not write
|
|
37
|
+
* logs there and may write them to stderr instead.
|
|
38
|
+
*
|
|
39
|
+
* The 2.0 client library recovers from stray stdout logs, but that behavior is not
|
|
40
|
+
* guaranteed. Move Payload logs to stderr so Payload does not add invalid data
|
|
41
|
+
* to stdout. Keep options from configurable loggers. Replace pre-built loggers
|
|
42
|
+
* because their output cannot be redirected.
|
|
43
|
+
*
|
|
44
|
+
* @see https://modelcontextprotocol.io/specification/2025-11-25/basic/transports#stdio
|
|
45
|
+
*/
|
|
46
|
+
const loggerConfig: { logger?: Config['logger'] } = config
|
|
47
|
+
if (
|
|
48
|
+
loggerConfig.logger &&
|
|
49
|
+
typeof loggerConfig.logger === 'object' &&
|
|
50
|
+
'options' in loggerConfig.logger
|
|
51
|
+
) {
|
|
52
|
+
loggerConfig.logger.destination = process.stderr
|
|
53
|
+
} else {
|
|
54
|
+
loggerConfig.logger = { destination: process.stderr, options: {} }
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const payload = await getPayload({ config, cron: false, disableOnInit: true })
|
|
58
|
+
|
|
59
|
+
let pluginConfig: SanitizedMCPPluginConfig
|
|
60
|
+
try {
|
|
61
|
+
pluginConfig = getPluginConfig({ config: payload.config })
|
|
62
|
+
} catch {
|
|
63
|
+
// The command also works when mcpPlugin() is not in the Payload config.
|
|
64
|
+
pluginConfig = sanitizeMCPConfig({ config: payload.config, pluginConfig: {} })
|
|
65
|
+
|
|
66
|
+
const fallbackPlugin: Plugin = (config) => config
|
|
67
|
+
Object.assign(fallbackPlugin, {
|
|
68
|
+
slug: '@payloadcms/plugin-mcp',
|
|
69
|
+
sanitizedOptions: pluginConfig,
|
|
70
|
+
})
|
|
71
|
+
payload.config.plugins ??= []
|
|
72
|
+
payload.config.plugins.push(fallbackPlugin)
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const overrideAccessEnv = process.env.PAYLOAD_MCP_OVERRIDE_ACCESS
|
|
76
|
+
let overrideAccess = false
|
|
77
|
+
|
|
78
|
+
if (overrideAccessEnv === 'true') {
|
|
79
|
+
overrideAccess = true
|
|
80
|
+
} else if (overrideAccessEnv && overrideAccessEnv !== 'false') {
|
|
81
|
+
throw new Error('PAYLOAD_MCP_OVERRIDE_ACCESS must be "true" or "false".')
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (overrideAccess && process.env.NODE_ENV !== 'development') {
|
|
85
|
+
throw new Error('PAYLOAD_MCP_OVERRIDE_ACCESS is only available in development.')
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const headers = new Headers()
|
|
89
|
+
if (process.env.PAYLOAD_MCP_AUTHORIZATION) {
|
|
90
|
+
headers.set('Authorization', process.env.PAYLOAD_MCP_AUTHORIZATION)
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const req = await createLocalReq({ req: { headers } }, payload)
|
|
94
|
+
req.payloadAPI = 'MCP' as const
|
|
95
|
+
const authorizedMCP = await getAuthorizedMCP({ overrideAccess, req })
|
|
96
|
+
|
|
97
|
+
const stdioServer = serveStdio(() => buildMcpServer({ authorizedMCP, pluginConfig, req }), {
|
|
98
|
+
onerror: (err) => {
|
|
99
|
+
// MCP messages use stdout, so write SDK errors to stderr.
|
|
100
|
+
console.error('[payload-mcp] error serving MCP over stdio:', err)
|
|
101
|
+
},
|
|
102
|
+
})
|
|
103
|
+
|
|
104
|
+
// Close the MCP server and Payload when the client disconnects or the process stops.
|
|
105
|
+
let isShuttingDown = false
|
|
106
|
+
const shutdown = async () => {
|
|
107
|
+
if (isShuttingDown) {
|
|
108
|
+
return
|
|
109
|
+
}
|
|
110
|
+
isShuttingDown = true
|
|
111
|
+
|
|
112
|
+
try {
|
|
113
|
+
await stdioServer.close()
|
|
114
|
+
} catch (err) {
|
|
115
|
+
console.error('[payload-mcp] error closing server:', err)
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
try {
|
|
119
|
+
await payload.destroy()
|
|
120
|
+
} catch (err) {
|
|
121
|
+
console.error('[payload-mcp] error destroying payload:', err)
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
process.exit(0)
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
process.once('SIGINT', () => void shutdown())
|
|
128
|
+
process.once('SIGTERM', () => void shutdown())
|
|
129
|
+
process.stdin.once('close', () => void shutdown())
|
|
130
|
+
}
|