@payloadcms/plugin-mcp 3.79.0 → 3.79.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/mcp/getMcpHandler.d.ts.map +1 -1
- package/dist/mcp/getMcpHandler.js +3 -1
- package/dist/mcp/getMcpHandler.js.map +1 -1
- package/package.json +4 -4
- package/src/mcp/getMcpHandler.ts +3 -1
- package/dist/mcp/helpers/conversion.d.ts +0 -2
- package/dist/mcp/helpers/conversion.d.ts.map +0 -1
- package/dist/mcp/helpers/conversion.js +0 -5
- package/dist/mcp/helpers/conversion.js.map +0 -1
- package/dist/mcp/helpers/validation.d.ts +0 -9
- package/dist/mcp/helpers/validation.d.ts.map +0 -1
- package/dist/mcp/helpers/validation.js +0 -22
- package/dist/mcp/helpers/validation.js.map +0 -1
- package/dist/utils/convertCollectionSchemaToZod.d.ts +0 -3
- package/dist/utils/convertCollectionSchemaToZod.d.ts.map +0 -1
- package/dist/utils/convertCollectionSchemaToZod.js +0 -80
- package/dist/utils/convertCollectionSchemaToZod.js.map +0 -1
- package/dist/utils/transformPointFields.d.ts +0 -3
- package/dist/utils/transformPointFields.d.ts.map +0 -1
- package/dist/utils/transformPointFields.js +0 -51
- package/dist/utils/transformPointFields.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getMcpHandler.d.ts","sourceRoot":"","sources":["../../src/mcp/getMcpHandler.ts"],"names":[],"mappings":"AAIA,OAAO,EAAgC,KAAK,cAAc,EAAkB,MAAM,SAAS,CAAA;AAE3F,OAAO,KAAK,EAAE,iBAAiB,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAA;AAuC3E,eAAO,MAAM,aAAa,kBACT,qBAAqB,qBACjB,iBAAiB,OAC/B,cAAc,
|
|
1
|
+
{"version":3,"file":"getMcpHandler.d.ts","sourceRoot":"","sources":["../../src/mcp/getMcpHandler.ts"],"names":[],"mappings":"AAIA,OAAO,EAAgC,KAAK,cAAc,EAAkB,MAAM,SAAS,CAAA;AAE3F,OAAO,KAAK,EAAE,iBAAiB,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAA;AAuC3E,eAAO,MAAM,aAAa,kBACT,qBAAqB,qBACjB,iBAAiB,OAC/B,cAAc,4CA+epB,CAAA"}
|
|
@@ -33,7 +33,9 @@ import { runJobTool } from './tools/job/run.js';
|
|
|
33
33
|
import { updateJobTool } from './tools/job/update.js';
|
|
34
34
|
export const getMCPHandler = (pluginOptions, mcpAccessSettings, req)=>{
|
|
35
35
|
const { payload } = req;
|
|
36
|
-
const configSchema = configToJSONSchema(payload.config, payload.db.defaultIDType, req.i18n
|
|
36
|
+
const configSchema = configToJSONSchema(payload.config, payload.db.defaultIDType, req.i18n, {
|
|
37
|
+
forceInlineBlocks: true
|
|
38
|
+
});
|
|
37
39
|
// Handler wrapper that injects req before the _extra argument
|
|
38
40
|
const wrapHandler = (handler)=>{
|
|
39
41
|
return async (...args)=>{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/mcp/getMcpHandler.ts"],"sourcesContent":["import type { JSONSchema4 } from 'json-schema'\n\nimport { createMcpHandler } from 'mcp-handler'\nimport { join } from 'path'\nimport { APIError, configToJSONSchema, type PayloadRequest, type TypedUser } from 'payload'\n\nimport type { MCPAccessSettings, PluginMCPServerConfig } from '../types.js'\n\nimport { toCamelCase } from '../utils/camelCase.js'\nimport { getEnabledSlugs } from '../utils/getEnabledSlugs.js'\nimport {\n getCollectionVirtualFieldNames,\n getGlobalVirtualFieldNames,\n} from '../utils/getVirtualFieldNames.js'\nimport { removeVirtualFieldsFromSchema } from '../utils/schemaConversion/removeVirtualFieldsFromSchema.js'\nimport { registerTool } from './registerTool.js'\n\n// Tools\nimport { findGlobalTool } from './tools/global/find.js'\nimport { updateGlobalTool } from './tools/global/update.js'\nimport { createResourceTool } from './tools/resource/create.js'\nimport { deleteResourceTool } from './tools/resource/delete.js'\nimport { findResourceTool } from './tools/resource/find.js'\nimport { updateResourceTool } from './tools/resource/update.js'\n\n// Experimental Tools\n/**\n * @experimental This tools are experimental and may change or be removed in the future.\n */\nimport { authTool } from './tools/auth/auth.js'\nimport { forgotPasswordTool } from './tools/auth/forgotPassword.js'\nimport { loginTool } from './tools/auth/login.js'\nimport { resetPasswordTool } from './tools/auth/resetPassword.js'\nimport { unlockTool } from './tools/auth/unlock.js'\nimport { verifyTool } from './tools/auth/verify.js'\nimport { createCollectionTool } from './tools/collection/create.js'\nimport { deleteCollectionTool } from './tools/collection/delete.js'\nimport { findCollectionTool } from './tools/collection/find.js'\nimport { updateCollectionTool } from './tools/collection/update.js'\nimport { findConfigTool } from './tools/config/find.js'\nimport { updateConfigTool } from './tools/config/update.js'\nimport { createJobTool } from './tools/job/create.js'\nimport { runJobTool } from './tools/job/run.js'\nimport { updateJobTool } from './tools/job/update.js'\n\nexport const getMCPHandler = (\n pluginOptions: PluginMCPServerConfig,\n mcpAccessSettings: MCPAccessSettings,\n req: PayloadRequest,\n) => {\n const { payload } = req\n const configSchema = configToJSONSchema(payload.config, payload.db.defaultIDType, req.i18n)\n\n // Handler wrapper that injects req before the _extra argument\n const wrapHandler = (handler: (...args: any[]) => any) => {\n return async (...args: any[]) => {\n const _extra = args[args.length - 1]\n const handlerArgs = args.slice(0, -1)\n return await handler(...handlerArgs, req, _extra)\n }\n }\n\n const payloadToolHandler = (\n handler: NonNullable<NonNullable<PluginMCPServerConfig['mcp']>['tools']>[number]['handler'],\n ) => wrapHandler(handler)\n\n const payloadPromptHandler = (\n handler: NonNullable<NonNullable<PluginMCPServerConfig['mcp']>['prompts']>[number]['handler'],\n ) => wrapHandler(handler)\n\n const payloadResourceHandler = (\n handler: NonNullable<NonNullable<PluginMCPServerConfig['mcp']>['resources']>[number]['handler'],\n ) => wrapHandler(handler)\n\n // User\n const user = mcpAccessSettings.user\n\n // MCP Server and Handler Options\n const MCPOptions = pluginOptions.mcp || {}\n const customMCPTools = MCPOptions.tools || []\n const customMCPPrompts = MCPOptions.prompts || []\n const customMCPResources = MCPOptions.resources || []\n const MCPHandlerOptions = MCPOptions.handlerOptions || {}\n const serverOptions = MCPOptions.serverOptions || {}\n const useVerboseLogs = MCPHandlerOptions.verboseLogs ?? false\n\n // Experimental MCP Tool Requirements\n const isDevelopment = process.env.NODE_ENV === 'development'\n const experimentalTools: NonNullable<PluginMCPServerConfig['experimental']>['tools'] =\n pluginOptions?.experimental?.tools || {}\n const collectionsPluginConfig = pluginOptions.collections || {}\n const globalsPluginConfig = pluginOptions.globals || {}\n const collectionsDirPath =\n experimentalTools && experimentalTools.collections?.collectionsDirPath\n ? experimentalTools.collections.collectionsDirPath\n : join(process.cwd(), 'src/collections')\n const configFilePath =\n experimentalTools && experimentalTools.config?.configFilePath\n ? experimentalTools.config.configFilePath\n : join(process.cwd(), 'src/payload.config.ts')\n const jobsDirPath =\n experimentalTools && experimentalTools.jobs?.jobsDirPath\n ? experimentalTools.jobs.jobsDirPath\n : join(process.cwd(), 'src/jobs')\n\n try {\n return createMcpHandler(\n (server) => {\n // Get enabled collections\n const enabledCollectionSlugs = getEnabledSlugs(collectionsPluginConfig, 'collection')\n\n // Collection Operation Tools\n enabledCollectionSlugs.forEach((enabledCollectionSlug) => {\n try {\n const rawSchema = configSchema.definitions?.[enabledCollectionSlug] as JSONSchema4\n\n const virtualFieldNames = getCollectionVirtualFieldNames(\n payload.config,\n enabledCollectionSlug,\n )\n const schema = removeVirtualFieldsFromSchema(\n JSON.parse(JSON.stringify(rawSchema)) as JSONSchema4,\n virtualFieldNames,\n )\n\n const toolCapabilities = mcpAccessSettings?.[\n `${toCamelCase(enabledCollectionSlug)}`\n ] as Record<string, unknown>\n const allowCreate: boolean | undefined = toolCapabilities?.create as boolean\n const allowUpdate: boolean | undefined = toolCapabilities?.update as boolean\n const allowFind: boolean | undefined = toolCapabilities?.find as boolean\n const allowDelete: boolean | undefined = toolCapabilities?.delete as boolean\n\n if (allowCreate) {\n registerTool(\n allowCreate,\n `Create ${enabledCollectionSlug}`,\n () =>\n createResourceTool(\n server,\n req,\n user,\n useVerboseLogs,\n enabledCollectionSlug,\n collectionsPluginConfig,\n schema,\n ),\n payload,\n useVerboseLogs,\n )\n }\n if (allowUpdate) {\n registerTool(\n allowUpdate,\n `Update ${enabledCollectionSlug}`,\n () =>\n updateResourceTool(\n server,\n req,\n user,\n useVerboseLogs,\n enabledCollectionSlug,\n collectionsPluginConfig,\n schema,\n ),\n payload,\n useVerboseLogs,\n )\n }\n if (allowFind) {\n registerTool(\n allowFind,\n `Find ${enabledCollectionSlug}`,\n () =>\n findResourceTool(\n server,\n req,\n user,\n useVerboseLogs,\n enabledCollectionSlug,\n collectionsPluginConfig,\n ),\n payload,\n useVerboseLogs,\n )\n }\n if (allowDelete) {\n registerTool(\n allowDelete,\n `Delete ${enabledCollectionSlug}`,\n () =>\n deleteResourceTool(\n server,\n req,\n user,\n useVerboseLogs,\n enabledCollectionSlug,\n collectionsPluginConfig,\n ),\n payload,\n useVerboseLogs,\n )\n }\n } catch (error) {\n throw new APIError(\n `Error registering tools for collection ${enabledCollectionSlug}: ${String(error)}`,\n 500,\n )\n }\n })\n\n // Global Operation Tools\n const enabledGlobalSlugs = getEnabledSlugs(globalsPluginConfig, 'global')\n\n enabledGlobalSlugs.forEach((enabledGlobalSlug) => {\n try {\n const rawSchema = configSchema.definitions?.[enabledGlobalSlug] as JSONSchema4\n\n const virtualFieldNames = getGlobalVirtualFieldNames(payload.config, enabledGlobalSlug)\n const schema = removeVirtualFieldsFromSchema(\n JSON.parse(JSON.stringify(rawSchema)) as JSONSchema4,\n virtualFieldNames,\n )\n\n const toolCapabilities = mcpAccessSettings?.[\n `${toCamelCase(enabledGlobalSlug)}`\n ] as Record<string, unknown>\n const allowFind: boolean | undefined = toolCapabilities?.['find'] as boolean\n const allowUpdate: boolean | undefined = toolCapabilities?.['update'] as boolean\n\n if (allowFind) {\n registerTool(\n allowFind,\n `Find ${enabledGlobalSlug}`,\n () =>\n findGlobalTool(\n server,\n req,\n user,\n useVerboseLogs,\n enabledGlobalSlug,\n globalsPluginConfig,\n ),\n payload,\n useVerboseLogs,\n )\n }\n if (allowUpdate) {\n registerTool(\n allowUpdate,\n `Update ${enabledGlobalSlug}`,\n () =>\n updateGlobalTool(\n server,\n req,\n user,\n useVerboseLogs,\n enabledGlobalSlug,\n globalsPluginConfig,\n schema,\n ),\n payload,\n useVerboseLogs,\n )\n }\n } catch (error) {\n throw new APIError(\n `Error registering tools for global ${enabledGlobalSlug}: ${String(error)}`,\n 500,\n )\n }\n })\n\n // Custom tools\n customMCPTools.forEach((tool) => {\n const camelCasedToolName = toCamelCase(tool.name)\n const isToolEnabled = mcpAccessSettings['payload-mcp-tool']?.[camelCasedToolName] ?? false\n\n registerTool(\n isToolEnabled,\n tool.name,\n () =>\n server.registerTool(\n tool.name,\n {\n description: tool.description,\n inputSchema: tool.parameters,\n },\n payloadToolHandler(tool.handler),\n ),\n payload,\n useVerboseLogs,\n )\n })\n\n // Custom prompts\n customMCPPrompts.forEach((prompt) => {\n const camelCasedPromptName = toCamelCase(prompt.name)\n const isPromptEnabled =\n mcpAccessSettings['payload-mcp-prompt']?.[camelCasedPromptName] ?? false\n\n if (isPromptEnabled) {\n server.registerPrompt(\n prompt.name,\n {\n argsSchema: prompt.argsSchema,\n description: prompt.description,\n title: prompt.title,\n },\n payloadPromptHandler(prompt.handler),\n )\n if (useVerboseLogs) {\n payload.logger.info(`[payload-mcp] ✅ Prompt: ${prompt.title} Registered.`)\n }\n } else if (useVerboseLogs) {\n payload.logger.info(`[payload-mcp] ⏭️ Prompt: ${prompt.title} Skipped.`)\n }\n })\n\n // Custom resources\n customMCPResources.forEach((resource) => {\n const camelCasedResourceName = toCamelCase(resource.name)\n const isResourceEnabled =\n mcpAccessSettings['payload-mcp-resource']?.[camelCasedResourceName] ?? false\n\n if (isResourceEnabled) {\n server.registerResource(\n resource.name,\n // @ts-expect-error - Overload type is not working however -- ResourceTemplate OR String is a valid type\n resource.uri,\n {\n description: resource.description,\n mimeType: resource.mimeType,\n title: resource.title,\n },\n payloadResourceHandler(resource.handler),\n )\n\n if (useVerboseLogs) {\n payload.logger.info(`[payload-mcp] ✅ Resource: ${resource.title} Registered.`)\n }\n } else if (useVerboseLogs) {\n payload.logger.info(`[payload-mcp] ⏭️ Resource: ${resource.title} Skipped.`)\n }\n })\n\n // Experimental - Collection Schema Modfication Tools\n if (\n mcpAccessSettings.collections?.create &&\n experimentalTools.collections?.enabled &&\n isDevelopment\n ) {\n registerTool(\n mcpAccessSettings.collections.create,\n 'Create Collection',\n () =>\n createCollectionTool(server, req, useVerboseLogs, collectionsDirPath, configFilePath),\n payload,\n useVerboseLogs,\n )\n }\n if (\n mcpAccessSettings.collections?.delete &&\n experimentalTools.collections?.enabled &&\n isDevelopment\n ) {\n registerTool(\n mcpAccessSettings.collections.delete,\n 'Delete Collection',\n () =>\n deleteCollectionTool(server, req, useVerboseLogs, collectionsDirPath, configFilePath),\n payload,\n useVerboseLogs,\n )\n }\n\n if (\n mcpAccessSettings.collections?.find &&\n experimentalTools.collections?.enabled &&\n isDevelopment\n ) {\n registerTool(\n mcpAccessSettings.collections.find,\n 'Find Collection',\n () => findCollectionTool(server, req, useVerboseLogs, collectionsDirPath),\n payload,\n useVerboseLogs,\n )\n }\n\n if (\n mcpAccessSettings.collections?.update &&\n experimentalTools.collections?.enabled &&\n isDevelopment\n ) {\n registerTool(\n mcpAccessSettings.collections.update,\n 'Update Collection',\n () =>\n updateCollectionTool(server, req, useVerboseLogs, collectionsDirPath, configFilePath),\n payload,\n useVerboseLogs,\n )\n }\n\n // Experimental - Payload Config Modification Tools\n if (mcpAccessSettings.config?.find && experimentalTools.config?.enabled && isDevelopment) {\n registerTool(\n mcpAccessSettings.config.find,\n 'Find Config',\n () => findConfigTool(server, req, useVerboseLogs, configFilePath),\n payload,\n useVerboseLogs,\n )\n }\n\n if (\n mcpAccessSettings.config?.update &&\n experimentalTools.config?.enabled &&\n isDevelopment\n ) {\n registerTool(\n mcpAccessSettings.config.update,\n 'Update Config',\n () => updateConfigTool(server, req, useVerboseLogs, configFilePath),\n payload,\n useVerboseLogs,\n )\n }\n\n // Experimental - Job Modification Tools\n if (mcpAccessSettings.jobs?.create && experimentalTools.jobs?.enabled && isDevelopment) {\n registerTool(\n mcpAccessSettings.jobs.create,\n 'Create Job',\n () => createJobTool(server, req, useVerboseLogs, jobsDirPath),\n payload,\n useVerboseLogs,\n )\n }\n\n if (mcpAccessSettings.jobs?.update && experimentalTools.jobs?.enabled && isDevelopment) {\n registerTool(\n mcpAccessSettings.jobs.update,\n 'Update Job',\n () => updateJobTool(server, req, useVerboseLogs, jobsDirPath),\n payload,\n useVerboseLogs,\n )\n }\n\n if (mcpAccessSettings.jobs?.run && experimentalTools.jobs?.enabled && isDevelopment) {\n registerTool(\n mcpAccessSettings.jobs.run,\n 'Run Job',\n () => runJobTool(server, req, useVerboseLogs),\n payload,\n useVerboseLogs,\n )\n }\n\n // Experimental - Auth Modification Tools\n if (mcpAccessSettings.auth?.auth && experimentalTools.auth?.enabled && isDevelopment) {\n registerTool(\n mcpAccessSettings.auth.auth,\n 'Auth',\n () => authTool(server, req, useVerboseLogs),\n payload,\n useVerboseLogs,\n )\n }\n\n if (mcpAccessSettings.auth?.login && experimentalTools.auth?.enabled && isDevelopment) {\n registerTool(\n mcpAccessSettings.auth.login,\n 'Login',\n () => loginTool(server, req, useVerboseLogs),\n payload,\n useVerboseLogs,\n )\n }\n\n if (mcpAccessSettings.auth?.verify && experimentalTools.auth?.enabled && isDevelopment) {\n registerTool(\n mcpAccessSettings.auth.verify,\n 'Verify',\n () => verifyTool(server, req, useVerboseLogs),\n payload,\n useVerboseLogs,\n )\n }\n\n if (mcpAccessSettings.auth?.resetPassword && experimentalTools.auth?.enabled) {\n registerTool(\n mcpAccessSettings.auth.resetPassword,\n 'Reset Password',\n () => resetPasswordTool(server, req, useVerboseLogs),\n payload,\n useVerboseLogs,\n )\n }\n\n if (mcpAccessSettings.auth?.forgotPassword && experimentalTools.auth?.enabled) {\n registerTool(\n mcpAccessSettings.auth.forgotPassword,\n 'Forgot Password',\n () => forgotPasswordTool(server, req, useVerboseLogs),\n payload,\n useVerboseLogs,\n )\n }\n\n if (mcpAccessSettings.auth?.unlock && experimentalTools.auth?.enabled) {\n registerTool(\n mcpAccessSettings.auth.unlock,\n 'Unlock',\n () => unlockTool(server, req, useVerboseLogs),\n payload,\n useVerboseLogs,\n )\n }\n\n if (useVerboseLogs) {\n payload.logger.info('[payload-mcp] 🚀 MCP Server Ready.')\n }\n },\n {\n serverInfo: serverOptions.serverInfo,\n },\n {\n basePath: MCPHandlerOptions.basePath || payload.config.routes?.api || '/api',\n disableSse: MCPHandlerOptions.disableSse ?? true,\n maxDuration: MCPHandlerOptions.maxDuration || 60,\n onEvent: MCPHandlerOptions.onEvent,\n redisUrl: MCPHandlerOptions.redisUrl,\n verboseLogs: useVerboseLogs,\n },\n )\n } catch (error) {\n throw new APIError(`Error initializing MCP handler: ${String(error)}`, 500)\n }\n}\n"],"names":["createMcpHandler","join","APIError","configToJSONSchema","toCamelCase","getEnabledSlugs","getCollectionVirtualFieldNames","getGlobalVirtualFieldNames","removeVirtualFieldsFromSchema","registerTool","findGlobalTool","updateGlobalTool","createResourceTool","deleteResourceTool","findResourceTool","updateResourceTool","authTool","forgotPasswordTool","loginTool","resetPasswordTool","unlockTool","verifyTool","createCollectionTool","deleteCollectionTool","findCollectionTool","updateCollectionTool","findConfigTool","updateConfigTool","createJobTool","runJobTool","updateJobTool","getMCPHandler","pluginOptions","mcpAccessSettings","req","payload","configSchema","config","db","defaultIDType","i18n","wrapHandler","handler","args","_extra","length","handlerArgs","slice","payloadToolHandler","payloadPromptHandler","payloadResourceHandler","user","MCPOptions","mcp","customMCPTools","tools","customMCPPrompts","prompts","customMCPResources","resources","MCPHandlerOptions","handlerOptions","serverOptions","useVerboseLogs","verboseLogs","isDevelopment","process","env","NODE_ENV","experimentalTools","experimental","collectionsPluginConfig","collections","globalsPluginConfig","globals","collectionsDirPath","cwd","configFilePath","jobsDirPath","jobs","server","enabledCollectionSlugs","forEach","enabledCollectionSlug","rawSchema","definitions","virtualFieldNames","schema","JSON","parse","stringify","toolCapabilities","allowCreate","create","allowUpdate","update","allowFind","find","allowDelete","delete","error","String","enabledGlobalSlugs","enabledGlobalSlug","tool","camelCasedToolName","name","isToolEnabled","description","inputSchema","parameters","prompt","camelCasedPromptName","isPromptEnabled","registerPrompt","argsSchema","title","logger","info","resource","camelCasedResourceName","isResourceEnabled","registerResource","uri","mimeType","enabled","run","auth","login","verify","resetPassword","forgotPassword","unlock","serverInfo","basePath","routes","api","disableSse","maxDuration","onEvent","redisUrl"],"mappings":"AAEA,SAASA,gBAAgB,QAAQ,cAAa;AAC9C,SAASC,IAAI,QAAQ,OAAM;AAC3B,SAASC,QAAQ,EAAEC,kBAAkB,QAA6C,UAAS;AAI3F,SAASC,WAAW,QAAQ,wBAAuB;AACnD,SAASC,eAAe,QAAQ,8BAA6B;AAC7D,SACEC,8BAA8B,EAC9BC,0BAA0B,QACrB,mCAAkC;AACzC,SAASC,6BAA6B,QAAQ,6DAA4D;AAC1G,SAASC,YAAY,QAAQ,oBAAmB;AAEhD,QAAQ;AACR,SAASC,cAAc,QAAQ,yBAAwB;AACvD,SAASC,gBAAgB,QAAQ,2BAA0B;AAC3D,SAASC,kBAAkB,QAAQ,6BAA4B;AAC/D,SAASC,kBAAkB,QAAQ,6BAA4B;AAC/D,SAASC,gBAAgB,QAAQ,2BAA0B;AAC3D,SAASC,kBAAkB,QAAQ,6BAA4B;AAE/D,qBAAqB;AACrB;;CAEC,GACD,SAASC,QAAQ,QAAQ,uBAAsB;AAC/C,SAASC,kBAAkB,QAAQ,iCAAgC;AACnE,SAASC,SAAS,QAAQ,wBAAuB;AACjD,SAASC,iBAAiB,QAAQ,gCAA+B;AACjE,SAASC,UAAU,QAAQ,yBAAwB;AACnD,SAASC,UAAU,QAAQ,yBAAwB;AACnD,SAASC,oBAAoB,QAAQ,+BAA8B;AAC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AAEF,SAAS;gBAC7EpH,aACEwB,kBAAkB8F,IAAI,CAACI,cAAc,EACrC,mBACA,IAAMlH,mBAAmB+D,QAAQ9C,KAAK6B,iBACtC5B,SACA4B;YAEJ;YAEA,IAAI9B,kBAAkB8F,IAAI,EAAEK,UAAU/D,kBAAkB0D,IAAI,EAAEF,SAAS;gBACrEpH,aACEwB,kBAAkB8F,IAAI,CAACK,MAAM,EAC7B,UACA,IAAMhH,WAAW4D,QAAQ9C,KAAK6B,iBAC9B5B,SACA4B;YAEJ;YAEA,IAAIA,gBAAgB;gBAClB5B,QAAQkF,MAAM,CAACC,IAAI,CAAC;YACtB;QACF,GACA;YACEe,YAAYvE,cAAcuE,UAAU;QACtC,GACA;YACEC,UAAU1E,kBAAkB0E,QAAQ,IAAInG,QAAQE,MAAM,CAACkG,MAAM,EAAEC,OAAO;YACtEC,YAAY7E,kBAAkB6E,UAAU,IAAI;YAC5CC,aAAa9E,kBAAkB8E,WAAW,IAAI;YAC9CC,SAAS/E,kBAAkB+E,OAAO;YAClCC,UAAUhF,kBAAkBgF,QAAQ;YACpC5E,aAAaD;QACf;IAEJ,EAAE,OAAOqC,OAAO;QACd,MAAM,IAAIlG,SAAS,CAAC,gCAAgC,EAAEmG,OAAOD,QAAQ,EAAE;IACzE;AACF,EAAC"}
|
|
1
|
+
{"version":3,"sources":["../../src/mcp/getMcpHandler.ts"],"sourcesContent":["import type { JSONSchema4 } from 'json-schema'\n\nimport { createMcpHandler } from 'mcp-handler'\nimport { join } from 'path'\nimport { APIError, configToJSONSchema, type PayloadRequest, type TypedUser } from 'payload'\n\nimport type { MCPAccessSettings, PluginMCPServerConfig } from '../types.js'\n\nimport { toCamelCase } from '../utils/camelCase.js'\nimport { getEnabledSlugs } from '../utils/getEnabledSlugs.js'\nimport {\n getCollectionVirtualFieldNames,\n getGlobalVirtualFieldNames,\n} from '../utils/getVirtualFieldNames.js'\nimport { removeVirtualFieldsFromSchema } from '../utils/schemaConversion/removeVirtualFieldsFromSchema.js'\nimport { registerTool } from './registerTool.js'\n\n// Tools\nimport { findGlobalTool } from './tools/global/find.js'\nimport { updateGlobalTool } from './tools/global/update.js'\nimport { createResourceTool } from './tools/resource/create.js'\nimport { deleteResourceTool } from './tools/resource/delete.js'\nimport { findResourceTool } from './tools/resource/find.js'\nimport { updateResourceTool } from './tools/resource/update.js'\n\n// Experimental Tools\n/**\n * @experimental This tools are experimental and may change or be removed in the future.\n */\nimport { authTool } from './tools/auth/auth.js'\nimport { forgotPasswordTool } from './tools/auth/forgotPassword.js'\nimport { loginTool } from './tools/auth/login.js'\nimport { resetPasswordTool } from './tools/auth/resetPassword.js'\nimport { unlockTool } from './tools/auth/unlock.js'\nimport { verifyTool } from './tools/auth/verify.js'\nimport { createCollectionTool } from './tools/collection/create.js'\nimport { deleteCollectionTool } from './tools/collection/delete.js'\nimport { findCollectionTool } from './tools/collection/find.js'\nimport { updateCollectionTool } from './tools/collection/update.js'\nimport { findConfigTool } from './tools/config/find.js'\nimport { updateConfigTool } from './tools/config/update.js'\nimport { createJobTool } from './tools/job/create.js'\nimport { runJobTool } from './tools/job/run.js'\nimport { updateJobTool } from './tools/job/update.js'\n\nexport const getMCPHandler = (\n pluginOptions: PluginMCPServerConfig,\n mcpAccessSettings: MCPAccessSettings,\n req: PayloadRequest,\n) => {\n const { payload } = req\n const configSchema = configToJSONSchema(payload.config, payload.db.defaultIDType, req.i18n, {\n forceInlineBlocks: true,\n })\n\n // Handler wrapper that injects req before the _extra argument\n const wrapHandler = (handler: (...args: any[]) => any) => {\n return async (...args: any[]) => {\n const _extra = args[args.length - 1]\n const handlerArgs = args.slice(0, -1)\n return await handler(...handlerArgs, req, _extra)\n }\n }\n\n const payloadToolHandler = (\n handler: NonNullable<NonNullable<PluginMCPServerConfig['mcp']>['tools']>[number]['handler'],\n ) => wrapHandler(handler)\n\n const payloadPromptHandler = (\n handler: NonNullable<NonNullable<PluginMCPServerConfig['mcp']>['prompts']>[number]['handler'],\n ) => wrapHandler(handler)\n\n const payloadResourceHandler = (\n handler: NonNullable<NonNullable<PluginMCPServerConfig['mcp']>['resources']>[number]['handler'],\n ) => wrapHandler(handler)\n\n // User\n const user = mcpAccessSettings.user\n\n // MCP Server and Handler Options\n const MCPOptions = pluginOptions.mcp || {}\n const customMCPTools = MCPOptions.tools || []\n const customMCPPrompts = MCPOptions.prompts || []\n const customMCPResources = MCPOptions.resources || []\n const MCPHandlerOptions = MCPOptions.handlerOptions || {}\n const serverOptions = MCPOptions.serverOptions || {}\n const useVerboseLogs = MCPHandlerOptions.verboseLogs ?? false\n\n // Experimental MCP Tool Requirements\n const isDevelopment = process.env.NODE_ENV === 'development'\n const experimentalTools: NonNullable<PluginMCPServerConfig['experimental']>['tools'] =\n pluginOptions?.experimental?.tools || {}\n const collectionsPluginConfig = pluginOptions.collections || {}\n const globalsPluginConfig = pluginOptions.globals || {}\n const collectionsDirPath =\n experimentalTools && experimentalTools.collections?.collectionsDirPath\n ? experimentalTools.collections.collectionsDirPath\n : join(process.cwd(), 'src/collections')\n const configFilePath =\n experimentalTools && experimentalTools.config?.configFilePath\n ? experimentalTools.config.configFilePath\n : join(process.cwd(), 'src/payload.config.ts')\n const jobsDirPath =\n experimentalTools && experimentalTools.jobs?.jobsDirPath\n ? experimentalTools.jobs.jobsDirPath\n : join(process.cwd(), 'src/jobs')\n\n try {\n return createMcpHandler(\n (server) => {\n // Get enabled collections\n const enabledCollectionSlugs = getEnabledSlugs(collectionsPluginConfig, 'collection')\n\n // Collection Operation Tools\n enabledCollectionSlugs.forEach((enabledCollectionSlug) => {\n try {\n const rawSchema = configSchema.definitions?.[enabledCollectionSlug] as JSONSchema4\n\n const virtualFieldNames = getCollectionVirtualFieldNames(\n payload.config,\n enabledCollectionSlug,\n )\n const schema = removeVirtualFieldsFromSchema(\n JSON.parse(JSON.stringify(rawSchema)) as JSONSchema4,\n virtualFieldNames,\n )\n\n const toolCapabilities = mcpAccessSettings?.[\n `${toCamelCase(enabledCollectionSlug)}`\n ] as Record<string, unknown>\n const allowCreate: boolean | undefined = toolCapabilities?.create as boolean\n const allowUpdate: boolean | undefined = toolCapabilities?.update as boolean\n const allowFind: boolean | undefined = toolCapabilities?.find as boolean\n const allowDelete: boolean | undefined = toolCapabilities?.delete as boolean\n\n if (allowCreate) {\n registerTool(\n allowCreate,\n `Create ${enabledCollectionSlug}`,\n () =>\n createResourceTool(\n server,\n req,\n user,\n useVerboseLogs,\n enabledCollectionSlug,\n collectionsPluginConfig,\n schema,\n ),\n payload,\n useVerboseLogs,\n )\n }\n if (allowUpdate) {\n registerTool(\n allowUpdate,\n `Update ${enabledCollectionSlug}`,\n () =>\n updateResourceTool(\n server,\n req,\n user,\n useVerboseLogs,\n enabledCollectionSlug,\n collectionsPluginConfig,\n schema,\n ),\n payload,\n useVerboseLogs,\n )\n }\n if (allowFind) {\n registerTool(\n allowFind,\n `Find ${enabledCollectionSlug}`,\n () =>\n findResourceTool(\n server,\n req,\n user,\n useVerboseLogs,\n enabledCollectionSlug,\n collectionsPluginConfig,\n ),\n payload,\n useVerboseLogs,\n )\n }\n if (allowDelete) {\n registerTool(\n allowDelete,\n `Delete ${enabledCollectionSlug}`,\n () =>\n deleteResourceTool(\n server,\n req,\n user,\n useVerboseLogs,\n enabledCollectionSlug,\n collectionsPluginConfig,\n ),\n payload,\n useVerboseLogs,\n )\n }\n } catch (error) {\n throw new APIError(\n `Error registering tools for collection ${enabledCollectionSlug}: ${String(error)}`,\n 500,\n )\n }\n })\n\n // Global Operation Tools\n const enabledGlobalSlugs = getEnabledSlugs(globalsPluginConfig, 'global')\n\n enabledGlobalSlugs.forEach((enabledGlobalSlug) => {\n try {\n const rawSchema = configSchema.definitions?.[enabledGlobalSlug] as JSONSchema4\n\n const virtualFieldNames = getGlobalVirtualFieldNames(payload.config, enabledGlobalSlug)\n const schema = removeVirtualFieldsFromSchema(\n JSON.parse(JSON.stringify(rawSchema)) as JSONSchema4,\n virtualFieldNames,\n )\n\n const toolCapabilities = mcpAccessSettings?.[\n `${toCamelCase(enabledGlobalSlug)}`\n ] as Record<string, unknown>\n const allowFind: boolean | undefined = toolCapabilities?.['find'] as boolean\n const allowUpdate: boolean | undefined = toolCapabilities?.['update'] as boolean\n\n if (allowFind) {\n registerTool(\n allowFind,\n `Find ${enabledGlobalSlug}`,\n () =>\n findGlobalTool(\n server,\n req,\n user,\n useVerboseLogs,\n enabledGlobalSlug,\n globalsPluginConfig,\n ),\n payload,\n useVerboseLogs,\n )\n }\n if (allowUpdate) {\n registerTool(\n allowUpdate,\n `Update ${enabledGlobalSlug}`,\n () =>\n updateGlobalTool(\n server,\n req,\n user,\n useVerboseLogs,\n enabledGlobalSlug,\n globalsPluginConfig,\n schema,\n ),\n payload,\n useVerboseLogs,\n )\n }\n } catch (error) {\n throw new APIError(\n `Error registering tools for global ${enabledGlobalSlug}: ${String(error)}`,\n 500,\n )\n }\n })\n\n // Custom tools\n customMCPTools.forEach((tool) => {\n const camelCasedToolName = toCamelCase(tool.name)\n const isToolEnabled = mcpAccessSettings['payload-mcp-tool']?.[camelCasedToolName] ?? false\n\n registerTool(\n isToolEnabled,\n tool.name,\n () =>\n server.registerTool(\n tool.name,\n {\n description: tool.description,\n inputSchema: tool.parameters,\n },\n payloadToolHandler(tool.handler),\n ),\n payload,\n useVerboseLogs,\n )\n })\n\n // Custom prompts\n customMCPPrompts.forEach((prompt) => {\n const camelCasedPromptName = toCamelCase(prompt.name)\n const isPromptEnabled =\n mcpAccessSettings['payload-mcp-prompt']?.[camelCasedPromptName] ?? false\n\n if (isPromptEnabled) {\n server.registerPrompt(\n prompt.name,\n {\n argsSchema: prompt.argsSchema,\n description: prompt.description,\n title: prompt.title,\n },\n payloadPromptHandler(prompt.handler),\n )\n if (useVerboseLogs) {\n payload.logger.info(`[payload-mcp] ✅ Prompt: ${prompt.title} Registered.`)\n }\n } else if (useVerboseLogs) {\n payload.logger.info(`[payload-mcp] ⏭️ Prompt: ${prompt.title} Skipped.`)\n }\n })\n\n // Custom resources\n customMCPResources.forEach((resource) => {\n const camelCasedResourceName = toCamelCase(resource.name)\n const isResourceEnabled =\n mcpAccessSettings['payload-mcp-resource']?.[camelCasedResourceName] ?? false\n\n if (isResourceEnabled) {\n server.registerResource(\n resource.name,\n // @ts-expect-error - Overload type is not working however -- ResourceTemplate OR String is a valid type\n resource.uri,\n {\n description: resource.description,\n mimeType: resource.mimeType,\n title: resource.title,\n },\n payloadResourceHandler(resource.handler),\n )\n\n if (useVerboseLogs) {\n payload.logger.info(`[payload-mcp] ✅ Resource: ${resource.title} Registered.`)\n }\n } else if (useVerboseLogs) {\n payload.logger.info(`[payload-mcp] ⏭️ Resource: ${resource.title} Skipped.`)\n }\n })\n\n // Experimental - Collection Schema Modfication Tools\n if (\n mcpAccessSettings.collections?.create &&\n experimentalTools.collections?.enabled &&\n isDevelopment\n ) {\n registerTool(\n mcpAccessSettings.collections.create,\n 'Create Collection',\n () =>\n createCollectionTool(server, req, useVerboseLogs, collectionsDirPath, configFilePath),\n payload,\n useVerboseLogs,\n )\n }\n if (\n mcpAccessSettings.collections?.delete &&\n experimentalTools.collections?.enabled &&\n isDevelopment\n ) {\n registerTool(\n mcpAccessSettings.collections.delete,\n 'Delete Collection',\n () =>\n deleteCollectionTool(server, req, useVerboseLogs, collectionsDirPath, configFilePath),\n payload,\n useVerboseLogs,\n )\n }\n\n if (\n mcpAccessSettings.collections?.find &&\n experimentalTools.collections?.enabled &&\n isDevelopment\n ) {\n registerTool(\n mcpAccessSettings.collections.find,\n 'Find Collection',\n () => findCollectionTool(server, req, useVerboseLogs, collectionsDirPath),\n payload,\n useVerboseLogs,\n )\n }\n\n if (\n mcpAccessSettings.collections?.update &&\n experimentalTools.collections?.enabled &&\n isDevelopment\n ) {\n registerTool(\n mcpAccessSettings.collections.update,\n 'Update Collection',\n () =>\n updateCollectionTool(server, req, useVerboseLogs, collectionsDirPath, configFilePath),\n payload,\n useVerboseLogs,\n )\n }\n\n // Experimental - Payload Config Modification Tools\n if (mcpAccessSettings.config?.find && experimentalTools.config?.enabled && isDevelopment) {\n registerTool(\n mcpAccessSettings.config.find,\n 'Find Config',\n () => findConfigTool(server, req, useVerboseLogs, configFilePath),\n payload,\n useVerboseLogs,\n )\n }\n\n if (\n mcpAccessSettings.config?.update &&\n experimentalTools.config?.enabled &&\n isDevelopment\n ) {\n registerTool(\n mcpAccessSettings.config.update,\n 'Update Config',\n () => updateConfigTool(server, req, useVerboseLogs, configFilePath),\n payload,\n useVerboseLogs,\n )\n }\n\n // Experimental - Job Modification Tools\n if (mcpAccessSettings.jobs?.create && experimentalTools.jobs?.enabled && isDevelopment) {\n registerTool(\n mcpAccessSettings.jobs.create,\n 'Create Job',\n () => createJobTool(server, req, useVerboseLogs, jobsDirPath),\n payload,\n useVerboseLogs,\n )\n }\n\n if (mcpAccessSettings.jobs?.update && experimentalTools.jobs?.enabled && isDevelopment) {\n registerTool(\n mcpAccessSettings.jobs.update,\n 'Update Job',\n () => updateJobTool(server, req, useVerboseLogs, jobsDirPath),\n payload,\n useVerboseLogs,\n )\n }\n\n if (mcpAccessSettings.jobs?.run && experimentalTools.jobs?.enabled && isDevelopment) {\n registerTool(\n mcpAccessSettings.jobs.run,\n 'Run Job',\n () => runJobTool(server, req, useVerboseLogs),\n payload,\n useVerboseLogs,\n )\n }\n\n // Experimental - Auth Modification Tools\n if (mcpAccessSettings.auth?.auth && experimentalTools.auth?.enabled && isDevelopment) {\n registerTool(\n mcpAccessSettings.auth.auth,\n 'Auth',\n () => authTool(server, req, useVerboseLogs),\n payload,\n useVerboseLogs,\n )\n }\n\n if (mcpAccessSettings.auth?.login && experimentalTools.auth?.enabled && isDevelopment) {\n registerTool(\n mcpAccessSettings.auth.login,\n 'Login',\n () => loginTool(server, req, useVerboseLogs),\n payload,\n useVerboseLogs,\n )\n }\n\n if (mcpAccessSettings.auth?.verify && experimentalTools.auth?.enabled && isDevelopment) {\n registerTool(\n mcpAccessSettings.auth.verify,\n 'Verify',\n () => verifyTool(server, req, useVerboseLogs),\n payload,\n useVerboseLogs,\n )\n }\n\n if (mcpAccessSettings.auth?.resetPassword && experimentalTools.auth?.enabled) {\n registerTool(\n mcpAccessSettings.auth.resetPassword,\n 'Reset Password',\n () => resetPasswordTool(server, req, useVerboseLogs),\n payload,\n useVerboseLogs,\n )\n }\n\n if (mcpAccessSettings.auth?.forgotPassword && experimentalTools.auth?.enabled) {\n registerTool(\n mcpAccessSettings.auth.forgotPassword,\n 'Forgot Password',\n () => forgotPasswordTool(server, req, useVerboseLogs),\n payload,\n useVerboseLogs,\n )\n }\n\n if (mcpAccessSettings.auth?.unlock && experimentalTools.auth?.enabled) {\n registerTool(\n mcpAccessSettings.auth.unlock,\n 'Unlock',\n () => unlockTool(server, req, useVerboseLogs),\n payload,\n useVerboseLogs,\n )\n }\n\n if (useVerboseLogs) {\n payload.logger.info('[payload-mcp] 🚀 MCP Server Ready.')\n }\n },\n {\n serverInfo: serverOptions.serverInfo,\n },\n {\n basePath: MCPHandlerOptions.basePath || payload.config.routes?.api || '/api',\n disableSse: MCPHandlerOptions.disableSse ?? true,\n maxDuration: MCPHandlerOptions.maxDuration || 60,\n onEvent: MCPHandlerOptions.onEvent,\n redisUrl: MCPHandlerOptions.redisUrl,\n verboseLogs: useVerboseLogs,\n },\n )\n } catch (error) {\n throw new APIError(`Error initializing MCP handler: ${String(error)}`, 500)\n }\n}\n"],"names":["createMcpHandler","join","APIError","configToJSONSchema","toCamelCase","getEnabledSlugs","getCollectionVirtualFieldNames","getGlobalVirtualFieldNames","removeVirtualFieldsFromSchema","registerTool","findGlobalTool","updateGlobalTool","createResourceTool","deleteResourceTool","findResourceTool","updateResourceTool","authTool","forgotPasswordTool","loginTool","resetPasswordTool","unlockTool","verifyTool","createCollectionTool","deleteCollectionTool","findCollectionTool","updateCollectionTool","findConfigTool","updateConfigTool","createJobTool","runJobTool","updateJobTool","getMCPHandler","pluginOptions","mcpAccessSettings","req","payload","configSchema","config","db","defaultIDType","i18n","forceInlineBlocks","wrapHandler","handler","args","_extra","length","handlerArgs","slice","payloadToolHandler","payloadPromptHandler","payloadResourceHandler","user","MCPOptions","mcp","customMCPTools","tools","customMCPPrompts","prompts","customMCPResources","resources","MCPHandlerOptions","handlerOptions","serverOptions","useVerboseLogs","verboseLogs","isDevelopment","process","env","NODE_ENV","experimentalTools","experimental","collectionsPluginConfig","collections","globalsPluginConfig","globals","collectionsDirPath","cwd","configFilePath","jobsDirPath","jobs","server","enabledCollectionSlugs","forEach","enabledCollectionSlug","rawSchema","definitions","virtualFieldNames","schema","JSON","parse","stringify","toolCapabilities","allowCreate","create","allowUpdate","update","allowFind","find","allowDelete","delete","error","String","enabledGlobalSlugs","enabledGlobalSlug","tool","camelCasedToolName","name","isToolEnabled","description","inputSchema","parameters","prompt","camelCasedPromptName","isPromptEnabled","registerPrompt","argsSchema","title","logger","info","resource","camelCasedResourceName","isResourceEnabled","registerResource","uri","mimeType","enabled","run","auth","login","verify","resetPassword","forgotPassword","unlock","serverInfo","basePath","routes","api","disableSse","maxDuration","onEvent","redisUrl"],"mappings":"AAEA,SAASA,gBAAgB,QAAQ,cAAa;AAC9C,SAASC,IAAI,QAAQ,OAAM;AAC3B,SAASC,QAAQ,EAAEC,kBAAkB,QAA6C,UAAS;AAI3F,SAASC,WAAW,QAAQ,wBAAuB;AACnD,SAASC,eAAe,QAAQ,8BAA6B;AAC7D,SACEC,8BAA8B,EAC9BC,0BAA0B,QACrB,mCAAkC;AACzC,SAASC,6BAA6B,QAAQ,6DAA4D;AAC1G,SAASC,YAAY,QAAQ,oBAAmB;AAEhD,QAAQ;AACR,SAASC,cAAc,QAAQ,yBAAwB;AACvD,SAASC,gBAAgB,QAAQ,2BAA0B;AAC3D,SAASC,kBAAkB,QAAQ,6BAA4B;AAC/D,SAASC,kBAAkB,QAAQ,6BAA4B;AAC/D,SAASC,gBAAgB,QAAQ,2BAA0B;AAC3D,SAASC,kBAAkB,QAAQ,6BAA4B;AAE/D,qBAAqB;AACrB;;CAEC,GACD,SAASC,QAAQ,QAAQ,uBA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AEG,iBAAiB7D,kBAAkB0D,IAAI,EAAEF,SAAS;gBAC5ErH,aACEwB,kBAAkB+F,IAAI,CAACG,aAAa,EACpC,kBACA,IAAMhH,kBAAkB8D,QAAQ/C,KAAK8B,iBACrC7B,SACA6B;YAEJ;YAEA,IAAI/B,kBAAkB+F,IAAI,EAAEI,kBAAkB9D,kBAAkB0D,IAAI,EAAEF,SAAS;gBAC7ErH,aACEwB,kBAAkB+F,IAAI,CAACI,cAAc,EACrC,mBACA,IAAMnH,mBAAmBgE,QAAQ/C,KAAK8B,iBACtC7B,SACA6B;YAEJ;YAEA,IAAI/B,kBAAkB+F,IAAI,EAAEK,UAAU/D,kBAAkB0D,IAAI,EAAEF,SAAS;gBACrErH,aACEwB,kBAAkB+F,IAAI,CAACK,MAAM,EAC7B,UACA,IAAMjH,WAAW6D,QAAQ/C,KAAK8B,iBAC9B7B,SACA6B;YAEJ;YAEA,IAAIA,gBAAgB;gBAClB7B,QAAQmF,MAAM,CAACC,IAAI,CAAC;YACtB;QACF,GACA;YACEe,YAAYvE,cAAcuE,UAAU;QACtC,GACA;YACEC,UAAU1E,kBAAkB0E,QAAQ,IAAIpG,QAAQE,MAAM,CAACmG,MAAM,EAAEC,OAAO;YACtEC,YAAY7E,kBAAkB6E,UAAU,IAAI;YAC5CC,aAAa9E,kBAAkB8E,WAAW,IAAI;YAC9CC,SAAS/E,kBAAkB+E,OAAO;YAClCC,UAAUhF,kBAAkBgF,QAAQ;YACpC5E,aAAaD;QACf;IAEJ,EAAE,OAAOqC,OAAO;QACd,MAAM,IAAInG,SAAS,CAAC,gCAAgC,EAAEoG,OAAOD,QAAQ,EAAE;IACzE;AACF,EAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@payloadcms/plugin-mcp",
|
|
3
|
-
"version": "3.79.
|
|
3
|
+
"version": "3.79.1",
|
|
4
4
|
"description": "MCP (Model Context Protocol) capabilities with Payload",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"plugin",
|
|
@@ -37,18 +37,18 @@
|
|
|
37
37
|
"dist"
|
|
38
38
|
],
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@modelcontextprotocol/sdk": "1.
|
|
40
|
+
"@modelcontextprotocol/sdk": "1.27.1",
|
|
41
41
|
"@types/json-schema": "7.0.15",
|
|
42
42
|
"json-schema-to-zod": "2.6.1",
|
|
43
43
|
"mcp-handler": "^1.0.7",
|
|
44
44
|
"zod": "^3.25.50"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
|
-
"payload": "3.79.
|
|
47
|
+
"payload": "3.79.1",
|
|
48
48
|
"@payloadcms/eslint-config": "3.28.0"
|
|
49
49
|
},
|
|
50
50
|
"peerDependencies": {
|
|
51
|
-
"payload": "3.79.
|
|
51
|
+
"payload": "3.79.1"
|
|
52
52
|
},
|
|
53
53
|
"homepage:": "https://payloadcms.com",
|
|
54
54
|
"scripts": {
|
package/src/mcp/getMcpHandler.ts
CHANGED
|
@@ -49,7 +49,9 @@ export const getMCPHandler = (
|
|
|
49
49
|
req: PayloadRequest,
|
|
50
50
|
) => {
|
|
51
51
|
const { payload } = req
|
|
52
|
-
const configSchema = configToJSONSchema(payload.config, payload.db.defaultIDType, req.i18n
|
|
52
|
+
const configSchema = configToJSONSchema(payload.config, payload.db.defaultIDType, req.i18n, {
|
|
53
|
+
forceInlineBlocks: true,
|
|
54
|
+
})
|
|
53
55
|
|
|
54
56
|
// Handler wrapper that injects req before the _extra argument
|
|
55
57
|
const wrapHandler = (handler: (...args: any[]) => any) => {
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"conversion.d.ts","sourceRoot":"","sources":["../../../src/mcp/helpers/conversion.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,WAAW,QAAS,MAAM,KAAG,MAEzC,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/mcp/helpers/conversion.ts"],"sourcesContent":["export const toCamelCase = (str: string): string => {\n return str.replace(/-([a-z])/g, (match, letter) => letter.toUpperCase())\n}\n"],"names":["toCamelCase","str","replace","match","letter","toUpperCase"],"mappings":"AAAA,OAAO,MAAMA,cAAc,CAACC;IAC1B,OAAOA,IAAIC,OAAO,CAAC,aAAa,CAACC,OAAOC,SAAWA,OAAOC,WAAW;AACvE,EAAC"}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Validates collection-specific data for resource creation
|
|
3
|
-
*/
|
|
4
|
-
export declare function validateCollectionData(collection: string, data: Record<string, unknown>, availableCollections: string[]): null | string;
|
|
5
|
-
/**
|
|
6
|
-
* Checks if a collection slug is valid
|
|
7
|
-
*/
|
|
8
|
-
export declare function validateCollectionSlug(collection: string, collections: Partial<Record<string, true>>): string | undefined;
|
|
9
|
-
//# sourceMappingURL=validation.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../../../src/mcp/helpers/validation.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,wBAAgB,sBAAsB,CACpC,UAAU,EAAE,MAAM,EAClB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,oBAAoB,EAAE,MAAM,EAAE,GAC7B,IAAI,GAAG,MAAM,CAWf;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CACpC,UAAU,EAAE,MAAM,EAClB,WAAW,EAAE,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC,sBAM3C"}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Validates collection-specific data for resource creation
|
|
3
|
-
*/ export function validateCollectionData(collection, data, availableCollections) {
|
|
4
|
-
// Check if collection exists
|
|
5
|
-
if (!availableCollections.includes(collection)) {
|
|
6
|
-
return `Unknown collection: ${collection}. Available collections: ${availableCollections.join(', ')}`;
|
|
7
|
-
}
|
|
8
|
-
if (!data || typeof data !== 'object' || Object.keys(data).length === 0) {
|
|
9
|
-
return `Collection "${collection}" requires data to be provided`;
|
|
10
|
-
}
|
|
11
|
-
return null;
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* Checks if a collection slug is valid
|
|
15
|
-
*/ export function validateCollectionSlug(collection, collections) {
|
|
16
|
-
const collectionSlugs = Object.keys(collections);
|
|
17
|
-
if (!collectionSlugs.includes(collection)) {
|
|
18
|
-
return `Collection "${collection}" is not valid`;
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
//# sourceMappingURL=validation.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/mcp/helpers/validation.ts"],"sourcesContent":["/**\n * Validates collection-specific data for resource creation\n */\nexport function validateCollectionData(\n collection: string,\n data: Record<string, unknown>,\n availableCollections: string[],\n): null | string {\n // Check if collection exists\n if (!availableCollections.includes(collection)) {\n return `Unknown collection: ${collection}. Available collections: ${availableCollections.join(', ')}`\n }\n\n if (!data || typeof data !== 'object' || Object.keys(data).length === 0) {\n return `Collection \"${collection}\" requires data to be provided`\n }\n\n return null\n}\n\n/**\n * Checks if a collection slug is valid\n */\nexport function validateCollectionSlug(\n collection: string,\n collections: Partial<Record<string, true>>,\n) {\n const collectionSlugs = Object.keys(collections)\n if (!collectionSlugs.includes(collection)) {\n return `Collection \"${collection}\" is not valid`\n }\n}\n"],"names":["validateCollectionData","collection","data","availableCollections","includes","join","Object","keys","length","validateCollectionSlug","collections","collectionSlugs"],"mappings":"AAAA;;CAEC,GACD,OAAO,SAASA,uBACdC,UAAkB,EAClBC,IAA6B,EAC7BC,oBAA8B;IAE9B,6BAA6B;IAC7B,IAAI,CAACA,qBAAqBC,QAAQ,CAACH,aAAa;QAC9C,OAAO,CAAC,oBAAoB,EAAEA,WAAW,yBAAyB,EAAEE,qBAAqBE,IAAI,CAAC,OAAO;IACvG;IAEA,IAAI,CAACH,QAAQ,OAAOA,SAAS,YAAYI,OAAOC,IAAI,CAACL,MAAMM,MAAM,KAAK,GAAG;QACvE,OAAO,CAAC,YAAY,EAAEP,WAAW,8BAA8B,CAAC;IAClE;IAEA,OAAO;AACT;AAEA;;CAEC,GACD,OAAO,SAASQ,uBACdR,UAAkB,EAClBS,WAA0C;IAE1C,MAAMC,kBAAkBL,OAAOC,IAAI,CAACG;IACpC,IAAI,CAACC,gBAAgBP,QAAQ,CAACH,aAAa;QACzC,OAAO,CAAC,YAAY,EAAEA,WAAW,cAAc,CAAC;IAClD;AACF"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"convertCollectionSchemaToZod.d.ts","sourceRoot":"","sources":["../../src/utils/convertCollectionSchemaToZod.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAsD9C,eAAO,MAAM,4BAA4B,WAAY,WAAW,QAwC/D,CAAA"}
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
import { jsonSchemaToZod } from 'json-schema-to-zod';
|
|
2
|
-
import * as ts from 'typescript';
|
|
3
|
-
import { z } from 'zod';
|
|
4
|
-
import { transformPointFieldsForMCP } from './transformPointFields.js';
|
|
5
|
-
/**
|
|
6
|
-
* Recursively processes JSON schema properties to simplify relationship fields.
|
|
7
|
-
* For create/update validation we only need to accept IDs (string/number),
|
|
8
|
-
* not populated objects. This removes the $ref option from oneOf unions
|
|
9
|
-
* that represent relationship fields, leaving only the ID shape.
|
|
10
|
-
*
|
|
11
|
-
* NOTE: This function must operate on a cloned schema to avoid mutating
|
|
12
|
-
* the original JSON schema used for tool listing.
|
|
13
|
-
*/ function simplifyRelationshipFields(schema) {
|
|
14
|
-
if (!schema || typeof schema !== 'object') {
|
|
15
|
-
return schema;
|
|
16
|
-
}
|
|
17
|
-
const processed = {
|
|
18
|
-
...schema
|
|
19
|
-
};
|
|
20
|
-
if (Array.isArray(processed.oneOf)) {
|
|
21
|
-
const hasRef = processed.oneOf.some((option)=>option && typeof option === 'object' && '$ref' in option);
|
|
22
|
-
processed.oneOf = processed.oneOf.map((option)=>{
|
|
23
|
-
if (option && typeof option === 'object' && '$ref' in option) {
|
|
24
|
-
// Replace unresolved $ref with a permissive object schema to keep the union shape
|
|
25
|
-
return {
|
|
26
|
-
type: 'object',
|
|
27
|
-
additionalProperties: true
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
return simplifyRelationshipFields(option);
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
if (processed.properties && typeof processed.properties === 'object') {
|
|
34
|
-
processed.properties = Object.fromEntries(Object.entries(processed.properties).map(([key, value])=>[
|
|
35
|
-
key,
|
|
36
|
-
simplifyRelationshipFields(value)
|
|
37
|
-
]));
|
|
38
|
-
}
|
|
39
|
-
if (processed.items && typeof processed.items === 'object' && !Array.isArray(processed.items)) {
|
|
40
|
-
processed.items = simplifyRelationshipFields(processed.items);
|
|
41
|
-
}
|
|
42
|
-
return processed;
|
|
43
|
-
}
|
|
44
|
-
export const convertCollectionSchemaToZod = (schema)=>{
|
|
45
|
-
// Clone to avoid mutating the original schema (used elsewhere for tool listing)
|
|
46
|
-
const schemaClone = JSON.parse(JSON.stringify(schema));
|
|
47
|
-
// Remove properties that should not be included in the Zod schema
|
|
48
|
-
delete schemaClone?.properties?.id;
|
|
49
|
-
delete schemaClone?.properties?.createdAt;
|
|
50
|
-
delete schemaClone?.properties?.updatedAt;
|
|
51
|
-
if (Array.isArray(schemaClone.required)) {
|
|
52
|
-
schemaClone.required = schemaClone.required.filter((field)=>field !== 'id');
|
|
53
|
-
if (schemaClone.required.length === 0) {
|
|
54
|
-
delete schemaClone.required;
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
const pointTransformed = transformPointFieldsForMCP(schemaClone);
|
|
58
|
-
const simplifiedSchema = simplifyRelationshipFields(pointTransformed);
|
|
59
|
-
const zodSchemaAsString = jsonSchemaToZod(simplifiedSchema);
|
|
60
|
-
// Transpile TypeScript to JavaScript
|
|
61
|
-
const transpileResult = ts.transpileModule(zodSchemaAsString, {
|
|
62
|
-
compilerOptions: {
|
|
63
|
-
module: ts.ModuleKind.CommonJS,
|
|
64
|
-
removeComments: true,
|
|
65
|
-
strict: false,
|
|
66
|
-
target: ts.ScriptTarget.ES2018
|
|
67
|
-
}
|
|
68
|
-
});
|
|
69
|
-
/**
|
|
70
|
-
* This Function evaluation is safe because:
|
|
71
|
-
* 1. The input schema comes from Payload's collection configuration, which is controlled by the application developer
|
|
72
|
-
* 2. The jsonSchemaToZod library converts JSON Schema to Zod schema definitions, producing only type validation code
|
|
73
|
-
* 3. The transpiled output contains only Zod schema definitions (z.string(), z.number(), etc.) - no executable logic
|
|
74
|
-
* 4. The resulting Zod schema is used only for parameter validation in MCP tools, not for data processing
|
|
75
|
-
* 5. No user input or external data is involved in the schema generation process
|
|
76
|
-
*/ // eslint-disable-next-line @typescript-eslint/no-implied-eval
|
|
77
|
-
return new Function('z', `return ${transpileResult.outputText}`)(z);
|
|
78
|
-
};
|
|
79
|
-
|
|
80
|
-
//# sourceMappingURL=convertCollectionSchemaToZod.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/convertCollectionSchemaToZod.ts"],"sourcesContent":["import type { JSONSchema4 } from 'json-schema'\n\nimport { jsonSchemaToZod } from 'json-schema-to-zod'\nimport * as ts from 'typescript'\nimport { z } from 'zod'\n\nimport { transformPointFieldsForMCP } from './transformPointFields.js'\n\n/**\n * Recursively processes JSON schema properties to simplify relationship fields.\n * For create/update validation we only need to accept IDs (string/number),\n * not populated objects. This removes the $ref option from oneOf unions\n * that represent relationship fields, leaving only the ID shape.\n *\n * NOTE: This function must operate on a cloned schema to avoid mutating\n * the original JSON schema used for tool listing.\n */\nfunction simplifyRelationshipFields(schema: JSONSchema4): JSONSchema4 {\n if (!schema || typeof schema !== 'object') {\n return schema\n }\n\n const processed = { ...schema }\n\n if (Array.isArray(processed.oneOf)) {\n const hasRef = processed.oneOf.some(\n (option) => option && typeof option === 'object' && '$ref' in option,\n )\n\n processed.oneOf = processed.oneOf.map((option) => {\n if (option && typeof option === 'object' && '$ref' in option) {\n // Replace unresolved $ref with a permissive object schema to keep the union shape\n return { type: 'object', additionalProperties: true }\n }\n return simplifyRelationshipFields(option)\n })\n }\n\n if (processed.properties && typeof processed.properties === 'object') {\n processed.properties = Object.fromEntries(\n Object.entries(processed.properties).map(([key, value]) => [\n key,\n simplifyRelationshipFields(value),\n ]),\n )\n }\n\n if (processed.items && typeof processed.items === 'object' && !Array.isArray(processed.items)) {\n processed.items = simplifyRelationshipFields(processed.items)\n }\n\n return processed\n}\n\nexport const convertCollectionSchemaToZod = (schema: JSONSchema4) => {\n // Clone to avoid mutating the original schema (used elsewhere for tool listing)\n const schemaClone = JSON.parse(JSON.stringify(schema)) as JSONSchema4\n\n // Remove properties that should not be included in the Zod schema\n delete schemaClone?.properties?.id\n delete schemaClone?.properties?.createdAt\n delete schemaClone?.properties?.updatedAt\n if (Array.isArray(schemaClone.required)) {\n schemaClone.required = schemaClone.required.filter((field) => field !== 'id')\n if (schemaClone.required.length === 0) {\n delete schemaClone.required\n }\n }\n\n const pointTransformed = transformPointFieldsForMCP(schemaClone)\n const simplifiedSchema = simplifyRelationshipFields(pointTransformed)\n\n const zodSchemaAsString = jsonSchemaToZod(simplifiedSchema)\n\n // Transpile TypeScript to JavaScript\n const transpileResult = ts.transpileModule(zodSchemaAsString, {\n compilerOptions: {\n module: ts.ModuleKind.CommonJS,\n removeComments: true,\n strict: false,\n target: ts.ScriptTarget.ES2018,\n },\n })\n\n /**\n * This Function evaluation is safe because:\n * 1. The input schema comes from Payload's collection configuration, which is controlled by the application developer\n * 2. The jsonSchemaToZod library converts JSON Schema to Zod schema definitions, producing only type validation code\n * 3. The transpiled output contains only Zod schema definitions (z.string(), z.number(), etc.) - no executable logic\n * 4. The resulting Zod schema is used only for parameter validation in MCP tools, not for data processing\n * 5. No user input or external data is involved in the schema generation process\n */\n // eslint-disable-next-line @typescript-eslint/no-implied-eval\n return new Function('z', `return ${transpileResult.outputText}`)(z)\n}\n"],"names":["jsonSchemaToZod","ts","z","transformPointFieldsForMCP","simplifyRelationshipFields","schema","processed","Array","isArray","oneOf","hasRef","some","option","map","type","additionalProperties","properties","Object","fromEntries","entries","key","value","items","convertCollectionSchemaToZod","schemaClone","JSON","parse","stringify","id","createdAt","updatedAt","required","filter","field","length","pointTransformed","simplifiedSchema","zodSchemaAsString","transpileResult","transpileModule","compilerOptions","module","ModuleKind","CommonJS","removeComments","strict","target","ScriptTarget","ES2018","Function","outputText"],"mappings":"AAEA,SAASA,eAAe,QAAQ,qBAAoB;AACpD,YAAYC,QAAQ,aAAY;AAChC,SAASC,CAAC,QAAQ,MAAK;AAEvB,SAASC,0BAA0B,QAAQ,4BAA2B;AAEtE;;;;;;;;CAQC,GACD,SAASC,2BAA2BC,MAAmB;IACrD,IAAI,CAACA,UAAU,OAAOA,WAAW,UAAU;QACzC,OAAOA;IACT;IAEA,MAAMC,YAAY;QAAE,GAAGD,MAAM;IAAC;IAE9B,IAAIE,MAAMC,OAAO,CAACF,UAAUG,KAAK,GAAG;QAClC,MAAMC,SAASJ,UAAUG,KAAK,CAACE,IAAI,CACjC,CAACC,SAAWA,UAAU,OAAOA,WAAW,YAAY,UAAUA;QAGhEN,UAAUG,KAAK,GAAGH,UAAUG,KAAK,CAACI,GAAG,CAAC,CAACD;YACrC,IAAIA,UAAU,OAAOA,WAAW,YAAY,UAAUA,QAAQ;gBAC5D,kFAAkF;gBAClF,OAAO;oBAAEE,MAAM;oBAAUC,sBAAsB;gBAAK;YACtD;YACA,OAAOX,2BAA2BQ;QACpC;IACF;IAEA,IAAIN,UAAUU,UAAU,IAAI,OAAOV,UAAUU,UAAU,KAAK,UAAU;QACpEV,UAAUU,UAAU,GAAGC,OAAOC,WAAW,CACvCD,OAAOE,OAAO,CAACb,UAAUU,UAAU,EAAEH,GAAG,CAAC,CAAC,CAACO,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PointFields.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAE9C,wBAAgB,0BAA0B,CAAC,MAAM,EAAE,WAAW,GAAG,WAAW,CAoD3E"}
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
export function transformPointFieldsForMCP(schema) {
|
|
2
|
-
if (!schema || typeof schema !== 'object') {
|
|
3
|
-
return schema;
|
|
4
|
-
}
|
|
5
|
-
const transformed = {
|
|
6
|
-
...schema
|
|
7
|
-
};
|
|
8
|
-
if (transformed.properties && typeof transformed.properties === 'object') {
|
|
9
|
-
transformed.properties = Object.fromEntries(Object.entries(transformed.properties).map(([key, value])=>{
|
|
10
|
-
const isArrayType = value.type === 'array' || Array.isArray(value.type) && value.type.includes('array');
|
|
11
|
-
if (value && typeof value === 'object' && isArrayType && Array.isArray(value.items) && value.items.length === 2 && value.items.every((item)=>item?.type === 'number')) {
|
|
12
|
-
// Transform to object format
|
|
13
|
-
const isNullable = Array.isArray(value.type) && value.type.includes('null');
|
|
14
|
-
return [
|
|
15
|
-
key,
|
|
16
|
-
{
|
|
17
|
-
type: isNullable ? [
|
|
18
|
-
'object',
|
|
19
|
-
'null'
|
|
20
|
-
] : 'object',
|
|
21
|
-
description: value.description || 'Geographic coordinates (longitude, latitude)',
|
|
22
|
-
properties: {
|
|
23
|
-
latitude: {
|
|
24
|
-
type: 'number',
|
|
25
|
-
description: 'Latitude coordinate'
|
|
26
|
-
},
|
|
27
|
-
longitude: {
|
|
28
|
-
type: 'number',
|
|
29
|
-
description: 'Longitude coordinate'
|
|
30
|
-
}
|
|
31
|
-
},
|
|
32
|
-
required: [
|
|
33
|
-
'longitude',
|
|
34
|
-
'latitude'
|
|
35
|
-
]
|
|
36
|
-
}
|
|
37
|
-
];
|
|
38
|
-
}
|
|
39
|
-
return [
|
|
40
|
-
key,
|
|
41
|
-
transformPointFieldsForMCP(value)
|
|
42
|
-
];
|
|
43
|
-
}));
|
|
44
|
-
}
|
|
45
|
-
if (transformed.items && typeof transformed.items === 'object' && !Array.isArray(transformed.items)) {
|
|
46
|
-
transformed.items = transformPointFieldsForMCP(transformed.items);
|
|
47
|
-
}
|
|
48
|
-
return transformed;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
//# sourceMappingURL=transformPointFields.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/transformPointFields.ts"],"sourcesContent":["import type { JSONSchema4 } from 'json-schema'\n\nexport function transformPointFieldsForMCP(schema: JSONSchema4): JSONSchema4 {\n if (!schema || typeof schema !== 'object') {\n return schema\n }\n\n const transformed = { ...schema }\n\n if (transformed.properties && typeof transformed.properties === 'object') {\n transformed.properties = Object.fromEntries(\n Object.entries(transformed.properties).map(([key, value]) => {\n const isArrayType =\n value.type === 'array' || (Array.isArray(value.type) && value.type.includes('array'))\n\n if (\n value &&\n typeof value === 'object' &&\n isArrayType &&\n Array.isArray(value.items) &&\n value.items.length === 2 &&\n value.items.every((item: JSONSchema4) => item?.type === 'number')\n ) {\n // Transform to object format\n const isNullable = Array.isArray(value.type) && value.type.includes('null')\n\n return [\n key,\n {\n type: isNullable ? ['object', 'null'] : 'object',\n description: value.description || 'Geographic coordinates (longitude, latitude)',\n properties: {\n latitude: { type: 'number', description: 'Latitude coordinate' },\n longitude: { type: 'number', description: 'Longitude coordinate' },\n },\n required: ['longitude', 'latitude'],\n },\n ]\n }\n\n return [key, transformPointFieldsForMCP(value)]\n }),\n )\n }\n\n if (\n transformed.items &&\n typeof transformed.items === 'object' &&\n !Array.isArray(transformed.items)\n ) {\n transformed.items = transformPointFieldsForMCP(transformed.items)\n }\n\n return transformed\n}\n"],"names":["transformPointFieldsForMCP","schema","transformed","properties","Object","fromEntries","entries","map","key","value","isArrayType","type","Array","isArray","includes","items","length","every","item","isNullable","description","latitude","longitude","required"],"mappings":"AAEA,OAAO,SAASA,2BAA2BC,MAAmB;IAC5D,IAAI,CAACA,UAAU,OAAOA,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