@payloadcms/plugin-mcp 3.86.0-internal.ac46214 → 4.0.0-canary.1
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/README.md +2 -2
- package/bin.js +39 -0
- package/dist/collection/getAccessField.d.ts +12 -0
- package/dist/collection/getAccessField.d.ts.map +1 -0
- package/dist/collection/getAccessField.js +57 -0
- package/dist/collection/getAccessField.js.map +1 -0
- package/dist/collection/index.d.ts +6 -0
- package/dist/collection/index.d.ts.map +1 -0
- package/dist/collection/index.js +60 -0
- package/dist/collection/index.js.map +1 -0
- package/dist/components/AccessField/index.client.d.ts +10 -0
- package/dist/components/AccessField/index.client.d.ts.map +1 -0
- package/dist/components/AccessField/index.client.js +305 -0
- package/dist/components/AccessField/index.client.js.map +1 -0
- package/dist/components/AccessField/index.css +93 -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 +10 -0
- package/dist/endpoint/access.d.ts.map +1 -0
- package/dist/endpoint/access.js +106 -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 +36 -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/index.d.ts +4 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +44 -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 +199 -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 +250 -0
- package/dist/mcp/builtin/collections/authTools.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 +94 -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 +102 -0
- package/dist/mcp/builtin/collections/deleteTool.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 +144 -0
- package/dist/mcp/builtin/collections/findTool.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 +35 -0
- package/dist/mcp/builtin/collections/getCollectionSchemaTool.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 +199 -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 +49 -0
- package/dist/mcp/builtin/getConfigInfoTool.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 +76 -0
- package/dist/mcp/builtin/globals/findTool.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 +35 -0
- package/dist/mcp/builtin/globals/getGlobalSchemaTool.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 +94 -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 +105 -0
- package/dist/mcp/builtinTools.d.ts.map +1 -0
- package/dist/mcp/builtinTools.js +107 -0
- package/dist/mcp/builtinTools.js.map +1 -0
- package/dist/mcp/sanitizeMCPConfig.d.ts +17 -0
- package/dist/mcp/sanitizeMCPConfig.d.ts.map +1 -0
- package/dist/mcp/sanitizeMCPConfig.js +188 -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 +89 -0
- package/dist/stdio.js.map +1 -0
- package/dist/types.d.ts +251 -455
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +6 -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/localAPIDefaults.d.ts +20 -0
- package/dist/utils/localAPIDefaults.d.ts.map +1 -0
- package/dist/utils/localAPIDefaults.js +19 -0
- package/dist/utils/localAPIDefaults.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/getEntityInputSchema.d.ts +11 -0
- package/dist/utils/schemaConversion/getEntityInputSchema.d.ts.map +1 -0
- package/dist/utils/schemaConversion/getEntityInputSchema.js +34 -0
- package/dist/utils/schemaConversion/getEntityInputSchema.js.map +1 -0
- package/dist/utils/schemaConversion/removeVirtualFieldsFromSchema.d.ts +2 -2
- package/dist/utils/schemaConversion/removeVirtualFieldsFromSchema.d.ts.map +1 -1
- package/dist/utils/schemaConversion/removeVirtualFieldsFromSchema.js.map +1 -1
- package/dist/utils/schemaConversion/sanitizeEntitySchema.d.ts +15 -0
- package/dist/utils/schemaConversion/sanitizeEntitySchema.d.ts.map +1 -0
- package/dist/utils/schemaConversion/sanitizeEntitySchema.js +464 -0
- package/dist/utils/schemaConversion/sanitizeEntitySchema.js.map +1 -0
- package/dist/utils/schemaConversion/sanitizeEntitySchema.spec.js +158 -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 +35 -10
- package/src/collection/getAccessField.ts +64 -0
- package/src/collection/index.ts +64 -0
- package/src/components/AccessField/index.client.tsx +347 -0
- package/src/components/AccessField/index.css +93 -0
- package/src/defineTool.ts +44 -0
- package/src/endpoint/access.ts +132 -0
- package/src/endpoint/index.ts +35 -0
- package/src/exports/client.ts +2 -0
- package/src/index.ts +35 -85
- package/src/mcp/buildMcpServer.ts +257 -0
- package/src/mcp/builtin/collections/authTools.ts +233 -0
- package/src/mcp/builtin/collections/createTool.ts +112 -0
- package/src/mcp/builtin/collections/deleteTool.ts +116 -0
- package/src/mcp/builtin/collections/findTool.ts +177 -0
- package/src/mcp/builtin/collections/formatCollectionError.ts +84 -0
- package/src/mcp/builtin/collections/getCollectionSchemaTool.ts +28 -0
- package/src/mcp/builtin/collections/updateTool.ts +211 -0
- package/src/mcp/builtin/getConfigInfoTool.ts +44 -0
- package/src/mcp/builtin/globals/findTool.ts +96 -0
- package/src/mcp/builtin/globals/getGlobalSchemaTool.ts +28 -0
- package/src/mcp/builtin/globals/updateTool.ts +115 -0
- package/src/mcp/builtin/validateEntityData.ts +132 -0
- package/src/mcp/builtinTools.ts +98 -0
- package/src/mcp/sanitizeMCPConfig.ts +260 -0
- package/src/stdio.ts +98 -0
- package/src/types.ts +290 -490
- package/src/utils/getLogger.ts +22 -0
- package/src/utils/getPluginConfig.ts +24 -0
- package/src/utils/localAPIDefaults.ts +22 -0
- package/src/utils/resolveProjectRoot.ts +17 -0
- package/src/utils/schemaConversion/getEntityInputSchema.ts +78 -0
- package/src/utils/schemaConversion/removeVirtualFieldsFromSchema.ts +3 -3
- package/src/utils/schemaConversion/sanitizeEntitySchema.spec.ts +103 -0
- package/src/utils/schemaConversion/sanitizeEntitySchema.ts +529 -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/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/sanitizeJsonSchema.ts +0 -62
- package/src/utils/schemaConversion/simplifyRelationshipFields.ts +0 -65
- package/src/utils/schemaConversion/transformPointFields.ts +0 -55
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
@layer payload-default {
|
|
2
|
+
.mcp-access-field {
|
|
3
|
+
display: flex;
|
|
4
|
+
flex-direction: column;
|
|
5
|
+
gap: var(--base);
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
.mcp-access-field__section {
|
|
9
|
+
display: flex;
|
|
10
|
+
flex-direction: column;
|
|
11
|
+
gap: calc(var(--base) / 2);
|
|
12
|
+
padding-bottom: var(--base);
|
|
13
|
+
/* Full-bleed separator: extend past the sidebar's horizontal gutter so the
|
|
14
|
+
border-block-end spans the entire sidebar width. */
|
|
15
|
+
margin-inline-start: calc(-1 * var(--sidebar-gutter-h-left, var(--gutter-h)));
|
|
16
|
+
margin-inline-end: calc(-1 * var(--sidebar-gutter-h-right, var(--gutter-h)));
|
|
17
|
+
padding-inline-start: var(--sidebar-gutter-h-left, var(--gutter-h));
|
|
18
|
+
padding-inline-end: var(--sidebar-gutter-h-right, var(--gutter-h));
|
|
19
|
+
border-block-end: 1px solid var(--theme-elevation-100);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
.mcp-access-field__section:last-child {
|
|
23
|
+
border-block-end: none;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
.mcp-access-field__section-header {
|
|
27
|
+
display: flex;
|
|
28
|
+
flex-direction: column;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
.mcp-access-field__section-header h4 {
|
|
32
|
+
margin: 0;
|
|
33
|
+
color: var(--color-text);
|
|
34
|
+
font-family: var(--text-heading-small-font-family);
|
|
35
|
+
font-size: var(--text-heading-small-font-size);
|
|
36
|
+
font-weight: var(--text-heading-small-font-weight);
|
|
37
|
+
line-height: var(--text-heading-small-line-height);
|
|
38
|
+
letter-spacing: var(--text-heading-small-letter-spacing);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
.mcp-access-field__section-header p {
|
|
42
|
+
margin: 0;
|
|
43
|
+
color: var(--color-text-secondary);
|
|
44
|
+
font-family: var(--text-body-medium-font-family);
|
|
45
|
+
font-size: var(--text-body-medium-font-size);
|
|
46
|
+
font-weight: var(--text-body-medium-font-weight);
|
|
47
|
+
line-height: var(--text-body-medium-line-height);
|
|
48
|
+
letter-spacing: var(--text-body-medium-letter-spacing);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
.mcp-access-field__group {
|
|
52
|
+
margin-block-end: calc(var(--base) / 2);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
.mcp-access-field__group-label {
|
|
56
|
+
font-weight: 600;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
.mcp-access-field__group-actions {
|
|
60
|
+
display: flex;
|
|
61
|
+
align-items: center;
|
|
62
|
+
gap: calc(var(--base) / 6);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
.mcp-access-field__action {
|
|
66
|
+
appearance: none;
|
|
67
|
+
background: none;
|
|
68
|
+
border: none;
|
|
69
|
+
color: var(--theme-elevation-500);
|
|
70
|
+
cursor: pointer;
|
|
71
|
+
font-size: 0.75rem;
|
|
72
|
+
padding: 0;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
.mcp-access-field__action:hover {
|
|
76
|
+
color: var(--theme-text);
|
|
77
|
+
text-decoration: underline;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
.mcp-access-field__action-sep {
|
|
81
|
+
color: var(--theme-elevation-300);
|
|
82
|
+
font-size: 0.75rem;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
.mcp-access-field__list {
|
|
86
|
+
list-style: none;
|
|
87
|
+
margin: 0;
|
|
88
|
+
padding: 0;
|
|
89
|
+
display: flex;
|
|
90
|
+
flex-direction: column;
|
|
91
|
+
gap: calc(var(--base) / 3);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { CollectionTool, GlobalTool, Prompt, Tool, ToolInputSchema } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Two-stage builder: pass the schema/metadata first, then chain `.handler(fn)`. Splitting the
|
|
4
|
+
* call lets TypeScript resolve `TSchema` from `input` (call 1) before contextually typing the
|
|
5
|
+
* handler (call 2). A single-call API hit a TS limitation where property order in the literal
|
|
6
|
+
* decided whether `TSchema` was inferred or pinned to its default.
|
|
7
|
+
*
|
|
8
|
+
* defineCollectionTool({ description, input })
|
|
9
|
+
* .handler(({ input }) => …) // ← input is fully typed here regardless of order
|
|
10
|
+
*
|
|
11
|
+
* Config and handler signatures are derived from `Tool` / `CollectionTool` / `GlobalTool` /
|
|
12
|
+
* `Prompt` via `Omit` + indexed access so there's no duplication with `types.ts`.
|
|
13
|
+
*/
|
|
14
|
+
export declare const defineTool: <TSchema extends ToolInputSchema | undefined = ToolInputSchema | undefined>(args: Omit<Tool<TSchema>, "handler">) => {
|
|
15
|
+
handler: (fn: Tool<TSchema>["handler"]) => Tool;
|
|
16
|
+
};
|
|
17
|
+
export declare const defineCollectionTool: <TSchema extends ToolInputSchema | undefined = ToolInputSchema | undefined>(args: Omit<CollectionTool<TSchema>, "handler">) => {
|
|
18
|
+
handler: (fn: CollectionTool<TSchema>["handler"]) => CollectionTool;
|
|
19
|
+
};
|
|
20
|
+
export declare const defineGlobalTool: <TSchema extends ToolInputSchema | undefined = ToolInputSchema | undefined>(args: Omit<GlobalTool<TSchema>, "handler">) => {
|
|
21
|
+
handler: (fn: GlobalTool<TSchema>["handler"]) => GlobalTool;
|
|
22
|
+
};
|
|
23
|
+
export declare const definePrompt: <TSchema extends ToolInputSchema = ToolInputSchema>(args: Omit<Prompt<TSchema>, "handler">) => {
|
|
24
|
+
handler: (fn: Prompt<TSchema>["handler"]) => Prompt;
|
|
25
|
+
};
|
|
26
|
+
//# sourceMappingURL=defineTool.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defineTool.d.ts","sourceRoot":"","sources":["../src/defineTool.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,EAAE,IAAI,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAE3F;;;;;;;;;;;GAWG;AAEH,eAAO,MAAM,UAAU,GACrB,OAAO,SAAS,eAAe,GAAG,SAAS,GAAG,eAAe,GAAG,SAAS,EAEzE,MAAM,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,SAAS,CAAC,KACnC;IAAE,OAAO,EAAE,CAAC,EAAE,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC,SAAS,CAAC,KAAK,IAAI,CAAA;CAElD,CAAA;AAEF,eAAO,MAAM,oBAAoB,GAC/B,OAAO,SAAS,eAAe,GAAG,SAAS,GAAG,eAAe,GAAG,SAAS,EAEzE,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,EAAE,SAAS,CAAC,KAC7C;IAAE,OAAO,EAAE,CAAC,EAAE,EAAE,cAAc,CAAC,OAAO,CAAC,CAAC,SAAS,CAAC,KAAK,cAAc,CAAA;CAEtE,CAAA;AAEF,eAAO,MAAM,gBAAgB,GAC3B,OAAO,SAAS,eAAe,GAAG,SAAS,GAAG,eAAe,GAAG,SAAS,EAEzE,MAAM,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,SAAS,CAAC,KACzC;IAAE,OAAO,EAAE,CAAC,EAAE,EAAE,UAAU,CAAC,OAAO,CAAC,CAAC,SAAS,CAAC,KAAK,UAAU,CAAA;CAE9D,CAAA;AAEF,eAAO,MAAM,YAAY,GAAI,OAAO,SAAS,eAAe,GAAG,eAAe,EAC5E,MAAM,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,SAAS,CAAC,KACrC;IAAE,OAAO,EAAE,CAAC,EAAE,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC,SAAS,CAAC,KAAK,MAAM,CAAA;CAEtD,CAAA"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Two-stage builder: pass the schema/metadata first, then chain `.handler(fn)`. Splitting the
|
|
3
|
+
* call lets TypeScript resolve `TSchema` from `input` (call 1) before contextually typing the
|
|
4
|
+
* handler (call 2). A single-call API hit a TS limitation where property order in the literal
|
|
5
|
+
* decided whether `TSchema` was inferred or pinned to its default.
|
|
6
|
+
*
|
|
7
|
+
* defineCollectionTool({ description, input })
|
|
8
|
+
* .handler(({ input }) => …) // ← input is fully typed here regardless of order
|
|
9
|
+
*
|
|
10
|
+
* Config and handler signatures are derived from `Tool` / `CollectionTool` / `GlobalTool` /
|
|
11
|
+
* `Prompt` via `Omit` + indexed access so there's no duplication with `types.ts`.
|
|
12
|
+
*/ export const defineTool = (args)=>({
|
|
13
|
+
handler: (fn)=>({
|
|
14
|
+
...args,
|
|
15
|
+
handler: fn
|
|
16
|
+
})
|
|
17
|
+
});
|
|
18
|
+
export const defineCollectionTool = (args)=>({
|
|
19
|
+
handler: (fn)=>({
|
|
20
|
+
...args,
|
|
21
|
+
handler: fn
|
|
22
|
+
})
|
|
23
|
+
});
|
|
24
|
+
export const defineGlobalTool = (args)=>({
|
|
25
|
+
handler: (fn)=>({
|
|
26
|
+
...args,
|
|
27
|
+
handler: fn
|
|
28
|
+
})
|
|
29
|
+
});
|
|
30
|
+
export const definePrompt = (args)=>({
|
|
31
|
+
handler: (fn)=>({
|
|
32
|
+
...args,
|
|
33
|
+
handler: fn
|
|
34
|
+
})
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
//# sourceMappingURL=defineTool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/defineTool.ts"],"sourcesContent":["import type { CollectionTool, GlobalTool, Prompt, Tool, ToolInputSchema } from './types.js'\n\n/**\n * Two-stage builder: pass the schema/metadata first, then chain `.handler(fn)`. Splitting the\n * call lets TypeScript resolve `TSchema` from `input` (call 1) before contextually typing the\n * handler (call 2). A single-call API hit a TS limitation where property order in the literal\n * decided whether `TSchema` was inferred or pinned to its default.\n *\n * defineCollectionTool({ description, input })\n * .handler(({ input }) => …) // ← input is fully typed here regardless of order\n *\n * Config and handler signatures are derived from `Tool` / `CollectionTool` / `GlobalTool` /\n * `Prompt` via `Omit` + indexed access so there's no duplication with `types.ts`.\n */\n\nexport const defineTool = <\n TSchema extends ToolInputSchema | undefined = ToolInputSchema | undefined,\n>(\n args: Omit<Tool<TSchema>, 'handler'>,\n): { handler: (fn: Tool<TSchema>['handler']) => Tool } => ({\n handler: (fn) => ({ ...args, handler: fn }) as unknown as Tool,\n})\n\nexport const defineCollectionTool = <\n TSchema extends ToolInputSchema | undefined = ToolInputSchema | undefined,\n>(\n args: Omit<CollectionTool<TSchema>, 'handler'>,\n): { handler: (fn: CollectionTool<TSchema>['handler']) => CollectionTool } => ({\n handler: (fn) => ({ ...args, handler: fn }) as unknown as CollectionTool,\n})\n\nexport const defineGlobalTool = <\n TSchema extends ToolInputSchema | undefined = ToolInputSchema | undefined,\n>(\n args: Omit<GlobalTool<TSchema>, 'handler'>,\n): { handler: (fn: GlobalTool<TSchema>['handler']) => GlobalTool } => ({\n handler: (fn) => ({ ...args, handler: fn }) as unknown as GlobalTool,\n})\n\nexport const definePrompt = <TSchema extends ToolInputSchema = ToolInputSchema>(\n args: Omit<Prompt<TSchema>, 'handler'>,\n): { handler: (fn: Prompt<TSchema>['handler']) => Prompt } => ({\n handler: (fn) => ({ ...args, handler: fn }) as unknown as Prompt,\n})\n"],"names":["defineTool","args","handler","fn","defineCollectionTool","defineGlobalTool","definePrompt"],"mappings":"AAEA;;;;;;;;;;;CAWC,GAED,OAAO,MAAMA,aAAa,CAGxBC,OACyD,CAAA;QACzDC,SAAS,CAACC,KAAQ,CAAA;gBAAE,GAAGF,IAAI;gBAAEC,SAASC;YAAG,CAAA;IAC3C,CAAA,EAAE;AAEF,OAAO,MAAMC,uBAAuB,CAGlCH,OAC6E,CAAA;QAC7EC,SAAS,CAACC,KAAQ,CAAA;gBAAE,GAAGF,IAAI;gBAAEC,SAASC;YAAG,CAAA;IAC3C,CAAA,EAAE;AAEF,OAAO,MAAME,mBAAmB,CAG9BJ,OACqE,CAAA;QACrEC,SAAS,CAACC,KAAQ,CAAA;gBAAE,GAAGF,IAAI;gBAAEC,SAASC;YAAG,CAAA;IAC3C,CAAA,EAAE;AAEF,OAAO,MAAMG,eAAe,CAC1BL,OAC6D,CAAA;QAC7DC,SAAS,CAACC,KAAQ,CAAA;gBAAE,GAAGF,IAAI;gBAAEC,SAASC;YAAG,CAAA;IAC3C,CAAA,EAAE"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { PayloadRequest } from 'payload';
|
|
2
|
+
import type { AuthorizedMCP } from '../types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Resolves the API key (or dev-mode session) and returns the items the caller
|
|
5
|
+
* may use. Denied items are dropped from the array.
|
|
6
|
+
*/
|
|
7
|
+
export declare const getAuthorizedMCP: (args: {
|
|
8
|
+
req: PayloadRequest;
|
|
9
|
+
}) => Promise<AuthorizedMCP>;
|
|
10
|
+
//# sourceMappingURL=access.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"access.d.ts","sourceRoot":"","sources":["../../src/endpoint/access.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAyB,cAAc,EAAa,MAAM,SAAS,CAAA;AAK/E,OAAO,KAAK,EAAE,aAAa,EAAiB,MAAM,aAAa,CAAA;AAK/D;;;GAGG;AACH,eAAO,MAAM,gBAAgB,EAAE,CAAC,IAAI,EAAE;IAAE,GAAG,EAAE,cAAc,CAAA;CAAE,KAAK,OAAO,CAAC,aAAa,CAiDtF,CAAA"}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import crypto from 'crypto';
|
|
2
|
+
import { UnauthorizedError } from 'payload';
|
|
3
|
+
import { getLogger } from '../utils/getLogger.js';
|
|
4
|
+
import { getPluginConfig } from '../utils/getPluginConfig.js';
|
|
5
|
+
/**
|
|
6
|
+
* Resolves the API key (or dev-mode session) and returns the items the caller
|
|
7
|
+
* may use. Denied items are dropped from the array.
|
|
8
|
+
*/ export const getAuthorizedMCP = async ({ req })=>{
|
|
9
|
+
const logger = getLogger({
|
|
10
|
+
payload: req.payload
|
|
11
|
+
});
|
|
12
|
+
const pluginConfig = getPluginConfig({
|
|
13
|
+
config: req.payload.config
|
|
14
|
+
});
|
|
15
|
+
const authHeader = req.headers.get('Authorization');
|
|
16
|
+
const hasBearerToken = authHeader?.startsWith('Bearer ');
|
|
17
|
+
const buildAuthorized = (apiKeyDoc)=>({
|
|
18
|
+
items: pluginConfig.items.filter((item)=>{
|
|
19
|
+
switch(item.type){
|
|
20
|
+
case 'collectionTool':
|
|
21
|
+
return apiKeyDoc.access.collections?.[item.collectionSlug]?.[item.configKey] !== false;
|
|
22
|
+
case 'globalTool':
|
|
23
|
+
return apiKeyDoc.access.globals?.[item.globalSlug]?.[item.configKey] !== false;
|
|
24
|
+
case 'prompt':
|
|
25
|
+
return apiKeyDoc.access.prompts?.[item.configKey] !== false;
|
|
26
|
+
case 'resource':
|
|
27
|
+
return apiKeyDoc.access.resources?.[item.configKey] !== false;
|
|
28
|
+
case 'tool':
|
|
29
|
+
return apiKeyDoc.access.tools?.[item.configKey] !== false;
|
|
30
|
+
}
|
|
31
|
+
}),
|
|
32
|
+
overrideAccess: typeof apiKeyDoc.overrideAccess === 'boolean' ? apiKeyDoc.overrideAccess : false,
|
|
33
|
+
user: apiKeyDoc.user
|
|
34
|
+
});
|
|
35
|
+
if (pluginConfig.overrideAuth) {
|
|
36
|
+
return await pluginConfig.overrideAuth({
|
|
37
|
+
getAPIKeyDoc: (overrideApiKey)=>getAPIKeyDoc({
|
|
38
|
+
logger,
|
|
39
|
+
overrideApiKey,
|
|
40
|
+
pluginConfig,
|
|
41
|
+
req
|
|
42
|
+
}),
|
|
43
|
+
getAuthorizedMCP: ({ apiKeyDoc })=>buildAuthorized(apiKeyDoc),
|
|
44
|
+
pluginConfig,
|
|
45
|
+
req
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
if (process.env.NODE_ENV === 'development' && !hasBearerToken) {
|
|
49
|
+
logger.info('Dev mode: skipping API key check, using session user');
|
|
50
|
+
return buildAuthorized({
|
|
51
|
+
id: -1,
|
|
52
|
+
access: {},
|
|
53
|
+
overrideAccess: true,
|
|
54
|
+
user: req.user ?? null
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
return buildAuthorized(await getAPIKeyDoc({
|
|
58
|
+
logger,
|
|
59
|
+
pluginConfig,
|
|
60
|
+
req
|
|
61
|
+
}));
|
|
62
|
+
};
|
|
63
|
+
const getAPIKeyDoc = async ({ logger, overrideApiKey, pluginConfig, req })=>{
|
|
64
|
+
const authHeader = req.headers.get('Authorization');
|
|
65
|
+
const hasBearerToken = authHeader?.startsWith('Bearer ');
|
|
66
|
+
const apiKey = overrideApiKey ?? (hasBearerToken ? authHeader?.replace('Bearer ', '').trim() || null : null);
|
|
67
|
+
if (!apiKey) {
|
|
68
|
+
throw new UnauthorizedError();
|
|
69
|
+
}
|
|
70
|
+
const sha256APIKeyIndex = crypto.createHmac('sha256', req.payload.secret).update(apiKey).digest('hex');
|
|
71
|
+
const doc = await req.payload.db.findOne({
|
|
72
|
+
collection: 'payload-mcp-api-keys',
|
|
73
|
+
req,
|
|
74
|
+
where: {
|
|
75
|
+
apiKeyIndex: {
|
|
76
|
+
equals: sha256APIKeyIndex
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
if (!doc || !doc.user) {
|
|
81
|
+
throw new UnauthorizedError();
|
|
82
|
+
}
|
|
83
|
+
logger.info('API Key is valid');
|
|
84
|
+
const userRef = doc.user;
|
|
85
|
+
const userID = typeof userRef === 'object' && userRef !== null && 'id' in userRef ? userRef.id : userRef;
|
|
86
|
+
const user = await req.payload.findByID({
|
|
87
|
+
id: userID,
|
|
88
|
+
collection: pluginConfig.userCollection,
|
|
89
|
+
depth: 0,
|
|
90
|
+
disableErrors: true,
|
|
91
|
+
req
|
|
92
|
+
});
|
|
93
|
+
if (!user) {
|
|
94
|
+
throw new UnauthorizedError();
|
|
95
|
+
}
|
|
96
|
+
return {
|
|
97
|
+
...doc,
|
|
98
|
+
user: {
|
|
99
|
+
...user,
|
|
100
|
+
_strategy: 'mcp-api-key',
|
|
101
|
+
collection: pluginConfig.userCollection
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
//# sourceMappingURL=access.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/endpoint/access.ts"],"sourcesContent":["import type { DefaultDocumentIDType, PayloadRequest, TypedUser } from 'payload'\n\nimport crypto from 'crypto'\nimport { UnauthorizedError } from 'payload'\n\nimport type { AuthorizedMCP, MCPAPIKeysDoc } from '../types.js'\n\nimport { getLogger } from '../utils/getLogger.js'\nimport { getPluginConfig } from '../utils/getPluginConfig.js'\n\n/**\n * Resolves the API key (or dev-mode session) and returns the items the caller\n * may use. Denied items are dropped from the array.\n */\nexport const getAuthorizedMCP: (args: { req: PayloadRequest }) => Promise<AuthorizedMCP> = async ({\n req,\n}) => {\n const logger = getLogger({ payload: req.payload })\n const pluginConfig = getPluginConfig({ config: req.payload.config })\n\n const authHeader = req.headers.get('Authorization')\n const hasBearerToken = authHeader?.startsWith('Bearer ')\n\n const buildAuthorized = (apiKeyDoc: MCPAPIKeysDoc): AuthorizedMCP => ({\n items: pluginConfig.items.filter((item) => {\n switch (item.type) {\n case 'collectionTool':\n return apiKeyDoc.access.collections?.[item.collectionSlug]?.[item.configKey] !== false\n case 'globalTool':\n return apiKeyDoc.access.globals?.[item.globalSlug]?.[item.configKey] !== false\n case 'prompt':\n return apiKeyDoc.access.prompts?.[item.configKey] !== false\n case 'resource':\n return apiKeyDoc.access.resources?.[item.configKey] !== false\n case 'tool':\n return apiKeyDoc.access.tools?.[item.configKey] !== false\n }\n }),\n overrideAccess:\n typeof apiKeyDoc.overrideAccess === 'boolean' ? apiKeyDoc.overrideAccess : false,\n user: apiKeyDoc.user,\n })\n\n if (pluginConfig.overrideAuth) {\n return await pluginConfig.overrideAuth({\n getAPIKeyDoc: (overrideApiKey) => getAPIKeyDoc({ logger, overrideApiKey, pluginConfig, req }),\n getAuthorizedMCP: ({ apiKeyDoc }) => buildAuthorized(apiKeyDoc),\n pluginConfig,\n req,\n })\n }\n\n if (process.env.NODE_ENV === 'development' && !hasBearerToken) {\n logger.info('Dev mode: skipping API key check, using session user')\n return buildAuthorized({\n id: -1,\n access: {},\n overrideAccess: true,\n user: req.user ?? null,\n })\n }\n\n return buildAuthorized(await getAPIKeyDoc({ logger, pluginConfig, req }))\n}\n\nconst getAPIKeyDoc = async ({\n logger,\n overrideApiKey,\n pluginConfig,\n req,\n}: {\n logger: ReturnType<typeof getLogger>\n overrideApiKey?: string\n pluginConfig: ReturnType<typeof getPluginConfig>\n req: PayloadRequest\n}): Promise<MCPAPIKeysDoc> => {\n const authHeader = req.headers.get('Authorization')\n const hasBearerToken = authHeader?.startsWith('Bearer ')\n\n const apiKey =\n overrideApiKey ?? (hasBearerToken ? authHeader?.replace('Bearer ', '').trim() || null : null)\n\n if (!apiKey) {\n throw new UnauthorizedError()\n }\n\n const sha256APIKeyIndex = crypto\n .createHmac('sha256', req.payload.secret)\n .update(apiKey)\n .digest('hex')\n\n const doc = await req.payload.db.findOne<MCPAPIKeysDoc>({\n collection: 'payload-mcp-api-keys',\n req,\n where: {\n apiKeyIndex: { equals: sha256APIKeyIndex },\n },\n })\n\n if (!doc || !doc.user) {\n throw new UnauthorizedError()\n }\n\n logger.info('API Key is valid')\n\n const userRef = doc.user\n const userID =\n typeof userRef === 'object' && userRef !== null && 'id' in userRef\n ? userRef.id\n : (userRef as unknown as DefaultDocumentIDType)\n\n const user = (await req.payload.findByID({\n id: userID,\n collection: pluginConfig.userCollection,\n depth: 0,\n disableErrors: true,\n req,\n })) as null | TypedUser\n\n if (!user) {\n throw new UnauthorizedError()\n }\n\n return {\n ...doc,\n user: {\n ...user,\n _strategy: 'mcp-api-key' as const,\n collection: pluginConfig.userCollection,\n },\n }\n}\n"],"names":["crypto","UnauthorizedError","getLogger","getPluginConfig","getAuthorizedMCP","req","logger","payload","pluginConfig","config","authHeader","headers","get","hasBearerToken","startsWith","buildAuthorized","apiKeyDoc","items","filter","item","type","access","collections","collectionSlug","configKey","globals","globalSlug","prompts","resources","tools","overrideAccess","user","overrideAuth","getAPIKeyDoc","overrideApiKey","process","env","NODE_ENV","info","id","apiKey","replace","trim","sha256APIKeyIndex","createHmac","secret","update","digest","doc","db","findOne","collection","where","apiKeyIndex","equals","userRef","userID","findByID","userCollection","depth","disableErrors","_strategy"],"mappings":"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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/endpoint/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAY,KAAK,cAAc,EAAE,MAAM,SAAS,CAAA;AAMvD,eAAO,MAAM,WAAW,EAAE,cA2BzB,CAAA"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { WebStandardStreamableHTTPServerTransport } from '@modelcontextprotocol/server';
|
|
2
|
+
import { APIError } from 'payload';
|
|
3
|
+
import { buildMcpServer } from '../mcp/buildMcpServer.js';
|
|
4
|
+
import { getPluginConfig } from '../utils/getPluginConfig.js';
|
|
5
|
+
import { getAuthorizedMCP } from './access.js';
|
|
6
|
+
export const mcpEndpoint = async (req)=>{
|
|
7
|
+
if (!req.url) {
|
|
8
|
+
throw new APIError('Missing request URL', 400);
|
|
9
|
+
}
|
|
10
|
+
req.payloadAPI = 'MCP';
|
|
11
|
+
const pluginConfig = getPluginConfig({
|
|
12
|
+
config: req.payload.config
|
|
13
|
+
});
|
|
14
|
+
const authorizedMCP = await getAuthorizedMCP({
|
|
15
|
+
req
|
|
16
|
+
});
|
|
17
|
+
const server = buildMcpServer({
|
|
18
|
+
authorizedMCP,
|
|
19
|
+
pluginConfig,
|
|
20
|
+
req
|
|
21
|
+
});
|
|
22
|
+
const transport = new WebStandardStreamableHTTPServerTransport({
|
|
23
|
+
enableJsonResponse: true,
|
|
24
|
+
sessionIdGenerator: undefined
|
|
25
|
+
});
|
|
26
|
+
await server.connect(transport);
|
|
27
|
+
const mcpRequest = new Request(req.url, {
|
|
28
|
+
body: req.body,
|
|
29
|
+
duplex: 'half',
|
|
30
|
+
headers: req.headers,
|
|
31
|
+
method: req.method
|
|
32
|
+
});
|
|
33
|
+
return await transport.handleRequest(mcpRequest);
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/endpoint/index.ts"],"sourcesContent":["import { WebStandardStreamableHTTPServerTransport } from '@modelcontextprotocol/server'\nimport { APIError, type PayloadHandler } from 'payload'\n\nimport { buildMcpServer } from '../mcp/buildMcpServer.js'\nimport { getPluginConfig } from '../utils/getPluginConfig.js'\nimport { getAuthorizedMCP } from './access.js'\n\nexport const mcpEndpoint: PayloadHandler = async (req) => {\n if (!req.url) {\n throw new APIError('Missing request URL', 400)\n }\n\n req.payloadAPI = 'MCP' as const\n\n const pluginConfig = getPluginConfig({ config: req.payload.config })\n const authorizedMCP = await getAuthorizedMCP({ req })\n\n const server = buildMcpServer({ authorizedMCP, pluginConfig, req })\n\n const transport = new WebStandardStreamableHTTPServerTransport({\n enableJsonResponse: true,\n sessionIdGenerator: undefined, // stateless mode\n })\n\n await server.connect(transport)\n\n const mcpRequest = new Request(req.url, {\n body: req.body,\n duplex: 'half',\n headers: req.headers,\n method: req.method,\n } as { duplex: 'half' } & RequestInit)\n\n return await transport.handleRequest(mcpRequest)\n}\n"],"names":["WebStandardStreamableHTTPServerTransport","APIError","buildMcpServer","getPluginConfig","getAuthorizedMCP","mcpEndpoint","req","url","payloadAPI","pluginConfig","config","payload","authorizedMCP","server","transport","enableJsonResponse","sessionIdGenerator","undefined","connect","mcpRequest","Request","body","duplex","headers","method","handleRequest"],"mappings":"AAAA,SAASA,wCAAwC,QAAQ,+BAA8B;AACvF,SAASC,QAAQ,QAA6B,UAAS;AAEvD,SAASC,cAAc,QAAQ,2BAA0B;AACzD,SAASC,eAAe,QAAQ,8BAA6B;AAC7D,SAASC,gBAAgB,QAAQ,cAAa;AAE9C,OAAO,MAAMC,cAA8B,OAAOC;IAChD,IAAI,CAACA,IAAIC,GAAG,EAAE;QACZ,MAAM,IAAIN,SAAS,uBAAuB;IAC5C;IAEAK,IAAIE,UAAU,GAAG;IAEjB,MAAMC,eAAeN,gBAAgB;QAAEO,QAAQJ,IAAIK,OAAO,CAACD,MAAM;IAAC;IAClE,MAAME,gBAAgB,MAAMR,iBAAiB;QAAEE;IAAI;IAEnD,MAAMO,SAASX,eAAe;QAAEU;QAAeH;QAAcH;IAAI;IAEjE,MAAMQ,YAAY,IAAId,yCAAyC;QAC7De,oBAAoB;QACpBC,oBAAoBC;IACtB;IAEA,MAAMJ,OAAOK,OAAO,CAACJ;IAErB,MAAMK,aAAa,IAAIC,QAAQd,IAAIC,GAAG,EAAE;QACtCc,MAAMf,IAAIe,IAAI;QACdC,QAAQ;QACRC,SAASjB,IAAIiB,OAAO;QACpBC,QAAQlB,IAAIkB,MAAM;IACpB;IAEA,OAAO,MAAMV,UAAUW,aAAa,CAACN;AACvC,EAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/exports/client.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,2CAA2C,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/exports/client.ts"],"sourcesContent":["'use client'\nexport { AccessField } from '../components/AccessField/index.client.js'\n"],"names":["AccessField"],"mappings":"AAAA;AACA,SAASA,WAAW,QAAQ,4CAA2C"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,17 +1,14 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { AuthorizedMCP, MCPPluginConfig, SanitizedMCPPluginConfig } from './types.js';
|
|
2
2
|
declare module 'payload' {
|
|
3
3
|
interface PayloadRequest {
|
|
4
4
|
payloadAPI: 'GraphQL' | 'local' | 'MCP' | 'REST';
|
|
5
5
|
}
|
|
6
6
|
interface RegisteredPlugins {
|
|
7
|
+
/** After the plugin's `plugin` callback runs, `options` holds the sanitized config. */
|
|
7
8
|
'@payloadcms/plugin-mcp': MCPPluginConfig;
|
|
8
9
|
}
|
|
9
10
|
}
|
|
10
|
-
export type {
|
|
11
|
-
|
|
12
|
-
* The MCP Plugin for Payload. This plugin allows you to add MCP capabilities to your Payload project.
|
|
13
|
-
*
|
|
14
|
-
* @param pluginOptions - The options for the MCP plugin.
|
|
15
|
-
*/
|
|
11
|
+
export type { AuthorizedMCP, MCPPluginConfig, SanitizedMCPPluginConfig };
|
|
12
|
+
export { defineCollectionTool, defineGlobalTool, definePrompt, defineTool } from './defineTool.js';
|
|
16
13
|
export declare const mcpPlugin: (options: MCPPluginConfig) => import("payload").Plugin;
|
|
17
14
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,eAAe,EAAE,wBAAwB,EAAE,MAAM,YAAY,CAAA;AAM1F,OAAO,QAAQ,SAAS,CAAC;IACvB,UAAiB,cAAc;QAC7B,UAAU,EAAE,SAAS,GAAG,OAAO,GAAG,KAAK,GAAG,MAAM,CAAA;KACjD;IACD,UAAU,iBAAiB;QACzB,uFAAuF;QACvF,wBAAwB,EAAE,eAAe,CAAA;KAC1C;CACF;AAED,YAAY,EAAE,aAAa,EAAE,eAAe,EAAE,wBAAwB,EAAE,CAAA;AAExE,OAAO,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAElG,eAAO,MAAM,SAAS,wDAwCpB,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -1,76 +1,53 @@
|
|
|
1
|
-
import { definePlugin } from 'payload';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
*
|
|
8
|
-
* @param pluginOptions - The options for the MCP plugin.
|
|
9
|
-
*/ export const mcpPlugin = definePlugin({
|
|
1
|
+
import { defaultUserCollection, definePlugin } from 'payload';
|
|
2
|
+
import { getAPIKeysCollection } from './collection/index.js';
|
|
3
|
+
import { mcpEndpoint } from './endpoint/index.js';
|
|
4
|
+
import { sanitizeMCPConfig } from './mcp/sanitizeMCPConfig.js';
|
|
5
|
+
export { defineCollectionTool, defineGlobalTool, definePrompt, defineTool } from './defineTool.js';
|
|
6
|
+
export const mcpPlugin = definePlugin({
|
|
10
7
|
slug: '@payloadcms/plugin-mcp',
|
|
11
8
|
order: 10,
|
|
12
|
-
plugin: ({ config, plugins
|
|
13
|
-
if
|
|
14
|
-
|
|
9
|
+
plugin: ({ config, plugins, ...rawConfig })=>{
|
|
10
|
+
// Our `payload-mcp-api-keys` is auth-enabled; if it'd be the only auth
|
|
11
|
+
// collection, Payload's later sanitize would pick it as `admin.user`.
|
|
12
|
+
// Pre-seed the default user collection to prevent that.
|
|
13
|
+
if (!config.admin?.user) {
|
|
14
|
+
const firstCollectionWithAuth = (config.collections ?? []).find(({ auth })=>Boolean(auth));
|
|
15
|
+
if (!firstCollectionWithAuth) {
|
|
16
|
+
;
|
|
17
|
+
(config.collections ??= []).push(defaultUserCollection);
|
|
18
|
+
}
|
|
15
19
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
//
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
// User Collection
|
|
26
|
-
pluginOptions.userCollection = pluginOptions.userCollection ?? config?.admin?.user ?? defaults.userCollection;
|
|
27
|
-
const experimentalTools = pluginOptions?.experimental?.tools || {};
|
|
28
|
-
/**
|
|
29
|
-
* API Keys
|
|
30
|
-
* --------
|
|
31
|
-
* High resolution control over MCP capabilities is crucial when using Payload with LLMs.
|
|
32
|
-
*
|
|
33
|
-
* This API Keys collection has ways for admins to create API keys and allow or disallow the MCP capabilities.
|
|
34
|
-
* This is useful when Admins want to allow or disallow the use of the MCP capabilities in real time.
|
|
35
|
-
* For example:
|
|
36
|
-
* - If a collection has all of its capabilities enabled, admins can allow or disallow the create, update, delete, and find capabilities on that collection.
|
|
37
|
-
* - If a collection only has the find capability enabled, admins can only allow or disallow the find capability on that collection.
|
|
38
|
-
* - If a global has all of its capabilities enabled, admins can allow or disallow the find and update capabilities on that global.
|
|
39
|
-
* - If a custom tool has gone haywire, admins can disallow that tool.
|
|
40
|
-
*
|
|
41
|
-
*/ const apiKeyCollection = createAPIKeysCollection(collections, globals, customTools, experimentalTools, pluginOptions);
|
|
42
|
-
if (pluginOptions.overrideApiKeyCollection) {
|
|
43
|
-
config.collections.push(pluginOptions.overrideApiKeyCollection(apiKeyCollection));
|
|
44
|
-
} else {
|
|
45
|
-
config.collections.push(apiKeyCollection);
|
|
20
|
+
const pluginConfig = sanitizeMCPConfig({
|
|
21
|
+
config,
|
|
22
|
+
pluginConfig: rawConfig
|
|
23
|
+
});
|
|
24
|
+
// Stash the sanitized config on plugin options so `getPluginConfig()` reads it.
|
|
25
|
+
const registered = plugins['@payloadcms/plugin-mcp'];
|
|
26
|
+
if (registered) {
|
|
27
|
+
// @ts-expect-error
|
|
28
|
+
registered.sanitizedOptions = pluginConfig;
|
|
46
29
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
30
|
+
;
|
|
31
|
+
(config.collections ??= []).push(getAPIKeysCollection({
|
|
32
|
+
pluginConfig
|
|
33
|
+
}));
|
|
34
|
+
// Keep the API-keys collection registered even when disabled, so DB schema
|
|
35
|
+
// and generated types don't drift between enabled/disabled environments.
|
|
36
|
+
if (pluginConfig.disabled) {
|
|
51
37
|
return config;
|
|
52
38
|
}
|
|
53
|
-
|
|
54
|
-
config
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
}
|
|
65
|
-
/**
|
|
66
|
-
* The GET response is always: {"jsonrpc":"2.0","error":{"code":-32000,"message":"Method not allowed."},"id":null} -- even with an API key
|
|
67
|
-
* This is expected behavior and MCP clients should always use the POST endpoint.
|
|
68
|
-
*/ config.endpoints.push({
|
|
69
|
-
handler: initializeMCPHandler(pluginOptions),
|
|
70
|
-
method: 'get',
|
|
71
|
-
path: '/mcp'
|
|
72
|
-
});
|
|
73
|
-
return config;
|
|
39
|
+
return {
|
|
40
|
+
...config,
|
|
41
|
+
endpoints: [
|
|
42
|
+
...config.endpoints ?? [],
|
|
43
|
+
// Payload prefixes /api, so the full path is /api/mcp.
|
|
44
|
+
{
|
|
45
|
+
handler: mcpEndpoint,
|
|
46
|
+
method: 'post',
|
|
47
|
+
path: '/mcp'
|
|
48
|
+
}
|
|
49
|
+
]
|
|
50
|
+
};
|
|
74
51
|
}
|
|
75
52
|
});
|
|
76
53
|
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import { definePlugin } from 'payload'\n\nimport type {
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import { defaultUserCollection, definePlugin } from 'payload'\n\nimport type { AuthorizedMCP, MCPPluginConfig, SanitizedMCPPluginConfig } from './types.js'\n\nimport { getAPIKeysCollection } from './collection/index.js'\nimport { mcpEndpoint } from './endpoint/index.js'\nimport { sanitizeMCPConfig } from './mcp/sanitizeMCPConfig.js'\n\ndeclare module 'payload' {\n export interface PayloadRequest {\n payloadAPI: 'GraphQL' | 'local' | 'MCP' | 'REST'\n }\n interface RegisteredPlugins {\n /** After the plugin's `plugin` callback runs, `options` holds the sanitized config. */\n '@payloadcms/plugin-mcp': MCPPluginConfig\n }\n}\n\nexport type { AuthorizedMCP, MCPPluginConfig, SanitizedMCPPluginConfig }\n\nexport { defineCollectionTool, defineGlobalTool, definePrompt, defineTool } from './defineTool.js'\n\nexport const mcpPlugin = definePlugin<MCPPluginConfig>({\n slug: '@payloadcms/plugin-mcp',\n order: 10,\n plugin: ({ config, plugins, ...rawConfig }) => {\n // Our `payload-mcp-api-keys` is auth-enabled; if it'd be the only auth\n // collection, Payload's later sanitize would pick it as `admin.user`.\n // Pre-seed the default user collection to prevent that.\n if (!config.admin?.user) {\n const firstCollectionWithAuth = (config.collections ?? []).find(({ auth }) => Boolean(auth))\n if (!firstCollectionWithAuth) {\n ;(config.collections ??= []).push(defaultUserCollection)\n }\n }\n\n const pluginConfig = sanitizeMCPConfig({ config, pluginConfig: rawConfig })\n\n // Stash the sanitized config on plugin options so `getPluginConfig()` reads it.\n const registered = plugins['@payloadcms/plugin-mcp']\n if (registered) {\n // @ts-expect-error\n registered.sanitizedOptions = pluginConfig as unknown as typeof registered.options\n }\n\n ;(config.collections ??= []).push(getAPIKeysCollection({ pluginConfig }))\n\n // Keep the API-keys collection registered even when disabled, so DB schema\n // and generated types don't drift between enabled/disabled environments.\n if (pluginConfig.disabled) {\n return config\n }\n\n return {\n ...config,\n endpoints: [\n ...(config.endpoints ?? []),\n // Payload prefixes /api, so the full path is /api/mcp.\n { handler: mcpEndpoint, method: 'post', path: '/mcp' },\n ],\n }\n },\n})\n"],"names":["defaultUserCollection","definePlugin","getAPIKeysCollection","mcpEndpoint","sanitizeMCPConfig","defineCollectionTool","defineGlobalTool","definePrompt","defineTool","mcpPlugin","slug","order","plugin","config","plugins","rawConfig","admin","user","firstCollectionWithAuth","collections","find","auth","Boolean","push","pluginConfig","registered","sanitizedOptions","disabled","endpoints","handler","method","path"],"mappings":"AAAA,SAASA,qBAAqB,EAAEC,YAAY,QAAQ,UAAS;AAI7D,SAASC,oBAAoB,QAAQ,wBAAuB;AAC5D,SAASC,WAAW,QAAQ,sBAAqB;AACjD,SAASC,iBAAiB,QAAQ,6BAA4B;AAc9D,SAASC,oBAAoB,EAAEC,gBAAgB,EAAEC,YAAY,EAAEC,UAAU,QAAQ,kBAAiB;AAElG,OAAO,MAAMC,YAAYR,aAA8B;IACrDS,MAAM;IACNC,OAAO;IACPC,QAAQ,CAAC,EAAEC,MAAM,EAAEC,OAAO,EAAE,GAAGC,WAAW;QACxC,uEAAuE;QACvE,sEAAsE;QACtE,wDAAwD;QACxD,IAAI,CAACF,OAAOG,KAAK,EAAEC,MAAM;YACvB,MAAMC,0BAA0B,AAACL,CAAAA,OAAOM,WAAW,IAAI,EAAE,AAAD,EAAGC,IAAI,CAAC,CAAC,EAAEC,IAAI,EAAE,GAAKC,QAAQD;YACtF,IAAI,CAACH,yBAAyB;;gBAC1BL,CAAAA,OAAOM,WAAW,KAAK,EAAE,AAAD,EAAGI,IAAI,CAACvB;YACpC;QACF;QAEA,MAAMwB,eAAepB,kBAAkB;YAAES;YAAQW,cAAcT;QAAU;QAEzE,gFAAgF;QAChF,MAAMU,aAAaX,OAAO,CAAC,yBAAyB;QACpD,IAAIW,YAAY;YACd,mBAAmB;YACnBA,WAAWC,gBAAgB,GAAGF;QAChC;;QAEEX,CAAAA,OAAOM,WAAW,KAAK,EAAE,AAAD,EAAGI,IAAI,CAACrB,qBAAqB;YAAEsB;QAAa;QAEtE,2EAA2E;QAC3E,yEAAyE;QACzE,IAAIA,aAAaG,QAAQ,EAAE;YACzB,OAAOd;QACT;QAEA,OAAO;YACL,GAAGA,MAAM;YACTe,WAAW;mBACLf,OAAOe,SAAS,IAAI,EAAE;gBAC1B,uDAAuD;gBACvD;oBAAEC,SAAS1B;oBAAa2B,QAAQ;oBAAQC,MAAM;gBAAO;aACtD;QACH;IACF;AACF,GAAE"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { McpServer } from '@modelcontextprotocol/server';
|
|
2
|
+
import { type PayloadRequest } from 'payload';
|
|
3
|
+
import type { AuthorizedMCP, SanitizedMCPPluginConfig } from '../types.js';
|
|
4
|
+
/**
|
|
5
|
+
* Transport-agnostic core: registers every authorized MCP item onto a fresh
|
|
6
|
+
* `McpServer` and returns it. The caller is responsible for picking a transport
|
|
7
|
+
* (`WebStandardStreamableHTTPServerTransport`, `StdioServerTransport`, …) and
|
|
8
|
+
* calling `server.connect(transport)`.
|
|
9
|
+
*
|
|
10
|
+
* `req` is the request context handlers see. For HTTP it's the live
|
|
11
|
+
* `PayloadRequest` derived from the incoming HTTP request; for stdio it's a
|
|
12
|
+
* synthesized one built via `createLocalReq`.
|
|
13
|
+
*/
|
|
14
|
+
export declare const buildMcpServer: ({ authorizedMCP, pluginConfig, req, }: {
|
|
15
|
+
authorizedMCP: AuthorizedMCP;
|
|
16
|
+
pluginConfig: SanitizedMCPPluginConfig;
|
|
17
|
+
req: PayloadRequest;
|
|
18
|
+
}) => McpServer;
|
|
19
|
+
//# sourceMappingURL=buildMcpServer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"buildMcpServer.d.ts","sourceRoot":"","sources":["../../src/mcp/buildMcpServer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAsB,MAAM,8BAA8B,CAAA;AAC5E,OAAO,EAAY,KAAK,cAAc,EAAE,MAAM,SAAS,CAAA;AAGvD,OAAO,KAAK,EACV,aAAa,EAMb,wBAAwB,EAEzB,MAAM,aAAa,CAAA;AAKpB;;;;;;;;;GASG;AACH,eAAO,MAAM,cAAc,GAAI,uCAI5B;IACD,aAAa,EAAE,aAAa,CAAA;IAC5B,YAAY,EAAE,wBAAwB,CAAA;IACtC,GAAG,EAAE,cAAc,CAAA;CACpB,KAAG,SAuLH,CAAA"}
|