@payloadcms/plugin-mcp 3.64.0-internal.deef021 → 3.64.0
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/collections/createApiKeysCollection.d.ts.map +1 -1
- package/dist/collections/createApiKeysCollection.js +6 -0
- package/dist/collections/createApiKeysCollection.js.map +1 -1
- package/dist/endpoints/mcp.d.ts.map +1 -1
- package/dist/endpoints/mcp.js +30 -24
- package/dist/endpoints/mcp.js.map +1 -1
- package/dist/index.d.ts +7 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/mcp/createRequest.d.ts.map +1 -1
- package/dist/mcp/createRequest.js +2 -2
- package/dist/mcp/createRequest.js.map +1 -1
- package/dist/mcp/getMcpHandler.d.ts.map +1 -1
- package/dist/mcp/getMcpHandler.js +10 -8
- package/dist/mcp/getMcpHandler.js.map +1 -1
- package/dist/mcp/tools/resource/create.d.ts.map +1 -1
- package/dist/mcp/tools/resource/create.js +1 -0
- package/dist/mcp/tools/resource/create.js.map +1 -1
- package/dist/mcp/tools/resource/delete.d.ts.map +1 -1
- package/dist/mcp/tools/resource/delete.js +1 -0
- package/dist/mcp/tools/resource/delete.js.map +1 -1
- package/dist/mcp/tools/resource/find.d.ts.map +1 -1
- package/dist/mcp/tools/resource/find.js +2 -0
- package/dist/mcp/tools/resource/find.js.map +1 -1
- package/dist/mcp/tools/resource/update.d.ts.map +1 -1
- package/dist/mcp/tools/resource/update.js +2 -0
- package/dist/mcp/tools/resource/update.js.map +1 -1
- package/dist/types.d.ts +13 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +3 -3
- package/src/collections/createApiKeysCollection.ts +7 -0
- package/src/endpoints/mcp.ts +42 -30
- package/src/index.ts +8 -1
- package/src/mcp/createRequest.ts +2 -2
- package/src/mcp/getMcpHandler.ts +10 -7
- package/src/mcp/tools/resource/create.ts +1 -0
- package/src/mcp/tools/resource/delete.ts +1 -0
- package/src/mcp/tools/resource/find.ts +2 -0
- package/src/mcp/tools/resource/update.ts +2 -0
- package/src/types.ts +18 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createApiKeysCollection.d.ts","sourceRoot":"","sources":["../../src/collections/createApiKeysCollection.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAE/C,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"createApiKeysCollection.d.ts","sourceRoot":"","sources":["../../src/collections/createApiKeysCollection.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAE/C,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAA;AAkHxD,eAAO,MAAM,uBAAuB,gBACrB,qBAAqB,CAAC,aAAa,CAAC,eACpC,KAAK,CAAC;IAAE,WAAW,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC,iCACtC,WAAW,CAAC,qBAAqB,CAAC,cAAc,CAAC,CAAC,CAAC,OAAO,CAAC,6BAC/D,qBAAqB,KACnC,gBAmWF,CAAA"}
|
|
@@ -13,6 +13,7 @@ const addEnabledCollectionTools = (collections)=>{
|
|
|
13
13
|
return enabledCollectionSlugs.map((enabledCollectionSlug)=>({
|
|
14
14
|
type: 'collapsible',
|
|
15
15
|
admin: {
|
|
16
|
+
description: `Manage client access to ${enabledCollectionSlug}`,
|
|
16
17
|
position: 'sidebar'
|
|
17
18
|
},
|
|
18
19
|
fields: [
|
|
@@ -112,6 +113,7 @@ export const createAPIKeysCollection = (collections, customTools = [], experimen
|
|
|
112
113
|
return {
|
|
113
114
|
slug: 'payload-mcp-api-keys',
|
|
114
115
|
admin: {
|
|
116
|
+
description: 'API keys control which collections, resources, tools, and prompts MCP clients can access',
|
|
115
117
|
group: 'MCP',
|
|
116
118
|
useAsTitle: 'label'
|
|
117
119
|
},
|
|
@@ -148,6 +150,7 @@ export const createAPIKeysCollection = (collections, customTools = [], experimen
|
|
|
148
150
|
{
|
|
149
151
|
type: 'collapsible',
|
|
150
152
|
admin: {
|
|
153
|
+
description: 'Manage client access to tools',
|
|
151
154
|
position: 'sidebar'
|
|
152
155
|
},
|
|
153
156
|
fields: [
|
|
@@ -165,6 +168,7 @@ export const createAPIKeysCollection = (collections, customTools = [], experimen
|
|
|
165
168
|
{
|
|
166
169
|
type: 'collapsible',
|
|
167
170
|
admin: {
|
|
171
|
+
description: 'Manage client access to resources',
|
|
168
172
|
position: 'sidebar'
|
|
169
173
|
},
|
|
170
174
|
fields: [
|
|
@@ -182,6 +186,7 @@ export const createAPIKeysCollection = (collections, customTools = [], experimen
|
|
|
182
186
|
{
|
|
183
187
|
type: 'collapsible',
|
|
184
188
|
admin: {
|
|
189
|
+
description: 'Manage client access to prompts',
|
|
185
190
|
position: 'sidebar'
|
|
186
191
|
},
|
|
187
192
|
fields: [
|
|
@@ -200,6 +205,7 @@ export const createAPIKeysCollection = (collections, customTools = [], experimen
|
|
|
200
205
|
{
|
|
201
206
|
type: 'collapsible',
|
|
202
207
|
admin: {
|
|
208
|
+
description: 'Manage client access to experimental tools',
|
|
203
209
|
position: 'sidebar'
|
|
204
210
|
},
|
|
205
211
|
fields: [
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/collections/createApiKeysCollection.ts"],"sourcesContent":["import type { CollectionConfig } from 'payload'\n\nimport type { PluginMCPServerConfig } from '../types.js'\n\nimport { toCamelCase } from '../utils/camelCase.js'\n\nconst addEnabledCollectionTools = (collections: PluginMCPServerConfig['collections']) => {\n const enabledCollectionSlugs = Object.keys(collections || {}).filter((collection) => {\n const fullyEnabled =\n typeof collections?.[collection]?.enabled === 'boolean' && collections?.[collection]?.enabled\n\n if (fullyEnabled) {\n return true\n }\n\n const partiallyEnabled =\n typeof collections?.[collection]?.enabled !== 'boolean' &&\n ((typeof collections?.[collection]?.enabled?.find === 'boolean' &&\n collections?.[collection]?.enabled?.find === true) ||\n (typeof collections?.[collection]?.enabled?.create === 'boolean' &&\n collections?.[collection]?.enabled?.create === true) ||\n (typeof collections?.[collection]?.enabled?.update === 'boolean' &&\n collections?.[collection]?.enabled?.update === true) ||\n (typeof collections?.[collection]?.enabled?.delete === 'boolean' &&\n collections?.[collection]?.enabled?.delete === true))\n\n if (partiallyEnabled) {\n return true\n }\n })\n return enabledCollectionSlugs.map((enabledCollectionSlug) => ({\n type: 'collapsible' as const,\n admin: {\n position: 'sidebar' as const,\n },\n fields: [\n {\n name: `${toCamelCase(enabledCollectionSlug)}`,\n type: 'group' as const,\n fields: [\n ...(collections?.[enabledCollectionSlug]?.enabled === true ||\n (typeof collections?.[enabledCollectionSlug]?.enabled !== 'boolean' &&\n typeof collections?.[enabledCollectionSlug]?.enabled?.find === 'boolean' &&\n collections?.[enabledCollectionSlug]?.enabled?.find === true)\n ? [\n {\n name: `find`,\n type: 'checkbox' as const,\n admin: {\n description: `Allow clients to find ${enabledCollectionSlug}.`,\n },\n defaultValue: false,\n label: 'Find',\n },\n ]\n : []),\n\n ...(collections?.[enabledCollectionSlug]?.enabled === true ||\n (typeof collections?.[enabledCollectionSlug]?.enabled !== 'boolean' &&\n typeof collections?.[enabledCollectionSlug]?.enabled?.create === 'boolean' &&\n collections?.[enabledCollectionSlug]?.enabled?.create === true)\n ? [\n {\n name: `create`,\n type: 'checkbox' as const,\n admin: {\n description: `Allow clients to create ${enabledCollectionSlug}.`,\n },\n defaultValue: false,\n label: 'Create',\n },\n ]\n : []),\n\n ...(collections?.[enabledCollectionSlug]?.enabled === true ||\n (typeof collections?.[enabledCollectionSlug]?.enabled !== 'boolean' &&\n typeof collections?.[enabledCollectionSlug]?.enabled?.update === 'boolean' &&\n collections?.[enabledCollectionSlug]?.enabled?.update === true)\n ? [\n {\n name: `update`,\n type: 'checkbox' as const,\n admin: {\n description: `Allow clients to update ${enabledCollectionSlug}.`,\n },\n defaultValue: false,\n label: 'Update',\n },\n ]\n : []),\n\n ...(collections?.[enabledCollectionSlug]?.enabled === true ||\n (typeof collections?.[enabledCollectionSlug]?.enabled !== 'boolean' &&\n typeof collections?.[enabledCollectionSlug]?.enabled?.delete === 'boolean' &&\n collections?.[enabledCollectionSlug]?.enabled?.delete === true)\n ? [\n {\n name: `delete`,\n type: 'checkbox' as const,\n admin: {\n description: `Allow clients to delete ${enabledCollectionSlug}.`,\n },\n defaultValue: false,\n label: 'Delete',\n },\n ]\n : []),\n ],\n label: false as const,\n },\n ],\n label: `${enabledCollectionSlug.charAt(0).toUpperCase() + toCamelCase(enabledCollectionSlug).slice(1)}`,\n }))\n}\n\nexport const createAPIKeysCollection = (\n collections: PluginMCPServerConfig['collections'],\n customTools: Array<{ description: string; name: string }> = [],\n experimentalTools: NonNullable<PluginMCPServerConfig['experimental']>['tools'] = {},\n pluginOptions: PluginMCPServerConfig,\n): CollectionConfig => {\n const customToolsFields = customTools.map((tool) => {\n const camelCasedName = toCamelCase(tool.name)\n return {\n name: camelCasedName,\n type: 'checkbox' as const,\n admin: {\n description: tool.description,\n },\n defaultValue: true,\n label: camelCasedName,\n }\n })\n\n const customResourceFields =\n pluginOptions.mcp?.resources?.map((resource) => {\n const camelCasedName = toCamelCase(resource.name)\n return {\n name: camelCasedName,\n type: 'checkbox' as const,\n admin: {\n description: resource.description,\n },\n defaultValue: true,\n label: camelCasedName,\n }\n }) || []\n\n const customPromptFields =\n pluginOptions.mcp?.prompts?.map((prompt) => {\n const camelCasedName = toCamelCase(prompt.name)\n return {\n name: camelCasedName,\n type: 'checkbox' as const,\n admin: {\n description: prompt.description,\n },\n defaultValue: true,\n label: camelCasedName,\n }\n }) || []\n\n const userCollection = pluginOptions.userCollection\n ? typeof pluginOptions.userCollection === 'string'\n ? pluginOptions.userCollection\n : pluginOptions.userCollection.slug\n : 'users'\n\n return {\n slug: 'payload-mcp-api-keys',\n admin: {\n group: 'MCP',\n useAsTitle: 'label',\n },\n auth: {\n disableLocalStrategy: true,\n useAPIKey: true,\n },\n fields: [\n {\n name: 'user',\n type: 'relationship',\n admin: {\n description: 'The user that the API key is associated with.',\n },\n relationTo: userCollection,\n required: true,\n },\n {\n name: 'label',\n type: 'text',\n admin: {\n description: 'A useful label for the API key.',\n },\n },\n {\n name: 'description',\n type: 'text',\n admin: {\n description: 'The purpose of the API key.',\n },\n },\n\n ...addEnabledCollectionTools(collections),\n\n ...(customTools.length > 0\n ? [\n {\n type: 'collapsible' as const,\n admin: {\n position: 'sidebar' as const,\n },\n fields: [\n {\n name: 'payload-mcp-tool',\n type: 'group' as const,\n fields: customToolsFields,\n label: false as const,\n },\n ],\n label: 'Tools',\n },\n ]\n : []),\n\n ...(pluginOptions.mcp?.resources && pluginOptions.mcp?.resources.length > 0\n ? [\n {\n type: 'collapsible' as const,\n admin: {\n position: 'sidebar' as const,\n },\n fields: [\n {\n name: 'payload-mcp-resource',\n type: 'group' as const,\n fields: customResourceFields,\n label: false as const,\n },\n ],\n label: 'Resources',\n },\n ]\n : []),\n\n ...(pluginOptions.mcp?.prompts && pluginOptions.mcp?.prompts.length > 0\n ? [\n {\n type: 'collapsible' as const,\n admin: {\n position: 'sidebar' as const,\n },\n fields: [\n {\n name: 'payload-mcp-prompt',\n type: 'group' as const,\n fields: customPromptFields,\n label: false as const,\n },\n ],\n label: 'Prompts',\n },\n ]\n : []),\n\n // Experimental Tools\n ...(process.env.NODE_ENV === 'development' &&\n (experimentalTools?.collections?.enabled ||\n experimentalTools?.jobs?.enabled ||\n experimentalTools?.config?.enabled ||\n experimentalTools?.auth?.enabled)\n ? [\n {\n type: 'collapsible' as const,\n admin: {\n position: 'sidebar' as const,\n },\n fields: [\n ...(experimentalTools?.collections?.enabled\n ? [\n {\n name: 'collections',\n type: 'group' as const,\n fields: [\n {\n name: 'find',\n type: 'checkbox' as const,\n admin: {\n description:\n 'Allow LLMs to find and list Payload collections with optional content and document counts.',\n },\n defaultValue: false,\n },\n {\n name: 'create',\n type: 'checkbox' as const,\n admin: {\n description:\n 'Allow LLMs to create new Payload collections with specified fields and configuration.',\n },\n defaultValue: false,\n },\n {\n name: 'update',\n type: 'checkbox' as const,\n admin: {\n description:\n 'Allow LLMs to update existing Payload collections with new fields, modifications, or configuration changes.',\n },\n defaultValue: false,\n },\n {\n name: 'delete',\n type: 'checkbox' as const,\n admin: {\n description:\n 'Allow LLMs to delete Payload collections and optionally update the configuration.',\n },\n defaultValue: false,\n },\n ],\n },\n ]\n : []),\n ...(experimentalTools?.jobs?.enabled\n ? [\n {\n name: 'jobs',\n type: 'group' as const,\n fields: [\n {\n name: 'create',\n type: 'checkbox' as const,\n admin: {\n description:\n 'Allow LLMs to create new Payload jobs (tasks and workflows) with custom schemas and configuration.',\n },\n defaultValue: false,\n },\n {\n name: 'run',\n type: 'checkbox' as const,\n admin: {\n description:\n 'Allow LLMs to execute Payload jobs with custom input data and queue options.',\n },\n defaultValue: false,\n },\n {\n name: 'update',\n type: 'checkbox' as const,\n admin: {\n description:\n 'Allow LLMs to update existing Payload jobs with new schemas, configuration, or handler code.',\n },\n defaultValue: false,\n },\n ],\n },\n ]\n : []),\n ...(experimentalTools?.config?.enabled\n ? [\n {\n name: 'config',\n type: 'group' as const,\n fields: [\n {\n name: 'find',\n type: 'checkbox' as const,\n admin: {\n description:\n 'Allow LLMs to read and display a Payload configuration file.',\n },\n defaultValue: false,\n },\n {\n name: 'update',\n type: 'checkbox' as const,\n admin: {\n description:\n 'Allow LLMs to update a Payload configuration file with various modifications.',\n },\n defaultValue: false,\n },\n ],\n },\n ]\n : []),\n ...(experimentalTools?.auth?.enabled\n ? [\n {\n name: 'auth',\n type: 'group' as const,\n fields: [\n {\n name: 'auth',\n type: 'checkbox' as const,\n admin: {\n description:\n 'Allow LLMs to check authentication status for a user by setting custom headers. (e.g. {\"Authorization\": \"Bearer <token>\"})',\n },\n defaultValue: false,\n label: 'Check Auth Status',\n },\n {\n name: 'login',\n type: 'checkbox' as const,\n admin: {\n description:\n 'Allow LLMs to authenticate a user with email and password.',\n },\n defaultValue: false,\n label: 'User Login',\n },\n {\n name: 'verify',\n type: 'checkbox' as const,\n admin: {\n description:\n 'Allow LLMs to verify a user email with a verification token.',\n },\n defaultValue: false,\n label: 'Email Verification',\n },\n {\n name: 'resetPassword',\n type: 'checkbox' as const,\n admin: {\n description:\n 'Allow LLMs to reset a user password with a reset token.',\n },\n defaultValue: false,\n label: 'Reset Password',\n },\n {\n name: 'forgotPassword',\n type: 'checkbox' as const,\n admin: {\n description: 'Allow LLMs to send a password reset email to a user.',\n },\n defaultValue: false,\n label: 'Forgot Password',\n },\n {\n name: 'unlock',\n type: 'checkbox' as const,\n admin: {\n description:\n 'Allow LLMs to unlock a user account that has been locked due to failed login attempts.',\n },\n defaultValue: false,\n label: 'Unlock Account',\n },\n ],\n },\n ]\n : []),\n ],\n label: 'Experimental Tools',\n },\n ]\n : []),\n ],\n labels: {\n plural: 'API Keys',\n singular: 'API Key',\n },\n }\n}\n"],"names":["toCamelCase","addEnabledCollectionTools","collections","enabledCollectionSlugs","Object","keys","filter","collection","fullyEnabled","enabled","partiallyEnabled","find","create","update","delete","map","enabledCollectionSlug","type","admin","position","fields","name","description","defaultValue","label","charAt","toUpperCase","slice","createAPIKeysCollection","customTools","experimentalTools","pluginOptions","customToolsFields","tool","camelCasedName","customResourceFields","mcp","resources","resource","customPromptFields","prompts","prompt","userCollection","slug","group","useAsTitle","auth","disableLocalStrategy","useAPIKey","relationTo","required","length","process","env","NODE_ENV","jobs","config","labels","plural","singular"],"mappings":"AAIA,SAASA,WAAW,QAAQ,wBAAuB;AAEnD,MAAMC,4BAA4B,CAACC;IACjC,MAAMC,yBAAyBC,OAAOC,IAAI,CAACH,eAAe,CAAC,GAAGI,MAAM,CAAC,CAACC;QACpE,MAAMC,eACJ,OAAON,aAAa,CAACK,WAAW,EAAEE,YAAY,aAAaP,aAAa,CAACK,WAAW,EAAEE;QAExF,IAAID,cAAc;YAChB,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4CACLI,aACE;wCACJ;wCACAC,cAAc;wCACdC,OAAO;oCACT;oCACA;wCACEH,MAAM;wCACNJ,MAAM;wCACNC,OAAO;4CACLI,aAAa;wCACf;wCACAC,cAAc;wCACdC,OAAO;oCACT;oCACA;wCACEH,MAAM;wCACNJ,MAAM;wCACNC,OAAO;4CACLI,aACE;wCACJ;wCACAC,cAAc;wCACdC,OAAO;oCACT;iCACD;4BACH;yBACD,GACD,EAAE;qBACP;oBACDA,OAAO;gBACT;aACD,GACD,EAAE;SACP;QACDiC,QAAQ;YACNC,QAAQ;YACRC,UAAU;QACZ;IACF;AACF,EAAC"}
|
|
1
|
+
{"version":3,"sources":["../../src/collections/createApiKeysCollection.ts"],"sourcesContent":["import type { CollectionConfig } from 'payload'\n\nimport type { PluginMCPServerConfig } from '../types.js'\n\nimport { toCamelCase } from '../utils/camelCase.js'\n\nconst addEnabledCollectionTools = (collections: PluginMCPServerConfig['collections']) => {\n const enabledCollectionSlugs = Object.keys(collections || {}).filter((collection) => {\n const fullyEnabled =\n typeof collections?.[collection]?.enabled === 'boolean' && collections?.[collection]?.enabled\n\n if (fullyEnabled) {\n return true\n }\n\n const partiallyEnabled =\n typeof collections?.[collection]?.enabled !== 'boolean' &&\n ((typeof collections?.[collection]?.enabled?.find === 'boolean' &&\n collections?.[collection]?.enabled?.find === true) ||\n (typeof collections?.[collection]?.enabled?.create === 'boolean' &&\n collections?.[collection]?.enabled?.create === true) ||\n (typeof collections?.[collection]?.enabled?.update === 'boolean' &&\n collections?.[collection]?.enabled?.update === true) ||\n (typeof collections?.[collection]?.enabled?.delete === 'boolean' &&\n collections?.[collection]?.enabled?.delete === true))\n\n if (partiallyEnabled) {\n return true\n }\n })\n return enabledCollectionSlugs.map((enabledCollectionSlug) => ({\n type: 'collapsible' as const,\n admin: {\n description: `Manage client access to ${enabledCollectionSlug}`,\n position: 'sidebar' as const,\n },\n fields: [\n {\n name: `${toCamelCase(enabledCollectionSlug)}`,\n type: 'group' as const,\n fields: [\n ...(collections?.[enabledCollectionSlug]?.enabled === true ||\n (typeof collections?.[enabledCollectionSlug]?.enabled !== 'boolean' &&\n typeof collections?.[enabledCollectionSlug]?.enabled?.find === 'boolean' &&\n collections?.[enabledCollectionSlug]?.enabled?.find === true)\n ? [\n {\n name: `find`,\n type: 'checkbox' as const,\n admin: {\n description: `Allow clients to find ${enabledCollectionSlug}.`,\n },\n defaultValue: false,\n label: 'Find',\n },\n ]\n : []),\n\n ...(collections?.[enabledCollectionSlug]?.enabled === true ||\n (typeof collections?.[enabledCollectionSlug]?.enabled !== 'boolean' &&\n typeof collections?.[enabledCollectionSlug]?.enabled?.create === 'boolean' &&\n collections?.[enabledCollectionSlug]?.enabled?.create === true)\n ? [\n {\n name: `create`,\n type: 'checkbox' as const,\n admin: {\n description: `Allow clients to create ${enabledCollectionSlug}.`,\n },\n defaultValue: false,\n label: 'Create',\n },\n ]\n : []),\n\n ...(collections?.[enabledCollectionSlug]?.enabled === true ||\n (typeof collections?.[enabledCollectionSlug]?.enabled !== 'boolean' &&\n typeof collections?.[enabledCollectionSlug]?.enabled?.update === 'boolean' &&\n collections?.[enabledCollectionSlug]?.enabled?.update === true)\n ? [\n {\n name: `update`,\n type: 'checkbox' as const,\n admin: {\n description: `Allow clients to update ${enabledCollectionSlug}.`,\n },\n defaultValue: false,\n label: 'Update',\n },\n ]\n : []),\n\n ...(collections?.[enabledCollectionSlug]?.enabled === true ||\n (typeof collections?.[enabledCollectionSlug]?.enabled !== 'boolean' &&\n typeof collections?.[enabledCollectionSlug]?.enabled?.delete === 'boolean' &&\n collections?.[enabledCollectionSlug]?.enabled?.delete === true)\n ? [\n {\n name: `delete`,\n type: 'checkbox' as const,\n admin: {\n description: `Allow clients to delete ${enabledCollectionSlug}.`,\n },\n defaultValue: false,\n label: 'Delete',\n },\n ]\n : []),\n ],\n label: false as const,\n },\n ],\n label: `${enabledCollectionSlug.charAt(0).toUpperCase() + toCamelCase(enabledCollectionSlug).slice(1)}`,\n }))\n}\n\nexport const createAPIKeysCollection = (\n collections: PluginMCPServerConfig['collections'],\n customTools: Array<{ description: string; name: string }> = [],\n experimentalTools: NonNullable<PluginMCPServerConfig['experimental']>['tools'] = {},\n pluginOptions: PluginMCPServerConfig,\n): CollectionConfig => {\n const customToolsFields = customTools.map((tool) => {\n const camelCasedName = toCamelCase(tool.name)\n return {\n name: camelCasedName,\n type: 'checkbox' as const,\n admin: {\n description: tool.description,\n },\n defaultValue: true,\n label: camelCasedName,\n }\n })\n\n const customResourceFields =\n pluginOptions.mcp?.resources?.map((resource) => {\n const camelCasedName = toCamelCase(resource.name)\n return {\n name: camelCasedName,\n type: 'checkbox' as const,\n admin: {\n description: resource.description,\n },\n defaultValue: true,\n label: camelCasedName,\n }\n }) || []\n\n const customPromptFields =\n pluginOptions.mcp?.prompts?.map((prompt) => {\n const camelCasedName = toCamelCase(prompt.name)\n return {\n name: camelCasedName,\n type: 'checkbox' as const,\n admin: {\n description: prompt.description,\n },\n defaultValue: true,\n label: camelCasedName,\n }\n }) || []\n\n const userCollection = pluginOptions.userCollection\n ? typeof pluginOptions.userCollection === 'string'\n ? pluginOptions.userCollection\n : pluginOptions.userCollection.slug\n : 'users'\n\n return {\n slug: 'payload-mcp-api-keys',\n admin: {\n description:\n 'API keys control which collections, resources, tools, and prompts MCP clients can access',\n group: 'MCP',\n useAsTitle: 'label',\n },\n auth: {\n disableLocalStrategy: true,\n useAPIKey: true,\n },\n fields: [\n {\n name: 'user',\n type: 'relationship',\n admin: {\n description: 'The user that the API key is associated with.',\n },\n relationTo: userCollection,\n required: true,\n },\n {\n name: 'label',\n type: 'text',\n admin: {\n description: 'A useful label for the API key.',\n },\n },\n {\n name: 'description',\n type: 'text',\n admin: {\n description: 'The purpose of the API key.',\n },\n },\n\n ...addEnabledCollectionTools(collections),\n\n ...(customTools.length > 0\n ? [\n {\n type: 'collapsible' as const,\n admin: {\n description: 'Manage client access to tools',\n position: 'sidebar' as const,\n },\n fields: [\n {\n name: 'payload-mcp-tool',\n type: 'group' as const,\n fields: customToolsFields,\n label: false as const,\n },\n ],\n label: 'Tools',\n },\n ]\n : []),\n\n ...(pluginOptions.mcp?.resources && pluginOptions.mcp?.resources.length > 0\n ? [\n {\n type: 'collapsible' as const,\n admin: {\n description: 'Manage client access to resources',\n position: 'sidebar' as const,\n },\n fields: [\n {\n name: 'payload-mcp-resource',\n type: 'group' as const,\n fields: customResourceFields,\n label: false as const,\n },\n ],\n label: 'Resources',\n },\n ]\n : []),\n\n ...(pluginOptions.mcp?.prompts && pluginOptions.mcp?.prompts.length > 0\n ? [\n {\n type: 'collapsible' as const,\n admin: {\n description: 'Manage client access to prompts',\n position: 'sidebar' as const,\n },\n fields: [\n {\n name: 'payload-mcp-prompt',\n type: 'group' as const,\n fields: customPromptFields,\n label: false as const,\n },\n ],\n label: 'Prompts',\n },\n ]\n : []),\n\n // Experimental Tools\n ...(process.env.NODE_ENV === 'development' &&\n (experimentalTools?.collections?.enabled ||\n experimentalTools?.jobs?.enabled ||\n experimentalTools?.config?.enabled ||\n experimentalTools?.auth?.enabled)\n ? [\n {\n type: 'collapsible' as const,\n admin: {\n description: 'Manage client access to experimental tools',\n position: 'sidebar' as const,\n },\n fields: [\n ...(experimentalTools?.collections?.enabled\n ? [\n {\n name: 'collections',\n type: 'group' as const,\n fields: [\n {\n name: 'find',\n type: 'checkbox' as const,\n admin: {\n description:\n 'Allow LLMs to find and list Payload collections with optional content and document counts.',\n },\n defaultValue: false,\n },\n {\n name: 'create',\n type: 'checkbox' as const,\n admin: {\n description:\n 'Allow LLMs to create new Payload collections with specified fields and configuration.',\n },\n defaultValue: false,\n },\n {\n name: 'update',\n type: 'checkbox' as const,\n admin: {\n description:\n 'Allow LLMs to update existing Payload collections with new fields, modifications, or configuration changes.',\n },\n defaultValue: false,\n },\n {\n name: 'delete',\n type: 'checkbox' as const,\n admin: {\n description:\n 'Allow LLMs to delete Payload collections and optionally update the configuration.',\n },\n defaultValue: false,\n },\n ],\n },\n ]\n : []),\n ...(experimentalTools?.jobs?.enabled\n ? [\n {\n name: 'jobs',\n type: 'group' as const,\n fields: [\n {\n name: 'create',\n type: 'checkbox' as const,\n admin: {\n description:\n 'Allow LLMs to create new Payload jobs (tasks and workflows) with custom schemas and configuration.',\n },\n defaultValue: false,\n },\n {\n name: 'run',\n type: 'checkbox' as const,\n admin: {\n description:\n 'Allow LLMs to execute Payload jobs with custom input data and queue options.',\n },\n defaultValue: false,\n },\n {\n name: 'update',\n type: 'checkbox' as const,\n admin: {\n description:\n 'Allow LLMs to update existing Payload jobs with new schemas, configuration, or handler code.',\n },\n defaultValue: false,\n },\n ],\n },\n ]\n : []),\n ...(experimentalTools?.config?.enabled\n ? [\n {\n name: 'config',\n type: 'group' as const,\n fields: [\n {\n name: 'find',\n type: 'checkbox' as const,\n admin: {\n description:\n 'Allow LLMs to read and display a Payload configuration file.',\n },\n defaultValue: false,\n },\n {\n name: 'update',\n type: 'checkbox' as const,\n admin: {\n description:\n 'Allow LLMs to update a Payload configuration file with various modifications.',\n },\n defaultValue: false,\n },\n ],\n },\n ]\n : []),\n ...(experimentalTools?.auth?.enabled\n ? [\n {\n name: 'auth',\n type: 'group' as const,\n fields: [\n {\n name: 'auth',\n type: 'checkbox' as const,\n admin: {\n description:\n 'Allow LLMs to check authentication status for a user by setting custom headers. (e.g. {\"Authorization\": \"Bearer <token>\"})',\n },\n defaultValue: false,\n label: 'Check Auth Status',\n },\n {\n name: 'login',\n type: 'checkbox' as const,\n admin: {\n description:\n 'Allow LLMs to authenticate a user with email and password.',\n },\n defaultValue: false,\n label: 'User Login',\n },\n {\n name: 'verify',\n type: 'checkbox' as const,\n admin: {\n description:\n 'Allow LLMs to verify a user email with a verification token.',\n },\n defaultValue: false,\n label: 'Email Verification',\n },\n {\n name: 'resetPassword',\n type: 'checkbox' as const,\n admin: {\n description:\n 'Allow LLMs to reset a user password with a reset token.',\n },\n defaultValue: false,\n label: 'Reset Password',\n },\n {\n name: 'forgotPassword',\n type: 'checkbox' as const,\n admin: {\n description: 'Allow LLMs to send a password reset email to a user.',\n },\n defaultValue: false,\n label: 'Forgot Password',\n },\n {\n name: 'unlock',\n type: 'checkbox' as const,\n admin: {\n description:\n 'Allow LLMs to unlock a user account that has been locked due to failed login attempts.',\n },\n defaultValue: false,\n label: 'Unlock Account',\n },\n ],\n },\n ]\n : []),\n ],\n label: 'Experimental Tools',\n },\n ]\n : []),\n ],\n labels: {\n plural: 'API Keys',\n singular: 'API Key',\n },\n }\n}\n"],"names":["toCamelCase","addEnabledCollectionTools","collections","enabledCollectionSlugs","Object","keys","filter","collection","fullyEnabled","enabled","partiallyEnabled","find","create","update","delete","map","enabledCollectionSlug","type","admin","description","position","fields","name","defaultValue","label","charAt","toUpperCase","slice","createAPIKeysCollection","customTools","experimentalTools","pluginOptions","customToolsFields","tool","camelCasedName","customResourceFields","mcp","resources","resource","customPromptFields","prompts","prompt","userCollection","slug","group","useAsTitle","auth","disableLocalStrategy","useAPIKey","relationTo","required","length","process","env","NODE_ENV","jobs","config","labels","plural","singular"],"mappings":"AAIA,SAASA,WAAW,QAAQ,wBAAuB;AAEnD,MAAMC,4BAA4B,CAACC;IACjC,MAAMC,yBAAyBC,OAAOC,IAAI,CAACH,eAAe,CAAC,GAAGI,MAAM,CAAC,CAACC;QACpE,MAAMC,eACJ,OAAON,aAAa,CAACK,WAAW,EAAEE,YAAY,aAAaP,aAAa,CAACK,WAAW,EAAEE;QAExF,IAAID,cAAc;YAChB,OAAO;QACT;QAEA,MAAME,mBACJ,OAAOR,aAAa,CAACK,WAAW,EAAEE,YAAY,aAC7C,CAAA,AAAC,OAAOP,aAAa,CAACK,WAAW,EAAEE,SAASE,SAAS,aACpDT,aAAa,CAACK,WAAW,EAAEE,SAASE,SAAS,QAC5C,OAAOT,aAAa,CAACK,WAAW,EAAEE,SAASG,WAAW,aACrDV,aAAa,CAACK,WAAW,EAAEE,SAASG,WAAW,QAChD,OAAOV,aAAa,CAACK,WAAW,EAAEE,SAASI,WAAW,aACrDX,aA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MAAM;wCACNL,MAAM;wCACNC,OAAO;4CACLC,aACE;wCACJ;wCACAI,cAAc;oCAChB;oCACA;wCACED,MAAM;wCACNL,MAAM;wCACNC,OAAO;4CACLC,aACE;wCACJ;wCACAI,cAAc;oCAChB;oCACA;wCACED,MAAM;wCACNL,MAAM;wCACNC,OAAO;4CACLC,aACE;wCACJ;wCACAI,cAAc;oCAChB;iCACD;4BACH;yBACD,GACD,EAAE;2BACFO,mBAAmB0B,QAAQ/C,UAC3B;4BACE;gCACEa,MAAM;gCACNL,MAAM;gCACNI,QAAQ;oCACN;wCACEC,MAAM;wCACNL,MAAM;wCACNC,OAAO;4CACLC,aACE;wCACJ;wCACAI,cAAc;oCAChB;oCACA;wCACED,MAAM;wCACNL,MAAM;wCACNC,OAAO;4CACLC,aACE;wCACJ;wCACAI,cAAc;oCAChB;iCACD;4BACH;yBACD,GACD,EAAE;2BACFO,mBAAmBgB,MAAMrC,UACzB;4BACE;gCACEa,MAAM;gCACNL,MAAM;gCACNI,QAAQ;oCACN;wCACEC,MAAM;wCACNL,MAAM;wCACNC,OAAO;4CACLC,aACE;wCACJ;wCACAI,cAAc;wCACdC,OAAO;oCACT;oCACA;wCACEF,MAAM;wCACNL,MAAM;wCACNC,OAAO;4CACLC,aACE;wCACJ;wCACAI,cAAc;wCACdC,OAAO;oCACT;oCACA;wCACEF,MAAM;wCACNL,MAAM;wCACNC,OAAO;4CACLC,aACE;wCACJ;wCACAI,cAAc;wCACdC,OAAO;oCACT;oCACA;wCACEF,MAAM;wCACNL,MAAM;wCACNC,OAAO;4CACLC,aACE;wCACJ;wCACAI,cAAc;wCACdC,OAAO;oCACT;oCACA;wCACEF,MAAM;wCACNL,MAAM;wCACNC,OAAO;4CACLC,aAAa;wCACf;wCACAI,cAAc;wCACdC,OAAO;oCACT;oCACA;wCACEF,MAAM;wCACNL,MAAM;wCACNC,OAAO;4CACLC,aACE;wCACJ;wCACAI,cAAc;wCACdC,OAAO;oCACT;iCACD;4BACH;yBACD,GACD,EAAE;qBACP;oBACDA,OAAO;gBACT;aACD,GACD,EAAE;SACP;QACDiC,QAAQ;YACNC,QAAQ;YACRC,UAAU;QACZ;IACF;AACF,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mcp.d.ts","sourceRoot":"","sources":["../../src/endpoints/mcp.ts"],"names":[],"mappings":"AACA,OAAO,
|
|
1
|
+
{"version":3,"file":"mcp.d.ts","sourceRoot":"","sources":["../../src/endpoints/mcp.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,cAAc,EAAiC,MAAM,SAAS,CAAA;AAE5E,OAAO,KAAK,EAAqB,qBAAqB,EAAE,MAAM,aAAa,CAAA;AAK3E,eAAO,MAAM,oBAAoB,kBAAmB,qBAAqB,mBA+DxE,CAAA"}
|
package/dist/endpoints/mcp.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import crypto from 'crypto';
|
|
2
|
-
import {
|
|
2
|
+
import { UnauthorizedError } from 'payload';
|
|
3
3
|
import { createRequestFromPayloadRequest } from '../mcp/createRequest.js';
|
|
4
4
|
import { getMCPHandler } from '../mcp/getMcpHandler.js';
|
|
5
5
|
export const initializeMCPHandler = (pluginOptions)=>{
|
|
@@ -8,32 +8,38 @@ export const initializeMCPHandler = (pluginOptions)=>{
|
|
|
8
8
|
const MCPOptions = pluginOptions.mcp || {};
|
|
9
9
|
const MCPHandlerOptions = MCPOptions.handlerOptions || {};
|
|
10
10
|
const useVerboseLogs = MCPHandlerOptions.verboseLogs ?? false;
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
11
|
+
req.payloadAPI = 'MCP';
|
|
12
|
+
const getDefaultMcpAccessSettings = async (overrideApiKey)=>{
|
|
13
|
+
const apiKey = overrideApiKey ?? req.headers.get('Authorization')?.startsWith('Bearer ') ? req.headers.get('Authorization')?.replace('Bearer ', '').trim() : null;
|
|
14
|
+
if (apiKey === null) {
|
|
15
|
+
throw new UnauthorizedError();
|
|
16
|
+
}
|
|
17
|
+
const sha256APIKeyIndex = crypto.createHmac('sha256', payload.secret).update(apiKey || '').digest('hex');
|
|
18
|
+
const apiKeyConstraints = [
|
|
19
|
+
{
|
|
20
|
+
apiKeyIndex: {
|
|
21
|
+
equals: sha256APIKeyIndex
|
|
22
|
+
}
|
|
20
23
|
}
|
|
24
|
+
];
|
|
25
|
+
const where = {
|
|
26
|
+
or: apiKeyConstraints
|
|
27
|
+
};
|
|
28
|
+
const { docs } = await payload.find({
|
|
29
|
+
collection: 'payload-mcp-api-keys',
|
|
30
|
+
limit: 1,
|
|
31
|
+
pagination: false,
|
|
32
|
+
where
|
|
33
|
+
});
|
|
34
|
+
if (docs.length === 0) {
|
|
35
|
+
throw new UnauthorizedError();
|
|
36
|
+
}
|
|
37
|
+
if (useVerboseLogs) {
|
|
38
|
+
payload.logger.info('[payload-mcp] API Key is valid');
|
|
21
39
|
}
|
|
22
|
-
|
|
23
|
-
const where = {
|
|
24
|
-
or: apiKeyConstraints
|
|
40
|
+
return docs[0];
|
|
25
41
|
};
|
|
26
|
-
const
|
|
27
|
-
collection: 'payload-mcp-api-keys',
|
|
28
|
-
where
|
|
29
|
-
});
|
|
30
|
-
if (docs.length === 0) {
|
|
31
|
-
throw new APIError('API Key is invalid', 401);
|
|
32
|
-
}
|
|
33
|
-
const mcpAccessSettings = docs[0];
|
|
34
|
-
if (useVerboseLogs) {
|
|
35
|
-
payload.logger.info('[payload-mcp] API Key is valid');
|
|
36
|
-
}
|
|
42
|
+
const mcpAccessSettings = pluginOptions.overrideAuth ? await pluginOptions.overrideAuth(req, getDefaultMcpAccessSettings) : await getDefaultMcpAccessSettings();
|
|
37
43
|
const handler = getMCPHandler(pluginOptions, mcpAccessSettings, req);
|
|
38
44
|
const request = createRequestFromPayloadRequest(req);
|
|
39
45
|
return await handler(request);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/endpoints/mcp.ts"],"sourcesContent":["import crypto from 'crypto'\nimport {
|
|
1
|
+
{"version":3,"sources":["../../src/endpoints/mcp.ts"],"sourcesContent":["import crypto from 'crypto'\nimport { type PayloadHandler, UnauthorizedError, type Where } from 'payload'\n\nimport type { MCPAccessSettings, PluginMCPServerConfig } from '../types.js'\n\nimport { createRequestFromPayloadRequest } from '../mcp/createRequest.js'\nimport { getMCPHandler } from '../mcp/getMcpHandler.js'\n\nexport const initializeMCPHandler = (pluginOptions: PluginMCPServerConfig) => {\n const mcpHandler: PayloadHandler = async (req) => {\n const { payload } = req\n const MCPOptions = pluginOptions.mcp || {}\n const MCPHandlerOptions = MCPOptions.handlerOptions || {}\n const useVerboseLogs = MCPHandlerOptions.verboseLogs ?? false\n\n req.payloadAPI = 'MCP' as const\n\n const getDefaultMcpAccessSettings = async (overrideApiKey?: null | string) => {\n const apiKey =\n (overrideApiKey ?? req.headers.get('Authorization')?.startsWith('Bearer '))\n ? req.headers.get('Authorization')?.replace('Bearer ', '').trim()\n : null\n\n if (apiKey === null) {\n throw new UnauthorizedError()\n }\n\n const sha256APIKeyIndex = crypto\n .createHmac('sha256', payload.secret)\n .update(apiKey || '')\n .digest('hex')\n\n const apiKeyConstraints = [\n {\n apiKeyIndex: {\n equals: sha256APIKeyIndex,\n },\n },\n ]\n\n const where: Where = {\n or: apiKeyConstraints,\n }\n\n const { docs } = await payload.find({\n collection: 'payload-mcp-api-keys',\n limit: 1,\n pagination: false,\n where,\n })\n\n if (docs.length === 0) {\n throw new UnauthorizedError()\n }\n\n if (useVerboseLogs) {\n payload.logger.info('[payload-mcp] API Key is valid')\n }\n\n return docs[0] as MCPAccessSettings\n }\n\n const mcpAccessSettings = pluginOptions.overrideAuth\n ? await pluginOptions.overrideAuth(req, getDefaultMcpAccessSettings)\n : await getDefaultMcpAccessSettings()\n\n const handler = getMCPHandler(pluginOptions, mcpAccessSettings, req)\n const request = createRequestFromPayloadRequest(req)\n return await handler(request)\n }\n return mcpHandler\n}\n"],"names":["crypto","UnauthorizedError","createRequestFromPayloadRequest","getMCPHandler","initializeMCPHandler","pluginOptions","mcpHandler","req","payload","MCPOptions","mcp","MCPHandlerOptions","handlerOptions","useVerboseLogs","verboseLogs","payloadAPI","getDefaultMcpAccessSettings","overrideApiKey","apiKey","headers","get","startsWith","replace","trim","sha256APIKeyIndex","createHmac","secret","update","digest","apiKeyConstraints","apiKeyIndex","equals","where","or","docs","find","collection","limit","pagination","length","logger","info","mcpAccessSettings","overrideAuth","handler","request"],"mappings":"AAAA,OAAOA,YAAY,SAAQ;AAC3B,SAA8BC,iBAAiB,QAAoB,UAAS;AAI5E,SAASC,+BAA+B,QAAQ,0BAAyB;AACzE,SAASC,aAAa,QAAQ,0BAAyB;AAEvD,OAAO,MAAMC,uBAAuB,CAACC;IACnC,MAAMC,aAA6B,OAAOC;QACxC,MAAM,EAAEC,OAAO,EAAE,GAAGD;QACpB,MAAME,aAAaJ,cAAcK,GAAG,IAAI,CAAC;QACzC,MAAMC,oBAAoBF,WAAWG,cAAc,IAAI,CAAC;QACxD,MAAMC,iBAAiBF,kBAAkBG,WAAW,IAAI;QAExDP,IAAIQ,UAAU,GAAG;QAEjB,MAAMC,8BAA8B,OAAOC;YACzC,MAAMC,SACJ,AAACD,kBAAkBV,IAAIY,OAAO,CAACC,GAAG,CAAC,kBAAkBC,WAAW,aAC5Dd,IAAIY,OAAO,CAACC,GAAG,CAAC,kBAAkBE,QAAQ,WAAW,IAAIC,SACzD;YAEN,IAAIL,WAAW,MAAM;gBACnB,MAAM,IAAIjB;YACZ;YAEA,MAAMuB,oBAAoBxB,OACvByB,UAAU,CAAC,UAAUjB,QAAQkB,MAAM,EACnCC,MAAM,CAACT,UAAU,IACjBU,MAAM,CAAC;YAEV,MAAMC,oBAAoB;gBACxB;oBACEC,aAAa;wBACXC,QAAQP;oBACV;gBACF;aACD;YAED,MAAMQ,QAAe;gBACnBC,IAAIJ;YACN;YAEA,MAAM,EAAEK,IAAI,EAAE,GAAG,MAAM1B,QAAQ2B,IAAI,CAAC;gBAClCC,YAAY;gBACZC,OAAO;gBACPC,YAAY;gBACZN;YACF;YAEA,IAAIE,KAAKK,MAAM,KAAK,GAAG;gBACrB,MAAM,IAAItC;YACZ;YAEA,IAAIY,gBAAgB;gBAClBL,QAAQgC,MAAM,CAACC,IAAI,CAAC;YACtB;YAEA,OAAOP,IAAI,CAAC,EAAE;QAChB;QAEA,MAAMQ,oBAAoBrC,cAAcsC,YAAY,GAChD,MAAMtC,cAAcsC,YAAY,CAACpC,KAAKS,+BACtC,MAAMA;QAEV,MAAM4B,UAAUzC,cAAcE,eAAeqC,mBAAmBnC;QAChE,MAAMsC,UAAU3C,gCAAgCK;QAChD,OAAO,MAAMqC,QAAQC;IACvB;IACA,OAAOvC;AACT,EAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
import type { Config } from 'payload';
|
|
2
|
-
import type { PluginMCPServerConfig } from './types.js';
|
|
2
|
+
import type { MCPAccessSettings, PluginMCPServerConfig } from './types.js';
|
|
3
|
+
declare module 'payload' {
|
|
4
|
+
interface PayloadRequest {
|
|
5
|
+
payloadAPI: 'GraphQL' | 'local' | 'MCP' | 'REST';
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
export type { MCPAccessSettings };
|
|
3
9
|
/**
|
|
4
10
|
* The MCP Plugin for Payload. This plugin allows you to add MCP capabilities to your Payload project.
|
|
5
11
|
*
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAErC,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAErC,OAAO,KAAK,EAAE,iBAAiB,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAA;AAK1E,OAAO,QAAQ,SAAS,CAAC;IACvB,UAAiB,cAAc;QAC7B,UAAU,EAAE,SAAS,GAAG,OAAO,GAAG,KAAK,GAAG,MAAM,CAAA;KACjD;CACF;AAED,YAAY,EAAE,iBAAiB,EAAE,CAAA;AACjC;;;;;GAKG;AACH,eAAO,MAAM,SAAS,kBACJ,qBAAqB,cAC5B,MAAM,KAAG,MA2EjB,CAAA"}
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { Config } from 'payload'\n\nimport type { PluginMCPServerConfig } from './types.js'\n\nimport { createAPIKeysCollection } from './collections/createApiKeysCollection.js'\nimport { initializeMCPHandler } from './endpoints/mcp.js'\n\n/**\n * The MCP Plugin for Payload. This plugin allows you to add MCP capabilities to your Payload project.\n *\n * @param pluginOptions - The options for the MCP plugin.\n * @experimental This plugin is experimental and may change in the future.\n */\nexport const mcpPlugin =\n (pluginOptions: PluginMCPServerConfig) =>\n (config: Config): Config => {\n if (!config.collections) {\n config.collections = []\n }\n\n // Collections\n const collections = pluginOptions.collections || {}\n // Extract custom tools for the global config\n const customTools =\n pluginOptions.mcp?.tools?.map((tool) => ({\n name: tool.name,\n description: tool.description,\n })) || []\n\n const experimentalTools = pluginOptions?.experimental?.tools || {}\n\n /**\n * API Keys\n * --------\n * High resolution control over MCP capabilities is crucial when using Payload with LLMs.\n *\n * This API Keys collection has ways for admins to create API keys and allow or disallow the MCP capabilities.\n * This is useful when Admins want to allow or disallow the use of the MCP capabilities in real time.\n * For example:\n * - If a collection has all of its capabilities enabled, admins can allow or disallow the create, update, delete, and find capabilities on that collection.\n * - If a collection only has the find capability enabled, admins can only allow or disallow the find capability on that collection.\n * - If a custom tool has gone haywire, admins can disallow that tool.\n *\n */\n const apiKeyCollection = createAPIKeysCollection(\n collections,\n customTools,\n experimentalTools,\n pluginOptions,\n )\n if (pluginOptions.overrideApiKeyCollection) {\n config.collections.push(pluginOptions.overrideApiKeyCollection(apiKeyCollection))\n } else {\n config.collections.push(apiKeyCollection)\n }\n\n /**\n * If the plugin is disabled, we still want to keep added collections/fields so the database schema is consistent which is important for migrations.\n * If your plugin heavily modifies the database schema, you may want to remove this property.\n */\n if (pluginOptions.disabled) {\n return config\n }\n\n if (!config.endpoints) {\n config.endpoints = []\n }\n\n /**\n * This is the primary MCP Server Endpoint.\n * Payload will automatically add the /api prefix to the path, so the full path is `/api/mcp`\n * NOTE: This is only transport method until we add full support for SSE which will be another endpoint at `/api/sse`\n */\n config.endpoints.push({\n handler: initializeMCPHandler(pluginOptions),\n method: 'post',\n path: '/mcp',\n })\n\n /**\n * The GET response is always: {\"jsonrpc\":\"2.0\",\"error\":{\"code\":-32000,\"message\":\"Method not allowed.\"},\"id\":null} -- even with an API key\n * This is expected behavior and MCP clients should always use the POST endpoint.\n */\n config.endpoints.push({\n handler: initializeMCPHandler(pluginOptions),\n method: 'get',\n path: '/mcp',\n })\n\n return config\n }\n"],"names":["createAPIKeysCollection","initializeMCPHandler","mcpPlugin","pluginOptions","config","collections","customTools","mcp","tools","map","tool","name","description","experimentalTools","experimental","apiKeyCollection","overrideApiKeyCollection","push","disabled","endpoints","handler","method","path"],"mappings":"AAIA,SAASA,uBAAuB,QAAQ,2CAA0C;AAClF,SAASC,oBAAoB,QAAQ,qBAAoB;
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { Config } from 'payload'\n\nimport type { MCPAccessSettings, PluginMCPServerConfig } from './types.js'\n\nimport { createAPIKeysCollection } from './collections/createApiKeysCollection.js'\nimport { initializeMCPHandler } from './endpoints/mcp.js'\n\ndeclare module 'payload' {\n export interface PayloadRequest {\n payloadAPI: 'GraphQL' | 'local' | 'MCP' | 'REST'\n }\n}\n\nexport type { MCPAccessSettings }\n/**\n * The MCP Plugin for Payload. This plugin allows you to add MCP capabilities to your Payload project.\n *\n * @param pluginOptions - The options for the MCP plugin.\n * @experimental This plugin is experimental and may change in the future.\n */\nexport const mcpPlugin =\n (pluginOptions: PluginMCPServerConfig) =>\n (config: Config): Config => {\n if (!config.collections) {\n config.collections = []\n }\n\n // Collections\n const collections = pluginOptions.collections || {}\n // Extract custom tools for the global config\n const customTools =\n pluginOptions.mcp?.tools?.map((tool) => ({\n name: tool.name,\n description: tool.description,\n })) || []\n\n const experimentalTools = pluginOptions?.experimental?.tools || {}\n\n /**\n * API Keys\n * --------\n * High resolution control over MCP capabilities is crucial when using Payload with LLMs.\n *\n * This API Keys collection has ways for admins to create API keys and allow or disallow the MCP capabilities.\n * This is useful when Admins want to allow or disallow the use of the MCP capabilities in real time.\n * For example:\n * - If a collection has all of its capabilities enabled, admins can allow or disallow the create, update, delete, and find capabilities on that collection.\n * - If a collection only has the find capability enabled, admins can only allow or disallow the find capability on that collection.\n * - If a custom tool has gone haywire, admins can disallow that tool.\n *\n */\n const apiKeyCollection = createAPIKeysCollection(\n collections,\n customTools,\n experimentalTools,\n pluginOptions,\n )\n if (pluginOptions.overrideApiKeyCollection) {\n config.collections.push(pluginOptions.overrideApiKeyCollection(apiKeyCollection))\n } else {\n config.collections.push(apiKeyCollection)\n }\n\n /**\n * If the plugin is disabled, we still want to keep added collections/fields so the database schema is consistent which is important for migrations.\n * If your plugin heavily modifies the database schema, you may want to remove this property.\n */\n if (pluginOptions.disabled) {\n return config\n }\n\n if (!config.endpoints) {\n config.endpoints = []\n }\n\n /**\n * This is the primary MCP Server Endpoint.\n * Payload will automatically add the /api prefix to the path, so the full path is `/api/mcp`\n * NOTE: This is only transport method until we add full support for SSE which will be another endpoint at `/api/sse`\n */\n config.endpoints.push({\n handler: initializeMCPHandler(pluginOptions),\n method: 'post',\n path: '/mcp',\n })\n\n /**\n * The GET response is always: {\"jsonrpc\":\"2.0\",\"error\":{\"code\":-32000,\"message\":\"Method not allowed.\"},\"id\":null} -- even with an API key\n * This is expected behavior and MCP clients should always use the POST endpoint.\n */\n config.endpoints.push({\n handler: initializeMCPHandler(pluginOptions),\n method: 'get',\n path: '/mcp',\n })\n\n return config\n }\n"],"names":["createAPIKeysCollection","initializeMCPHandler","mcpPlugin","pluginOptions","config","collections","customTools","mcp","tools","map","tool","name","description","experimentalTools","experimental","apiKeyCollection","overrideApiKeyCollection","push","disabled","endpoints","handler","method","path"],"mappings":"AAIA,SAASA,uBAAuB,QAAQ,2CAA0C;AAClF,SAASC,oBAAoB,QAAQ,qBAAoB;AASzD;;;;;CAKC,GACD,OAAO,MAAMC,YACX,CAACC,gBACD,CAACC;QACC,IAAI,CAACA,OAAOC,WAAW,EAAE;YACvBD,OAAOC,WAAW,GAAG,EAAE;QACzB;QAEA,cAAc;QACd,MAAMA,cAAcF,cAAcE,WAAW,IAAI,CAAC;QAClD,6CAA6C;QAC7C,MAAMC,cACJH,cAAcI,GAAG,EAAEC,OAAOC,IAAI,CAACC,OAAU,CAAA;gBACvCC,MAAMD,KAAKC,IAAI;gBACfC,aAAaF,KAAKE,WAAW;YAC/B,CAAA,MAAO,EAAE;QAEX,MAAMC,oBAAoBV,eAAeW,cAAcN,SAAS,CAAC;QAEjE;;;;;;;;;;;;KAYC,GACD,MAAMO,mBAAmBf,wBACvBK,aACAC,aACAO,mBACAV;QAEF,IAAIA,cAAca,wBAAwB,EAAE;YAC1CZ,OAAOC,WAAW,CAACY,IAAI,CAACd,cAAca,wBAAwB,CAACD;QACjE,OAAO;YACLX,OAAOC,WAAW,CAACY,IAAI,CAACF;QAC1B;QAEA;;;KAGC,GACD,IAAIZ,cAAce,QAAQ,EAAE;YAC1B,OAAOd;QACT;QAEA,IAAI,CAACA,OAAOe,SAAS,EAAE;YACrBf,OAAOe,SAAS,GAAG,EAAE;QACvB;QAEA;;;;KAIC,GACDf,OAAOe,SAAS,CAACF,IAAI,CAAC;YACpBG,SAASnB,qBAAqBE;YAC9BkB,QAAQ;YACRC,MAAM;QACR;QAEA;;;KAGC,GACDlB,OAAOe,SAAS,CAACF,IAAI,CAAC;YACpBG,SAASnB,qBAAqBE;YAC9BkB,QAAQ;YACRC,MAAM;QACR;QAEA,OAAOlB;IACT,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createRequest.d.ts","sourceRoot":"","sources":["../../src/mcp/createRequest.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"createRequest.d.ts","sourceRoot":"","sources":["../../src/mcp/createRequest.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuB,KAAK,cAAc,EAAE,MAAM,SAAS,CAAA;AAElE,eAAO,MAAM,+BAA+B,QAAS,cAAc,YAUlE,CAAA"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AuthenticationError } from 'payload';
|
|
2
2
|
export const createRequestFromPayloadRequest = (req)=>{
|
|
3
3
|
if (!req.url) {
|
|
4
|
-
throw new
|
|
4
|
+
throw new AuthenticationError();
|
|
5
5
|
}
|
|
6
6
|
return new Request(req.url, {
|
|
7
7
|
body: req.body,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/mcp/createRequest.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"sources":["../../src/mcp/createRequest.ts"],"sourcesContent":["import { AuthenticationError, type PayloadRequest } from 'payload'\n\nexport const createRequestFromPayloadRequest = (req: PayloadRequest) => {\n if (!req.url) {\n throw new AuthenticationError()\n }\n return new Request(req.url, {\n body: req.body,\n duplex: 'half',\n headers: req.headers,\n method: req.method,\n } as { duplex: 'half' } & RequestInit)\n}\n"],"names":["AuthenticationError","createRequestFromPayloadRequest","req","url","Request","body","duplex","headers","method"],"mappings":"AAAA,SAASA,mBAAmB,QAA6B,UAAS;AAElE,OAAO,MAAMC,kCAAkC,CAACC;IAC9C,IAAI,CAACA,IAAIC,GAAG,EAAE;QACZ,MAAM,IAAIH;IACZ;IACA,OAAO,IAAII,QAAQF,IAAIC,GAAG,EAAE;QAC1BE,MAAMH,IAAIG,IAAI;QACdC,QAAQ;QACRC,SAASL,IAAIK,OAAO;QACpBC,QAAQN,IAAIM,MAAM;IACpB;AACF,EAAC"}
|
|
@@ -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;
|
|
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;AA+B3E,eAAO,MAAM,aAAa,kBACT,qBAAqB,qBACjB,iBAAiB,OAC/B,cAAc,4CA+ZpB,CAAA"}
|
|
@@ -9,7 +9,9 @@ import { deleteResourceTool } from './tools/resource/delete.js';
|
|
|
9
9
|
import { findResourceTool } from './tools/resource/find.js';
|
|
10
10
|
import { updateResourceTool } from './tools/resource/update.js';
|
|
11
11
|
// Experimental Tools
|
|
12
|
-
|
|
12
|
+
/**
|
|
13
|
+
* @experimental This tools are experimental and may change or be removed in the future.
|
|
14
|
+
*/ import { authTool } from './tools/auth/auth.js';
|
|
13
15
|
import { forgotPasswordTool } from './tools/auth/forgotPassword.js';
|
|
14
16
|
import { loginTool } from './tools/auth/login.js';
|
|
15
17
|
import { resetPasswordTool } from './tools/auth/resetPassword.js';
|
|
@@ -61,10 +63,10 @@ export const getMCPHandler = (pluginOptions, mcpAccessSettings, req)=>{
|
|
|
61
63
|
try {
|
|
62
64
|
const schema = configSchema.definitions?.[enabledCollectionSlug];
|
|
63
65
|
const toolCapabilities = mcpAccessSettings?.[`${toCamelCase(enabledCollectionSlug)}`];
|
|
64
|
-
const allowCreate = toolCapabilities
|
|
65
|
-
const allowUpdate = toolCapabilities
|
|
66
|
-
const allowFind = toolCapabilities
|
|
67
|
-
const allowDelete = toolCapabilities
|
|
66
|
+
const allowCreate = toolCapabilities?.create;
|
|
67
|
+
const allowUpdate = toolCapabilities?.update;
|
|
68
|
+
const allowFind = toolCapabilities?.find;
|
|
69
|
+
const allowDelete = toolCapabilities?.delete;
|
|
68
70
|
if (allowCreate) {
|
|
69
71
|
registerTool(allowCreate, `Create ${enabledCollectionSlug}`, ()=>createResourceTool(server, req, user, useVerboseLogs, enabledCollectionSlug, collectionsPluginConfig, schema), payload, useVerboseLogs);
|
|
70
72
|
}
|
|
@@ -84,13 +86,13 @@ export const getMCPHandler = (pluginOptions, mcpAccessSettings, req)=>{
|
|
|
84
86
|
// Custom tools
|
|
85
87
|
customMCPTools.forEach((tool)=>{
|
|
86
88
|
const camelCasedToolName = toCamelCase(tool.name);
|
|
87
|
-
const isToolEnabled = mcpAccessSettings['payload-mcp-tool']?.[camelCasedToolName] ??
|
|
89
|
+
const isToolEnabled = mcpAccessSettings['payload-mcp-tool']?.[camelCasedToolName] ?? false;
|
|
88
90
|
registerTool(isToolEnabled, tool.name, ()=>server.tool(tool.name, tool.description, tool.parameters, tool.handler), payload, useVerboseLogs);
|
|
89
91
|
});
|
|
90
92
|
// Custom prompts
|
|
91
93
|
customMCPPrompts.forEach((prompt)=>{
|
|
92
94
|
const camelCasedPromptName = toCamelCase(prompt.name);
|
|
93
|
-
const isPromptEnabled = mcpAccessSettings['payload-mcp-prompt']?.[camelCasedPromptName] ??
|
|
95
|
+
const isPromptEnabled = mcpAccessSettings['payload-mcp-prompt']?.[camelCasedPromptName] ?? false;
|
|
94
96
|
if (isPromptEnabled) {
|
|
95
97
|
server.registerPrompt(prompt.name, {
|
|
96
98
|
argsSchema: prompt.argsSchema,
|
|
@@ -107,7 +109,7 @@ export const getMCPHandler = (pluginOptions, mcpAccessSettings, req)=>{
|
|
|
107
109
|
// Custom resources
|
|
108
110
|
customMCPResources.forEach((resource)=>{
|
|
109
111
|
const camelCasedResourceName = toCamelCase(resource.name);
|
|
110
|
-
const isResourceEnabled = mcpAccessSettings['payload-mcp-resource']?.[camelCasedResourceName] ??
|
|
112
|
+
const isResourceEnabled = mcpAccessSettings['payload-mcp-resource']?.[camelCasedResourceName] ?? false;
|
|
111
113
|
if (isResourceEnabled) {
|
|
112
114
|
server.registerResource(resource.name, // @ts-expect-error - Overload type is not working however -- ResourceTemplate OR String is a valid type
|
|
113
115
|
resource.uri, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/mcp/getMcpHandler.ts"],"sourcesContent":["import type { JSONSchema4 } from 'json-schema'\n\nimport { createMcpHandler } from '@vercel/mcp-adapter'\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 { registerTool } from './registerTool.js'\n\n// Tools\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\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)\n\n // User\n const user = mcpAccessSettings.user as TypedUser\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 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 const enabledCollectionSlugs = Object.keys(collectionsPluginConfig || {}).filter(\n (collection) => {\n const fullyEnabled =\n typeof collectionsPluginConfig?.[collection]?.enabled === 'boolean' &&\n collectionsPluginConfig?.[collection]?.enabled\n\n if (fullyEnabled) {\n return true\n }\n\n const partiallyEnabled =\n typeof collectionsPluginConfig?.[collection]?.enabled !== 'boolean' &&\n ((typeof collectionsPluginConfig?.[collection]?.enabled?.find === 'boolean' &&\n collectionsPluginConfig?.[collection]?.enabled?.find === true) ||\n (typeof collectionsPluginConfig?.[collection]?.enabled?.create === 'boolean' &&\n collectionsPluginConfig?.[collection]?.enabled?.create === true) ||\n (typeof collectionsPluginConfig?.[collection]?.enabled?.update === 'boolean' &&\n collectionsPluginConfig?.[collection]?.enabled?.update === true) ||\n (typeof collectionsPluginConfig?.[collection]?.enabled?.delete === 'boolean' &&\n collectionsPluginConfig?.[collection]?.enabled?.delete === true))\n\n if (partiallyEnabled) {\n return true\n }\n },\n )\n\n // Collection Operation Tools\n enabledCollectionSlugs.forEach((enabledCollectionSlug) => {\n try {\n const schema = configSchema.definitions?.[enabledCollectionSlug] as JSONSchema4\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 // Custom tools\n customMCPTools.forEach((tool) => {\n const camelCasedToolName = toCamelCase(tool.name)\n const isToolEnabled = mcpAccessSettings['payload-mcp-tool']?.[camelCasedToolName] ?? true\n\n registerTool(\n isToolEnabled,\n tool.name,\n () => server.tool(tool.name, tool.description, tool.parameters, tool.handler),\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] ?? true\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 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] ?? true\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 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 || '/api',\n maxDuration: MCPHandlerOptions.maxDuration || 60,\n // INFO: Disabled until developer clarity is reached for server side streaming and we have an auth pattern for all SSE patterns\n // redisUrl: MCPHandlerOptions.redisUrl || process.env.REDIS_URL,\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","registerTool","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","user","MCPOptions","mcp","customMCPTools","tools","customMCPPrompts","prompts","customMCPResources","resources","MCPHandlerOptions","handlerOptions","serverOptions","useVerboseLogs","verboseLogs","isDevelopment","process","env","NODE_ENV","experimentalTools","experimental","collectionsPluginConfig","collections","collectionsDirPath","cwd","configFilePath","jobsDirPath","jobs","server","enabledCollectionSlugs","Object","keys","filter","collection","fullyEnabled","enabled","partiallyEnabled","find","create","update","delete","forEach","enabledCollectionSlug","schema","definitions","toolCapabilities","allowCreate","allowUpdate","allowFind","allowDelete","error","String","tool","camelCasedToolName","name","isToolEnabled","description","parameters","handler","prompt","camelCasedPromptName","isPromptEnabled","registerPrompt","argsSchema","title","logger","info","resource","camelCasedResourceName","isResourceEnabled","registerResource","uri","mimeType","run","auth","login","verify","resetPassword","forgotPassword","unlock","serverInfo","basePath","maxDuration"],"mappings":"AAEA,SAASA,gBAAgB,QAAQ,sBAAqB;AACtD,SAASC,IAAI,Q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YAEJ;YAEA,IAAIA,gBAAgB;gBAClBf,QAAQmE,MAAM,CAACC,IAAI,CAAC;YACtB;QACF,GACA;YACEc,YAAYpE,cAAcoE,UAAU;QACtC,GACA;YACEC,UAAUvE,kBAAkBuE,QAAQ,IAAI;YACxCC,aAAaxE,kBAAkBwE,WAAW,IAAI;YAC9C,+HAA+H;YAC/H,iEAAiE;YACjEpE,aAAaD;QACf;IAEJ,EAAE,OAAOqC,OAAO;QACd,MAAM,IAAI/E,SAAS,CAAC,gCAAgC,EAAEgF,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 '@vercel/mcp-adapter'\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 { registerTool } from './registerTool.js'\n\n// Tools\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)\n\n // User\n const user = mcpAccessSettings.user as TypedUser\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 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 const enabledCollectionSlugs = Object.keys(collectionsPluginConfig || {}).filter(\n (collection) => {\n const fullyEnabled =\n typeof collectionsPluginConfig?.[collection]?.enabled === 'boolean' &&\n collectionsPluginConfig?.[collection]?.enabled\n\n if (fullyEnabled) {\n return true\n }\n\n const partiallyEnabled =\n typeof collectionsPluginConfig?.[collection]?.enabled !== 'boolean' &&\n ((typeof collectionsPluginConfig?.[collection]?.enabled?.find === 'boolean' &&\n collectionsPluginConfig?.[collection]?.enabled?.find === true) ||\n (typeof collectionsPluginConfig?.[collection]?.enabled?.create === 'boolean' &&\n collectionsPluginConfig?.[collection]?.enabled?.create === true) ||\n (typeof collectionsPluginConfig?.[collection]?.enabled?.update === 'boolean' &&\n collectionsPluginConfig?.[collection]?.enabled?.update === true) ||\n (typeof collectionsPluginConfig?.[collection]?.enabled?.delete === 'boolean' &&\n collectionsPluginConfig?.[collection]?.enabled?.delete === true))\n\n if (partiallyEnabled) {\n return true\n }\n },\n )\n\n // Collection Operation Tools\n enabledCollectionSlugs.forEach((enabledCollectionSlug) => {\n try {\n const schema = configSchema.definitions?.[enabledCollectionSlug] as JSONSchema4\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 // 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 () => server.tool(tool.name, tool.description, tool.parameters, tool.handler),\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 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 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 || '/api',\n maxDuration: MCPHandlerOptions.maxDuration || 60,\n // INFO: Disabled until developer clarity is reached for server side streaming and we have an auth pattern for all SSE patterns\n // redisUrl: MCPHandlerOptions.redisUrl || process.env.REDIS_URL,\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","registerTool","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","user","MCPOptions","mcp","customMCPTools","tools","customMCPPrompts","prompts","customMCPResources","resources","MCPHandlerOptions","handlerOptions","serverOptions","useVerboseLogs","verboseLogs","isDevelopment","process","env","NODE_ENV","experimentalTools","experimental","collectionsPluginConfig","collections","collectionsDirPath","cwd","configFilePath","jobsDirPath","jobs","server","enabledCollectionSlugs","Object","keys","filter","collection","fullyEnabled","enabled","partiallyEnabled","find","create","update","delete","forEach","enabledCollectionSlug","schema","definitions","toolCapabilities","allowCreate","allowUpdate","allowFind","allowDelete","error","String","tool","camelCasedToolName","name","isToolEnabled","description","parameters","handler","prompt","camelCasedPromptName","isPromptEnabled","registerPrompt","argsSchema","title","logger","info","resource","camelCasedResourceName","isResourceEnabled","registerResource","uri","mimeType","run","auth","login","verify","resetPassword","forgotPassword","unlock","serverInfo","basePath","maxDuration"],"mappings":"AAEA,SAASA,gBAAgB,QAAQ,sBAAqB;AACtD,SAASC,IAAI,QAAQ,OAAM;AAC3B,SAASC,QAAQ,EAAEC,kBAAkB,QAA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GACA;YACEc,YAAYpE,cAAcoE,UAAU;QACtC,GACA;YACEC,UAAUvE,kBAAkBuE,QAAQ,IAAI;YACxCC,aAAaxE,kBAAkBwE,WAAW,IAAI;YAC9C,+HAA+H;YAC/H,iEAAiE;YACjEpE,aAAaD;QACf;IAEJ,EAAE,OAAOqC,OAAO;QACd,MAAM,IAAI/E,SAAS,CAAC,gCAAgC,EAAEgF,OAAOD,QAAQ,EAAE;IACzE;AACF,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create.d.ts","sourceRoot":"","sources":["../../../../src/mcp/tools/resource/create.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAA;AACxE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAC9C,OAAO,KAAK,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AAExD,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAA;AAK9D,eAAO,MAAM,kBAAkB,WACrB,SAAS,OACZ,cAAc,QACb,SAAS,eACF,OAAO,kBACJ,MAAM,eACT,qBAAqB,CAAC,aAAa,CAAC,UACzC,WAAW,
|
|
1
|
+
{"version":3,"file":"create.d.ts","sourceRoot":"","sources":["../../../../src/mcp/tools/resource/create.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAA;AACxE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAC9C,OAAO,KAAK,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AAExD,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAA;AAK9D,eAAO,MAAM,kBAAkB,WACrB,SAAS,OACZ,cAAc,QACb,SAAS,eACF,OAAO,kBACJ,MAAM,eACT,qBAAqB,CAAC,aAAa,CAAC,UACzC,WAAW,SA0GpB,CAAA"}
|
|
@@ -29,6 +29,7 @@ export const createResourceTool = (server, req, user, verboseLogs, collectionSlu
|
|
|
29
29
|
// Create the resource
|
|
30
30
|
const result = await payload.create({
|
|
31
31
|
collection: collectionSlug,
|
|
32
|
+
req,
|
|
32
33
|
// TODO: Move the override to a `beforeChange` hook and extend the payloadAPI context req to include MCP request info.
|
|
33
34
|
data: collections?.[collectionSlug]?.override?.(parsedData, req) || parsedData,
|
|
34
35
|
overrideAccess: false,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/mcp/tools/resource/create.ts"],"sourcesContent":["import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'\nimport type { JSONSchema4 } from 'json-schema'\nimport type { PayloadRequest, TypedUser } from 'payload'\n\nimport type { PluginMCPServerConfig } from '../../../types.js'\n\nimport { toCamelCase } from '../../../utils/camelCase.js'\nimport { convertCollectionSchemaToZod } from '../../../utils/convertCollectionSchemaToZod.js'\nimport { toolSchemas } from '../schemas.js'\nexport const createResourceTool = (\n server: McpServer,\n req: PayloadRequest,\n user: TypedUser,\n verboseLogs: boolean,\n collectionSlug: string,\n collections: PluginMCPServerConfig['collections'],\n schema: JSONSchema4,\n) => {\n const tool = async (\n data: string,\n ): Promise<{\n content: Array<{\n text: string\n type: 'text'\n }>\n }> => {\n const payload = req.payload\n\n if (verboseLogs) {\n payload.logger.info(`[payload-mcp] Creating resource in collection: ${collectionSlug}`)\n }\n\n try {\n // Parse the data JSON\n let parsedData: Record<string, unknown>\n try {\n parsedData = JSON.parse(data)\n if (verboseLogs) {\n payload.logger.info(\n `[payload-mcp] Parsed data for ${collectionSlug}: ${JSON.stringify(parsedData)}`,\n )\n }\n } catch (_parseError) {\n payload.logger.error(`[payload-mcp] Invalid JSON data provided: ${data}`)\n return {\n content: [{ type: 'text' as const, text: 'Error: Invalid JSON data provided' }],\n }\n }\n\n // Create the resource\n const result = await payload.create({\n collection: collectionSlug,\n // TODO: Move the override to a `beforeChange` hook and extend the payloadAPI context req to include MCP request info.\n data: collections?.[collectionSlug]?.override?.(parsedData, req) || parsedData,\n overrideAccess: false,\n user,\n })\n\n if (verboseLogs) {\n payload.logger.info(\n `[payload-mcp] Successfully created resource in ${collectionSlug} with ID: ${result.id}`,\n )\n }\n\n const response = {\n content: [\n {\n type: 'text' as const,\n text: `Resource created successfully in collection \"${collectionSlug}\"!\nCreated resource:\n\\`\\`\\`json\n${JSON.stringify(result, null, 2)}\n\\`\\`\\``,\n },\n ],\n }\n\n return (collections?.[collectionSlug]?.overrideResponse?.(response, result, req) ||\n response) as {\n content: Array<{\n text: string\n type: 'text'\n }>\n }\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : 'Unknown error'\n payload.logger.error(\n `[payload-mcp] Error creating resource in ${collectionSlug}: ${errorMessage}`,\n )\n\n const response = {\n content: [\n {\n type: 'text' as const,\n text: `Error creating resource in collection \"${collectionSlug}\": ${errorMessage}`,\n },\n ],\n }\n\n return (collections?.[collectionSlug]?.overrideResponse?.(response, {}, req) || response) as {\n content: Array<{\n text: string\n type: 'text'\n }>\n }\n }\n }\n\n if (collections?.[collectionSlug]?.enabled) {\n const convertedFields = convertCollectionSchemaToZod(schema)\n\n server.tool(\n `create${collectionSlug.charAt(0).toUpperCase() + toCamelCase(collectionSlug).slice(1)}`,\n `${collections?.[collectionSlug]?.description || toolSchemas.createResource.description.trim()}`,\n convertedFields.shape,\n async (params: Record<string, unknown>) => {\n const data = JSON.stringify(params)\n return await tool(data)\n },\n )\n }\n}\n"],"names":["toCamelCase","convertCollectionSchemaToZod","toolSchemas","createResourceTool","server","req","user","verboseLogs","collectionSlug","collections","schema","tool","data","payload","logger","info","parsedData","JSON","parse","stringify","_parseError","error","content","type","text","result","create","collection","override","overrideAccess","id","response","overrideResponse","errorMessage","Error","message","enabled","convertedFields","charAt","toUpperCase","slice","description","createResource","trim","shape","params"],"mappings":"AAMA,SAASA,WAAW,QAAQ,8BAA6B;AACzD,SAASC,4BAA4B,QAAQ,iDAAgD;AAC7F,SAASC,WAAW,QAAQ,gBAAe;AAC3C,OAAO,MAAMC,qBAAqB,CAChCC,QACAC,KACAC,MACAC,aACAC,gBACAC,aACAC;IAEA,MAAMC,OAAO,OACXC;QAOA,MAAMC,UAAUR,IAAIQ,OAAO;QAE3B,IAAIN,aAAa;YACfM,QAAQC,MAAM,CAACC,IAAI,CAAC,CAAC,+CAA+C,EAAEP,gBAAgB;QACxF;QAEA,IAAI;YACF,sBAAsB;YACtB,IAAIQ;YACJ,IAAI;gBACFA,aAAaC,KAAKC,KAAK,CAACN;gBACxB,IAAIL,aAAa;oBACfM,QAAQC,MAAM,CAACC,IAAI,CACjB,CAAC,8BAA8B,EAAEP,eAAe,EAAE,EAAES,KAAKE,SAAS,CAACH,aAAa;gBAEpF;YACF,EAAE,OAAOI,aAAa;gBACpBP,QAAQC,MAAM,CAACO,KAAK,CAAC,CAAC,0CAA0C,EAAET,MAAM;gBACxE,OAAO;oBACLU,SAAS;wBAAC;4BAAEC,MAAM;4BAAiBC,MAAM;wBAAoC;qBAAE;gBACjF;YACF;YAEA,sBAAsB;YACtB,MAAMC,SAAS,MAAMZ,QAAQa,MAAM,CAAC;gBAClCC,YAAYnB;
|
|
1
|
+
{"version":3,"sources":["../../../../src/mcp/tools/resource/create.ts"],"sourcesContent":["import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'\nimport type { JSONSchema4 } from 'json-schema'\nimport type { PayloadRequest, TypedUser } from 'payload'\n\nimport type { PluginMCPServerConfig } from '../../../types.js'\n\nimport { toCamelCase } from '../../../utils/camelCase.js'\nimport { convertCollectionSchemaToZod } from '../../../utils/convertCollectionSchemaToZod.js'\nimport { toolSchemas } from '../schemas.js'\nexport const createResourceTool = (\n server: McpServer,\n req: PayloadRequest,\n user: TypedUser,\n verboseLogs: boolean,\n collectionSlug: string,\n collections: PluginMCPServerConfig['collections'],\n schema: JSONSchema4,\n) => {\n const tool = async (\n data: string,\n ): Promise<{\n content: Array<{\n text: string\n type: 'text'\n }>\n }> => {\n const payload = req.payload\n\n if (verboseLogs) {\n payload.logger.info(`[payload-mcp] Creating resource in collection: ${collectionSlug}`)\n }\n\n try {\n // Parse the data JSON\n let parsedData: Record<string, unknown>\n try {\n parsedData = JSON.parse(data)\n if (verboseLogs) {\n payload.logger.info(\n `[payload-mcp] Parsed data for ${collectionSlug}: ${JSON.stringify(parsedData)}`,\n )\n }\n } catch (_parseError) {\n payload.logger.error(`[payload-mcp] Invalid JSON data provided: ${data}`)\n return {\n content: [{ type: 'text' as const, text: 'Error: Invalid JSON data provided' }],\n }\n }\n\n // Create the resource\n const result = await payload.create({\n collection: collectionSlug,\n req,\n // TODO: Move the override to a `beforeChange` hook and extend the payloadAPI context req to include MCP request info.\n data: collections?.[collectionSlug]?.override?.(parsedData, req) || parsedData,\n overrideAccess: false,\n user,\n })\n\n if (verboseLogs) {\n payload.logger.info(\n `[payload-mcp] Successfully created resource in ${collectionSlug} with ID: ${result.id}`,\n )\n }\n\n const response = {\n content: [\n {\n type: 'text' as const,\n text: `Resource created successfully in collection \"${collectionSlug}\"!\nCreated resource:\n\\`\\`\\`json\n${JSON.stringify(result, null, 2)}\n\\`\\`\\``,\n },\n ],\n }\n\n return (collections?.[collectionSlug]?.overrideResponse?.(response, result, req) ||\n response) as {\n content: Array<{\n text: string\n type: 'text'\n }>\n }\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : 'Unknown error'\n payload.logger.error(\n `[payload-mcp] Error creating resource in ${collectionSlug}: ${errorMessage}`,\n )\n\n const response = {\n content: [\n {\n type: 'text' as const,\n text: `Error creating resource in collection \"${collectionSlug}\": ${errorMessage}`,\n },\n ],\n }\n\n return (collections?.[collectionSlug]?.overrideResponse?.(response, {}, req) || response) as {\n content: Array<{\n text: string\n type: 'text'\n }>\n }\n }\n }\n\n if (collections?.[collectionSlug]?.enabled) {\n const convertedFields = convertCollectionSchemaToZod(schema)\n\n server.tool(\n `create${collectionSlug.charAt(0).toUpperCase() + toCamelCase(collectionSlug).slice(1)}`,\n `${collections?.[collectionSlug]?.description || toolSchemas.createResource.description.trim()}`,\n convertedFields.shape,\n async (params: Record<string, unknown>) => {\n const data = JSON.stringify(params)\n return await tool(data)\n },\n )\n }\n}\n"],"names":["toCamelCase","convertCollectionSchemaToZod","toolSchemas","createResourceTool","server","req","user","verboseLogs","collectionSlug","collections","schema","tool","data","payload","logger","info","parsedData","JSON","parse","stringify","_parseError","error","content","type","text","result","create","collection","override","overrideAccess","id","response","overrideResponse","errorMessage","Error","message","enabled","convertedFields","charAt","toUpperCase","slice","description","createResource","trim","shape","params"],"mappings":"AAMA,SAASA,WAAW,QAAQ,8BAA6B;AACzD,SAASC,4BAA4B,QAAQ,iDAAgD;AAC7F,SAASC,WAAW,QAAQ,gBAAe;AAC3C,OAAO,MAAMC,qBAAqB,CAChCC,QACAC,KACAC,MACAC,aACAC,gBACAC,aACAC;IAEA,MAAMC,OAAO,OACXC;QAOA,MAAMC,UAAUR,IAAIQ,OAAO;QAE3B,IAAIN,aAAa;YACfM,QAAQC,MAAM,CAACC,IAAI,CAAC,CAAC,+CAA+C,EAAEP,gBAAgB;QACxF;QAEA,IAAI;YACF,sBAAsB;YACtB,IAAIQ;YACJ,IAAI;gBACFA,aAAaC,KAAKC,KAAK,CAACN;gBACxB,IAAIL,aAAa;oBACfM,QAAQC,MAAM,CAACC,IAAI,CACjB,CAAC,8BAA8B,EAAEP,eAAe,EAAE,EAAES,KAAKE,SAAS,CAACH,aAAa;gBAEpF;YACF,EAAE,OAAOI,aAAa;gBACpBP,QAAQC,MAAM,CAACO,KAAK,CAAC,CAAC,0CAA0C,EAAET,MAAM;gBACxE,OAAO;oBACLU,SAAS;wBAAC;4BAAEC,MAAM;4BAAiBC,MAAM;wBAAoC;qBAAE;gBACjF;YACF;YAEA,sBAAsB;YACtB,MAAMC,SAAS,MAAMZ,QAAQa,MAAM,CAAC;gBAClCC,YAAYnB;gBACZH;gBACA,sHAAsH;gBACtHO,MAAMH,aAAa,CAACD,eAA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