@payloadcms/plugin-mcp 4.0.0-internal.38b7f1d → 4.0.0-internal.40de3ec
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,22 @@
|
|
|
1
|
+
import type { Payload } from 'payload'
|
|
2
|
+
|
|
3
|
+
import { getPluginConfig } from './getPluginConfig.js'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Get the logger for the MCP plugin. Child of the main Payload logger, prefixed with `[plugin-mcp]`
|
|
7
|
+
* and tagged with a structured `plugin: 'mcp'` field. When `verboseLogs` is off, info/debug calls
|
|
8
|
+
* are silenced; warn/error still surface so operators don't lose error signal.
|
|
9
|
+
*/
|
|
10
|
+
export const getLogger: (args: { payload: Payload }) => Payload['logger'] = ({ payload }) => {
|
|
11
|
+
const pluginConfig = getPluginConfig({ config: payload.config })
|
|
12
|
+
|
|
13
|
+
const useVerboseLogs = pluginConfig?.mcp?.verboseLogs ?? false
|
|
14
|
+
|
|
15
|
+
const logger = payload.logger.child({ plugin: 'mcp' }, { msgPrefix: '[plugin-mcp] ' })
|
|
16
|
+
|
|
17
|
+
if (!useVerboseLogs) {
|
|
18
|
+
logger.level = 'warn'
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return logger
|
|
22
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { PluginsMap, SanitizedConfig } from 'payload'
|
|
2
|
+
|
|
3
|
+
import type { SanitizedMCPPluginConfig } from '../types.js'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Returns the sanitized plugin config — the form produced by
|
|
7
|
+
* `sanitizeMCPConfig` and stashed back on the plugin's `options` during init.
|
|
8
|
+
* Callers downstream of plugin init can rely on `items`, `userCollection`, etc.
|
|
9
|
+
* being fully resolved.
|
|
10
|
+
*/
|
|
11
|
+
export const getPluginConfig: (args: { config: SanitizedConfig }) => SanitizedMCPPluginConfig = ({
|
|
12
|
+
config,
|
|
13
|
+
}) => {
|
|
14
|
+
const plugin = config.plugins?.find(
|
|
15
|
+
(plugin) => plugin.slug === '@payloadcms/plugin-mcp',
|
|
16
|
+
) as PluginsMap['@payloadcms/plugin-mcp']
|
|
17
|
+
|
|
18
|
+
if (!plugin) {
|
|
19
|
+
throw new Error('MCP Plugin not found in config.plugins.')
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// @ts-expect-error
|
|
23
|
+
return plugin.sanitizedOptions
|
|
24
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { AuthorizedMCP } from '../types.js'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Returns the `user` and `overrideAccess` arguments every Payload local API call
|
|
5
|
+
* should receive when initiated from an MCP request. Spread the result into the
|
|
6
|
+
* call's arg object so the two pieces of caller state can't drift apart.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* await req.payload.create({
|
|
11
|
+
* collection: 'posts',
|
|
12
|
+
* data,
|
|
13
|
+
* ...localAPIDefaults(authorizedMCP),
|
|
14
|
+
* })
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export const localAPIDefaults = (
|
|
18
|
+
authorizedMCP: AuthorizedMCP,
|
|
19
|
+
): { overrideAccess: boolean; user: AuthorizedMCP['user'] } => ({
|
|
20
|
+
overrideAccess: authorizedMCP.overrideAccess,
|
|
21
|
+
user: authorizedMCP.user,
|
|
22
|
+
})
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import path from 'path'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Returns the project root: the parent of the outermost `node_modules` segment in
|
|
5
|
+
* `fromPath`. Returns `null` when the path has no `node_modules` (e.g. running from
|
|
6
|
+
* source inside the Payload monorepo).
|
|
7
|
+
*/
|
|
8
|
+
export const resolveProjectRoot = (fromPath: string): null | string => {
|
|
9
|
+
const segments = fromPath.split(path.sep)
|
|
10
|
+
const nodeModulesIndex = segments.indexOf('node_modules')
|
|
11
|
+
|
|
12
|
+
if (nodeModulesIndex <= 0) {
|
|
13
|
+
return null
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
return segments.slice(0, nodeModulesIndex).join(path.sep) || null
|
|
17
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import type { StandardSchemaWithJSON } from '@modelcontextprotocol/server'
|
|
2
|
+
|
|
3
|
+
import { z } from 'zod'
|
|
4
|
+
|
|
5
|
+
import type { JsonSchemaType } from '../../types.js'
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Builds a create/update tool's `input`: a `data` field (the document's fields) plus controls like
|
|
9
|
+
* `depth` and `draft`. Using just `z.fromJSONSchema(ourJSONSchema)` has a few problems which are mitigated
|
|
10
|
+
* in this function. z.fromJSONSchema is both bigger and lossier (≈40% larger on the lexical schema).
|
|
11
|
+
* Each example below is `what we publish` => `what a plain zod round-trip would publish instead`.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* Bigger - zod inlines shared defs instead of keeping our `$ref`s (and adds junk integer bounds), so a
|
|
15
|
+
* reused def is duplicated at every use:
|
|
16
|
+
* `{ $ref: '#/$defs/author' }` => `{ type: 'object', properties: { id, name }, additionalProperties: false }`
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* Lossier - zod drops the `description` on `enum`/`const` fields:
|
|
20
|
+
* `{ enum: ['draft', 'published'], description: 'Publish state' }` → `{ enum: ['draft', 'published'] }`
|
|
21
|
+
*/
|
|
22
|
+
export const buildToolInput = <TControls extends z.ZodRawShape>({
|
|
23
|
+
controls,
|
|
24
|
+
dataDescription,
|
|
25
|
+
dataSchema,
|
|
26
|
+
}: {
|
|
27
|
+
/** Tool options alongside `data` (depth, draft, where, …) as plain zod - inferred into `input`. */
|
|
28
|
+
controls: TControls
|
|
29
|
+
dataDescription: string
|
|
30
|
+
dataSchema: JsonSchemaType
|
|
31
|
+
}) => {
|
|
32
|
+
// `sanitizeEntitySchema` already emits draft 2020-12 with `$defs`, which is what zod's `fromJSONSchema`
|
|
33
|
+
// and MCP clients both expect. Drop only the root `$schema` keyword, redundant once it's a sub-schema.
|
|
34
|
+
const { $schema: _schema, ...entitySchema } = dataSchema as Record<string, unknown>
|
|
35
|
+
|
|
36
|
+
const schema = z.object({
|
|
37
|
+
data: z.fromJSONSchema(entitySchema as unknown as z.core.JSONSchema.JSONSchema),
|
|
38
|
+
...controls,
|
|
39
|
+
})
|
|
40
|
+
const standard = (schema as unknown as StandardSchemaWithJSON)['~standard']
|
|
41
|
+
|
|
42
|
+
return {
|
|
43
|
+
'~standard': {
|
|
44
|
+
...standard,
|
|
45
|
+
jsonSchema: {
|
|
46
|
+
...standard.jsonSchema,
|
|
47
|
+
input: (options) => {
|
|
48
|
+
// Start from zod's JSON Schema for the whole input, then replace its lossy `data` schema with
|
|
49
|
+
// the sanitized entity schema. The entity's `$defs` move to the root so the `$ref`s resolve.
|
|
50
|
+
const generated = standard.jsonSchema.input(options)
|
|
51
|
+
const { $defs, ...entityBody } = entitySchema
|
|
52
|
+
;(generated.properties as Record<string, unknown>).data = {
|
|
53
|
+
...entityBody,
|
|
54
|
+
description: dataDescription,
|
|
55
|
+
}
|
|
56
|
+
if ($defs) {
|
|
57
|
+
generated.$defs = $defs as object
|
|
58
|
+
} else {
|
|
59
|
+
delete generated.$defs
|
|
60
|
+
}
|
|
61
|
+
return generated
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
} as StandardSchemaWithJSON<
|
|
66
|
+
{ data: Record<string, unknown> } & Omit<z.output<typeof schema>, 'data'>
|
|
67
|
+
>
|
|
68
|
+
}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { JsonSchemaType } from '../../types.js'
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Removes virtual fields from a JSON Schema by name so they don't appear
|
|
5
5
|
* in the generated MCP tool input schema.
|
|
6
6
|
*/
|
|
7
7
|
export function removeVirtualFieldsFromSchema(
|
|
8
|
-
schema:
|
|
8
|
+
schema: JsonSchemaType,
|
|
9
9
|
virtualFieldNames: string[],
|
|
10
|
-
):
|
|
10
|
+
): JsonSchemaType {
|
|
11
11
|
if (virtualFieldNames.length === 0) {
|
|
12
12
|
return schema
|
|
13
13
|
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest'
|
|
2
|
+
|
|
3
|
+
import type { JsonSchemaType } from '../../types.js'
|
|
4
|
+
|
|
5
|
+
import { sanitizeEntitySchema } from './sanitizeEntitySchema.js'
|
|
6
|
+
|
|
7
|
+
describe('sanitizeEntitySchema', () => {
|
|
8
|
+
it('keeps a Lexical node union strict (oneOf) while simplifying relationship values to IDs', () => {
|
|
9
|
+
// Shaped like the schema the MCP server prepares for a collection with a Lexical richText field:
|
|
10
|
+
// a `$defs` node union (a `oneOf` of node shapes) where a relationship node's `value` is either
|
|
11
|
+
// an ID or a `$ref` to the populated related collection.
|
|
12
|
+
const standalone: JsonSchemaType = {
|
|
13
|
+
type: 'object',
|
|
14
|
+
$defs: {
|
|
15
|
+
LexicalNodes_ABCDEF12: {
|
|
16
|
+
oneOf: [
|
|
17
|
+
{
|
|
18
|
+
type: 'object',
|
|
19
|
+
additionalProperties: false,
|
|
20
|
+
properties: { type: { const: 'paragraph' } },
|
|
21
|
+
required: ['type'],
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
type: 'object',
|
|
25
|
+
additionalProperties: false,
|
|
26
|
+
properties: {
|
|
27
|
+
type: { const: 'relationship' },
|
|
28
|
+
value: { oneOf: [{ type: 'string' }, { $ref: '#/$defs/posts' }] },
|
|
29
|
+
},
|
|
30
|
+
required: ['type'],
|
|
31
|
+
},
|
|
32
|
+
],
|
|
33
|
+
},
|
|
34
|
+
posts: {
|
|
35
|
+
type: 'object',
|
|
36
|
+
additionalProperties: false,
|
|
37
|
+
properties: { id: { type: 'string' }, title: { type: 'string' } },
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
properties: {
|
|
41
|
+
id: { type: 'string' },
|
|
42
|
+
content: {
|
|
43
|
+
type: 'object',
|
|
44
|
+
properties: {
|
|
45
|
+
root: {
|
|
46
|
+
type: 'object',
|
|
47
|
+
properties: {
|
|
48
|
+
children: { type: 'array', items: { $ref: '#/$defs/LexicalNodes_ABCDEF12' } },
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
expect(sanitizeEntitySchema(standalone)).toStrictEqual({
|
|
57
|
+
type: 'object',
|
|
58
|
+
$defs: {
|
|
59
|
+
// The node union is renamed to a short, readable `node`, and stays a strict discriminated
|
|
60
|
+
// `oneOf` - not loosened to `anyOf`...
|
|
61
|
+
node: {
|
|
62
|
+
oneOf: [
|
|
63
|
+
{
|
|
64
|
+
type: 'object',
|
|
65
|
+
additionalProperties: false,
|
|
66
|
+
properties: { type: { const: 'paragraph' } },
|
|
67
|
+
required: ['type'],
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
type: 'object',
|
|
71
|
+
additionalProperties: false,
|
|
72
|
+
properties: {
|
|
73
|
+
type: { const: 'relationship' },
|
|
74
|
+
// ...while the relationship `value` is simplified to a bare ID (the populated-doc `$ref` is dropped).
|
|
75
|
+
value: { type: 'string', description: 'The ID of the related "posts" document.' },
|
|
76
|
+
},
|
|
77
|
+
required: ['type'],
|
|
78
|
+
},
|
|
79
|
+
],
|
|
80
|
+
},
|
|
81
|
+
posts: {
|
|
82
|
+
type: 'object',
|
|
83
|
+
additionalProperties: false,
|
|
84
|
+
properties: { id: { type: 'string' }, title: { type: 'string' } },
|
|
85
|
+
},
|
|
86
|
+
},
|
|
87
|
+
properties: {
|
|
88
|
+
// `id` is dropped - it's a Payload-managed field MCP clients never set.
|
|
89
|
+
content: {
|
|
90
|
+
type: 'object',
|
|
91
|
+
properties: {
|
|
92
|
+
root: {
|
|
93
|
+
type: 'object',
|
|
94
|
+
properties: {
|
|
95
|
+
children: { type: 'array', items: { $ref: '#/$defs/node' } },
|
|
96
|
+
},
|
|
97
|
+
},
|
|
98
|
+
},
|
|
99
|
+
},
|
|
100
|
+
},
|
|
101
|
+
})
|
|
102
|
+
})
|
|
103
|
+
})
|