@payloadcms/plugin-mcp 4.0.0-internal.5b1e7cd → 4.0.0-internal.a0ef1b8
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/bin.js +39 -0
- package/dist/@types/assets.d.js +2 -0
- package/dist/@types/assets.d.js.map +1 -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 +170 -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 +91 -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 +117 -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 +159 -0
- package/dist/mcp/builtin/collections/findTool.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 +191 -0
- package/dist/mcp/builtin/collections/updateTool.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/updateTool.d.ts +2 -0
- package/dist/mcp/builtin/globals/updateTool.d.ts.map +1 -0
- package/dist/mcp/builtin/globals/updateTool.js +96 -0
- package/dist/mcp/builtin/globals/updateTool.js.map +1 -0
- package/dist/mcp/builtinTools.d.ts +37 -0
- package/dist/mcp/builtinTools.d.ts.map +1 -0
- package/dist/mcp/builtinTools.js +64 -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 +167 -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 +262 -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/buildToolInput.d.ts +29 -0
- package/dist/utils/schemaConversion/buildToolInput.d.ts.map +1 -0
- package/dist/utils/schemaConversion/buildToolInput.js +51 -0
- package/dist/utils/schemaConversion/buildToolInput.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/package.json +35 -10
- package/src/@types/assets.d.ts +3 -0
- package/src/collection/getAccessField.ts +64 -0
- package/src/collection/index.ts +64 -0
- package/src/components/AccessField/index.client.tsx +344 -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 +229 -0
- package/src/mcp/builtin/collections/authTools.ts +233 -0
- package/src/mcp/builtin/collections/createTool.ts +116 -0
- package/src/mcp/builtin/collections/deleteTool.ts +123 -0
- package/src/mcp/builtin/collections/findTool.ts +187 -0
- package/src/mcp/builtin/collections/updateTool.ts +210 -0
- package/src/mcp/builtin/globals/findTool.ts +96 -0
- package/src/mcp/builtin/globals/updateTool.ts +120 -0
- package/src/mcp/builtinTools.ts +84 -0
- package/src/mcp/sanitizeMCPConfig.ts +239 -0
- package/src/stdio.ts +98 -0
- package/src/types.ts +295 -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/buildToolInput.ts +68 -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/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 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/mcp/builtin/globals/findTool.ts"],"sourcesContent":["import type { SelectType } from 'payload'\n\nimport { z } from 'zod'\n\nimport { defineGlobalTool } from '../../../defineTool.js'\nimport { getLogger } from '../../../utils/getLogger.js'\nimport { localAPIDefaults } from '../../../utils/localAPIDefaults.js'\n\nconst DEFAULT_DESCRIPTION = 'Find a Payload global singleton configuration.'\n\nexport const findGlobalTool = defineGlobalTool({\n description: DEFAULT_DESCRIPTION,\n input: z.object({\n depth: z\n .number()\n .int()\n .min(0)\n .max(10)\n .describe('Depth of population for relationships')\n .optional()\n .default(0),\n fallbackLocale: z\n .string()\n .describe('Optional: fallback locale code to use when requested locale is not available')\n .optional(),\n locale: z\n .string()\n .describe(\n 'Optional: locale code to retrieve data in (e.g., \"en\", \"es\"). Use \"all\" to retrieve all locales for localized fields',\n )\n .optional(),\n select: z\n .string()\n .describe(\n \"Optional: define exactly which fields you'd like to return in the response (JSON), e.g., '{\\\"title\\\": true}'\",\n )\n .optional(),\n }),\n}).handler(async ({ authorizedMCP, globalSlug, input, req }) => {\n const payload = req.payload\n const logger = getLogger({ payload })\n\n const { depth, fallbackLocale, locale, select } = input\n\n logger.info(\n `Reading global: ${globalSlug}, depth: ${depth}${locale ? `, locale: ${locale}` : ''}`,\n )\n\n try {\n const findOptions: Parameters<typeof payload.findGlobal>[0] = {\n slug: globalSlug,\n depth,\n ...localAPIDefaults(authorizedMCP),\n }\n\n let selectClause: SelectType | undefined\n if (select) {\n try {\n selectClause = JSON.parse(select) as SelectType\n } catch {\n logger.warn(`Invalid select clause JSON for global: ${select}`)\n return { content: [{ type: 'text', text: 'Error: Invalid JSON in select clause' }] }\n }\n }\n\n if (locale) {\n findOptions.locale = locale\n }\n if (fallbackLocale) {\n findOptions.fallbackLocale = fallbackLocale\n }\n if (selectClause) {\n findOptions.select = selectClause\n }\n\n const result = await payload.findGlobal(findOptions)\n\n return {\n content: [\n {\n type: 'text',\n text: `Global \"${globalSlug}\":\\n\\`\\`\\`json\\n${JSON.stringify(result)}\\n\\`\\`\\``,\n },\n ],\n doc: result as Record<string, unknown>,\n }\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : 'Unknown error'\n logger.error(`Error reading global ${globalSlug}: ${errorMessage}`)\n return {\n content: [\n { type: 'text', text: `❌ **Error reading global \"${globalSlug}\":** ${errorMessage}` },\n ],\n }\n }\n})\n"],"names":["z","defineGlobalTool","getLogger","localAPIDefaults","DEFAULT_DESCRIPTION","findGlobalTool","description","input","object","depth","number","int","min","max","describe","optional","default","fallbackLocale","string","locale","select","handler","authorizedMCP","globalSlug","req","payload","logger","info","findOptions","slug","selectClause","JSON","parse","warn","content","type","text","result","findGlobal","stringify","doc","error","errorMessage","Error","message"],"mappings":"AAEA,SAASA,CAAC,QAAQ,MAAK;AAEvB,SAASC,gBAAgB,QAAQ,yBAAwB;AACzD,SAASC,SAAS,QAAQ,8BAA6B;AACvD,SAASC,gBAAgB,QAAQ,qCAAoC;AAErE,MAAMC,sBAAsB;AAE5B,OAAO,MAAMC,iBAAiBJ,iBAAiB;IAC7CK,aAAaF;IACbG,OAAOP,EAAEQ,MAAM,CAAC;QACdC,OAAOT,EACJU,MAAM,GACNC,GAAG,GACHC,GAAG,CAAC,GACJC,GAAG,CAAC,IACJC,QAAQ,CAAC,yCACTC,QAAQ,GACRC,OAAO,CAAC;QACXC,gBAAgBjB,EACbkB,MAAM,GACNJ,QAAQ,CAAC,gFACTC,QAAQ;QACXI,QAAQnB,EACLkB,MAAM,GACNJ,QAAQ,CACP,wHAEDC,QAAQ;QACXK,QAAQpB,EACLkB,MAAM,GACNJ,QAAQ,CACP,gHAEDC,QAAQ;IACb;AACF,GAAGM,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AAc;QAClE,OAAO;YACLR,SAAS;gBACP;oBAAEC,MAAM;oBAAQC,MAAM,CAAC,0BAA0B,EAAEb,WAAW,KAAK,EAAEmB,cAAc;gBAAC;aACrF;QACH;IACF;AACF,GAAE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"updateTool.d.ts","sourceRoot":"","sources":["../../../../src/mcp/builtin/globals/updateTool.ts"],"names":[],"mappings":"AAgBA,eAAO,MAAM,gBAAgB,wCAuG3B,CAAA"}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { defineGlobalTool } from '../../../defineTool.js';
|
|
3
|
+
import { getLogger } from '../../../utils/getLogger.js';
|
|
4
|
+
import { getGlobalVirtualFieldNames, stripVirtualFields } from '../../../utils/getVirtualFieldNames.js';
|
|
5
|
+
import { localAPIDefaults } from '../../../utils/localAPIDefaults.js';
|
|
6
|
+
import { buildToolInput } from '../../../utils/schemaConversion/buildToolInput.js';
|
|
7
|
+
import { sanitizeEntitySchema } from '../../../utils/schemaConversion/sanitizeEntitySchema.js';
|
|
8
|
+
const DEFAULT_DESCRIPTION = 'Update a Payload global singleton configuration.';
|
|
9
|
+
export const updateGlobalTool = defineGlobalTool({
|
|
10
|
+
description: DEFAULT_DESCRIPTION,
|
|
11
|
+
input: ({ globalSchema })=>{
|
|
12
|
+
const partialSchema = sanitizeEntitySchema(globalSchema);
|
|
13
|
+
// Global updates do not require all required fields to be passed => delete .required.
|
|
14
|
+
//
|
|
15
|
+
// Local API equivalent: packages/payload/src/global/operations/local/update.ts#BaseOptions#data:
|
|
16
|
+
// data: DeepPartial<Omit<DataFromGlobalSlug<TSlug>, 'id'>>
|
|
17
|
+
delete partialSchema.required;
|
|
18
|
+
return buildToolInput({
|
|
19
|
+
controls: {
|
|
20
|
+
depth: z.number().describe('Optional: Depth of relationships to populate').optional().default(0),
|
|
21
|
+
draft: z.boolean().describe('Optional: Whether to save as draft (default: false)').optional().default(false),
|
|
22
|
+
fallbackLocale: z.string().describe('Optional: fallback locale code to use when requested locale is not available').optional(),
|
|
23
|
+
locale: z.string().describe('Optional: locale code to update data in (e.g., "en", "es"). Use "all" to update all locales for localized fields').optional(),
|
|
24
|
+
select: z.string().describe('Optional: define exactly which fields you\'d like to return in the response (JSON), e.g., \'{"siteName": "My Site"}\'').optional()
|
|
25
|
+
},
|
|
26
|
+
dataDescription: 'The fields to update',
|
|
27
|
+
dataSchema: partialSchema
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
}).handler(async ({ authorizedMCP, globalSlug, input, req })=>{
|
|
31
|
+
const payload = req.payload;
|
|
32
|
+
const logger = getLogger({
|
|
33
|
+
payload
|
|
34
|
+
});
|
|
35
|
+
const { data, depth, draft, fallbackLocale, locale, select } = input;
|
|
36
|
+
logger.info(`Updating global: ${globalSlug}, draft: ${draft}${locale ? `, locale: ${locale}` : ''}`);
|
|
37
|
+
try {
|
|
38
|
+
const virtualFieldNames = getGlobalVirtualFieldNames(payload.config, globalSlug);
|
|
39
|
+
const parsedData = stripVirtualFields(data, virtualFieldNames);
|
|
40
|
+
let selectClause;
|
|
41
|
+
if (select) {
|
|
42
|
+
try {
|
|
43
|
+
selectClause = JSON.parse(select);
|
|
44
|
+
} catch {
|
|
45
|
+
logger.warn(`Invalid select clause JSON for global: ${select}`);
|
|
46
|
+
return {
|
|
47
|
+
content: [
|
|
48
|
+
{
|
|
49
|
+
type: 'text',
|
|
50
|
+
text: 'Error: Invalid JSON in select clause'
|
|
51
|
+
}
|
|
52
|
+
]
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
const updateOptions = {
|
|
57
|
+
slug: globalSlug,
|
|
58
|
+
data: parsedData,
|
|
59
|
+
depth,
|
|
60
|
+
draft,
|
|
61
|
+
...localAPIDefaults(authorizedMCP)
|
|
62
|
+
};
|
|
63
|
+
if (locale) {
|
|
64
|
+
updateOptions.locale = locale;
|
|
65
|
+
}
|
|
66
|
+
if (fallbackLocale) {
|
|
67
|
+
updateOptions.fallbackLocale = fallbackLocale;
|
|
68
|
+
}
|
|
69
|
+
if (selectClause) {
|
|
70
|
+
updateOptions.select = selectClause;
|
|
71
|
+
}
|
|
72
|
+
const result = await payload.updateGlobal(updateOptions);
|
|
73
|
+
return {
|
|
74
|
+
content: [
|
|
75
|
+
{
|
|
76
|
+
type: 'text',
|
|
77
|
+
text: `Global "${globalSlug}" updated successfully!\n\`\`\`json\n${JSON.stringify(result)}\n\`\`\``
|
|
78
|
+
}
|
|
79
|
+
],
|
|
80
|
+
doc: result
|
|
81
|
+
};
|
|
82
|
+
} catch (error) {
|
|
83
|
+
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
|
|
84
|
+
logger.error(`Error updating global ${globalSlug}: ${errorMessage}`);
|
|
85
|
+
return {
|
|
86
|
+
content: [
|
|
87
|
+
{
|
|
88
|
+
type: 'text',
|
|
89
|
+
text: `Error updating global "${globalSlug}": ${errorMessage}`
|
|
90
|
+
}
|
|
91
|
+
]
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
//# sourceMappingURL=updateTool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/mcp/builtin/globals/updateTool.ts"],"sourcesContent":["import type { SelectType } from 'payload'\n\nimport { z } from 'zod'\n\nimport { defineGlobalTool } from '../../../defineTool.js'\nimport { getLogger } from '../../../utils/getLogger.js'\nimport {\n getGlobalVirtualFieldNames,\n stripVirtualFields,\n} from '../../../utils/getVirtualFieldNames.js'\nimport { localAPIDefaults } from '../../../utils/localAPIDefaults.js'\nimport { buildToolInput } from '../../../utils/schemaConversion/buildToolInput.js'\nimport { sanitizeEntitySchema } from '../../../utils/schemaConversion/sanitizeEntitySchema.js'\n\nconst DEFAULT_DESCRIPTION = 'Update a Payload global singleton configuration.'\n\nexport const updateGlobalTool = defineGlobalTool({\n description: DEFAULT_DESCRIPTION,\n input: ({ globalSchema }) => {\n const partialSchema = sanitizeEntitySchema(globalSchema)\n // Global updates do not require all required fields to be passed => delete .required.\n //\n // Local API equivalent: packages/payload/src/global/operations/local/update.ts#BaseOptions#data:\n // data: DeepPartial<Omit<DataFromGlobalSlug<TSlug>, 'id'>>\n delete partialSchema.required\n\n return buildToolInput({\n controls: {\n depth: z\n .number()\n .describe('Optional: Depth of relationships to populate')\n .optional()\n .default(0),\n draft: z\n .boolean()\n .describe('Optional: Whether to save as draft (default: false)')\n .optional()\n .default(false),\n fallbackLocale: z\n .string()\n .describe('Optional: fallback locale code to use when requested locale is not available')\n .optional(),\n locale: z\n .string()\n .describe(\n 'Optional: locale code to update data in (e.g., \"en\", \"es\"). Use \"all\" to update all locales for localized fields',\n )\n .optional(),\n select: z\n .string()\n .describe(\n 'Optional: define exactly which fields you\\'d like to return in the response (JSON), e.g., \\'{\"siteName\": \"My Site\"}\\'',\n )\n .optional(),\n },\n dataDescription: 'The fields to update',\n dataSchema: partialSchema,\n })\n },\n}).handler(async ({ authorizedMCP, globalSlug, input, req }) => {\n const payload = req.payload\n const logger = getLogger({ payload })\n\n const { data, depth, draft, fallbackLocale, locale, select } = input\n\n logger.info(\n `Updating global: ${globalSlug}, draft: ${draft}${locale ? `, locale: ${locale}` : ''}`,\n )\n\n try {\n const virtualFieldNames = getGlobalVirtualFieldNames(payload.config, globalSlug)\n const parsedData = stripVirtualFields(data, virtualFieldNames)\n\n let selectClause: SelectType | undefined\n if (select) {\n try {\n selectClause = JSON.parse(select) as SelectType\n } catch {\n logger.warn(`Invalid select clause JSON for global: ${select}`)\n return { content: [{ type: 'text', text: 'Error: Invalid JSON in select clause' }] }\n }\n }\n\n const updateOptions: Parameters<typeof payload.updateGlobal>[0] = {\n slug: globalSlug,\n data: parsedData,\n depth,\n draft,\n ...localAPIDefaults(authorizedMCP),\n }\n\n if (locale) {\n updateOptions.locale = locale\n }\n if (fallbackLocale) {\n updateOptions.fallbackLocale = fallbackLocale\n }\n if (selectClause) {\n updateOptions.select = selectClause\n }\n\n const result = await payload.updateGlobal(updateOptions)\n\n return {\n content: [\n {\n type: 'text',\n text: `Global \"${globalSlug}\" updated successfully!\\n\\`\\`\\`json\\n${JSON.stringify(result)}\\n\\`\\`\\``,\n },\n ],\n doc: result as Record<string, unknown>,\n }\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : 'Unknown error'\n logger.error(`Error updating global ${globalSlug}: ${errorMessage}`)\n return {\n content: [{ type: 'text', text: `Error updating global \"${globalSlug}\": ${errorMessage}` }],\n }\n }\n})\n"],"names":["z","defineGlobalTool","getLogger","getGlobalVirtualFieldNames","stripVirtualFields","localAPIDefaults","buildToolInput","sanitizeEntitySchema","DEFAULT_DESCRIPTION","updateGlobalTool","description","input","globalSchema","partialSchema","required","controls","depth","number","describe","optional","default","draft","boolean","fallbackLocale","string","locale","select","dataDescription","dataSchema","handler","authorizedMCP","globalSlug","req","payload","logger","data","info","virtualFieldNames","config","parsedData","selectClause","JSON","parse","warn","content","type","text","updateOptions","slug","result","updateGlobal","stringify","doc","error","errorMessage","Error","message"],"mappings":"AAEA,SAASA,CAAC,QAAQ,MAAK;AAEvB,SAASC,gBAAgB,QAAQ,yBAAwB;AACzD,SAASC,SAAS,QAAQ,8BAA6B;AACvD,SACEC,0BAA0B,EAC1BC,kBAAkB,QACb,yCAAwC;AAC/C,SAASC,gBAAgB,QAAQ,qCAAoC;AACrE,SAASC,cAAc,QAAQ,oDAAmD;AAClF,SAASC,oBAAoB,QAAQ,0DAAyD;AAE9F,MAAMC,sBAAsB;AAE5B,OAAO,MAAMC,mBAAmBR,iBAAiB;IAC/CS,aAAaF;IACbG,OAAO,CAAC,EAAEC,YAAY,EAAE;QACtB,MAAMC,gBAAgBN,qBAAqBK;QAC3C,sFAAsF;QACtF,EAAE;QACF,iGAAiG;QACjG,2DAA2D;QAC3D,OAAOC,cAAcC,QAAQ;QAE7B,OAAOR,eAAe;YACpBS,UAAU;gBACRC,OAAOhB,EACJiB,MAAM,GAC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AAIL,QAAQ;YACVsB,cAActB,MAAM,GAAGA;QACzB;QACA,IAAIF,gBAAgB;YAClBwB,cAAcxB,cAAc,GAAGA;QACjC;QACA,IAAIiB,cAAc;YAChBO,cAAcrB,MAAM,GAAGc;QACzB;QAEA,MAAMS,SAAS,MAAMhB,QAAQiB,YAAY,CAACH;QAE1C,OAAO;YACLH,SAAS;gBACP;oBACEC,MAAM;oBACNC,MAAM,CAAC,QAAQ,EAAEf,WAAW,qCAAqC,EAAEU,KAAKU,SAAS,CAACF,QAAQ,QAAQ,CAAC;gBACrG;aACD;YACDG,KAAKH;QACP;IACF,EAAE,OAAOI,OAAO;QACd,MAAMC,eAAeD,iBAAiBE,QAAQF,MAAMG,OAAO,GAAG;QAC9DtB,OAAOmB,KAAK,CAAC,CAAC,sBAAsB,EAAEtB,WAAW,EAAE,EAAEuB,cAAc;QACnE,OAAO;YACLV,SAAS;gBAAC;oBAAEC,MAAM;oBAAQC,MAAM,CAAC,uBAAuB,EAAEf,WAAW,GAAG,EAAEuB,cAAc;gBAAC;aAAE;QAC7F;IACF;AACF,GAAE"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { CollectionTool, GlobalTool } from '../types.js';
|
|
2
|
+
/**
|
|
3
|
+
* The static built-in collection CRUD tools. Keys here are the source of truth
|
|
4
|
+
* for `MCPCollectionBuiltinName` — adding/removing an entry updates the type
|
|
5
|
+
* automatically.
|
|
6
|
+
*/
|
|
7
|
+
export declare const COLLECTION_BUILTINS: Record<MCPCollectionBuiltinName, CollectionTool>;
|
|
8
|
+
/**
|
|
9
|
+
* The static auth tools surfaced under auth-enabled collections. Each entry
|
|
10
|
+
* carries the admin-UI label alongside the tool. Keys are the source of truth
|
|
11
|
+
* for `MCPCollectionAuthToolName`.
|
|
12
|
+
*/
|
|
13
|
+
export declare const COLLECTION_AUTH_BUILTINS: Record<MCPCollectionAuthToolName, {
|
|
14
|
+
label: string;
|
|
15
|
+
tool: CollectionTool;
|
|
16
|
+
}>;
|
|
17
|
+
/**
|
|
18
|
+
* The static built-in global tools. Keys are the source of truth for
|
|
19
|
+
* `MCPGlobalBuiltinName`.
|
|
20
|
+
*/
|
|
21
|
+
export declare const GLOBAL_BUILTINS: Record<MCPGlobalBuiltinName, GlobalTool>;
|
|
22
|
+
export type MCPCollectionBuiltinName = 'create' | 'delete' | 'find' | 'update';
|
|
23
|
+
export type MCPCollectionAuthToolName = 'auth' | 'forgotPassword' | 'login' | 'resetPassword' | 'unlock' | 'verify';
|
|
24
|
+
export type MCPGlobalBuiltinName = 'find' | 'update';
|
|
25
|
+
/**
|
|
26
|
+
* Pre-typed `Object.entries` for each registry. The cast from `string` to the
|
|
27
|
+
* literal key union lives here once so consumers can iterate without their own
|
|
28
|
+
* cast — TypeScript's `Object.entries` always widens keys to `string`, which
|
|
29
|
+
* defeats the narrow type lookups on `MCPCollectionToolsMap`.
|
|
30
|
+
*/
|
|
31
|
+
export declare const COLLECTION_BUILTIN_ENTRIES: Array<[MCPCollectionBuiltinName, CollectionTool]>;
|
|
32
|
+
export declare const COLLECTION_AUTH_BUILTIN_ENTRIES: Array<[MCPCollectionAuthToolName, {
|
|
33
|
+
label: string;
|
|
34
|
+
tool: CollectionTool;
|
|
35
|
+
}]>;
|
|
36
|
+
export declare const GLOBAL_BUILTIN_ENTRIES: Array<[MCPGlobalBuiltinName, GlobalTool]>;
|
|
37
|
+
//# sourceMappingURL=builtinTools.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"builtinTools.d.ts","sourceRoot":"","sources":["../../src/mcp/builtinTools.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAiB7D;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,EAAE,MAAM,CAAC,wBAAwB,EAAE,cAAc,CAKhF,CAAA;AAED;;;;GAIG;AACH,eAAO,MAAM,wBAAwB,EAAE,MAAM,CAC3C,yBAAyB,EACzB;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,cAAc,CAAA;CAAE,CAQxC,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,eAAe,EAAE,MAAM,CAAC,oBAAoB,EAAE,UAAU,CAGpE,CAAA;AAED,MAAM,MAAM,wBAAwB,GAAG,QAAQ,GAAG,QAAQ,GAAG,MAAM,GAAG,QAAQ,CAAA;AAE9E,MAAM,MAAM,yBAAyB,GACjC,MAAM,GACN,gBAAgB,GAChB,OAAO,GACP,eAAe,GACf,QAAQ,GACR,QAAQ,CAAA;AAEZ,MAAM,MAAM,oBAAoB,GAAG,MAAM,GAAG,QAAQ,CAAA;AAEpD;;;;;GAKG;AACH,eAAO,MAAM,0BAA0B,EAA0C,KAAK,CACpF,CAAC,wBAAwB,EAAE,cAAc,CAAC,CAC3C,CAAA;AAED,eAAO,MAAM,+BAA+B,EAA+C,KAAK,CAC9F,CAAC,yBAAyB,EAAE;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,cAAc,CAAA;CAAE,CAAC,CACrE,CAAA;AAED,eAAO,MAAM,sBAAsB,EAAsC,KAAK,CAC5E,CAAC,oBAAoB,EAAE,UAAU,CAAC,CACnC,CAAA"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { authCollectionTool, forgotPasswordCollectionTool, loginCollectionTool, resetPasswordCollectionTool, unlockCollectionTool, verifyCollectionTool } from './builtin/collections/authTools.js';
|
|
2
|
+
import { createCollectionTool } from './builtin/collections/createTool.js';
|
|
3
|
+
import { deleteCollectionTool } from './builtin/collections/deleteTool.js';
|
|
4
|
+
import { findCollectionTool } from './builtin/collections/findTool.js';
|
|
5
|
+
import { updateCollectionTool } from './builtin/collections/updateTool.js';
|
|
6
|
+
import { findGlobalTool } from './builtin/globals/findTool.js';
|
|
7
|
+
import { updateGlobalTool } from './builtin/globals/updateTool.js';
|
|
8
|
+
/**
|
|
9
|
+
* The static built-in collection CRUD tools. Keys here are the source of truth
|
|
10
|
+
* for `MCPCollectionBuiltinName` — adding/removing an entry updates the type
|
|
11
|
+
* automatically.
|
|
12
|
+
*/ export const COLLECTION_BUILTINS = {
|
|
13
|
+
create: createCollectionTool,
|
|
14
|
+
delete: deleteCollectionTool,
|
|
15
|
+
find: findCollectionTool,
|
|
16
|
+
update: updateCollectionTool
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* The static auth tools surfaced under auth-enabled collections. Each entry
|
|
20
|
+
* carries the admin-UI label alongside the tool. Keys are the source of truth
|
|
21
|
+
* for `MCPCollectionAuthToolName`.
|
|
22
|
+
*/ export const COLLECTION_AUTH_BUILTINS = {
|
|
23
|
+
auth: {
|
|
24
|
+
label: 'Check Auth Status',
|
|
25
|
+
tool: authCollectionTool
|
|
26
|
+
},
|
|
27
|
+
forgotPassword: {
|
|
28
|
+
label: 'Forgot Password',
|
|
29
|
+
tool: forgotPasswordCollectionTool
|
|
30
|
+
},
|
|
31
|
+
login: {
|
|
32
|
+
label: 'User Login',
|
|
33
|
+
tool: loginCollectionTool
|
|
34
|
+
},
|
|
35
|
+
resetPassword: {
|
|
36
|
+
label: 'Reset Password',
|
|
37
|
+
tool: resetPasswordCollectionTool
|
|
38
|
+
},
|
|
39
|
+
unlock: {
|
|
40
|
+
label: 'Unlock Account',
|
|
41
|
+
tool: unlockCollectionTool
|
|
42
|
+
},
|
|
43
|
+
verify: {
|
|
44
|
+
label: 'Email Verification',
|
|
45
|
+
tool: verifyCollectionTool
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* The static built-in global tools. Keys are the source of truth for
|
|
50
|
+
* `MCPGlobalBuiltinName`.
|
|
51
|
+
*/ export const GLOBAL_BUILTINS = {
|
|
52
|
+
find: findGlobalTool,
|
|
53
|
+
update: updateGlobalTool
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* Pre-typed `Object.entries` for each registry. The cast from `string` to the
|
|
57
|
+
* literal key union lives here once so consumers can iterate without their own
|
|
58
|
+
* cast — TypeScript's `Object.entries` always widens keys to `string`, which
|
|
59
|
+
* defeats the narrow type lookups on `MCPCollectionToolsMap`.
|
|
60
|
+
*/ export const COLLECTION_BUILTIN_ENTRIES = Object.entries(COLLECTION_BUILTINS);
|
|
61
|
+
export const COLLECTION_AUTH_BUILTIN_ENTRIES = Object.entries(COLLECTION_AUTH_BUILTINS);
|
|
62
|
+
export const GLOBAL_BUILTIN_ENTRIES = Object.entries(GLOBAL_BUILTINS);
|
|
63
|
+
|
|
64
|
+
//# sourceMappingURL=builtinTools.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/mcp/builtinTools.ts"],"sourcesContent":["import type { CollectionTool, GlobalTool } from '../types.js'\n\nimport {\n authCollectionTool,\n forgotPasswordCollectionTool,\n loginCollectionTool,\n resetPasswordCollectionTool,\n unlockCollectionTool,\n verifyCollectionTool,\n} from './builtin/collections/authTools.js'\nimport { createCollectionTool } from './builtin/collections/createTool.js'\nimport { deleteCollectionTool } from './builtin/collections/deleteTool.js'\nimport { findCollectionTool } from './builtin/collections/findTool.js'\nimport { updateCollectionTool } from './builtin/collections/updateTool.js'\nimport { findGlobalTool } from './builtin/globals/findTool.js'\nimport { updateGlobalTool } from './builtin/globals/updateTool.js'\n\n/**\n * The static built-in collection CRUD tools. Keys here are the source of truth\n * for `MCPCollectionBuiltinName` — adding/removing an entry updates the type\n * automatically.\n */\nexport const COLLECTION_BUILTINS: Record<MCPCollectionBuiltinName, CollectionTool> = {\n create: createCollectionTool,\n delete: deleteCollectionTool,\n find: findCollectionTool,\n update: updateCollectionTool,\n}\n\n/**\n * The static auth tools surfaced under auth-enabled collections. Each entry\n * carries the admin-UI label alongside the tool. Keys are the source of truth\n * for `MCPCollectionAuthToolName`.\n */\nexport const COLLECTION_AUTH_BUILTINS: Record<\n MCPCollectionAuthToolName,\n { label: string; tool: CollectionTool }\n> = {\n auth: { label: 'Check Auth Status', tool: authCollectionTool },\n forgotPassword: { label: 'Forgot Password', tool: forgotPasswordCollectionTool },\n login: { label: 'User Login', tool: loginCollectionTool },\n resetPassword: { label: 'Reset Password', tool: resetPasswordCollectionTool },\n unlock: { label: 'Unlock Account', tool: unlockCollectionTool },\n verify: { label: 'Email Verification', tool: verifyCollectionTool },\n}\n\n/**\n * The static built-in global tools. Keys are the source of truth for\n * `MCPGlobalBuiltinName`.\n */\nexport const GLOBAL_BUILTINS: Record<MCPGlobalBuiltinName, GlobalTool> = {\n find: findGlobalTool,\n update: updateGlobalTool,\n}\n\nexport type MCPCollectionBuiltinName = 'create' | 'delete' | 'find' | 'update'\n\nexport type MCPCollectionAuthToolName =\n | 'auth'\n | 'forgotPassword'\n | 'login'\n | 'resetPassword'\n | 'unlock'\n | 'verify'\n\nexport type MCPGlobalBuiltinName = 'find' | 'update'\n\n/**\n * Pre-typed `Object.entries` for each registry. The cast from `string` to the\n * literal key union lives here once so consumers can iterate without their own\n * cast — TypeScript's `Object.entries` always widens keys to `string`, which\n * defeats the narrow type lookups on `MCPCollectionToolsMap`.\n */\nexport const COLLECTION_BUILTIN_ENTRIES = Object.entries(COLLECTION_BUILTINS) as Array<\n [MCPCollectionBuiltinName, CollectionTool]\n>\n\nexport const COLLECTION_AUTH_BUILTIN_ENTRIES = Object.entries(COLLECTION_AUTH_BUILTINS) as Array<\n [MCPCollectionAuthToolName, { label: string; tool: CollectionTool }]\n>\n\nexport const GLOBAL_BUILTIN_ENTRIES = Object.entries(GLOBAL_BUILTINS) as Array<\n [MCPGlobalBuiltinName, GlobalTool]\n>\n"],"names":["authCollectionTool","forgotPasswordCollectionTool","loginCollectionTool","resetPasswordCollectionTool","unlockCollectionTool","verifyCollectionTool","createCollectionTool","deleteCollectionTool","findCollectionTool","updateCollectionTool","findGlobalTool","updateGlobalTool","COLLECTION_BUILTINS","create","delete","find","update","COLLECTION_AUTH_BUILTINS","auth","label","tool","forgotPassword","login","resetPassword","unlock","verify","GLOBAL_BUILTINS","COLLECTION_BUIL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|
|
2
|
+
import type { MCPPluginConfig, SanitizedMCPPluginConfig } from '../types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Converts the user-configured `MCPPluginConfig` into a `SanitizedMCPPluginConfig`:
|
|
5
|
+
* - Flattens `tools` / `prompts` / `resources` / per-collection / per-global
|
|
6
|
+
* tool maps into a single `items` array.
|
|
7
|
+
* - Applies built-in tools for collections and globals, respecting opt-out user overrides.
|
|
8
|
+
* - Applies the `userCollection` default
|
|
9
|
+
*
|
|
10
|
+
* Called once during plugin init. After that, `plugins['@payloadcms/plugin-mcp']
|
|
11
|
+
* ?.options` holds the sanitized result
|
|
12
|
+
*/
|
|
13
|
+
export declare const sanitizeMCPConfig: ({ config, pluginConfig, }: {
|
|
14
|
+
config: Config | SanitizedConfig;
|
|
15
|
+
pluginConfig: MCPPluginConfig;
|
|
16
|
+
}) => SanitizedMCPPluginConfig;
|
|
17
|
+
//# sourceMappingURL=sanitizeMCPConfig.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sanitizeMCPConfig.d.ts","sourceRoot":"","sources":["../../src/mcp/sanitizeMCPConfig.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,MAAM,EAGN,eAAe,EAEhB,MAAM,SAAS,CAAA;AAEhB,OAAO,KAAK,EAMV,eAAe,EAEf,wBAAwB,EACzB,MAAM,aAAa,CAAA;AAWpB;;;;;;;;;GASG;AACH,eAAO,MAAM,iBAAiB,GAAI,2BAG/B;IACD,MAAM,EAAE,MAAM,GAAG,eAAe,CAAA;IAChC,YAAY,EAAE,eAAe,CAAA;CAC9B,KAAG,wBAkDH,CAAA"}
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import { COLLECTION_AUTH_BUILTIN_ENTRIES, COLLECTION_AUTH_BUILTINS, COLLECTION_BUILTIN_ENTRIES, COLLECTION_BUILTINS, GLOBAL_BUILTIN_ENTRIES, GLOBAL_BUILTINS } from './builtinTools.js';
|
|
2
|
+
/**
|
|
3
|
+
* Converts the user-configured `MCPPluginConfig` into a `SanitizedMCPPluginConfig`:
|
|
4
|
+
* - Flattens `tools` / `prompts` / `resources` / per-collection / per-global
|
|
5
|
+
* tool maps into a single `items` array.
|
|
6
|
+
* - Applies built-in tools for collections and globals, respecting opt-out user overrides.
|
|
7
|
+
* - Applies the `userCollection` default
|
|
8
|
+
*
|
|
9
|
+
* Called once during plugin init. After that, `plugins['@payloadcms/plugin-mcp']
|
|
10
|
+
* ?.options` holds the sanitized result
|
|
11
|
+
*/ export const sanitizeMCPConfig = ({ config, pluginConfig })=>{
|
|
12
|
+
const items = [];
|
|
13
|
+
for (const collection of config.collections ?? []){
|
|
14
|
+
items.push(...sanitizeCollectionConfig({
|
|
15
|
+
collection,
|
|
16
|
+
pluginConfig
|
|
17
|
+
}));
|
|
18
|
+
}
|
|
19
|
+
for (const global of config.globals ?? []){
|
|
20
|
+
items.push(...sanitizeGlobalConfig({
|
|
21
|
+
global,
|
|
22
|
+
pluginConfig
|
|
23
|
+
}));
|
|
24
|
+
}
|
|
25
|
+
for (const [key, tool] of Object.entries(pluginConfig.tools ?? {})){
|
|
26
|
+
items.push({
|
|
27
|
+
type: 'tool',
|
|
28
|
+
key,
|
|
29
|
+
label: key,
|
|
30
|
+
tool
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
for (const [key, prompt] of Object.entries(pluginConfig.prompts ?? {})){
|
|
34
|
+
items.push({
|
|
35
|
+
type: 'prompt',
|
|
36
|
+
key,
|
|
37
|
+
label: prompt.title ?? key,
|
|
38
|
+
prompt
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
for (const [key, resource] of Object.entries(pluginConfig.resources ?? {})){
|
|
42
|
+
items.push({
|
|
43
|
+
type: 'resource',
|
|
44
|
+
key,
|
|
45
|
+
label: resource.title ?? key,
|
|
46
|
+
resource
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
// Mirror Payload's own admin.user detection (sanitize.ts) since plugins run first.
|
|
50
|
+
const firstCollectionWithAuth = config.collections.find(({ auth })=>Boolean(auth));
|
|
51
|
+
return {
|
|
52
|
+
disabled: pluginConfig.disabled,
|
|
53
|
+
items,
|
|
54
|
+
mcp: pluginConfig.mcp,
|
|
55
|
+
overrideApiKeyCollection: pluginConfig.overrideApiKeyCollection,
|
|
56
|
+
overrideAuth: pluginConfig.overrideAuth,
|
|
57
|
+
userCollection: pluginConfig.userCollection ?? config.admin?.user ?? firstCollectionWithAuth?.slug ?? 'users'
|
|
58
|
+
};
|
|
59
|
+
};
|
|
60
|
+
const sanitizeCollectionConfig = ({ collection, pluginConfig })=>{
|
|
61
|
+
if (collection.slug === 'payload-mcp-api-keys') {
|
|
62
|
+
return [];
|
|
63
|
+
}
|
|
64
|
+
const slug = collection.slug;
|
|
65
|
+
const collectionPluginConfig = pluginConfig.collections?.[slug];
|
|
66
|
+
const items = [];
|
|
67
|
+
for (const [toolKey, tool] of COLLECTION_BUILTIN_ENTRIES){
|
|
68
|
+
const matchedConfigEntry = collectionPluginConfig?.tools?.[toolKey];
|
|
69
|
+
if (matchedConfigEntry === false) {
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
items.push({
|
|
73
|
+
type: 'collectionTool',
|
|
74
|
+
collectionSlug: slug,
|
|
75
|
+
key: toolKey,
|
|
76
|
+
label: capitalize(toolKey),
|
|
77
|
+
tool: overrideBuiltinTool(tool, matchedConfigEntry, collectionPluginConfig)
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
if (collection.auth) {
|
|
81
|
+
for (const [authToolKey, { label, tool }] of COLLECTION_AUTH_BUILTIN_ENTRIES){
|
|
82
|
+
const matchedConfigEntry = collectionPluginConfig?.tools?.[authToolKey];
|
|
83
|
+
if (!matchedConfigEntry) {
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
// `true` means "enable, no override"; only the object form carries fields.
|
|
87
|
+
const override = typeof matchedConfigEntry === 'object' ? matchedConfigEntry : undefined;
|
|
88
|
+
items.push({
|
|
89
|
+
type: 'collectionTool',
|
|
90
|
+
collectionSlug: slug,
|
|
91
|
+
key: authToolKey,
|
|
92
|
+
label,
|
|
93
|
+
tool: overrideBuiltinTool(tool, override, collectionPluginConfig)
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
// Cast: builtin keys are filtered out below, so the remaining values are
|
|
98
|
+
// always custom tools (`CollectionTool`) or undefined
|
|
99
|
+
const customEntries = Object.entries(collectionPluginConfig?.tools ?? {});
|
|
100
|
+
for (const [key, customTool] of customEntries){
|
|
101
|
+
if (key in COLLECTION_BUILTINS || key in COLLECTION_AUTH_BUILTINS) {
|
|
102
|
+
continue;
|
|
103
|
+
}
|
|
104
|
+
if (!customTool) {
|
|
105
|
+
continue;
|
|
106
|
+
}
|
|
107
|
+
items.push({
|
|
108
|
+
type: 'collectionTool',
|
|
109
|
+
collectionSlug: slug,
|
|
110
|
+
key,
|
|
111
|
+
label: key,
|
|
112
|
+
tool: customTool
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
return items;
|
|
116
|
+
};
|
|
117
|
+
const sanitizeGlobalConfig = ({ global, pluginConfig })=>{
|
|
118
|
+
const slug = global.slug;
|
|
119
|
+
const globalPluginConfig = pluginConfig.globals?.[slug];
|
|
120
|
+
const items = [];
|
|
121
|
+
for (const [toolKey, baseTool] of GLOBAL_BUILTIN_ENTRIES){
|
|
122
|
+
const matchedConfigEntry = globalPluginConfig?.tools?.[toolKey];
|
|
123
|
+
if (matchedConfigEntry === false) {
|
|
124
|
+
continue;
|
|
125
|
+
}
|
|
126
|
+
items.push({
|
|
127
|
+
type: 'globalTool',
|
|
128
|
+
globalSlug: slug,
|
|
129
|
+
key: toolKey,
|
|
130
|
+
label: capitalize(toolKey),
|
|
131
|
+
tool: overrideBuiltinTool(baseTool, matchedConfigEntry, globalPluginConfig)
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
const customEntries = Object.entries(globalPluginConfig?.tools ?? {});
|
|
135
|
+
for (const [key, customTool] of customEntries){
|
|
136
|
+
if (key in GLOBAL_BUILTINS) {
|
|
137
|
+
continue;
|
|
138
|
+
}
|
|
139
|
+
if (!customTool) {
|
|
140
|
+
continue;
|
|
141
|
+
}
|
|
142
|
+
items.push({
|
|
143
|
+
type: 'globalTool',
|
|
144
|
+
globalSlug: slug,
|
|
145
|
+
key,
|
|
146
|
+
label: key,
|
|
147
|
+
tool: customTool
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
return items;
|
|
151
|
+
};
|
|
152
|
+
const capitalize = (s)=>s.charAt(0).toUpperCase() + s.slice(1);
|
|
153
|
+
/**
|
|
154
|
+
* Spread the static built-in tool and apply consumer-side overrides.
|
|
155
|
+
* Precedence: per-tool override > scope-level (collection/global) override >
|
|
156
|
+
* the static tool's defaults. `toolEntry` is whatever the user put under
|
|
157
|
+
* `tools: { find: ... }` — could be `true`, `false`, or an override object —
|
|
158
|
+
* so it's narrowed internally.
|
|
159
|
+
*/ const overrideBuiltinTool = (tool, toolOverride, entityPluginConfig)=>{
|
|
160
|
+
return {
|
|
161
|
+
...tool,
|
|
162
|
+
description: toolOverride?.description ?? entityPluginConfig?.description ?? tool.description,
|
|
163
|
+
overrideResponse: toolOverride?.overrideResponse ?? entityPluginConfig?.overrideResponse ?? tool.overrideResponse
|
|
164
|
+
};
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
//# sourceMappingURL=sanitizeMCPConfig.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/mcp/sanitizeMCPConfig.ts"],"sourcesContent":["import type {\n CollectionConfig,\n Config,\n GlobalConfig,\n SanitizedCollectionConfig,\n SanitizedConfig,\n SanitizedGlobalConfig,\n} from 'payload'\n\nimport type {\n CollectionTool,\n GlobalTool,\n MCPBuiltInToolOverride,\n MCPItem,\n MCPPluginCollectionConfig,\n MCPPluginConfig,\n MCPPluginGlobalConfig,\n SanitizedMCPPluginConfig,\n} from '../types.js'\n\nimport {\n COLLECTION_AUTH_BUILTIN_ENTRIES,\n COLLECTION_AUTH_BUILTINS,\n COLLECTION_BUILTIN_ENTRIES,\n COLLECTION_BUILTINS,\n GLOBAL_BUILTIN_ENTRIES,\n GLOBAL_BUILTINS,\n} from './builtinTools.js'\n\n/**\n * Converts the user-configured `MCPPluginConfig` into a `SanitizedMCPPluginConfig`:\n * - Flattens `tools` / `prompts` / `resources` / per-collection / per-global\n * tool maps into a single `items` array.\n * - Applies built-in tools for collections and globals, respecting opt-out user overrides.\n * - Applies the `userCollection` default\n *\n * Called once during plugin init. After that, `plugins['@payloadcms/plugin-mcp']\n * ?.options` holds the sanitized result\n */\nexport const sanitizeMCPConfig = ({\n config,\n pluginConfig,\n}: {\n config: Config | SanitizedConfig\n pluginConfig: MCPPluginConfig\n}): SanitizedMCPPluginConfig => {\n const items: MCPItem[] = []\n\n for (const collection of config.collections ?? []) {\n items.push(...sanitizeCollectionConfig({ collection, pluginConfig }))\n }\n\n for (const global of config.globals ?? []) {\n items.push(...sanitizeGlobalConfig({ global, pluginConfig }))\n }\n\n for (const [key, tool] of Object.entries(pluginConfig.tools ?? {})) {\n items.push({\n type: 'tool',\n key,\n label: key,\n tool,\n })\n }\n\n for (const [key, prompt] of Object.entries(pluginConfig.prompts ?? {})) {\n items.push({\n type: 'prompt',\n key,\n label: prompt.title ?? key,\n prompt,\n })\n }\n\n for (const [key, resource] of Object.entries(pluginConfig.resources ?? {})) {\n items.push({\n type: 'resource',\n key,\n label: resource.title ?? key,\n resource,\n })\n }\n\n // Mirror Payload's own admin.user detection (sanitize.ts) since plugins run first.\n const firstCollectionWithAuth = config.collections!.find(({ auth }) => Boolean(auth))\n\n return {\n disabled: pluginConfig.disabled,\n items,\n mcp: pluginConfig.mcp,\n overrideApiKeyCollection: pluginConfig.overrideApiKeyCollection,\n overrideAuth: pluginConfig.overrideAuth,\n userCollection:\n pluginConfig.userCollection ?? config.admin?.user ?? firstCollectionWithAuth?.slug ?? 'users',\n }\n}\n\nconst sanitizeCollectionConfig = ({\n collection,\n pluginConfig,\n}: {\n collection: CollectionConfig | SanitizedCollectionConfig\n pluginConfig: MCPPluginConfig\n}): MCPItem[] => {\n if (collection.slug === 'payload-mcp-api-keys') {\n return []\n }\n const slug = collection.slug\n const collectionPluginConfig = pluginConfig.collections?.[slug]\n const items: MCPItem[] = []\n\n for (const [toolKey, tool] of COLLECTION_BUILTIN_ENTRIES) {\n const matchedConfigEntry = collectionPluginConfig?.tools?.[toolKey]\n if (matchedConfigEntry === false) {\n continue\n }\n items.push({\n type: 'collectionTool',\n collectionSlug: slug,\n key: toolKey,\n label: capitalize(toolKey),\n tool: overrideBuiltinTool(tool, matchedConfigEntry, collectionPluginConfig),\n })\n }\n\n if (collection.auth) {\n for (const [authToolKey, { label, tool }] of COLLECTION_AUTH_BUILTIN_ENTRIES) {\n const matchedConfigEntry = collectionPluginConfig?.tools?.[authToolKey]\n if (!matchedConfigEntry) {\n continue\n }\n // `true` means \"enable, no override\"; only the object form carries fields.\n const override = typeof matchedConfigEntry === 'object' ? matchedConfigEntry : undefined\n items.push({\n type: 'collectionTool',\n collectionSlug: slug,\n key: authToolKey,\n label,\n tool: overrideBuiltinTool(tool, override, collectionPluginConfig),\n })\n }\n }\n\n // Cast: builtin keys are filtered out below, so the remaining values are\n // always custom tools (`CollectionTool`) or undefined\n const customEntries = Object.entries(collectionPluginConfig?.tools ?? {}) as Array<\n [string, CollectionTool | undefined]\n >\n for (const [key, customTool] of customEntries) {\n if (key in COLLECTION_BUILTINS || key in COLLECTION_AUTH_BUILTINS) {\n continue\n }\n if (!customTool) {\n continue\n }\n items.push({\n type: 'collectionTool',\n collectionSlug: slug,\n key,\n label: key,\n tool: customTool,\n })\n }\n\n return items\n}\n\nconst sanitizeGlobalConfig = ({\n global,\n pluginConfig,\n}: {\n global: GlobalConfig | SanitizedGlobalConfig\n pluginConfig: MCPPluginConfig\n}): MCPItem[] => {\n const slug = global.slug\n const globalPluginConfig = pluginConfig.globals?.[slug]\n const items: MCPItem[] = []\n\n for (const [toolKey, baseTool] of GLOBAL_BUILTIN_ENTRIES) {\n const matchedConfigEntry = globalPluginConfig?.tools?.[toolKey]\n if (matchedConfigEntry === false) {\n continue\n }\n items.push({\n type: 'globalTool',\n globalSlug: slug,\n key: toolKey,\n label: capitalize(toolKey),\n tool: overrideBuiltinTool(baseTool, matchedConfigEntry, globalPluginConfig),\n })\n }\n\n const customEntries = Object.entries(globalPluginConfig?.tools ?? {}) as Array<\n [string, GlobalTool | undefined]\n >\n for (const [key, customTool] of customEntries) {\n if (key in GLOBAL_BUILTINS) {\n continue\n }\n if (!customTool) {\n continue\n }\n items.push({\n type: 'globalTool',\n globalSlug: slug,\n key,\n label: key,\n tool: customTool,\n })\n }\n\n return items\n}\n\nconst capitalize = (s: string): string => s.charAt(0).toUpperCase() + s.slice(1)\n\n/**\n * Spread the static built-in tool and apply consumer-side overrides.\n * Precedence: per-tool override > scope-level (collection/global) override >\n * the static tool's defaults. `toolEntry` is whatever the user put under\n * `tools: { find: ... }` — could be `true`, `false`, or an override object —\n * so it's narrowed internally.\n */\nconst overrideBuiltinTool = <TTool extends CollectionTool | GlobalTool>(\n tool: TTool,\n toolOverride?: MCPBuiltInToolOverride,\n entityPluginConfig?: TTool extends CollectionTool\n ? MCPPluginCollectionConfig<any>\n : MCPPluginGlobalConfig,\n): TTool => {\n return {\n ...tool,\n description: toolOverride?.description ?? entityPluginConfig?.description ?? tool.description,\n overrideResponse:\n toolOverride?.overrideResponse ??\n entityPluginConfig?.overrideResponse ??\n tool.overrideResponse,\n }\n}\n"],"names":["COLLECTION_AUTH_BUILTIN_ENTRIES","COLLECTION_AUTH_BUILTINS","COLLECTION_BUILTIN_ENTRIES","COLLECTION_BUILTINS","GLOBAL_BUILTIN_ENTRIES","GLOBAL_BUILTINS","sanitizeMCPConfig","config","pluginConfig","items","collection","collections","push","sanitizeCollectionConfig","global","globals","sanitizeGlobalConfig","key","tool","Object","entries","tools","type","label","prompt","prompts","title","resource","resources","firstCollectionWithAuth","find","auth","Boolean","disabled","mcp","overrideApiKeyCollection","overrideAuth","userCollection","admin","user","slug","collectionPluginConfig","toolKey","matchedConfigEntry","collectionSlug","capitalize","overrideBuiltinTool","authToolKey","override","undefined","customEntries","customTool","globalPluginConfig","baseTool","globalSlug","s","charAt","toUpperCase","slice","toolOverride","entityPluginConfig","description","overrideResponse"],"mappings":"AAoBA,SACEA,+BAA+B,EAC/BC,wBAAwB,EACxBC,0BAA0B,EAC1BC,mBAAmB,EACnBC,sBAAsB,EACtBC,eAAe,QACV,oBAAmB;AAE1B;;;;;;;;;CASC,GACD,OAAO,MAAMC,oBAAoB,CAAC,EAChCC,MAAM,EACNC,YAAY,EAIb;IACC,MAAMC,QAAmB,EAAE;IAE3B,KAAK,MAAMC,cAAcH,OAAOI,WAAW,IAAI,EAAE,CAAE;QACjDF,MAAMG,IAAI,IAAIC,yBAAyB;YAAEH;YAAYF;QAAa;IACpE;IAEA,KAAK,MAAMM,UAAUP,OAAOQ,OAAO,IAAI,EAAE,CAAE;QACzCN,MAAMG,IAAI,IAAII,qBAAqB;YAAEF;YAAQN;QAAa;IAC5D;IAEA,KAAK,MAAM,CAACS,KAAKC,KAAK,IAAIC,OAAOC,OAAO,CAACZ,aAAaa,KAAK,IAAI,CAAC,GAAI;QAClEZ,MAAMG,IAAI,CAAC;YACTU,MAAM;YACNL;YACAM,OAAON;YACPC;QACF;IACF;IAEA,KAAK,MAAM,CAACD,KAAKO,OAAO,IAAIL,OAAOC,OAAO,CAACZ,aAAaiB,OAAO,IAAI,CAAC,GAAI;QACtEhB,MAAMG,IAAI,CAAC;YACTU,MAAM;YACNL;YACAM,OAAOC,OAAOE,KAAK,IAAIT;YACvBO;QACF;IACF;IAEA,KAAK,MAAM,CAACP,KAAKU,SAAS,IAAIR,OAAOC,OAAO,CAACZ,aAAaoB,SAAS,IAAI,CAAC,GAAI;QAC1EnB,MAAMG,IAAI,CAAC;YACTU,MAAM;YACNL;YACA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M;YACNgC,YAAYd;YACZvB;YACAM,OAAON;YACPC,MAAMiC;QACR;IACF;IAEA,OAAO1C;AACT;AAEA,MAAMoC,aAAa,CAACU,IAAsBA,EAAEC,MAAM,CAAC,GAAGC,WAAW,KAAKF,EAAEG,KAAK,CAAC;AAE9E;;;;;;CAMC,GACD,MAAMZ,sBAAsB,CAC1B5B,MACAyC,cACAC;IAIA,OAAO;QACL,GAAG1C,IAAI;QACP2C,aAAaF,cAAcE,eAAeD,oBAAoBC,eAAe3C,KAAK2C,WAAW;QAC7FC,kBACEH,cAAcG,oBACdF,oBAAoBE,oBACpB5C,KAAK4C,gBAAgB;IACzB;AACF"}
|
package/dist/stdio.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stdio adapter for the Payload MCP server.
|
|
3
|
+
*
|
|
4
|
+
* Do not use in production. There's no auth; whoever can spawn the process gets
|
|
5
|
+
* full access to your local data.
|
|
6
|
+
*/
|
|
7
|
+
export declare const runMcpStdio: () => Promise<void>;
|
|
8
|
+
//# sourceMappingURL=stdio.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stdio.d.ts","sourceRoot":"","sources":["../src/stdio.ts"],"names":[],"mappings":"AAeA;;;;;GAKG;AACH,eAAO,MAAM,WAAW,QAAa,OAAO,CAAC,IAAI,CA4EhD,CAAA"}
|
package/dist/stdio.js
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/* eslint-disable no-console */ import { StdioServerTransport } from '@modelcontextprotocol/server';
|
|
2
|
+
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
3
|
+
import { createLocalReq, getPayload } from 'payload';
|
|
4
|
+
import { findConfig } from 'payload/node';
|
|
5
|
+
import { buildMcpServer } from './mcp/buildMcpServer.js';
|
|
6
|
+
import { sanitizeMCPConfig } from './mcp/sanitizeMCPConfig.js';
|
|
7
|
+
import { getPluginConfig } from './utils/getPluginConfig.js';
|
|
8
|
+
import { resolveProjectRoot } from './utils/resolveProjectRoot.js';
|
|
9
|
+
/**
|
|
10
|
+
* Stdio adapter for the Payload MCP server.
|
|
11
|
+
*
|
|
12
|
+
* Do not use in production. There's no auth; whoever can spawn the process gets
|
|
13
|
+
* full access to your local data.
|
|
14
|
+
*/ export const runMcpStdio = async ()=>{
|
|
15
|
+
/**
|
|
16
|
+
* If MCP clients spawn stdio servers from an arbitrary working directory,
|
|
17
|
+
* Payload's cwd-anchored `findConfig()` can't locate the project on
|
|
18
|
+
* its own. This module always lives inside the project's `node_modules`, so
|
|
19
|
+
* we derive the project root from its own path and `chdir` into it.
|
|
20
|
+
*
|
|
21
|
+
* An absolute `PAYLOAD_CONFIG_PATH` still overrides everything; unusual
|
|
22
|
+
* layouts (e.g. a monorepo where the package is hoisted above the app) can
|
|
23
|
+
* fall back to it. See the implementation of findConfig for details.
|
|
24
|
+
*/ const projectRoot = resolveProjectRoot(fileURLToPath(import.meta.url));
|
|
25
|
+
if (projectRoot) {
|
|
26
|
+
process.chdir(projectRoot);
|
|
27
|
+
}
|
|
28
|
+
const configPath = findConfig();
|
|
29
|
+
const configModule = await import(pathToFileURL(configPath).toString());
|
|
30
|
+
const config = await (configModule.default ?? configModule);
|
|
31
|
+
const payload = await getPayload({
|
|
32
|
+
config
|
|
33
|
+
});
|
|
34
|
+
/**
|
|
35
|
+
* If the user added `mcpPlugin({...})` to their `plugins` array, read the
|
|
36
|
+
* sanitized config they registered. Otherwise fall back to the defaults. That way,
|
|
37
|
+
* the mcp works on any project that has `@payloadcms/plugin-mcp` installed,
|
|
38
|
+
* even if the plugin is not added to the plugins array.
|
|
39
|
+
*/ let pluginConfig;
|
|
40
|
+
try {
|
|
41
|
+
pluginConfig = getPluginConfig({
|
|
42
|
+
config: payload.config
|
|
43
|
+
});
|
|
44
|
+
} catch {
|
|
45
|
+
pluginConfig = sanitizeMCPConfig({
|
|
46
|
+
config: payload.config,
|
|
47
|
+
pluginConfig: {}
|
|
48
|
+
});
|
|
49
|
+
const fakePluginFn = (config)=>config;
|
|
50
|
+
fakePluginFn.slug = '@payloadcms/plugin-mcp';
|
|
51
|
+
// @ts-expect-error
|
|
52
|
+
fakePluginFn.sanitizedOptions = pluginConfig;
|
|
53
|
+
(payload.config.plugins ??= []).push(fakePluginFn);
|
|
54
|
+
}
|
|
55
|
+
const authorizedMCP = {
|
|
56
|
+
items: pluginConfig.items,
|
|
57
|
+
overrideAccess: true,
|
|
58
|
+
user: null
|
|
59
|
+
};
|
|
60
|
+
const req = await createLocalReq({}, payload);
|
|
61
|
+
req.payloadAPI = 'MCP';
|
|
62
|
+
const server = buildMcpServer({
|
|
63
|
+
authorizedMCP,
|
|
64
|
+
pluginConfig,
|
|
65
|
+
req
|
|
66
|
+
});
|
|
67
|
+
const transport = new StdioServerTransport();
|
|
68
|
+
await server.connect(transport);
|
|
69
|
+
// Process now lives until stdin closes. Wire graceful shutdown so DB
|
|
70
|
+
// connections (and any other Payload-managed resources) get released.
|
|
71
|
+
const shutdown = async (code = 0)=>{
|
|
72
|
+
try {
|
|
73
|
+
await server.close();
|
|
74
|
+
} catch (err) {
|
|
75
|
+
console.error('[payload-mcp] error closing server:', err);
|
|
76
|
+
}
|
|
77
|
+
try {
|
|
78
|
+
await payload.destroy();
|
|
79
|
+
} catch (err) {
|
|
80
|
+
console.error('[payload-mcp] error destroying payload:', err);
|
|
81
|
+
}
|
|
82
|
+
process.exit(code);
|
|
83
|
+
};
|
|
84
|
+
process.on('SIGINT', ()=>void shutdown(0));
|
|
85
|
+
process.on('SIGTERM', ()=>void shutdown(0));
|
|
86
|
+
process.stdin.on('close', ()=>void shutdown(0));
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
//# sourceMappingURL=stdio.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/stdio.ts"],"sourcesContent":["import type { MaybePromise, Plugin, SanitizedConfig } from 'payload'\n\n/* eslint-disable no-console */\nimport { StdioServerTransport } from '@modelcontextprotocol/server'\nimport { fileURLToPath, pathToFileURL } from 'node:url'\nimport { createLocalReq, getPayload } from 'payload'\nimport { findConfig } from 'payload/node'\n\nimport type { AuthorizedMCP, SanitizedMCPPluginConfig } from './types.js'\n\nimport { buildMcpServer } from './mcp/buildMcpServer.js'\nimport { sanitizeMCPConfig } from './mcp/sanitizeMCPConfig.js'\nimport { getPluginConfig } from './utils/getPluginConfig.js'\nimport { resolveProjectRoot } from './utils/resolveProjectRoot.js'\n\n/**\n * Stdio adapter for the Payload MCP server.\n *\n * Do not use in production. There's no auth; whoever can spawn the process gets\n * full access to your local data.\n */\nexport const runMcpStdio = async (): Promise<void> => {\n /**\n * If MCP clients spawn stdio servers from an arbitrary working directory,\n * Payload's cwd-anchored `findConfig()` can't locate the project on\n * its own. This module always lives inside the project's `node_modules`, so\n * we derive the project root from its own path and `chdir` into it.\n *\n * An absolute `PAYLOAD_CONFIG_PATH` still overrides everything; unusual\n * layouts (e.g. a monorepo where the package is hoisted above the app) can\n * fall back to it. See the implementation of findConfig for details.\n */\n const projectRoot = resolveProjectRoot(fileURLToPath(import.meta.url))\n if (projectRoot) {\n process.chdir(projectRoot)\n }\n\n const configPath = findConfig()\n const configModule = await import(pathToFileURL(configPath).toString())\n const config = (await (configModule.default ?? configModule)) as MaybePromise<SanitizedConfig>\n\n const payload = await getPayload({ config })\n\n /**\n * If the user added `mcpPlugin({...})` to their `plugins` array, read the\n * sanitized config they registered. Otherwise fall back to the defaults. That way,\n * the mcp works on any project that has `@payloadcms/plugin-mcp` installed,\n * even if the plugin is not added to the plugins array.\n */\n let pluginConfig: SanitizedMCPPluginConfig\n try {\n pluginConfig = getPluginConfig({ config: payload.config })\n } catch {\n pluginConfig = sanitizeMCPConfig({ config: payload.config, pluginConfig: {} })\n\n const fakePluginFn: Plugin = (config) => config\n fakePluginFn.slug = '@payloadcms/plugin-mcp'\n // @ts-expect-error\n fakePluginFn.sanitizedOptions = pluginConfig\n\n // Push to payload config, to ensure consecutive calls to `getPluginConfig()` work\n ;(payload.config.plugins ??= []).push(fakePluginFn)\n }\n\n const authorizedMCP: AuthorizedMCP = {\n items: pluginConfig.items,\n overrideAccess: true,\n user: null,\n }\n\n const req = await createLocalReq({}, payload)\n req.payloadAPI = 'MCP' as const\n\n const server = buildMcpServer({ authorizedMCP, pluginConfig, req })\n\n const transport = new StdioServerTransport()\n await server.connect(transport)\n\n // Process now lives until stdin closes. Wire graceful shutdown so DB\n // connections (and any other Payload-managed resources) get released.\n const shutdown = async (code = 0) => {\n try {\n await server.close()\n } catch (err) {\n console.error('[payload-mcp] error closing server:', err)\n }\n try {\n await payload.destroy()\n } catch (err) {\n console.error('[payload-mcp] error destroying payload:', err)\n }\n process.exit(code)\n }\n\n process.on('SIGINT', () => void shutdown(0))\n process.on('SIGTERM', () => void shutdown(0))\n process.stdin.on('close', () => void shutdown(0))\n}\n"],"names":["StdioServerTransport","fileURLToPath","pathToFileURL","createLocalReq","getPayload","findConfig","buildMcpServer","sanitizeMCPConfig","getPluginConfig","resolveProjectRoot","runMcpStdio","projectRoot","url","process","chdir","configPath","configModule","toString","config","default","payload","pluginConfig","fakePluginFn","slug","sanitizedOptions","plugins","push","authorizedMCP","items","overrideAccess","user","req","payloadAPI","server","transport","connect","shutdown","code","close","err","console","error","destroy","exit","on","stdin"],"mappings":"AAEA,6BAA6B,GAC7B,SAASA,oBAAoB,QAAQ,+BAA8B;AACnE,SAASC,aAAa,EAAEC,aAAa,QAAQ,WAAU;AACvD,SAASC,cAAc,EAAEC,UAAU,QAAQ,UAAS;AACpD,SAASC,UAAU,QAAQ,eAAc;AAIzC,SAASC,cAAc,QAAQ,0BAAyB;AACxD,SAASC,iBAAiB,QAAQ,6BAA4B;AAC9D,SAASC,eAAe,QAAQ,6BAA4B;AAC5D,SAASC,kBAAkB,QAAQ,gCAA+B;AAElE;;;;;CAKC,GACD,OAAO,MAAMC,cAAc;IACzB;;;;;;;;;GASC,GACD,MAAMC,cAAcF,mBAAmBR,cAAc,YAAYW,GA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