@payloadcms/plugin-mcp 4.0.0-internal.d28e9fb → 4.0.0-internal.d7d662c
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +1 -1
- package/bin.js +39 -0
- package/dist/defaultAccess.d.ts +3 -0
- package/dist/defaultAccess.d.ts.map +1 -0
- package/dist/defaultAccess.js +3 -0
- package/dist/defaultAccess.js.map +1 -0
- package/dist/defineTool.d.ts +26 -0
- package/dist/defineTool.d.ts.map +1 -0
- package/dist/defineTool.js +37 -0
- package/dist/defineTool.js.map +1 -0
- package/dist/endpoint/access.d.ts +17 -0
- package/dist/endpoint/access.d.ts.map +1 -0
- package/dist/endpoint/access.js +105 -0
- package/dist/endpoint/access.js.map +1 -0
- package/dist/endpoint/index.d.ts +3 -0
- package/dist/endpoint/index.d.ts.map +1 -0
- package/dist/endpoint/index.js +129 -0
- package/dist/endpoint/index.js.map +1 -0
- package/dist/endpoint/oauth.d.ts +35 -0
- package/dist/endpoint/oauth.d.ts.map +1 -0
- package/dist/endpoint/oauth.js +87 -0
- package/dist/endpoint/oauth.js.map +1 -0
- package/dist/exports/client.d.ts +2 -0
- package/dist/exports/client.d.ts.map +1 -0
- package/dist/exports/client.js +4 -0
- package/dist/exports/client.js.map +1 -0
- package/dist/exports/internal.d.ts +2 -0
- package/dist/exports/internal.d.ts.map +1 -0
- package/dist/exports/internal.js +3 -0
- package/dist/exports/internal.js.map +1 -0
- package/dist/index.d.ts +14 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +50 -67
- package/dist/index.js.map +1 -1
- package/dist/mcp/buildMcpServer.d.ts +19 -0
- package/dist/mcp/buildMcpServer.d.ts.map +1 -0
- package/dist/mcp/buildMcpServer.js +235 -0
- package/dist/mcp/buildMcpServer.js.map +1 -0
- package/dist/mcp/builtin/collections/authTools.d.ts +7 -0
- package/dist/mcp/builtin/collections/authTools.d.ts.map +1 -0
- package/dist/mcp/builtin/collections/authTools.js +312 -0
- package/dist/mcp/builtin/collections/authTools.js.map +1 -0
- package/dist/mcp/builtin/collections/countTool.d.ts +2 -0
- package/dist/mcp/builtin/collections/countTool.d.ts.map +1 -0
- package/dist/mcp/builtin/collections/countTool.js +63 -0
- package/dist/mcp/builtin/collections/countTool.js.map +1 -0
- package/dist/mcp/builtin/collections/countVersionsTool.d.ts +2 -0
- package/dist/mcp/builtin/collections/countVersionsTool.d.ts.map +1 -0
- package/dist/mcp/builtin/collections/countVersionsTool.js +60 -0
- package/dist/mcp/builtin/collections/countVersionsTool.js.map +1 -0
- package/dist/mcp/builtin/collections/createTool.d.ts +2 -0
- package/dist/mcp/builtin/collections/createTool.d.ts.map +1 -0
- package/dist/mcp/builtin/collections/createTool.js +137 -0
- package/dist/mcp/builtin/collections/createTool.js.map +1 -0
- package/dist/mcp/builtin/collections/deleteTool.d.ts +2 -0
- package/dist/mcp/builtin/collections/deleteTool.d.ts.map +1 -0
- package/dist/mcp/builtin/collections/deleteTool.js +111 -0
- package/dist/mcp/builtin/collections/deleteTool.js.map +1 -0
- package/dist/mcp/builtin/collections/duplicateTool.d.ts +2 -0
- package/dist/mcp/builtin/collections/duplicateTool.d.ts.map +1 -0
- package/dist/mcp/builtin/collections/duplicateTool.js +90 -0
- package/dist/mcp/builtin/collections/duplicateTool.js.map +1 -0
- package/dist/mcp/builtin/collections/fileInput.d.ts +28 -0
- package/dist/mcp/builtin/collections/fileInput.d.ts.map +1 -0
- package/dist/mcp/builtin/collections/fileInput.js +88 -0
- package/dist/mcp/builtin/collections/fileInput.js.map +1 -0
- package/dist/mcp/builtin/collections/findDistinctTool.d.ts +2 -0
- package/dist/mcp/builtin/collections/findDistinctTool.d.ts.map +1 -0
- package/dist/mcp/builtin/collections/findDistinctTool.js +77 -0
- package/dist/mcp/builtin/collections/findDistinctTool.js.map +1 -0
- package/dist/mcp/builtin/collections/findTool.d.ts +2 -0
- package/dist/mcp/builtin/collections/findTool.d.ts.map +1 -0
- package/dist/mcp/builtin/collections/findTool.js +146 -0
- package/dist/mcp/builtin/collections/findTool.js.map +1 -0
- package/dist/mcp/builtin/collections/findVersionByIDTool.d.ts +2 -0
- package/dist/mcp/builtin/collections/findVersionByIDTool.d.ts.map +1 -0
- package/dist/mcp/builtin/collections/findVersionByIDTool.js +74 -0
- package/dist/mcp/builtin/collections/findVersionByIDTool.js.map +1 -0
- package/dist/mcp/builtin/collections/findVersionsTool.d.ts +2 -0
- package/dist/mcp/builtin/collections/findVersionsTool.d.ts.map +1 -0
- package/dist/mcp/builtin/collections/findVersionsTool.js +84 -0
- package/dist/mcp/builtin/collections/findVersionsTool.js.map +1 -0
- package/dist/mcp/builtin/collections/getCollectionSchemaTool.d.ts +2 -0
- package/dist/mcp/builtin/collections/getCollectionSchemaTool.d.ts.map +1 -0
- package/dist/mcp/builtin/collections/getCollectionSchemaTool.js +103 -0
- package/dist/mcp/builtin/collections/getCollectionSchemaTool.js.map +1 -0
- package/dist/mcp/builtin/collections/restoreVersionTool.d.ts +2 -0
- package/dist/mcp/builtin/collections/restoreVersionTool.d.ts.map +1 -0
- package/dist/mcp/builtin/collections/restoreVersionTool.js +69 -0
- package/dist/mcp/builtin/collections/restoreVersionTool.js.map +1 -0
- package/dist/mcp/builtin/collections/updateTool.d.ts +2 -0
- package/dist/mcp/builtin/collections/updateTool.d.ts.map +1 -0
- package/dist/mcp/builtin/collections/updateTool.js +172 -0
- package/dist/mcp/builtin/collections/updateTool.js.map +1 -0
- package/dist/mcp/builtin/collections/uploadInstructionsTool.d.ts +2 -0
- package/dist/mcp/builtin/collections/uploadInstructionsTool.d.ts.map +1 -0
- package/dist/mcp/builtin/collections/uploadInstructionsTool.js +55 -0
- package/dist/mcp/builtin/collections/uploadInstructionsTool.js.map +1 -0
- package/dist/mcp/builtin/formatEntityError.d.ts +16 -0
- package/dist/mcp/builtin/formatEntityError.d.ts.map +1 -0
- package/dist/mcp/builtin/formatEntityError.js +55 -0
- package/dist/mcp/builtin/formatEntityError.js.map +1 -0
- package/dist/mcp/builtin/getConfigInfoTool.d.ts +2 -0
- package/dist/mcp/builtin/getConfigInfoTool.d.ts.map +1 -0
- package/dist/mcp/builtin/getConfigInfoTool.js +69 -0
- package/dist/mcp/builtin/getConfigInfoTool.js.map +1 -0
- package/dist/mcp/builtin/globals/countVersionsTool.d.ts +2 -0
- package/dist/mcp/builtin/globals/countVersionsTool.d.ts.map +1 -0
- package/dist/mcp/builtin/globals/countVersionsTool.js +60 -0
- package/dist/mcp/builtin/globals/countVersionsTool.js.map +1 -0
- package/dist/mcp/builtin/globals/findTool.d.ts +2 -0
- package/dist/mcp/builtin/globals/findTool.d.ts.map +1 -0
- package/dist/mcp/builtin/globals/findTool.js +67 -0
- package/dist/mcp/builtin/globals/findTool.js.map +1 -0
- package/dist/mcp/builtin/globals/findVersionByIDTool.d.ts +2 -0
- package/dist/mcp/builtin/globals/findVersionByIDTool.d.ts.map +1 -0
- package/dist/mcp/builtin/globals/findVersionByIDTool.js +68 -0
- package/dist/mcp/builtin/globals/findVersionByIDTool.js.map +1 -0
- package/dist/mcp/builtin/globals/findVersionsTool.d.ts +2 -0
- package/dist/mcp/builtin/globals/findVersionsTool.d.ts.map +1 -0
- package/dist/mcp/builtin/globals/findVersionsTool.js +78 -0
- package/dist/mcp/builtin/globals/findVersionsTool.js.map +1 -0
- package/dist/mcp/builtin/globals/getGlobalSchemaTool.d.ts +2 -0
- package/dist/mcp/builtin/globals/getGlobalSchemaTool.d.ts.map +1 -0
- package/dist/mcp/builtin/globals/getGlobalSchemaTool.js +81 -0
- package/dist/mcp/builtin/globals/getGlobalSchemaTool.js.map +1 -0
- package/dist/mcp/builtin/globals/restoreVersionTool.d.ts +2 -0
- package/dist/mcp/builtin/globals/restoreVersionTool.d.ts.map +1 -0
- package/dist/mcp/builtin/globals/restoreVersionTool.js +70 -0
- package/dist/mcp/builtin/globals/restoreVersionTool.js.map +1 -0
- package/dist/mcp/builtin/globals/updateTool.d.ts +2 -0
- package/dist/mcp/builtin/globals/updateTool.d.ts.map +1 -0
- package/dist/mcp/builtin/globals/updateTool.js +78 -0
- package/dist/mcp/builtin/globals/updateTool.js.map +1 -0
- package/dist/mcp/builtinTools.d.ts +168 -0
- package/dist/mcp/builtinTools.d.ts.map +1 -0
- package/dist/mcp/builtinTools.js +169 -0
- package/dist/mcp/builtinTools.js.map +1 -0
- package/dist/mcp/sanitizeMCPConfig.d.ts +16 -0
- package/dist/mcp/sanitizeMCPConfig.d.ts.map +1 -0
- package/dist/mcp/sanitizeMCPConfig.js +234 -0
- package/dist/mcp/sanitizeMCPConfig.js.map +1 -0
- package/dist/stdio.d.ts +8 -0
- package/dist/stdio.d.ts.map +1 -0
- package/dist/stdio.js +128 -0
- package/dist/stdio.js.map +1 -0
- package/dist/types.d.ts +298 -446
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +4 -1
- package/dist/types.js.map +1 -1
- package/dist/utils/getLogger.d.ts +10 -0
- package/dist/utils/getLogger.d.ts.map +1 -0
- package/dist/utils/getLogger.js +22 -0
- package/dist/utils/getLogger.js.map +1 -0
- package/dist/utils/getPluginConfig.d.ts +12 -0
- package/dist/utils/getPluginConfig.d.ts.map +1 -0
- package/dist/utils/getPluginConfig.js +15 -0
- package/dist/utils/getPluginConfig.js.map +1 -0
- package/dist/utils/resolveProjectRoot.d.ts +7 -0
- package/dist/utils/resolveProjectRoot.d.ts.map +1 -0
- package/dist/utils/resolveProjectRoot.js +15 -0
- package/dist/utils/resolveProjectRoot.js.map +1 -0
- package/dist/utils/toStandardSchema.d.ts +5 -0
- package/dist/utils/toStandardSchema.d.ts.map +1 -0
- package/dist/utils/toStandardSchema.js +4 -0
- package/dist/utils/toStandardSchema.js.map +1 -0
- package/package.json +41 -26
- package/src/defaultAccess.ts +3 -0
- package/src/defineTool.ts +44 -0
- package/src/endpoint/access.ts +120 -0
- package/src/endpoint/index.ts +115 -0
- package/src/endpoint/oauth.ts +90 -0
- package/src/exports/client.ts +3 -0
- package/src/exports/internal.ts +1 -0
- package/src/index.ts +47 -88
- package/src/mcp/buildMcpServer.ts +294 -0
- package/src/mcp/builtin/collections/authTools.ts +280 -0
- package/src/mcp/builtin/collections/countTool.ts +61 -0
- package/src/mcp/builtin/collections/countVersionsTool.ts +60 -0
- package/src/mcp/builtin/collections/createTool.ts +143 -0
- package/src/mcp/builtin/collections/deleteTool.ts +97 -0
- package/src/mcp/builtin/collections/duplicateTool.ts +84 -0
- package/src/mcp/builtin/collections/fileInput.spec.ts +93 -0
- package/src/mcp/builtin/collections/fileInput.ts +127 -0
- package/src/mcp/builtin/collections/findDistinctTool.ts +67 -0
- package/src/mcp/builtin/collections/findTool.ts +134 -0
- package/src/mcp/builtin/collections/findVersionByIDTool.ts +66 -0
- package/src/mcp/builtin/collections/findVersionsTool.ts +83 -0
- package/src/mcp/builtin/collections/getCollectionSchemaTool.ts +91 -0
- package/src/mcp/builtin/collections/restoreVersionTool.ts +65 -0
- package/src/mcp/builtin/collections/updateTool.ts +173 -0
- package/src/mcp/builtin/collections/uploadInstructionsTool.ts +64 -0
- package/src/mcp/builtin/formatEntityError.ts +77 -0
- package/src/mcp/builtin/getConfigInfoTool.ts +68 -0
- package/src/mcp/builtin/globals/countVersionsTool.ts +60 -0
- package/src/mcp/builtin/globals/findTool.ts +66 -0
- package/src/mcp/builtin/globals/findVersionByIDTool.ts +64 -0
- package/src/mcp/builtin/globals/findVersionsTool.ts +69 -0
- package/src/mcp/builtin/globals/getGlobalSchemaTool.ts +73 -0
- package/src/mcp/builtin/globals/restoreVersionTool.ts +68 -0
- package/src/mcp/builtin/globals/updateTool.ts +92 -0
- package/src/mcp/builtinTools.ts +161 -0
- package/src/mcp/sanitizeMCPConfig.ts +282 -0
- package/src/stdio.ts +131 -0
- package/src/types.ts +346 -486
- package/src/utils/getLogger.ts +22 -0
- package/src/utils/getPluginConfig.ts +24 -0
- package/src/utils/resolveProjectRoot.ts +17 -0
- package/src/utils/toStandardSchema.ts +9 -0
- package/dist/collections/createApiKeysCollection.d.ts +0 -7
- package/dist/collections/createApiKeysCollection.d.ts.map +0 -1
- package/dist/collections/createApiKeysCollection.js +0 -317
- package/dist/collections/createApiKeysCollection.js.map +0 -1
- package/dist/defaults.d.ts +0 -4
- package/dist/defaults.d.ts.map +0 -1
- package/dist/defaults.js +0 -5
- package/dist/defaults.js.map +0 -1
- package/dist/endpoints/mcp.d.ts +0 -4
- package/dist/endpoints/mcp.d.ts.map +0 -1
- package/dist/endpoints/mcp.js +0 -71
- package/dist/endpoints/mcp.js.map +0 -1
- package/dist/mcp/createRequest.d.ts +0 -3
- package/dist/mcp/createRequest.d.ts.map +0 -1
- package/dist/mcp/createRequest.js +0 -14
- package/dist/mcp/createRequest.js.map +0 -1
- package/dist/mcp/getMcpHandler.d.ts +0 -4
- package/dist/mcp/getMcpHandler.d.ts.map +0 -1
- package/dist/mcp/getMcpHandler.js +0 -231
- package/dist/mcp/getMcpHandler.js.map +0 -1
- package/dist/mcp/helpers/config.d.ts +0 -22
- package/dist/mcp/helpers/config.d.ts.map +0 -1
- package/dist/mcp/helpers/config.js +0 -153
- package/dist/mcp/helpers/config.js.map +0 -1
- package/dist/mcp/helpers/fields.d.ts +0 -19
- package/dist/mcp/helpers/fields.d.ts.map +0 -1
- package/dist/mcp/helpers/fields.js +0 -102
- package/dist/mcp/helpers/fields.js.map +0 -1
- package/dist/mcp/helpers/fileValidation.d.ts +0 -67
- package/dist/mcp/helpers/fileValidation.d.ts.map +0 -1
- package/dist/mcp/helpers/fileValidation.js +0 -267
- package/dist/mcp/helpers/fileValidation.js.map +0 -1
- package/dist/mcp/registerTool.d.ts +0 -6
- package/dist/mcp/registerTool.d.ts.map +0 -1
- package/dist/mcp/registerTool.js +0 -18
- package/dist/mcp/registerTool.js.map +0 -1
- package/dist/mcp/tools/auth/auth.d.ts +0 -4
- package/dist/mcp/tools/auth/auth.d.ts.map +0 -1
- package/dist/mcp/tools/auth/auth.js +0 -57
- package/dist/mcp/tools/auth/auth.js.map +0 -1
- package/dist/mcp/tools/auth/forgotPassword.d.ts +0 -4
- package/dist/mcp/tools/auth/forgotPassword.d.ts.map +0 -1
- package/dist/mcp/tools/auth/forgotPassword.js +0 -48
- package/dist/mcp/tools/auth/forgotPassword.js.map +0 -1
- package/dist/mcp/tools/auth/login.d.ts +0 -4
- package/dist/mcp/tools/auth/login.d.ts.map +0 -1
- package/dist/mcp/tools/auth/login.js +0 -51
- package/dist/mcp/tools/auth/login.js.map +0 -1
- package/dist/mcp/tools/auth/resetPassword.d.ts +0 -4
- package/dist/mcp/tools/auth/resetPassword.d.ts.map +0 -1
- package/dist/mcp/tools/auth/resetPassword.js +0 -49
- package/dist/mcp/tools/auth/resetPassword.js.map +0 -1
- package/dist/mcp/tools/auth/unlock.d.ts +0 -4
- package/dist/mcp/tools/auth/unlock.d.ts.map +0 -1
- package/dist/mcp/tools/auth/unlock.js +0 -48
- package/dist/mcp/tools/auth/unlock.js.map +0 -1
- package/dist/mcp/tools/auth/verify.d.ts +0 -4
- package/dist/mcp/tools/auth/verify.d.ts.map +0 -1
- package/dist/mcp/tools/auth/verify.js +0 -45
- package/dist/mcp/tools/auth/verify.js.map +0 -1
- package/dist/mcp/tools/collection/create.d.ts +0 -10
- package/dist/mcp/tools/collection/create.d.ts.map +0 -1
- package/dist/mcp/tools/collection/create.js +0 -139
- package/dist/mcp/tools/collection/create.js.map +0 -1
- package/dist/mcp/tools/collection/delete.d.ts +0 -10
- package/dist/mcp/tools/collection/delete.d.ts.map +0 -1
- package/dist/mcp/tools/collection/delete.js +0 -154
- package/dist/mcp/tools/collection/delete.js.map +0 -1
- package/dist/mcp/tools/collection/find.d.ts +0 -10
- package/dist/mcp/tools/collection/find.d.ts.map +0 -1
- package/dist/mcp/tools/collection/find.js +0 -165
- package/dist/mcp/tools/collection/find.js.map +0 -1
- package/dist/mcp/tools/collection/update.d.ts +0 -10
- package/dist/mcp/tools/collection/update.d.ts.map +0 -1
- package/dist/mcp/tools/collection/update.js +0 -209
- package/dist/mcp/tools/collection/update.js.map +0 -1
- package/dist/mcp/tools/config/find.d.ts +0 -10
- package/dist/mcp/tools/config/find.d.ts.map +0 -1
- package/dist/mcp/tools/config/find.js +0 -97
- package/dist/mcp/tools/config/find.js.map +0 -1
- package/dist/mcp/tools/config/update.d.ts +0 -10
- package/dist/mcp/tools/config/update.d.ts.map +0 -1
- package/dist/mcp/tools/config/update.js +0 -215
- package/dist/mcp/tools/config/update.js.map +0 -1
- package/dist/mcp/tools/global/find.d.ts +0 -5
- package/dist/mcp/tools/global/find.d.ts.map +0 -1
- package/dist/mcp/tools/global/find.js +0 -82
- package/dist/mcp/tools/global/find.js.map +0 -1
- package/dist/mcp/tools/global/update.d.ts +0 -6
- package/dist/mcp/tools/global/update.d.ts.map +0 -1
- package/dist/mcp/tools/global/update.js +0 -124
- package/dist/mcp/tools/global/update.js.map +0 -1
- package/dist/mcp/tools/job/create.d.ts +0 -10
- package/dist/mcp/tools/job/create.d.ts.map +0 -1
- package/dist/mcp/tools/job/create.js +0 -293
- package/dist/mcp/tools/job/create.js.map +0 -1
- package/dist/mcp/tools/job/run.d.ts +0 -10
- package/dist/mcp/tools/job/run.d.ts.map +0 -1
- package/dist/mcp/tools/job/run.js +0 -129
- package/dist/mcp/tools/job/run.js.map +0 -1
- package/dist/mcp/tools/job/update.d.ts +0 -11
- package/dist/mcp/tools/job/update.d.ts.map +0 -1
- package/dist/mcp/tools/job/update.js +0 -186
- package/dist/mcp/tools/job/update.js.map +0 -1
- package/dist/mcp/tools/resource/create.d.ts +0 -6
- package/dist/mcp/tools/resource/create.d.ts.map +0 -1
- package/dist/mcp/tools/resource/create.js +0 -124
- package/dist/mcp/tools/resource/create.js.map +0 -1
- package/dist/mcp/tools/resource/delete.d.ts +0 -5
- package/dist/mcp/tools/resource/delete.d.ts.map +0 -1
- package/dist/mcp/tools/resource/delete.js +0 -151
- package/dist/mcp/tools/resource/delete.js.map +0 -1
- package/dist/mcp/tools/resource/find.d.ts +0 -5
- package/dist/mcp/tools/resource/find.d.ts.map +0 -1
- package/dist/mcp/tools/resource/find.js +0 -170
- package/dist/mcp/tools/resource/find.js.map +0 -1
- package/dist/mcp/tools/resource/update.d.ts +0 -6
- package/dist/mcp/tools/resource/update.d.ts.map +0 -1
- package/dist/mcp/tools/resource/update.js +0 -256
- package/dist/mcp/tools/resource/update.js.map +0 -1
- package/dist/mcp/tools/schemas.d.ts +0 -457
- package/dist/mcp/tools/schemas.d.ts.map +0 -1
- package/dist/mcp/tools/schemas.js +0 -243
- package/dist/mcp/tools/schemas.js.map +0 -1
- package/dist/utils/adminEntitySettings.d.ts +0 -17
- package/dist/utils/adminEntitySettings.d.ts.map +0 -1
- package/dist/utils/adminEntitySettings.js +0 -41
- package/dist/utils/adminEntitySettings.js.map +0 -1
- package/dist/utils/createApiKeyFields.d.ts +0 -15
- package/dist/utils/createApiKeyFields.d.ts.map +0 -1
- package/dist/utils/createApiKeyFields.js +0 -57
- package/dist/utils/createApiKeyFields.js.map +0 -1
- package/dist/utils/getEnabledSlugs.d.ts +0 -13
- package/dist/utils/getEnabledSlugs.d.ts.map +0 -1
- package/dist/utils/getEnabledSlugs.js +0 -32
- package/dist/utils/getEnabledSlugs.js.map +0 -1
- package/dist/utils/getVirtualFieldNames.d.ts +0 -14
- package/dist/utils/getVirtualFieldNames.d.ts.map +0 -1
- package/dist/utils/getVirtualFieldNames.js +0 -35
- package/dist/utils/getVirtualFieldNames.js.map +0 -1
- package/dist/utils/schemaConversion/convertCollectionSchemaToZod.d.ts +0 -3
- package/dist/utils/schemaConversion/convertCollectionSchemaToZod.d.ts.map +0 -1
- package/dist/utils/schemaConversion/convertCollectionSchemaToZod.js +0 -43
- package/dist/utils/schemaConversion/convertCollectionSchemaToZod.js.map +0 -1
- package/dist/utils/schemaConversion/removeVirtualFieldsFromSchema.d.ts +0 -7
- package/dist/utils/schemaConversion/removeVirtualFieldsFromSchema.d.ts.map +0 -1
- package/dist/utils/schemaConversion/removeVirtualFieldsFromSchema.js +0 -20
- package/dist/utils/schemaConversion/removeVirtualFieldsFromSchema.js.map +0 -1
- package/dist/utils/schemaConversion/sanitizeJsonSchema.d.ts +0 -13
- package/dist/utils/schemaConversion/sanitizeJsonSchema.d.ts.map +0 -1
- package/dist/utils/schemaConversion/sanitizeJsonSchema.js +0 -56
- package/dist/utils/schemaConversion/sanitizeJsonSchema.js.map +0 -1
- package/dist/utils/schemaConversion/simplifyRelationshipFields.d.ts +0 -20
- package/dist/utils/schemaConversion/simplifyRelationshipFields.d.ts.map +0 -1
- package/dist/utils/schemaConversion/simplifyRelationshipFields.js +0 -53
- package/dist/utils/schemaConversion/simplifyRelationshipFields.js.map +0 -1
- package/dist/utils/schemaConversion/transformPointFields.d.ts +0 -3
- package/dist/utils/schemaConversion/transformPointFields.d.ts.map +0 -1
- package/dist/utils/schemaConversion/transformPointFields.js +0 -51
- package/dist/utils/schemaConversion/transformPointFields.js.map +0 -1
- package/dist/utils/transformPointDataToPayload.d.ts +0 -7
- package/dist/utils/transformPointDataToPayload.d.ts.map +0 -1
- package/dist/utils/transformPointDataToPayload.js +0 -28
- package/dist/utils/transformPointDataToPayload.js.map +0 -1
- package/src/collections/createApiKeysCollection.ts +0 -373
- package/src/defaults.ts +0 -3
- package/src/endpoints/mcp.ts +0 -91
- package/src/mcp/createRequest.ts +0 -13
- package/src/mcp/getMcpHandler.ts +0 -545
- package/src/mcp/helpers/config.ts +0 -213
- package/src/mcp/helpers/fields.ts +0 -154
- package/src/mcp/helpers/fileValidation.ts +0 -362
- package/src/mcp/registerTool.ts +0 -22
- package/src/mcp/tools/auth/auth.ts +0 -71
- package/src/mcp/tools/auth/forgotPassword.ts +0 -70
- package/src/mcp/tools/auth/login.ts +0 -72
- package/src/mcp/tools/auth/resetPassword.ts +0 -61
- package/src/mcp/tools/auth/unlock.ts +0 -64
- package/src/mcp/tools/auth/verify.ts +0 -57
- package/src/mcp/tools/collection/create.ts +0 -210
- package/src/mcp/tools/collection/delete.ts +0 -211
- package/src/mcp/tools/collection/find.ts +0 -224
- package/src/mcp/tools/collection/update.ts +0 -290
- package/src/mcp/tools/config/find.ts +0 -128
- package/src/mcp/tools/config/update.ts +0 -280
- package/src/mcp/tools/global/find.ts +0 -128
- package/src/mcp/tools/global/update.ts +0 -207
- package/src/mcp/tools/job/create.ts +0 -416
- package/src/mcp/tools/job/run.ts +0 -167
- package/src/mcp/tools/job/update.ts +0 -274
- package/src/mcp/tools/resource/create.ts +0 -211
- package/src/mcp/tools/resource/delete.ts +0 -218
- package/src/mcp/tools/resource/find.ts +0 -246
- package/src/mcp/tools/resource/update.ts +0 -383
- package/src/mcp/tools/schemas.ts +0 -520
- package/src/utils/adminEntitySettings.ts +0 -40
- package/src/utils/createApiKeyFields.ts +0 -72
- package/src/utils/getEnabledSlugs.ts +0 -42
- package/src/utils/getVirtualFieldNames.ts +0 -53
- package/src/utils/schemaConversion/convertCollectionSchemaToZod.ts +0 -52
- package/src/utils/schemaConversion/removeVirtualFieldsFromSchema.ts +0 -27
- package/src/utils/schemaConversion/sanitizeJsonSchema.ts +0 -62
- package/src/utils/schemaConversion/simplifyRelationshipFields.ts +0 -65
- package/src/utils/schemaConversion/transformPointFields.ts +0 -55
- package/src/utils/transformPointDataToPayload.ts +0 -40
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import type { PayloadHandler, PayloadRequest } from 'payload'
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
createMcpHandler,
|
|
5
|
+
isLegacyRequest,
|
|
6
|
+
readRequestBody,
|
|
7
|
+
WebStandardStreamableHTTPServerTransport,
|
|
8
|
+
} from '@modelcontextprotocol/server'
|
|
9
|
+
import { APIError } from 'payload'
|
|
10
|
+
|
|
11
|
+
import { buildMcpServer } from '../mcp/buildMcpServer.js'
|
|
12
|
+
import { getPluginConfig } from '../utils/getPluginConfig.js'
|
|
13
|
+
import { getAuthorizedMCP } from './access.js'
|
|
14
|
+
import { getMCPResource, oauthChallenge } from './oauth.js'
|
|
15
|
+
|
|
16
|
+
export const mcpEndpoint: PayloadHandler = async (req) => {
|
|
17
|
+
if (!req.url) {
|
|
18
|
+
throw new APIError('Missing request URL', 400)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
req.payloadAPI = 'MCP' as const
|
|
22
|
+
// Lets auth strategies check that an OAuth access token was issued for this MCP server
|
|
23
|
+
req.context.mcp = { resource: getMCPResource({ config: req.payload.config, url: req.url }) }
|
|
24
|
+
|
|
25
|
+
const pluginConfig = getPluginConfig({ config: req.payload.config })
|
|
26
|
+
const overrideAccessParam = new URL(req.url).searchParams.get('overrideAccess')
|
|
27
|
+
|
|
28
|
+
if (overrideAccessParam !== null && process.env.NODE_ENV !== 'development') {
|
|
29
|
+
throw new APIError('MCP overrideAccess is only available in development.', 400)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
let overrideAccess = false
|
|
33
|
+
if (overrideAccessParam === 'true') {
|
|
34
|
+
overrideAccess = true
|
|
35
|
+
} else if (overrideAccessParam !== null && overrideAccessParam !== 'false') {
|
|
36
|
+
throw new APIError('MCP overrideAccess must be "true" or "false".', 400)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const authorizedMCP = await getAuthorizedMCP({ overrideAccess, req })
|
|
40
|
+
|
|
41
|
+
if (pluginConfig.oauth && !req.user) {
|
|
42
|
+
return oauthChallenge({ req })
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const maxRequestBodySize = pluginConfig.mcp?.maxRequestBodySize
|
|
46
|
+
// Payload augments the original web-standard Request in place.
|
|
47
|
+
const mcpRequest = req as PayloadRequest & Request
|
|
48
|
+
const parsedBody = await parseRequestBody({ maxRequestBodySize, request: mcpRequest })
|
|
49
|
+
|
|
50
|
+
// Keep the old JSON-only, stateless behavior because the SDK's 2025 fallback uses SSE.
|
|
51
|
+
if (await isLegacyRequest(mcpRequest, parsedBody, { maxRequestBodySize })) {
|
|
52
|
+
const server = buildMcpServer({ authorizedMCP, pluginConfig, req })
|
|
53
|
+
const transport = new WebStandardStreamableHTTPServerTransport({
|
|
54
|
+
enableJsonResponse: true,
|
|
55
|
+
maxRequestBodySize,
|
|
56
|
+
sessionIdGenerator: undefined, // stateless mode
|
|
57
|
+
})
|
|
58
|
+
transport.onerror = (err) => {
|
|
59
|
+
req.payload.logger.error({ err, msg: 'Error serving legacy MCP request' })
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
try {
|
|
63
|
+
await server.connect(transport)
|
|
64
|
+
return await transport.handleRequest(mcpRequest, { parsedBody })
|
|
65
|
+
} finally {
|
|
66
|
+
await server.close().catch((err) => {
|
|
67
|
+
req.payload.logger.error({ err, msg: 'Error closing MCP server' })
|
|
68
|
+
})
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const handler = createMcpHandler(() => buildMcpServer({ authorizedMCP, pluginConfig, req }), {
|
|
73
|
+
legacy: 'reject',
|
|
74
|
+
maxRequestBodySize,
|
|
75
|
+
// SDK subscriptions always use SSE, so disable them to keep every response JSON-only.
|
|
76
|
+
maxSubscriptions: 0,
|
|
77
|
+
onerror: (err) => {
|
|
78
|
+
req.payload.logger.error({ err, msg: 'Error serving modern MCP request' })
|
|
79
|
+
},
|
|
80
|
+
responseMode: 'json',
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
try {
|
|
84
|
+
return await handler.fetch(mcpRequest, { parsedBody })
|
|
85
|
+
} finally {
|
|
86
|
+
await handler.close().catch((err) => {
|
|
87
|
+
req.payload.logger.error({ err, msg: 'Error closing modern MCP handler' })
|
|
88
|
+
})
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Parses a POST body once so the era check and the SDK handler can share it. The SDK
|
|
94
|
+
* skips its size limit for a pre-parsed body, so this reads with the same limit. It reads
|
|
95
|
+
* a clone and returns `undefined` for any body the SDK should reject (too large, unreadable,
|
|
96
|
+
* or not JSON), leaving the original request for the SDK to read and answer.
|
|
97
|
+
*/
|
|
98
|
+
const parseRequestBody = async ({
|
|
99
|
+
maxRequestBodySize,
|
|
100
|
+
request,
|
|
101
|
+
}: {
|
|
102
|
+
maxRequestBodySize?: number
|
|
103
|
+
request: Request
|
|
104
|
+
}): Promise<unknown> => {
|
|
105
|
+
if (request.method.toUpperCase() !== 'POST') {
|
|
106
|
+
return undefined
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
try {
|
|
110
|
+
const body = await readRequestBody(request.clone(), maxRequestBodySize)
|
|
111
|
+
return body.tooLarge ? undefined : JSON.parse(body.text)
|
|
112
|
+
} catch {
|
|
113
|
+
return undefined
|
|
114
|
+
}
|
|
115
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import type { OAuthProtectedResourceMetadata } from '@modelcontextprotocol/server'
|
|
2
|
+
import type { PayloadHandler, PayloadRequest, SanitizedConfig } from 'payload'
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
bearerAuthChallengeResponse,
|
|
6
|
+
OAuthError,
|
|
7
|
+
OAuthErrorCode,
|
|
8
|
+
} from '@modelcontextprotocol/server'
|
|
9
|
+
import { createPayloadRequest, getPayload } from 'payload'
|
|
10
|
+
|
|
11
|
+
import { getPluginConfig } from '../utils/getPluginConfig.js'
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Serves the OAuth protected resource metadata (RFC 9728) at `/api/mcp/oauth-protected-resource`.
|
|
15
|
+
* The OAuth challenge links here, so MCP clients find the authorization server without setup.
|
|
16
|
+
*/
|
|
17
|
+
export const oauthProtectedResourceEndpoint: PayloadHandler = (req) => getMetadataResponse({ req })
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Serves the same metadata for clients that ignore the challenge's link and only look at
|
|
21
|
+
* `/.well-known/oauth-protected-resource`. Mount it at the site root, e.g. in Next.js at
|
|
22
|
+
* `app/.well-known/oauth-protected-resource/[[...path]]/route.ts`:
|
|
23
|
+
*
|
|
24
|
+
* ```ts
|
|
25
|
+
* import config from '@payload-config'
|
|
26
|
+
* import { oauthProtectedResourceHandler } from '@payloadcms/plugin-mcp'
|
|
27
|
+
*
|
|
28
|
+
* export const GET = oauthProtectedResourceHandler(config)
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export const oauthProtectedResourceHandler =
|
|
32
|
+
(config: Promise<SanitizedConfig> | SanitizedConfig) =>
|
|
33
|
+
async (request: Request): Promise<Response> =>
|
|
34
|
+
getMetadataResponse({
|
|
35
|
+
req: await createPayloadRequest({ payload: await getPayload({ config }), req: request }),
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Answers an unauthenticated MCP request with a challenge linking to the protected resource
|
|
40
|
+
* metadata, which starts the client's OAuth flow.
|
|
41
|
+
*/
|
|
42
|
+
export const oauthChallenge = ({ req }: { req: PayloadRequest }): Response => {
|
|
43
|
+
const response = bearerAuthChallengeResponse(
|
|
44
|
+
new OAuthError(OAuthErrorCode.InvalidToken, req.t('error:unauthorized')),
|
|
45
|
+
{
|
|
46
|
+
requiredScopes: getPluginConfig({ config: req.payload.config }).oauth?.scopes,
|
|
47
|
+
resourceMetadataUrl: `${getMCPURL({ config: req.payload.config, url: req.url! })}/oauth-protected-resource`,
|
|
48
|
+
},
|
|
49
|
+
)
|
|
50
|
+
|
|
51
|
+
// Lets browser-based MCP clients read the challenge, when Payload's `cors` setting allows them
|
|
52
|
+
response.headers.set('Access-Control-Expose-Headers', 'WWW-Authenticate')
|
|
53
|
+
|
|
54
|
+
return response
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* The MCP endpoint's address, as advertised in the metadata's `resource`. Clients send it when
|
|
59
|
+
* they sign in, and authorization servers that support it put it in the access token's audience.
|
|
60
|
+
*/
|
|
61
|
+
export const getMCPResource = ({ config, url }: { config: SanitizedConfig; url: string }): string =>
|
|
62
|
+
getPluginConfig({ config }).oauth?.resource ?? getMCPURL({ config, url })
|
|
63
|
+
|
|
64
|
+
const getMCPURL = ({ config, url }: { config: SanitizedConfig; url: string }): string =>
|
|
65
|
+
new URL(`${config.routes.api}/mcp`, config.serverURL || url).href
|
|
66
|
+
|
|
67
|
+
const getMetadataResponse = async ({ req }: { req: PayloadRequest }): Promise<Response> => {
|
|
68
|
+
const { config } = req.payload
|
|
69
|
+
const pluginConfig = getPluginConfig({ config })
|
|
70
|
+
|
|
71
|
+
if (!pluginConfig.oauth) {
|
|
72
|
+
return new Response(null, { status: 404 })
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const { authorizationServers, scopes } = pluginConfig.oauth
|
|
76
|
+
|
|
77
|
+
return Response.json(
|
|
78
|
+
{
|
|
79
|
+
authorization_servers:
|
|
80
|
+
typeof authorizationServers === 'function'
|
|
81
|
+
? await authorizationServers({ req })
|
|
82
|
+
: authorizationServers,
|
|
83
|
+
bearer_methods_supported: ['header'],
|
|
84
|
+
resource: getMCPResource({ config, url: req.url! }),
|
|
85
|
+
scopes_supported: scopes,
|
|
86
|
+
} satisfies OAuthProtectedResourceMetadata,
|
|
87
|
+
// Public document, readable by browser-based MCP clients on any origin
|
|
88
|
+
{ headers: { 'Access-Control-Allow-Origin': '*' } },
|
|
89
|
+
)
|
|
90
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { filterMCPItems, getAuthorizedMCP } from '../endpoint/access.js'
|
package/src/index.ts
CHANGED
|
@@ -1,113 +1,72 @@
|
|
|
1
1
|
import { definePlugin } from 'payload'
|
|
2
2
|
|
|
3
|
-
import type {
|
|
3
|
+
import type { AuthorizedMCP, MCPPluginConfig, SanitizedMCPPluginConfig } from './types.js'
|
|
4
4
|
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
5
|
+
import { mcpEndpoint } from './endpoint/index.js'
|
|
6
|
+
import { oauthProtectedResourceEndpoint } from './endpoint/oauth.js'
|
|
7
|
+
import { sanitizeMCPConfig } from './mcp/sanitizeMCPConfig.js'
|
|
7
8
|
|
|
8
9
|
declare module 'payload' {
|
|
9
|
-
export interface
|
|
10
|
-
|
|
10
|
+
export interface PayloadRequestAPI {
|
|
11
|
+
MCP: true
|
|
11
12
|
}
|
|
12
13
|
interface RegisteredPlugins {
|
|
14
|
+
/** After the plugin's `plugin` callback runs, `options` holds the sanitized config. */
|
|
13
15
|
'@payloadcms/plugin-mcp': MCPPluginConfig
|
|
14
16
|
}
|
|
17
|
+
export interface RequestContext {
|
|
18
|
+
/** Set on MCP requests before they're authenticated. */
|
|
19
|
+
mcp?: {
|
|
20
|
+
/** The MCP endpoint's address, which OAuth access tokens for MCP are issued for. */
|
|
21
|
+
resource: string
|
|
22
|
+
}
|
|
23
|
+
}
|
|
15
24
|
}
|
|
16
25
|
|
|
17
|
-
|
|
26
|
+
export type { AuthorizedMCP, MCPPluginConfig, SanitizedMCPPluginConfig }
|
|
18
27
|
|
|
19
|
-
export
|
|
28
|
+
export { defineCollectionTool, defineGlobalTool, definePrompt, defineTool } from './defineTool.js'
|
|
29
|
+
export { oauthProtectedResourceHandler } from './endpoint/oauth.js'
|
|
20
30
|
|
|
21
|
-
/**
|
|
22
|
-
* The MCP Plugin for Payload. This plugin allows you to add MCP capabilities to your Payload project.
|
|
23
|
-
*
|
|
24
|
-
* @param pluginOptions - The options for the MCP plugin.
|
|
25
|
-
*/
|
|
26
31
|
export const mcpPlugin = definePlugin<MCPPluginConfig>({
|
|
27
32
|
slug: '@payloadcms/plugin-mcp',
|
|
28
33
|
order: 10,
|
|
29
|
-
plugin: ({ config,
|
|
30
|
-
|
|
31
|
-
config.collections = []
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
// Collections
|
|
35
|
-
const collections = pluginOptions.collections || {}
|
|
36
|
-
// Globals
|
|
37
|
-
const globals = pluginOptions.globals || {}
|
|
38
|
-
// Extract custom tools for the global config
|
|
39
|
-
const customTools =
|
|
40
|
-
pluginOptions.mcp?.tools?.map((tool) => ({
|
|
41
|
-
name: tool.name,
|
|
42
|
-
description: tool.description,
|
|
43
|
-
})) || []
|
|
44
|
-
|
|
45
|
-
// User Collection
|
|
46
|
-
pluginOptions.userCollection =
|
|
47
|
-
pluginOptions.userCollection ?? config?.admin?.user ?? defaults.userCollection
|
|
34
|
+
plugin: ({ config, options, plugins }) => {
|
|
35
|
+
const pluginConfig = sanitizeMCPConfig({ config, pluginConfig: options })
|
|
48
36
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
* High resolution control over MCP capabilities is crucial when using Payload with LLMs.
|
|
55
|
-
*
|
|
56
|
-
* This API Keys collection has ways for admins to create API keys and allow or disallow the MCP capabilities.
|
|
57
|
-
* This is useful when Admins want to allow or disallow the use of the MCP capabilities in real time.
|
|
58
|
-
* For example:
|
|
59
|
-
* - If a collection has all of its capabilities enabled, admins can allow or disallow the create, update, delete, and find capabilities on that collection.
|
|
60
|
-
* - If a collection only has the find capability enabled, admins can only allow or disallow the find capability on that collection.
|
|
61
|
-
* - If a global has all of its capabilities enabled, admins can allow or disallow the find and update capabilities on that global.
|
|
62
|
-
* - If a custom tool has gone haywire, admins can disallow that tool.
|
|
63
|
-
*
|
|
64
|
-
*/
|
|
65
|
-
const apiKeyCollection = createAPIKeysCollection(
|
|
66
|
-
collections,
|
|
67
|
-
globals,
|
|
68
|
-
customTools,
|
|
69
|
-
experimentalTools,
|
|
70
|
-
pluginOptions,
|
|
71
|
-
)
|
|
72
|
-
if (pluginOptions.overrideApiKeyCollection) {
|
|
73
|
-
config.collections.push(pluginOptions.overrideApiKeyCollection(apiKeyCollection))
|
|
74
|
-
} else {
|
|
75
|
-
config.collections.push(apiKeyCollection)
|
|
37
|
+
// Stash the sanitized config on plugin options so `getPluginConfig()` reads it.
|
|
38
|
+
const registered = plugins['@payloadcms/plugin-mcp']
|
|
39
|
+
if (registered) {
|
|
40
|
+
// @ts-expect-error
|
|
41
|
+
registered.sanitizedOptions = pluginConfig
|
|
76
42
|
}
|
|
77
43
|
|
|
78
|
-
|
|
79
|
-
* If the plugin is disabled, we still want to keep added collections/fields so the database schema is consistent which is important for migrations.
|
|
80
|
-
* If your plugin heavily modifies the database schema, you may want to remove this property.
|
|
81
|
-
*/
|
|
82
|
-
if (pluginOptions.disabled) {
|
|
44
|
+
if (pluginConfig.disabled) {
|
|
83
45
|
return config
|
|
84
46
|
}
|
|
85
47
|
|
|
86
|
-
|
|
87
|
-
config
|
|
48
|
+
return {
|
|
49
|
+
...config,
|
|
50
|
+
endpoints: [
|
|
51
|
+
...(config.endpoints ?? []),
|
|
52
|
+
// Payload prefixes /api, so the full path is /api/mcp. getAuthorizedMCP authenticates the
|
|
53
|
+
// request with dev auto-login turned off, so Payload doesn't authenticate it first.
|
|
54
|
+
{ disableAuth: true, handler: mcpEndpoint, method: 'post', path: '/mcp' },
|
|
55
|
+
// Streamable HTTP's optional server=>client GET stream. We don't offer
|
|
56
|
+
// one, so answer 405 per spec-— clients then skip it cleanly
|
|
57
|
+
{
|
|
58
|
+
disableAuth: true,
|
|
59
|
+
handler: () => new Response(null, { headers: { Allow: 'POST' }, status: 405 }),
|
|
60
|
+
method: 'get',
|
|
61
|
+
path: '/mcp',
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
disableAuth: true,
|
|
65
|
+
handler: oauthProtectedResourceEndpoint,
|
|
66
|
+
method: 'get',
|
|
67
|
+
path: '/mcp/oauth-protected-resource',
|
|
68
|
+
},
|
|
69
|
+
],
|
|
88
70
|
}
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* This is the primary MCP Server Endpoint.
|
|
92
|
-
* Payload will automatically add the /api prefix to the path, so the full path is `/api/mcp`
|
|
93
|
-
* NOTE: This is only transport method until we add full support for SSE which will be another endpoint at `/api/sse`
|
|
94
|
-
*/
|
|
95
|
-
config.endpoints.push({
|
|
96
|
-
handler: initializeMCPHandler(pluginOptions),
|
|
97
|
-
method: 'post',
|
|
98
|
-
path: '/mcp',
|
|
99
|
-
})
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* The GET response is always: {"jsonrpc":"2.0","error":{"code":-32000,"message":"Method not allowed."},"id":null} -- even with an API key
|
|
103
|
-
* This is expected behavior and MCP clients should always use the POST endpoint.
|
|
104
|
-
*/
|
|
105
|
-
config.endpoints.push({
|
|
106
|
-
handler: initializeMCPHandler(pluginOptions),
|
|
107
|
-
method: 'get',
|
|
108
|
-
path: '/mcp',
|
|
109
|
-
})
|
|
110
|
-
|
|
111
|
-
return config
|
|
112
71
|
},
|
|
113
72
|
})
|
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
import type { PayloadRequest } from 'payload'
|
|
2
|
+
|
|
3
|
+
import { McpServer, type ServerContext } from '@modelcontextprotocol/server'
|
|
4
|
+
import { APIError, strictObject, z } from 'payload'
|
|
5
|
+
|
|
6
|
+
import type {
|
|
7
|
+
AuthorizedMCP,
|
|
8
|
+
CollectionMCPItem,
|
|
9
|
+
GlobalMCPItem,
|
|
10
|
+
JsonSchemaType,
|
|
11
|
+
MCPResponseOverride,
|
|
12
|
+
MCPToolResponse,
|
|
13
|
+
SanitizedMCPPluginConfig,
|
|
14
|
+
ToolInputSchema,
|
|
15
|
+
} from '../types.js'
|
|
16
|
+
|
|
17
|
+
import { getLogger } from '../utils/getLogger.js'
|
|
18
|
+
import { toStandardSchema } from '../utils/toStandardSchema.js'
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Serving-entry-agnostic core: registers every authorized MCP item onto a fresh
|
|
22
|
+
* `McpServer` and returns it. The HTTP and stdio entry point callers provide fresh
|
|
23
|
+
* instances from this builder while they own the transport and protocol-era
|
|
24
|
+
* decision.
|
|
25
|
+
*
|
|
26
|
+
* `req` is the request context handlers see. For HTTP it's the live
|
|
27
|
+
* `PayloadRequest` derived from the incoming HTTP request; for stdio it's a
|
|
28
|
+
* synthesized one built via `createPayloadRequest`.
|
|
29
|
+
*/
|
|
30
|
+
export const buildMcpServer = ({
|
|
31
|
+
authorizedMCP,
|
|
32
|
+
pluginConfig,
|
|
33
|
+
req,
|
|
34
|
+
}: {
|
|
35
|
+
authorizedMCP: AuthorizedMCP
|
|
36
|
+
pluginConfig: SanitizedMCPPluginConfig
|
|
37
|
+
req: PayloadRequest
|
|
38
|
+
}): McpServer => {
|
|
39
|
+
z.config(z.locales.en())
|
|
40
|
+
|
|
41
|
+
const serverOptions = pluginConfig.mcp?.serverOptions || {}
|
|
42
|
+
const server = new McpServer(
|
|
43
|
+
{ name: 'Payload MCP Server', version: '1.0.0', ...serverOptions.serverInfo },
|
|
44
|
+
serverOptions.options,
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
const logger = getLogger({ payload: req.payload })
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Wrap a tool handler's response with the tool's `overrideResponse`, then
|
|
51
|
+
* strip the internal `doc` field so it doesn't leak onto the wire.
|
|
52
|
+
*/
|
|
53
|
+
const finalizeToolResponse = async ({
|
|
54
|
+
input,
|
|
55
|
+
overrideResponse,
|
|
56
|
+
response,
|
|
57
|
+
toolName,
|
|
58
|
+
}: {
|
|
59
|
+
input: unknown
|
|
60
|
+
overrideResponse?: MCPResponseOverride
|
|
61
|
+
response: MCPToolResponse
|
|
62
|
+
toolName: string
|
|
63
|
+
}): Promise<MCPToolResponse> => {
|
|
64
|
+
let overridden = overrideResponse?.(response, response.doc ?? {}, req) ?? response
|
|
65
|
+
for (const hook of pluginConfig.hooks?.afterToolCall ?? []) {
|
|
66
|
+
overridden = await hook({ input, req, response: overridden, toolName })
|
|
67
|
+
}
|
|
68
|
+
const { doc: _doc, ...rest } = overridden
|
|
69
|
+
return rest
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Runs a collection/global tool call:
|
|
74
|
+
* - reads `slug` from the input
|
|
75
|
+
* - runs access control: errors if `authorizedMCP.items` has no entry for this tool + slug
|
|
76
|
+
* - runs the tool handler and finalizes its response
|
|
77
|
+
*/
|
|
78
|
+
const callEntityTool = async ({
|
|
79
|
+
input,
|
|
80
|
+
item,
|
|
81
|
+
serverContext,
|
|
82
|
+
}: {
|
|
83
|
+
input: unknown
|
|
84
|
+
item: CollectionMCPItem | GlobalMCPItem
|
|
85
|
+
serverContext: ServerContext
|
|
86
|
+
}): Promise<MCPToolResponse> => {
|
|
87
|
+
const entity = item.type === 'collectionTool' ? 'collection' : 'global'
|
|
88
|
+
const toolInput = (input ?? {}) as Record<string, unknown>
|
|
89
|
+
const slug = toolInput.slug as string | undefined
|
|
90
|
+
|
|
91
|
+
if (!slug) {
|
|
92
|
+
return {
|
|
93
|
+
content: [
|
|
94
|
+
{
|
|
95
|
+
type: 'text',
|
|
96
|
+
text: `Error: "${item.mcpName}" requires slug. Use getConfigInfo to inspect ${entity} slugs.`,
|
|
97
|
+
},
|
|
98
|
+
],
|
|
99
|
+
isError: true,
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const match = authorizedMCP.items.find(
|
|
104
|
+
(candidate): candidate is CollectionMCPItem | GlobalMCPItem =>
|
|
105
|
+
candidate.type === item.type &&
|
|
106
|
+
candidate.mcpName === item.mcpName &&
|
|
107
|
+
(candidate.type === 'collectionTool'
|
|
108
|
+
? candidate.collectionSlug === slug
|
|
109
|
+
: candidate.type === 'globalTool' && candidate.globalSlug === slug),
|
|
110
|
+
)
|
|
111
|
+
|
|
112
|
+
if (!match) {
|
|
113
|
+
return {
|
|
114
|
+
content: [
|
|
115
|
+
{
|
|
116
|
+
type: 'text',
|
|
117
|
+
text: `Error: MCP access to "${item.mcpName}" is not enabled for ${entity} "${slug}"`,
|
|
118
|
+
},
|
|
119
|
+
],
|
|
120
|
+
isError: true,
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
const handlerArgs = {
|
|
125
|
+
authorizedMCP,
|
|
126
|
+
input: toolInput,
|
|
127
|
+
req,
|
|
128
|
+
serverContext,
|
|
129
|
+
}
|
|
130
|
+
const response = await (match.type === 'collectionTool'
|
|
131
|
+
? match.tool.handler({ ...handlerArgs, slug })
|
|
132
|
+
: match.tool.handler({ ...handlerArgs, slug }))
|
|
133
|
+
|
|
134
|
+
return finalizeToolResponse({
|
|
135
|
+
input: toolInput,
|
|
136
|
+
overrideResponse: match.tool.overrideResponse,
|
|
137
|
+
response,
|
|
138
|
+
toolName: match.mcpName,
|
|
139
|
+
})
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
try {
|
|
143
|
+
const registeredEntityTools = new Set<string>()
|
|
144
|
+
|
|
145
|
+
for (const item of authorizedMCP.items) {
|
|
146
|
+
switch (item.type) {
|
|
147
|
+
case 'collectionTool':
|
|
148
|
+
case 'globalTool': {
|
|
149
|
+
if (registeredEntityTools.has(item.mcpName)) {
|
|
150
|
+
break
|
|
151
|
+
}
|
|
152
|
+
registeredEntityTools.add(item.mcpName)
|
|
153
|
+
|
|
154
|
+
const inputSchema = withSlugInput({ input: item.tool.input })
|
|
155
|
+
|
|
156
|
+
server.registerTool(
|
|
157
|
+
item.mcpName,
|
|
158
|
+
{
|
|
159
|
+
annotations: item.tool.annotations,
|
|
160
|
+
description: item.tool.description,
|
|
161
|
+
inputSchema: toStandardSchema(inputSchema),
|
|
162
|
+
},
|
|
163
|
+
async (input: unknown, ctx: ServerContext) =>
|
|
164
|
+
callEntityTool({ input, item, serverContext: ctx }),
|
|
165
|
+
)
|
|
166
|
+
logger.info(`✅ Tool: ${item.mcpName} Registered.`)
|
|
167
|
+
break
|
|
168
|
+
}
|
|
169
|
+
case 'prompt': {
|
|
170
|
+
const prompt = item.prompt
|
|
171
|
+
server.registerPrompt(
|
|
172
|
+
item.mcpName,
|
|
173
|
+
{
|
|
174
|
+
argsSchema: prompt.argsSchema ? toStandardSchema(prompt.argsSchema) : undefined,
|
|
175
|
+
description: prompt.description,
|
|
176
|
+
title: prompt.title,
|
|
177
|
+
},
|
|
178
|
+
async (input: unknown, ctx: ServerContext) =>
|
|
179
|
+
prompt.handler({
|
|
180
|
+
input: (input ?? {}) as Record<string, unknown>,
|
|
181
|
+
req,
|
|
182
|
+
serverContext: ctx,
|
|
183
|
+
}),
|
|
184
|
+
)
|
|
185
|
+
logger.info(`✅ Prompt: ${prompt.title} Registered.`)
|
|
186
|
+
break
|
|
187
|
+
}
|
|
188
|
+
case 'resource': {
|
|
189
|
+
const resource = item.resource
|
|
190
|
+
server.registerResource(
|
|
191
|
+
item.mcpName,
|
|
192
|
+
// @ts-expect-error - Overload type ambiguity (string OR ResourceTemplate is valid)
|
|
193
|
+
resource.uri,
|
|
194
|
+
{
|
|
195
|
+
description: resource.description,
|
|
196
|
+
mimeType: resource.mimeType,
|
|
197
|
+
title: resource.title,
|
|
198
|
+
},
|
|
199
|
+
// Static URIs call (uri, ctx); ResourceTemplates call (uri, params, ctx).
|
|
200
|
+
// The rest-params shape lets us collect either signature uniformly.
|
|
201
|
+
async (...sdkArgs: unknown[]) => {
|
|
202
|
+
const ctx = sdkArgs[sdkArgs.length - 1] as ServerContext
|
|
203
|
+
const uri = sdkArgs[0] as URL
|
|
204
|
+
const params = (sdkArgs.length > 2 ? sdkArgs[1] : {}) as Record<string, string>
|
|
205
|
+
return resource.handler({ params, req, serverContext: ctx, uri })
|
|
206
|
+
},
|
|
207
|
+
)
|
|
208
|
+
logger.info(`✅ Resource: ${resource.title} Registered.`)
|
|
209
|
+
break
|
|
210
|
+
}
|
|
211
|
+
case 'tool': {
|
|
212
|
+
const tool = item.tool
|
|
213
|
+
server.registerTool(
|
|
214
|
+
item.mcpName,
|
|
215
|
+
{
|
|
216
|
+
annotations: tool.annotations,
|
|
217
|
+
description: tool.description,
|
|
218
|
+
inputSchema: tool.input ? toStandardSchema(tool.input) : undefined,
|
|
219
|
+
},
|
|
220
|
+
async (input: unknown, ctx: ServerContext) => {
|
|
221
|
+
const toolInput = (input ?? {}) as Record<string, unknown>
|
|
222
|
+
const response = await tool.handler({
|
|
223
|
+
authorizedMCP,
|
|
224
|
+
input: toolInput,
|
|
225
|
+
req,
|
|
226
|
+
serverContext: ctx,
|
|
227
|
+
})
|
|
228
|
+
return finalizeToolResponse({
|
|
229
|
+
input: toolInput,
|
|
230
|
+
overrideResponse: tool.overrideResponse,
|
|
231
|
+
response,
|
|
232
|
+
toolName: item.mcpName,
|
|
233
|
+
})
|
|
234
|
+
},
|
|
235
|
+
)
|
|
236
|
+
logger.info(`✅ Tool: ${item.mcpName} Registered.`)
|
|
237
|
+
break
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
} catch (error) {
|
|
242
|
+
throw new APIError(`Error initializing MCP handler: ${String(error)}`, 500)
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
return server
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
const withSlugInput = ({ input }: { input?: ToolInputSchema }): ToolInputSchema => {
|
|
249
|
+
const description = 'The target slug.'
|
|
250
|
+
const slugSchema = z.string().check(z.describe(description))
|
|
251
|
+
|
|
252
|
+
if (!input) {
|
|
253
|
+
return strictObject({ slug: slugSchema })
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
if (typeof input === 'object' && input !== null && '~standard' in input) {
|
|
257
|
+
const schema = input['~standard'].jsonSchema.input({ target: 'draft-2020-12' })
|
|
258
|
+
const properties = schema.properties as Record<string, unknown> | undefined
|
|
259
|
+
|
|
260
|
+
if (properties?.slug) {
|
|
261
|
+
return input
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
return addSlugToJSONSchema({ description, schema })
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
return addSlugToJSONSchema({ description, schema: input })
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
const addSlugToJSONSchema = ({
|
|
271
|
+
description,
|
|
272
|
+
schema,
|
|
273
|
+
}: {
|
|
274
|
+
description: string
|
|
275
|
+
schema: JsonSchemaType
|
|
276
|
+
}): JsonSchemaType => {
|
|
277
|
+
const objectSchema = schema as {
|
|
278
|
+
properties?: Record<string, JsonSchemaType>
|
|
279
|
+
required?: string[]
|
|
280
|
+
} & JsonSchemaType
|
|
281
|
+
|
|
282
|
+
return {
|
|
283
|
+
...objectSchema,
|
|
284
|
+
type: 'object',
|
|
285
|
+
properties: {
|
|
286
|
+
...objectSchema.properties,
|
|
287
|
+
slug: {
|
|
288
|
+
type: 'string',
|
|
289
|
+
description,
|
|
290
|
+
},
|
|
291
|
+
},
|
|
292
|
+
required: Array.from(new Set(['slug', ...(objectSchema.required ?? [])])),
|
|
293
|
+
}
|
|
294
|
+
}
|