@payloadcms/plugin-mcp 3.64.0-canary.3 → 3.64.0-canary.5
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 +29 -24
- package/dist/endpoints/mcp.js.map +1 -1
- package/dist/index.d.ts +2 -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/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 +40 -30
- package/src/index.ts +2 -1
- package/src/mcp/createRequest.ts +2 -2
- package/src/mcp/getMcpHandler.ts +10 -7
- 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,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,aAAa,CAACK,WAAW,EAAEE,SAASI,WAAW,QAChD,OAAOX,aAAa,CAACK,WAAW,EAAEE,SAASK,WAAW,aACrDZ,aAAa,CAACK,WAAW,EAAEE,SAASK,WAAW,IAAI;QAEzD,IAAIJ,kBAAkB;YACpB,OAAO;QACT;IACF;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,EAAE;2BACFO,mBAAmB0B,QAAQ/C,UAC3B;4BACE;gCACEY,MAAM;gCACNJ,MAAM;gCACNG,QAAQ;oCACN;wCACEC,MAAM;wCACNJ,MAAM;wCACNC,OAAO;4CACLI,aACE;wCACJ;wCACAC,cAAc;oCAChB;oCACA;wCACEF,MAAM;wCACNJ,MAAM;wCACNC,OAAO;4CACLI,aACE;wCACJ;wCACAC,cAAc;oCAChB;iCACD;4BACH;yBACD,GACD,EAAE;2BACFO,mBAAmBgB,MAAMrC,UACzB;4BACE;gCACEY,MAAM;gCACNJ,MAAM;gCACNG,QAAQ;oCACN;wCACEC,MAAM;wCACNJ,MAAM;wCACNC,OAAO;4CACLI,aACE;wCACJ;wCACAC,cAAc;wCACdC,OAAO;oCACT;oCACA;wCACEH,MAAM;wCACNJ,MAAM;wCACNC,OAAO;4CACLI,aACE;wCACJ;wCACAC,cAAc;wCACdC,OAAO;oCACT;oCACA;wCACEH,MAAM;wCACNJ,MAAM;wCACNC,OAAO;4CACLI,aACE;wCACJ;wCACAC,cAAc;wCACdC,OAAO;oCACT;oCACA;wCACEH,MAAM;wCACNJ,MAAM;wCACNC,OAAO;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,aAAa,CAACK,WAAW,EAAEE,SAASI,WAAW,QAChD,OAAOX,aAAa,CAACK,WAAW,EAAEE,SAASK,WAAW,aACrDZ,aAAa,CAACK,WAAW,EAAEE,SAASK,WAAW,IAAI;QAEzD,IAAIJ,kBAAkB;YACpB,OAAO;QACT;IACF;IACA,OAAOP,uBAAuBY,GAAG,CAAC,CAACC,wBAA2B,CAAA;YAC5DC,MAAM;YACNC,OAAO;gBACLC,aAAa,CAAC,wBAAwB,EAAEH,uBAAuB;gBAC/DI,UAAU;YACZ;YACAC,QAAQ;gBACN;oBACEC,MAAM,GAAGtB,YAAYgB,wBAAwB;oBAC7CC,MAAM;oBACNI,QAAQ;2BACFnB,aAAa,CAACc,sBAAsB,EAAEP,YAAY,QACrD,OAAOP,aAAa,CAACc,sBAAsB,EAAEP,YAAY,aACxD,OAAO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AC/BqB,mBAAmByB,MAAM9C,WACzBqB,mBAAmB0B,QAAQ/C,WAC3BqB,mBAAmBgB,MAAMrC,OAAM,IAC7B;gBACE;oBACEQ,MAAM;oBACNC,OAAO;wBACLC,aAAa;wBACbC,UAAU;oBACZ;oBACAC,QAAQ;2BACFS,mBAAmB5B,aAAaO,UAChC;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;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,mBAAmByB,MAAM9C,UACzB;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;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,mBA6DxE,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,37 @@ export const initializeMCPHandler = (pluginOptions)=>{
|
|
|
8
8
|
const MCPOptions = pluginOptions.mcp || {};
|
|
9
9
|
const MCPHandlerOptions = MCPOptions.handlerOptions || {};
|
|
10
10
|
const useVerboseLogs = MCPHandlerOptions.verboseLogs ?? false;
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
11
|
+
const getDefaultMcpAccessSettings = async (overrideApiKey)=>{
|
|
12
|
+
const apiKey = overrideApiKey ?? req.headers.get('Authorization')?.startsWith('Bearer ') ? req.headers.get('Authorization')?.replace('Bearer ', '').trim() : null;
|
|
13
|
+
if (apiKey === null) {
|
|
14
|
+
throw new UnauthorizedError();
|
|
15
|
+
}
|
|
16
|
+
const sha256APIKeyIndex = crypto.createHmac('sha256', payload.secret).update(apiKey || '').digest('hex');
|
|
17
|
+
const apiKeyConstraints = [
|
|
18
|
+
{
|
|
19
|
+
apiKeyIndex: {
|
|
20
|
+
equals: sha256APIKeyIndex
|
|
21
|
+
}
|
|
20
22
|
}
|
|
23
|
+
];
|
|
24
|
+
const where = {
|
|
25
|
+
or: apiKeyConstraints
|
|
26
|
+
};
|
|
27
|
+
const { docs } = await payload.find({
|
|
28
|
+
collection: 'payload-mcp-api-keys',
|
|
29
|
+
limit: 1,
|
|
30
|
+
pagination: false,
|
|
31
|
+
where
|
|
32
|
+
});
|
|
33
|
+
if (docs.length === 0) {
|
|
34
|
+
throw new UnauthorizedError();
|
|
35
|
+
}
|
|
36
|
+
if (useVerboseLogs) {
|
|
37
|
+
payload.logger.info('[payload-mcp] API Key is valid');
|
|
21
38
|
}
|
|
22
|
-
|
|
23
|
-
const where = {
|
|
24
|
-
or: apiKeyConstraints
|
|
39
|
+
return docs[0];
|
|
25
40
|
};
|
|
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
|
-
}
|
|
41
|
+
const mcpAccessSettings = pluginOptions.overrideAuth ? await pluginOptions.overrideAuth(req, getDefaultMcpAccessSettings) : await getDefaultMcpAccessSettings();
|
|
37
42
|
const handler = getMCPHandler(pluginOptions, mcpAccessSettings, req);
|
|
38
43
|
const request = createRequestFromPayloadRequest(req);
|
|
39
44
|
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 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","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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
-
import type { PluginMCPServerConfig } from './types.js';
|
|
2
|
+
import type { MCPAccessSettings, PluginMCPServerConfig } from './types.js';
|
|
3
|
+
export type { MCPAccessSettings };
|
|
3
4
|
/**
|
|
4
5
|
* The MCP Plugin for Payload. This plugin allows you to add MCP capabilities to your Payload project.
|
|
5
6
|
*
|
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,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\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;AAGzD;;;;;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,QAAQ,OAAM;AAC3B,SAASC,QAAQ,EAAEC,kBAAkB,QAA6C,UAAS;AAI3F,SAASC,WAAW,QAAQ,wBAAuB;AACnD,SAASC,YAAY,QAAQ,oBAAmB;AAEhD,QAAQ;AACR,SAASC,kBAAkB,QAAQ,6BAA4B;AAC/D,SAASC,kBAAkB,QAAQ,6BAA4B;AAC/D,SAASC,gBAAgB,QAAQ,2BAA0B;AAC3D,SAASC,kBAAkB,QAAQ,6BAA4B;AAE/D,qBAAqB;AACrB,SAASC,QAAQ,QAAQ,uBAAsB;AAC/C,SAASC,kBAAkB,QAAQ,iCAAgC;AACnE,SAASC,SAAS,QAAQ,wBAAuB;AACjD,SAASC,iBAAiB,QAAQ,gCAA+B;AACjE,SAASC,UAAU,QAAQ,yBAAwB;AACnD,SAASC,UAAU,QAAQ,yBAAwB;AACnD,SAASC,oBAAoB,QAAQ,+BAA8B;AACnE,SAASC,oBAAoB,QAAQ,+BAA8B;AACnE,SAASC,kBAAkB,QAAQ,6BAA4B;AAC/D,SAASC,oBAAoB,QAAQ,+BAA8B;AACnE,SAASC,cAAc,QAAQ,yBAAwB;AACvD,SAASC,gBAAgB,QAAQ,2BAA0B;AAC3D,SAASC,aAAa,QAAQ,wBAAuB;AACrD,SAASC,UAAU,QAAQ,qBAAoB;AAC/C,SAASC,aAAa,QAAQ,wBAAuB;AAErD,OAAO,MAAMC,gBAAgB,CAC3BC,eACAC,mBACAC;IAEA,MAAM,EAAEC,OAAO,EAAE,GAAGD;IACpB,MAAME,eAAe3B,m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kBAAkB8E,IAAI,CAACI,cAAc,EACrC,mBACA,IAAMlG,mBAAmBgD,QAAQ/B,KAAKgB,iBACtCf,SACAe;YAEJ;YAEA,IAAIjB,kBAAkB8E,IAAI,EAAEK,UAAU5D,kBAAkBuD,IAAI,EAAEvC,SAAS;gBACrE7D,aACEsB,kBAAkB8E,IAAI,CAACK,MAAM,EAC7B,UACA,IAAMhG,WAAW6C,QAAQ/B,KAAKgB,iBAC9Bf,SACAe;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,QAA6C,UAAS;AAI3F,SAASC,WAAW,QAAQ,wBAAuB;AACnD,SAASC,YAAY,QAAQ,oBAAmB;AAEhD,QAAQ;AACR,SAASC,kBAAkB,QAAQ,6BAA4B;AAC/D,SAASC,kBAAkB,QAAQ,6BAA4B;AAC/D,SAASC,gBAAgB,QAAQ,2BAA0B;AAC3D,SAASC,kBAAkB,QAAQ,6BAA4B;AAE/D,qBAAqB;AACrB;;CAEC,GACD,SAASC,QAAQ,QAAQ,uBAAsB;AAC/C,SAASC,kBAAkB,QAAQ,iCAAgC;AACnE,SAASC,SAAS,QAAQ,wBAAuB;AACjD,SAASC,iBAAiB,QAAQ,gCAA+B;AACjE,SAASC,UAAU,QAAQ,yBAAwB;AACnD,SAASC,UAAU,QAAQ,yBAAwB;AACnD,SAASC,oBAAoB,QAAQ,+BAA8B;AACnE,SAASC,oBAAoB,QAAQ,+BAA8B;AACnE,SAASC,kBAAkB,QAAQ,6BAA4B;AAC/D,SAASC,oBAAoB,QAAQ,+BAA8B;AACnE,SAASC,cAAc,QAAQ,yBAAwB;AACvD,SAASC,gBAAgB,QAAQ,2BAA0B;AAC3D,SAASC,aAAa,QAAQ,wBAAuB;AACrD,SAASC,UAAU,QAAQ,qBAAoB;AAC/C,SAASC,aAAa,QAAQ,wBAAuB;AAErD,OAAO,MAAMC,gBAAgB,CAC3BC,eACAC,mBACAC;IAEA,MAAM,EAAEC,OAAO,EAAE,GAAGD;IACpB,MAAME,eAAe3B,mBAAmB0B,QAAQE,MAAM;IAEtD,OAAO;IACP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ACtCf,SACAe;YAEJ;YAEA,IAAIjB,kBAAkB8E,IAAI,EAAEK,UAAU5D,kBAAkBuD,IAAI,EAAEvC,SAAS;gBACrE7D,aACEsB,kBAAkB8E,IAAI,CAACK,MAAM,EAC7B,UACA,IAAMhG,WAAW6C,QAAQ/B,KAAKgB,iBAC9Bf,SACAe;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"}
|
package/dist/types.d.ts
CHANGED
|
@@ -197,7 +197,20 @@ export type PluginMCPServerConfig = {
|
|
|
197
197
|
parameters: z.ZodRawShape;
|
|
198
198
|
}[];
|
|
199
199
|
};
|
|
200
|
+
/**
|
|
201
|
+
* Override the API key collection.
|
|
202
|
+
* This allows you to add fields to the API key collection or modify the collection in any way you want.
|
|
203
|
+
* @param collection - The API key collection.
|
|
204
|
+
* @returns The modified API key collection.
|
|
205
|
+
*/
|
|
200
206
|
overrideApiKeyCollection?: (collection: CollectionConfig) => CollectionConfig;
|
|
207
|
+
/**
|
|
208
|
+
* Override the authentication method.
|
|
209
|
+
* This allows you to use a custom authentication method instead of the default API key authentication.
|
|
210
|
+
* @param req - The request object.
|
|
211
|
+
* @returns The MCP access settings.
|
|
212
|
+
*/
|
|
213
|
+
overrideAuth?: (req: PayloadRequest, getDefaultMcpAccessSettings: (overrideApiKey?: null | string) => Promise<MCPAccessSettings>) => MCPAccessSettings | Promise<MCPAccessSettings>;
|
|
201
214
|
/**
|
|
202
215
|
* Set the users collection that API keys should be associated with.
|
|
203
216
|
*/
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAC/E,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAE5B,OAAO,EAAE,KAAK,gBAAgB,EAAE,MAAM,yCAAyC,CAAA;AAE/E,MAAM,MAAM,qBAAqB,GAAG;IAClC;;OAEG;IACH,WAAW,CAAC,EAAE,OAAO,CACnB,MAAM,CACJ,cAAc,EACd;QACE;;WAEG;QACH,WAAW,CAAC,EAAE,MAAM,CAAA;QACpB;;WAEG;QACH,OAAO,EACH;YACE,MAAM,CAAC,EAAE,OAAO,CAAA;YAChB,MAAM,CAAC,EAAE,OAAO,CAAA;YAChB,IAAI,CAAC,EAAE,OAAO,CAAA;YACd,MAAM,CAAC,EAAE,OAAO,CAAA;SACjB,GACD,OAAO,CAAA;QACX;;WAEG;QACH,QAAQ,CAAC,EAAE,CACT,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACjC,GAAG,EAAE,cAAc,KAChB,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;QAE5B;;WAEG;QACH,gBAAgB,CAAC,EAAE,CACjB,QAAQ,EAAE;YACR,OAAO,EAAE,KAAK,CAAC;gBACb,IAAI,EAAE,MAAM,CAAA;gBACZ,IAAI,EAAE,MAAM,CAAA;aACb,CAAC,CAAA;SACH,EACD,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC5B,GAAG,EAAE,cAAc,KAChB;YACH,OAAO,EAAE,KAAK,CAAC;gBACb,IAAI,EAAE,MAAM,CAAA;gBACZ,IAAI,EAAE,MAAM,CAAA;aACb,CAAC,CAAA;SACH,CAAA;KACF,CACF,CACF,CA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type { CollectionConfig, CollectionSlug, PayloadRequest } from 'payload'\nimport type { z } from 'zod'\n\nimport { type ResourceTemplate } from '@modelcontextprotocol/sdk/server/mcp.js'\n\nexport type PluginMCPServerConfig = {\n /**\n * Set the collections that should be available as resources via MCP.\n */\n collections?: Partial<\n Record<\n CollectionSlug,\n {\n /**\n * Set the description of the collection. This is used by MCP clients to determine when to use the collecton as a resource.\n */\n description?: string\n /**\n * Set the enabled capabilities of the collection. Admins can then allow or disallow the use of the capability by MCP clients.\n */\n enabled:\n | {\n create?: boolean\n delete?: boolean\n find?: boolean\n update?: boolean\n }\n | boolean\n /**\n * Override the data generated by the MCP client. This allows you to modify the data that is sent to the MCP client. This is useful for adding additional data to the response, data normalization, or verifying data.\n */\n override?: (\n original: Record<string, unknown>,\n req: PayloadRequest,\n ) => Record<string, unknown>\n\n /**\n * Override the response generated by the MCP client. This allows you to modify the response that is sent to the MCP client. This is useful for adding additional data to the response, data normalization, or verifying data.\n */\n overrideResponse?: (\n response: {\n content: Array<{\n text: string\n type: string\n }>\n },\n doc: Record<string, unknown>,\n req: PayloadRequest,\n ) => {\n content: Array<{\n text: string\n type: string\n }>\n }\n }\n >\n >\n /**\n * Disable the MCP plugin.\n */\n disabled?: boolean\n /**\n * Experimental features\n * **These features are for experimental purposes -- They are Disabled in Production by Default**\n */\n experimental?: {\n /**\n * These are MCP tools that can be used by a client to modify Payload.\n */\n tools: {\n /**\n * **Experimental** -- Auth MCP tools allow a client to change authentication priviliages for users. This is for developing ideas that help Admins with authentication tasks.\n */\n auth?: {\n /**\n * Enable the auth MCP tools. This allows Admins to enable or disable the auth capabilities.\n * @default false\n */\n enabled: boolean\n }\n /**\n * **Experimental** -- Collection MCP tools allow for the creation, modification, and deletion of Payload collections. This is for developing ideas that help Developers with collection tasks.\n */\n collections?: {\n /**\n * Set the directory path to the collections directory. This can be a directory outside of your default directory, or another Payload project.\n */\n collectionsDirPath: string\n /**\n * Enable the collection MCP tools. This allows Admins to enable or disable the Collection modification capabilities.\n * @default false\n */\n enabled: boolean\n }\n /**\n * **Experimental** -- Config MCP tools allow for the modification of a Payload Config. This is for developing ideas that help Developers with config tasks.\n */\n config?: {\n /**\n * Set the directory path to the config directory. This can be a directory outside of your default directory, or another Payload project.\n */\n configFilePath: string\n /**\n * Enable the config MCP tools. This allows Admins to enable or disable the Payload Config modification capabilities.\n * @default false\n */\n enabled: boolean\n }\n /**\n * **Experimental** -- Jobs MCP tools allow for the modification of Payload jobs. This is for developing ideas that help Developers with job tasks.\n */\n jobs?: {\n /**\n * Enable the jobs MCP tools. This allows Admins to enable or disable the Job modification capabilities.\n * @default false\n */\n enabled: boolean\n /**\n * Set the directory path to the jobs directory. This can be a directory outside of your default directory, or another Payload project.\n */\n jobsDirPath: string\n }\n }\n }\n /**\n * MCP Server options.\n */\n mcp?: {\n handlerOptions?: MCPHandlerOptions\n /**\n * Add custom MCP Prompts.\n */\n prompts?: {\n /**\n * Set the args schema of the prompt. This is the args schema that will be passed to the prompt. This is used by MCP clients to determine the arguments that will be passed to the prompt.\n */\n argsSchema: z.ZodRawShape\n /**\n * Set the description of the prompt. This is used by MCP clients to determine when to use the prompt.\n */\n description: string\n /**\n * Set the handler of the prompt. This is the function that will be called when the prompt is used.\n */\n handler: (...args: any) => any\n /**\n * Set the function name of the prompt.\n */\n name: string\n /**\n * Set the title of the prompt. LLMs will interperate the title to determine when to use the prompt.\n */\n title: string\n }[]\n\n /**\n * Add custom MCP Resource.\n */\n resources?: {\n /**\n * Set the description of the resource. This is used by MCP clients to determine when to use the resource.\n * example: 'Data is a resource that contains special data.'\n */\n description: string\n /**\n * Set the handler of the resource. This is the function that will be called when the resource is used.\n */\n handler: (...args: any) => any\n /**\n * Set the mime type of the resource.\n * example: 'text/plain'\n */\n mimeType: string\n /**\n * Set the function name of the resource.\n * example: 'data'\n */\n name: string\n /**\n * Set the title of the resource. LLMs will interperate the title to determine when to use the resource.\n * example: 'Data'\n */\n title: string\n /**\n * Set the uri of the resource.\n * example: 'data://app'\n */\n uri: ResourceTemplate | string\n }[]\n serverOptions?: MCPServerOptions\n /**\n * Add custom MCP Tools.\n */\n tools?: {\n /**\n * Set the description of the tool. This is used by MCP clients to determine when to use the tool.\n */\n description: string\n /**\n * Set the handler of the tool. This is the function that will be called when the tool is used.\n */\n handler: (args: Record<string, unknown>) => Promise<{\n content: Array<{\n text: string\n type: 'text'\n }>\n }>\n /**\n * Set the name of the tool. This is the name that will be used to identify the tool. LLMs will interperate the name to determine when to use the tool.\n */\n name: string\n /**\n * Set the parameters of the tool. This is the parameters that will be passed to the tool.\n */\n parameters: z.ZodRawShape\n }[]\n }\n overrideApiKeyCollection?: (collection: CollectionConfig) => CollectionConfig\n\n /**\n * Set the users collection that API keys should be associated with.\n */\n userCollection?: CollectionConfig | string\n}\n\n/**\n * MCP Handler options.\n */\nexport type MCPHandlerOptions = {\n /**\n * Set the base path of the MCP handler. This is the path that will be used to access the MCP handler.\n * @default /api\n */\n basePath?: string\n /**\n * Set the maximum duration of the MCP handler. This is the maximum duration that the MCP handler will run for.\n * @default 60\n */\n maxDuration?: number\n /**\n * Set the Redis URL for the MCP handler. This is the URL that will be used to access the Redis server.\n * @default process.env.REDIS_URL\n * INFO: Disabled until developer clarity is reached for server side streaming and we have an auth pattern for all SSE patterns\n */\n // redisUrl?: string\n /**\n * Set verbose logging.\n * @default false\n */\n verboseLogs?: boolean\n}\n\n/**\n * MCP Server options.\n */\nexport type MCPServerOptions = {\n /**\n * Set the server info of the MCP server.\n */\n serverInfo?: {\n /**\n * Set the name of the MCP server.\n * @default 'Payload MCP Server'\n */\n name: string\n /**\n * Set the version of the MCP server.\n * @default '1.0.0'\n */\n version: string\n }\n}\n\nexport type MCPAccessSettings = {\n auth?: {\n auth?: boolean\n forgotPassword?: boolean\n login?: boolean\n resetPassword?: boolean\n unlock?: boolean\n verify?: boolean\n }\n collections?: {\n create?: boolean\n delete?: boolean\n find?: boolean\n update?: boolean\n }\n config?: {\n find?: boolean\n update?: boolean\n }\n jobs?: {\n create?: boolean\n run?: boolean\n update?: boolean\n }\n 'payload-mcp-prompt'?: Record<string, boolean>\n 'payload-mcp-resource'?: Record<string, boolean>\n 'payload-mcp-tool'?: Record<string, boolean>\n} & Record<string, unknown>\n\nexport type FieldDefinition = {\n description?: string\n name: string\n options?: { label: string; value: string }[]\n position?: 'main' | 'sidebar'\n required?: boolean\n type: string\n}\n\nexport type FieldModification = {\n changes: {\n description?: string\n options?: { label: string; value: string }[]\n position?: 'main' | 'sidebar'\n required?: boolean\n type?: string\n }\n fieldName: string\n}\n\nexport type CollectionConfigUpdates = {\n access?: {\n create?: string\n delete?: string\n read?: string\n update?: string\n }\n description?: string\n slug?: string\n timestamps?: boolean\n versioning?: boolean\n}\n\nexport type AdminConfig = {\n avatar?: string\n css?: string\n dateFormat?: string\n inactivityRoute?: string\n livePreview?: {\n breakpoints?: Array<{\n height: number\n label: string\n name: string\n width: number\n }>\n }\n logoutRoute?: string\n meta?: {\n favicon?: string\n ogImage?: string\n titleSuffix?: string\n }\n user?: string\n}\n\nexport type DatabaseConfig = {\n connectOptions?: string\n type?: 'mongodb' | 'postgres'\n url?: string\n}\n\nexport type PluginUpdates = {\n add?: string[]\n remove?: string[]\n}\n\nexport type GeneralConfig = {\n cookiePrefix?: string\n cors?: string\n csrf?: string\n graphQL?: {\n disable?: boolean\n schemaOutputFile?: string\n }\n rateLimit?: {\n max?: number\n skip?: string\n window?: number\n }\n secret?: string\n serverURL?: string\n typescript?: {\n declare?: boolean\n outputFile?: string\n }\n}\n\nexport interface SchemaField {\n description?: string\n name: string\n options?: string[]\n required?: boolean\n type: string\n}\n\nexport interface TaskSequenceItem {\n description?: string\n retries?: number\n taskId: string\n taskSlug: string\n timeout?: number\n}\n\nexport interface JobConfigUpdate {\n description?: string\n queue?: string\n retries?: number\n timeout?: number\n}\n"],"names":[],"mappings":"AAqZA,WAKC"}
|
|
1
|
+
{"version":3,"sources":["../src/types.ts"],"sourcesContent":["import type { CollectionConfig, CollectionSlug, PayloadRequest } from 'payload'\nimport type { z } from 'zod'\n\nimport { type ResourceTemplate } from '@modelcontextprotocol/sdk/server/mcp.js'\n\nexport type PluginMCPServerConfig = {\n /**\n * Set the collections that should be available as resources via MCP.\n */\n collections?: Partial<\n Record<\n CollectionSlug,\n {\n /**\n * Set the description of the collection. This is used by MCP clients to determine when to use the collecton as a resource.\n */\n description?: string\n /**\n * Set the enabled capabilities of the collection. Admins can then allow or disallow the use of the capability by MCP clients.\n */\n enabled:\n | {\n create?: boolean\n delete?: boolean\n find?: boolean\n update?: boolean\n }\n | boolean\n /**\n * Override the data generated by the MCP client. This allows you to modify the data that is sent to the MCP client. This is useful for adding additional data to the response, data normalization, or verifying data.\n */\n override?: (\n original: Record<string, unknown>,\n req: PayloadRequest,\n ) => Record<string, unknown>\n\n /**\n * Override the response generated by the MCP client. This allows you to modify the response that is sent to the MCP client. This is useful for adding additional data to the response, data normalization, or verifying data.\n */\n overrideResponse?: (\n response: {\n content: Array<{\n text: string\n type: string\n }>\n },\n doc: Record<string, unknown>,\n req: PayloadRequest,\n ) => {\n content: Array<{\n text: string\n type: string\n }>\n }\n }\n >\n >\n /**\n * Disable the MCP plugin.\n */\n disabled?: boolean\n /**\n * Experimental features\n * **These features are for experimental purposes -- They are Disabled in Production by Default**\n */\n experimental?: {\n /**\n * These are MCP tools that can be used by a client to modify Payload.\n */\n tools: {\n /**\n * **Experimental** -- Auth MCP tools allow a client to change authentication priviliages for users. This is for developing ideas that help Admins with authentication tasks.\n */\n auth?: {\n /**\n * Enable the auth MCP tools. This allows Admins to enable or disable the auth capabilities.\n * @default false\n */\n enabled: boolean\n }\n /**\n * **Experimental** -- Collection MCP tools allow for the creation, modification, and deletion of Payload collections. This is for developing ideas that help Developers with collection tasks.\n */\n collections?: {\n /**\n * Set the directory path to the collections directory. This can be a directory outside of your default directory, or another Payload project.\n */\n collectionsDirPath: string\n /**\n * Enable the collection MCP tools. This allows Admins to enable or disable the Collection modification capabilities.\n * @default false\n */\n enabled: boolean\n }\n /**\n * **Experimental** -- Config MCP tools allow for the modification of a Payload Config. This is for developing ideas that help Developers with config tasks.\n */\n config?: {\n /**\n * Set the directory path to the config directory. This can be a directory outside of your default directory, or another Payload project.\n */\n configFilePath: string\n /**\n * Enable the config MCP tools. This allows Admins to enable or disable the Payload Config modification capabilities.\n * @default false\n */\n enabled: boolean\n }\n /**\n * **Experimental** -- Jobs MCP tools allow for the modification of Payload jobs. This is for developing ideas that help Developers with job tasks.\n */\n jobs?: {\n /**\n * Enable the jobs MCP tools. This allows Admins to enable or disable the Job modification capabilities.\n * @default false\n */\n enabled: boolean\n /**\n * Set the directory path to the jobs directory. This can be a directory outside of your default directory, or another Payload project.\n */\n jobsDirPath: string\n }\n }\n }\n /**\n * MCP Server options.\n */\n mcp?: {\n handlerOptions?: MCPHandlerOptions\n /**\n * Add custom MCP Prompts.\n */\n prompts?: {\n /**\n * Set the args schema of the prompt. This is the args schema that will be passed to the prompt. This is used by MCP clients to determine the arguments that will be passed to the prompt.\n */\n argsSchema: z.ZodRawShape\n /**\n * Set the description of the prompt. This is used by MCP clients to determine when to use the prompt.\n */\n description: string\n /**\n * Set the handler of the prompt. This is the function that will be called when the prompt is used.\n */\n handler: (...args: any) => any\n /**\n * Set the function name of the prompt.\n */\n name: string\n /**\n * Set the title of the prompt. LLMs will interperate the title to determine when to use the prompt.\n */\n title: string\n }[]\n\n /**\n * Add custom MCP Resource.\n */\n resources?: {\n /**\n * Set the description of the resource. This is used by MCP clients to determine when to use the resource.\n * example: 'Data is a resource that contains special data.'\n */\n description: string\n /**\n * Set the handler of the resource. This is the function that will be called when the resource is used.\n */\n handler: (...args: any) => any\n /**\n * Set the mime type of the resource.\n * example: 'text/plain'\n */\n mimeType: string\n /**\n * Set the function name of the resource.\n * example: 'data'\n */\n name: string\n /**\n * Set the title of the resource. LLMs will interperate the title to determine when to use the resource.\n * example: 'Data'\n */\n title: string\n /**\n * Set the uri of the resource.\n * example: 'data://app'\n */\n uri: ResourceTemplate | string\n }[]\n serverOptions?: MCPServerOptions\n /**\n * Add custom MCP Tools.\n */\n tools?: {\n /**\n * Set the description of the tool. This is used by MCP clients to determine when to use the tool.\n */\n description: string\n /**\n * Set the handler of the tool. This is the function that will be called when the tool is used.\n */\n handler: (args: Record<string, unknown>) => Promise<{\n content: Array<{\n text: string\n type: 'text'\n }>\n }>\n /**\n * Set the name of the tool. This is the name that will be used to identify the tool. LLMs will interperate the name to determine when to use the tool.\n */\n name: string\n /**\n * Set the parameters of the tool. This is the parameters that will be passed to the tool.\n */\n parameters: z.ZodRawShape\n }[]\n }\n\n /**\n * Override the API key collection.\n * This allows you to add fields to the API key collection or modify the collection in any way you want.\n * @param collection - The API key collection.\n * @returns The modified API key collection.\n */\n overrideApiKeyCollection?: (collection: CollectionConfig) => CollectionConfig\n\n /**\n * Override the authentication method.\n * This allows you to use a custom authentication method instead of the default API key authentication.\n * @param req - The request object.\n * @returns The MCP access settings.\n */\n overrideAuth?: (\n req: PayloadRequest,\n getDefaultMcpAccessSettings: (overrideApiKey?: null | string) => Promise<MCPAccessSettings>,\n ) => MCPAccessSettings | Promise<MCPAccessSettings>\n\n /**\n * Set the users collection that API keys should be associated with.\n */\n userCollection?: CollectionConfig | string\n}\n\n/**\n * MCP Handler options.\n */\nexport type MCPHandlerOptions = {\n /**\n * Set the base path of the MCP handler. This is the path that will be used to access the MCP handler.\n * @default /api\n */\n basePath?: string\n /**\n * Set the maximum duration of the MCP handler. This is the maximum duration that the MCP handler will run for.\n * @default 60\n */\n maxDuration?: number\n /**\n * Set the Redis URL for the MCP handler. This is the URL that will be used to access the Redis server.\n * @default process.env.REDIS_URL\n * INFO: Disabled until developer clarity is reached for server side streaming and we have an auth pattern for all SSE patterns\n */\n // redisUrl?: string\n /**\n * Set verbose logging.\n * @default false\n */\n verboseLogs?: boolean\n}\n\n/**\n * MCP Server options.\n */\nexport type MCPServerOptions = {\n /**\n * Set the server info of the MCP server.\n */\n serverInfo?: {\n /**\n * Set the name of the MCP server.\n * @default 'Payload MCP Server'\n */\n name: string\n /**\n * Set the version of the MCP server.\n * @default '1.0.0'\n */\n version: string\n }\n}\n\nexport type MCPAccessSettings = {\n auth?: {\n auth?: boolean\n forgotPassword?: boolean\n login?: boolean\n resetPassword?: boolean\n unlock?: boolean\n verify?: boolean\n }\n collections?: {\n create?: boolean\n delete?: boolean\n find?: boolean\n update?: boolean\n }\n config?: {\n find?: boolean\n update?: boolean\n }\n jobs?: {\n create?: boolean\n run?: boolean\n update?: boolean\n }\n 'payload-mcp-prompt'?: Record<string, boolean>\n 'payload-mcp-resource'?: Record<string, boolean>\n 'payload-mcp-tool'?: Record<string, boolean>\n} & Record<string, unknown>\n\nexport type FieldDefinition = {\n description?: string\n name: string\n options?: { label: string; value: string }[]\n position?: 'main' | 'sidebar'\n required?: boolean\n type: string\n}\n\nexport type FieldModification = {\n changes: {\n description?: string\n options?: { label: string; value: string }[]\n position?: 'main' | 'sidebar'\n required?: boolean\n type?: string\n }\n fieldName: string\n}\n\nexport type CollectionConfigUpdates = {\n access?: {\n create?: string\n delete?: string\n read?: string\n update?: string\n }\n description?: string\n slug?: string\n timestamps?: boolean\n versioning?: boolean\n}\n\nexport type AdminConfig = {\n avatar?: string\n css?: string\n dateFormat?: string\n inactivityRoute?: string\n livePreview?: {\n breakpoints?: Array<{\n height: number\n label: string\n name: string\n width: number\n }>\n }\n logoutRoute?: string\n meta?: {\n favicon?: string\n ogImage?: string\n titleSuffix?: string\n }\n user?: string\n}\n\nexport type DatabaseConfig = {\n connectOptions?: string\n type?: 'mongodb' | 'postgres'\n url?: string\n}\n\nexport type PluginUpdates = {\n add?: string[]\n remove?: string[]\n}\n\nexport type GeneralConfig = {\n cookiePrefix?: string\n cors?: string\n csrf?: string\n graphQL?: {\n disable?: boolean\n schemaOutputFile?: string\n }\n rateLimit?: {\n max?: number\n skip?: string\n window?: number\n }\n secret?: string\n serverURL?: string\n typescript?: {\n declare?: boolean\n outputFile?: string\n }\n}\n\nexport interface SchemaField {\n description?: string\n name: string\n options?: string[]\n required?: boolean\n type: string\n}\n\nexport interface TaskSequenceItem {\n description?: string\n retries?: number\n taskId: string\n taskSlug: string\n timeout?: number\n}\n\nexport interface JobConfigUpdate {\n description?: string\n queue?: string\n retries?: number\n timeout?: number\n}\n"],"names":[],"mappings":"AAuaA,WAKC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@payloadcms/plugin-mcp",
|
|
3
|
-
"version": "3.64.0-canary.
|
|
3
|
+
"version": "3.64.0-canary.5",
|
|
4
4
|
"description": "MCP (Model Context Protocol) capabilities with Payload",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"plugin",
|
|
@@ -45,10 +45,10 @@
|
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
47
|
"@payloadcms/eslint-config": "3.28.0",
|
|
48
|
-
"payload": "3.64.0-canary.
|
|
48
|
+
"payload": "3.64.0-canary.5"
|
|
49
49
|
},
|
|
50
50
|
"peerDependencies": {
|
|
51
|
-
"payload": "3.64.0-canary.
|
|
51
|
+
"payload": "3.64.0-canary.5"
|
|
52
52
|
},
|
|
53
53
|
"homepage:": "https://payloadcms.com",
|
|
54
54
|
"scripts": {
|
|
@@ -31,6 +31,7 @@ const addEnabledCollectionTools = (collections: PluginMCPServerConfig['collectio
|
|
|
31
31
|
return enabledCollectionSlugs.map((enabledCollectionSlug) => ({
|
|
32
32
|
type: 'collapsible' as const,
|
|
33
33
|
admin: {
|
|
34
|
+
description: `Manage client access to ${enabledCollectionSlug}`,
|
|
34
35
|
position: 'sidebar' as const,
|
|
35
36
|
},
|
|
36
37
|
fields: [
|
|
@@ -169,6 +170,8 @@ export const createAPIKeysCollection = (
|
|
|
169
170
|
return {
|
|
170
171
|
slug: 'payload-mcp-api-keys',
|
|
171
172
|
admin: {
|
|
173
|
+
description:
|
|
174
|
+
'API keys control which collections, resources, tools, and prompts MCP clients can access',
|
|
172
175
|
group: 'MCP',
|
|
173
176
|
useAsTitle: 'label',
|
|
174
177
|
},
|
|
@@ -208,6 +211,7 @@ export const createAPIKeysCollection = (
|
|
|
208
211
|
{
|
|
209
212
|
type: 'collapsible' as const,
|
|
210
213
|
admin: {
|
|
214
|
+
description: 'Manage client access to tools',
|
|
211
215
|
position: 'sidebar' as const,
|
|
212
216
|
},
|
|
213
217
|
fields: [
|
|
@@ -228,6 +232,7 @@ export const createAPIKeysCollection = (
|
|
|
228
232
|
{
|
|
229
233
|
type: 'collapsible' as const,
|
|
230
234
|
admin: {
|
|
235
|
+
description: 'Manage client access to resources',
|
|
231
236
|
position: 'sidebar' as const,
|
|
232
237
|
},
|
|
233
238
|
fields: [
|
|
@@ -248,6 +253,7 @@ export const createAPIKeysCollection = (
|
|
|
248
253
|
{
|
|
249
254
|
type: 'collapsible' as const,
|
|
250
255
|
admin: {
|
|
256
|
+
description: 'Manage client access to prompts',
|
|
251
257
|
position: 'sidebar' as const,
|
|
252
258
|
},
|
|
253
259
|
fields: [
|
|
@@ -273,6 +279,7 @@ export const createAPIKeysCollection = (
|
|
|
273
279
|
{
|
|
274
280
|
type: 'collapsible' as const,
|
|
275
281
|
admin: {
|
|
282
|
+
description: 'Manage client access to experimental tools',
|
|
276
283
|
position: 'sidebar' as const,
|
|
277
284
|
},
|
|
278
285
|
fields: [
|
package/src/endpoints/mcp.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import crypto from 'crypto'
|
|
2
|
-
import {
|
|
2
|
+
import { type PayloadHandler, UnauthorizedError, type Where } from 'payload'
|
|
3
3
|
|
|
4
4
|
import type { MCPAccessSettings, PluginMCPServerConfig } from '../types.js'
|
|
5
5
|
|
|
@@ -13,45 +13,55 @@ export const initializeMCPHandler = (pluginOptions: PluginMCPServerConfig) => {
|
|
|
13
13
|
const MCPHandlerOptions = MCPOptions.handlerOptions || {}
|
|
14
14
|
const useVerboseLogs = MCPHandlerOptions.verboseLogs ?? false
|
|
15
15
|
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
const getDefaultMcpAccessSettings = async (overrideApiKey?: null | string) => {
|
|
17
|
+
const apiKey =
|
|
18
|
+
(overrideApiKey ?? req.headers.get('Authorization')?.startsWith('Bearer '))
|
|
19
|
+
? req.headers.get('Authorization')?.replace('Bearer ', '').trim()
|
|
20
|
+
: null
|
|
19
21
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
22
|
+
if (apiKey === null) {
|
|
23
|
+
throw new UnauthorizedError()
|
|
24
|
+
}
|
|
23
25
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
26
|
+
const sha256APIKeyIndex = crypto
|
|
27
|
+
.createHmac('sha256', payload.secret)
|
|
28
|
+
.update(apiKey || '')
|
|
29
|
+
.digest('hex')
|
|
28
30
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
31
|
+
const apiKeyConstraints = [
|
|
32
|
+
{
|
|
33
|
+
apiKeyIndex: {
|
|
34
|
+
equals: sha256APIKeyIndex,
|
|
35
|
+
},
|
|
33
36
|
},
|
|
34
|
-
|
|
35
|
-
]
|
|
36
|
-
const where: Where = {
|
|
37
|
-
or: apiKeyConstraints,
|
|
38
|
-
}
|
|
37
|
+
]
|
|
39
38
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
})
|
|
39
|
+
const where: Where = {
|
|
40
|
+
or: apiKeyConstraints,
|
|
41
|
+
}
|
|
44
42
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
43
|
+
const { docs } = await payload.find({
|
|
44
|
+
collection: 'payload-mcp-api-keys',
|
|
45
|
+
limit: 1,
|
|
46
|
+
pagination: false,
|
|
47
|
+
where,
|
|
48
|
+
})
|
|
48
49
|
|
|
49
|
-
|
|
50
|
+
if (docs.length === 0) {
|
|
51
|
+
throw new UnauthorizedError()
|
|
52
|
+
}
|
|
50
53
|
|
|
51
|
-
|
|
52
|
-
|
|
54
|
+
if (useVerboseLogs) {
|
|
55
|
+
payload.logger.info('[payload-mcp] API Key is valid')
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return docs[0] as MCPAccessSettings
|
|
53
59
|
}
|
|
54
60
|
|
|
61
|
+
const mcpAccessSettings = pluginOptions.overrideAuth
|
|
62
|
+
? await pluginOptions.overrideAuth(req, getDefaultMcpAccessSettings)
|
|
63
|
+
: await getDefaultMcpAccessSettings()
|
|
64
|
+
|
|
55
65
|
const handler = getMCPHandler(pluginOptions, mcpAccessSettings, req)
|
|
56
66
|
const request = createRequestFromPayloadRequest(req)
|
|
57
67
|
return await handler(request)
|
package/src/index.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import type { Config } from 'payload'
|
|
2
2
|
|
|
3
|
-
import type { PluginMCPServerConfig } from './types.js'
|
|
3
|
+
import type { MCPAccessSettings, PluginMCPServerConfig } from './types.js'
|
|
4
4
|
|
|
5
5
|
import { createAPIKeysCollection } from './collections/createApiKeysCollection.js'
|
|
6
6
|
import { initializeMCPHandler } from './endpoints/mcp.js'
|
|
7
7
|
|
|
8
|
+
export type { MCPAccessSettings }
|
|
8
9
|
/**
|
|
9
10
|
* The MCP Plugin for Payload. This plugin allows you to add MCP capabilities to your Payload project.
|
|
10
11
|
*
|
package/src/mcp/createRequest.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AuthenticationError, type PayloadRequest } from 'payload'
|
|
2
2
|
|
|
3
3
|
export const createRequestFromPayloadRequest = (req: PayloadRequest) => {
|
|
4
4
|
if (!req.url) {
|
|
5
|
-
throw new
|
|
5
|
+
throw new AuthenticationError()
|
|
6
6
|
}
|
|
7
7
|
return new Request(req.url, {
|
|
8
8
|
body: req.body,
|
package/src/mcp/getMcpHandler.ts
CHANGED
|
@@ -16,6 +16,9 @@ import { findResourceTool } from './tools/resource/find.js'
|
|
|
16
16
|
import { updateResourceTool } from './tools/resource/update.js'
|
|
17
17
|
|
|
18
18
|
// Experimental Tools
|
|
19
|
+
/**
|
|
20
|
+
* @experimental This tools are experimental and may change or be removed in the future.
|
|
21
|
+
*/
|
|
19
22
|
import { authTool } from './tools/auth/auth.js'
|
|
20
23
|
import { forgotPasswordTool } from './tools/auth/forgotPassword.js'
|
|
21
24
|
import { loginTool } from './tools/auth/login.js'
|
|
@@ -108,10 +111,10 @@ export const getMCPHandler = (
|
|
|
108
111
|
const toolCapabilities = mcpAccessSettings?.[
|
|
109
112
|
`${toCamelCase(enabledCollectionSlug)}`
|
|
110
113
|
] as Record<string, unknown>
|
|
111
|
-
const allowCreate: boolean | undefined = toolCapabilities
|
|
112
|
-
const allowUpdate: boolean | undefined = toolCapabilities
|
|
113
|
-
const allowFind: boolean | undefined = toolCapabilities
|
|
114
|
-
const allowDelete: boolean | undefined = toolCapabilities
|
|
114
|
+
const allowCreate: boolean | undefined = toolCapabilities?.create as boolean
|
|
115
|
+
const allowUpdate: boolean | undefined = toolCapabilities?.update as boolean
|
|
116
|
+
const allowFind: boolean | undefined = toolCapabilities?.find as boolean
|
|
117
|
+
const allowDelete: boolean | undefined = toolCapabilities?.delete as boolean
|
|
115
118
|
|
|
116
119
|
if (allowCreate) {
|
|
117
120
|
registerTool(
|
|
@@ -194,7 +197,7 @@ export const getMCPHandler = (
|
|
|
194
197
|
// Custom tools
|
|
195
198
|
customMCPTools.forEach((tool) => {
|
|
196
199
|
const camelCasedToolName = toCamelCase(tool.name)
|
|
197
|
-
const isToolEnabled = mcpAccessSettings['payload-mcp-tool']?.[camelCasedToolName] ??
|
|
200
|
+
const isToolEnabled = mcpAccessSettings['payload-mcp-tool']?.[camelCasedToolName] ?? false
|
|
198
201
|
|
|
199
202
|
registerTool(
|
|
200
203
|
isToolEnabled,
|
|
@@ -209,7 +212,7 @@ export const getMCPHandler = (
|
|
|
209
212
|
customMCPPrompts.forEach((prompt) => {
|
|
210
213
|
const camelCasedPromptName = toCamelCase(prompt.name)
|
|
211
214
|
const isPromptEnabled =
|
|
212
|
-
mcpAccessSettings['payload-mcp-prompt']?.[camelCasedPromptName] ??
|
|
215
|
+
mcpAccessSettings['payload-mcp-prompt']?.[camelCasedPromptName] ?? false
|
|
213
216
|
|
|
214
217
|
if (isPromptEnabled) {
|
|
215
218
|
server.registerPrompt(
|
|
@@ -233,7 +236,7 @@ export const getMCPHandler = (
|
|
|
233
236
|
customMCPResources.forEach((resource) => {
|
|
234
237
|
const camelCasedResourceName = toCamelCase(resource.name)
|
|
235
238
|
const isResourceEnabled =
|
|
236
|
-
mcpAccessSettings['payload-mcp-resource']?.[camelCasedResourceName] ??
|
|
239
|
+
mcpAccessSettings['payload-mcp-resource']?.[camelCasedResourceName] ?? false
|
|
237
240
|
|
|
238
241
|
if (isResourceEnabled) {
|
|
239
242
|
server.registerResource(
|
package/src/types.ts
CHANGED
|
@@ -215,8 +215,26 @@ export type PluginMCPServerConfig = {
|
|
|
215
215
|
parameters: z.ZodRawShape
|
|
216
216
|
}[]
|
|
217
217
|
}
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* Override the API key collection.
|
|
221
|
+
* This allows you to add fields to the API key collection or modify the collection in any way you want.
|
|
222
|
+
* @param collection - The API key collection.
|
|
223
|
+
* @returns The modified API key collection.
|
|
224
|
+
*/
|
|
218
225
|
overrideApiKeyCollection?: (collection: CollectionConfig) => CollectionConfig
|
|
219
226
|
|
|
227
|
+
/**
|
|
228
|
+
* Override the authentication method.
|
|
229
|
+
* This allows you to use a custom authentication method instead of the default API key authentication.
|
|
230
|
+
* @param req - The request object.
|
|
231
|
+
* @returns The MCP access settings.
|
|
232
|
+
*/
|
|
233
|
+
overrideAuth?: (
|
|
234
|
+
req: PayloadRequest,
|
|
235
|
+
getDefaultMcpAccessSettings: (overrideApiKey?: null | string) => Promise<MCPAccessSettings>,
|
|
236
|
+
) => MCPAccessSettings | Promise<MCPAccessSettings>
|
|
237
|
+
|
|
220
238
|
/**
|
|
221
239
|
* Set the users collection that API keys should be associated with.
|
|
222
240
|
*/
|