@payloadcms/plugin-mcp 3.63.0-internal.dc01f92 → 3.64.0-internal.23abf20
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 +2 -2
- package/dist/collections/createApiKeysCollection.d.ts.map +1 -1
- package/dist/collections/createApiKeysCollection.js +67 -6
- package/dist/collections/createApiKeysCollection.js.map +1 -1
- package/dist/endpoints/mcp.d.ts.map +1 -1
- package/dist/endpoints/mcp.js +2 -2
- package/dist/endpoints/mcp.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/mcp/getMcpHandler.d.ts +2 -2
- package/dist/mcp/getMcpHandler.d.ts.map +1 -1
- package/dist/mcp/getMcpHandler.js +61 -49
- package/dist/mcp/getMcpHandler.js.map +1 -1
- package/dist/mcp/tools/resource/create.d.ts.map +1 -1
- package/dist/mcp/tools/resource/create.js +2 -1
- package/dist/mcp/tools/resource/create.js.map +1 -1
- package/dist/mcp/tools/resource/delete.d.ts.map +1 -1
- package/dist/mcp/tools/resource/delete.js +2 -1
- package/dist/mcp/tools/resource/delete.js.map +1 -1
- package/dist/mcp/tools/resource/find.d.ts.map +1 -1
- package/dist/mcp/tools/resource/find.js +3 -1
- package/dist/mcp/tools/resource/find.js.map +1 -1
- package/dist/mcp/tools/resource/update.d.ts.map +1 -1
- package/dist/mcp/tools/resource/update.js +4 -2
- package/dist/mcp/tools/resource/update.js.map +1 -1
- package/dist/mcp/tools/schemas.js +13 -13
- package/dist/mcp/tools/schemas.js.map +1 -1
- package/dist/types.d.ts +9 -3
- 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 +80 -3
- package/src/endpoints/mcp.ts +3 -3
- package/src/index.ts +6 -1
- package/src/mcp/getMcpHandler.ts +79 -59
- package/src/mcp/tools/resource/create.ts +2 -1
- package/src/mcp/tools/resource/delete.ts +2 -1
- package/src/mcp/tools/resource/find.ts +3 -1
- package/src/mcp/tools/resource/update.ts +4 -2
- package/src/mcp/tools/schemas.ts +13 -13
- package/src/types.ts +10 -4
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { CollectionConfig } from 'payload';
|
|
2
2
|
import type { PluginMCPServerConfig } from '../types.js';
|
|
3
|
-
export declare const createAPIKeysCollection: (collections: PluginMCPServerConfig["collections"], customTools
|
|
3
|
+
export declare const createAPIKeysCollection: (collections: PluginMCPServerConfig["collections"], customTools: Array<{
|
|
4
4
|
description: string;
|
|
5
5
|
name: string;
|
|
6
|
-
}
|
|
6
|
+
}> | undefined, experimentalTools: NonNullable<PluginMCPServerConfig["experimental"]>["tools"] | undefined, pluginOptions: PluginMCPServerConfig) => CollectionConfig;
|
|
7
7
|
//# sourceMappingURL=createApiKeysCollection.d.ts.map
|
|
@@ -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;AAiHxD,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,gBA6VF,CAAA"}
|
|
@@ -64,13 +64,14 @@ const addEnabledCollectionTools = (collections)=>{
|
|
|
64
64
|
label: 'Delete'
|
|
65
65
|
}
|
|
66
66
|
] : []
|
|
67
|
-
]
|
|
67
|
+
],
|
|
68
|
+
label: false
|
|
68
69
|
}
|
|
69
70
|
],
|
|
70
71
|
label: `${enabledCollectionSlug.charAt(0).toUpperCase() + toCamelCase(enabledCollectionSlug).slice(1)}`
|
|
71
72
|
}));
|
|
72
73
|
};
|
|
73
|
-
export const createAPIKeysCollection = (collections, customTools = [], experimentalTools = {})=>{
|
|
74
|
+
export const createAPIKeysCollection = (collections, customTools = [], experimentalTools = {}, pluginOptions)=>{
|
|
74
75
|
const customToolsFields = customTools.map((tool)=>{
|
|
75
76
|
const camelCasedName = toCamelCase(tool.name);
|
|
76
77
|
return {
|
|
@@ -83,6 +84,31 @@ export const createAPIKeysCollection = (collections, customTools = [], experimen
|
|
|
83
84
|
label: camelCasedName
|
|
84
85
|
};
|
|
85
86
|
});
|
|
87
|
+
const customResourceFields = pluginOptions.mcp?.resources?.map((resource)=>{
|
|
88
|
+
const camelCasedName = toCamelCase(resource.name);
|
|
89
|
+
return {
|
|
90
|
+
name: camelCasedName,
|
|
91
|
+
type: 'checkbox',
|
|
92
|
+
admin: {
|
|
93
|
+
description: resource.description
|
|
94
|
+
},
|
|
95
|
+
defaultValue: true,
|
|
96
|
+
label: camelCasedName
|
|
97
|
+
};
|
|
98
|
+
}) || [];
|
|
99
|
+
const customPromptFields = pluginOptions.mcp?.prompts?.map((prompt)=>{
|
|
100
|
+
const camelCasedName = toCamelCase(prompt.name);
|
|
101
|
+
return {
|
|
102
|
+
name: camelCasedName,
|
|
103
|
+
type: 'checkbox',
|
|
104
|
+
admin: {
|
|
105
|
+
description: prompt.description
|
|
106
|
+
},
|
|
107
|
+
defaultValue: true,
|
|
108
|
+
label: camelCasedName
|
|
109
|
+
};
|
|
110
|
+
}) || [];
|
|
111
|
+
const userCollection = pluginOptions.userCollection ? typeof pluginOptions.userCollection === 'string' ? pluginOptions.userCollection : pluginOptions.userCollection.slug : 'users';
|
|
86
112
|
return {
|
|
87
113
|
slug: 'payload-mcp-api-keys',
|
|
88
114
|
admin: {
|
|
@@ -100,7 +126,7 @@ export const createAPIKeysCollection = (collections, customTools = [], experimen
|
|
|
100
126
|
admin: {
|
|
101
127
|
description: 'The user that the API key is associated with.'
|
|
102
128
|
},
|
|
103
|
-
relationTo:
|
|
129
|
+
relationTo: userCollection,
|
|
104
130
|
required: true
|
|
105
131
|
},
|
|
106
132
|
{
|
|
@@ -126,12 +152,47 @@ export const createAPIKeysCollection = (collections, customTools = [], experimen
|
|
|
126
152
|
},
|
|
127
153
|
fields: [
|
|
128
154
|
{
|
|
129
|
-
name: '
|
|
155
|
+
name: 'payload-mcp-tool',
|
|
156
|
+
type: 'group',
|
|
157
|
+
fields: customToolsFields,
|
|
158
|
+
label: false
|
|
159
|
+
}
|
|
160
|
+
],
|
|
161
|
+
label: 'Tools'
|
|
162
|
+
}
|
|
163
|
+
] : [],
|
|
164
|
+
...pluginOptions.mcp?.resources && pluginOptions.mcp?.resources.length > 0 ? [
|
|
165
|
+
{
|
|
166
|
+
type: 'collapsible',
|
|
167
|
+
admin: {
|
|
168
|
+
position: 'sidebar'
|
|
169
|
+
},
|
|
170
|
+
fields: [
|
|
171
|
+
{
|
|
172
|
+
name: 'payload-mcp-resource',
|
|
173
|
+
type: 'group',
|
|
174
|
+
fields: customResourceFields,
|
|
175
|
+
label: false
|
|
176
|
+
}
|
|
177
|
+
],
|
|
178
|
+
label: 'Resources'
|
|
179
|
+
}
|
|
180
|
+
] : [],
|
|
181
|
+
...pluginOptions.mcp?.prompts && pluginOptions.mcp?.prompts.length > 0 ? [
|
|
182
|
+
{
|
|
183
|
+
type: 'collapsible',
|
|
184
|
+
admin: {
|
|
185
|
+
position: 'sidebar'
|
|
186
|
+
},
|
|
187
|
+
fields: [
|
|
188
|
+
{
|
|
189
|
+
name: 'payload-mcp-prompt',
|
|
130
190
|
type: 'group',
|
|
131
|
-
fields:
|
|
191
|
+
fields: customPromptFields,
|
|
192
|
+
label: false
|
|
132
193
|
}
|
|
133
194
|
],
|
|
134
|
-
label: '
|
|
195
|
+
label: 'Prompts'
|
|
135
196
|
}
|
|
136
197
|
] : [],
|
|
137
198
|
// Experimental Tools
|
|
@@ -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 },\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): 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 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: 'users',\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: 'custom',\n type: 'group' as const,\n fields: customToolsFields,\n },\n ],\n label: 'Custom Tools',\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","customToolsFields","tool","camelCasedName","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,CAAC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GACD,EAAE;qBACP;oBACDA,OAAO;gBACT;aACD,GACD,EAAE;SACP;QACDwB,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 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;IACA,OAAOP,uBAAuBY,GAAG,CAAC,CAACC,wBAA2B,CAAA;YAC5DC,MAAM;YACNC,OAAO;gBACLC,UAAU;YACZ;YACAC,QAAQ;gBACN;oBACEC,MAAM,GAAGrB,YAAYgB,wBAAwB;oBAC7CC,MAAM;oBACNG,QAAQ;2BACFlB,aAAa,CAACc,sBAAsB,EAAEP,YAAY,QACr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E;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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mcp.d.ts","sourceRoot":"","sources":["../../src/endpoints/mcp.ts"],"names":[],"mappings":"AACA,OAAO,EAAY,KAAK,cAAc,EAAc,MAAM,SAAS,CAAA;AAEnE,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"mcp.d.ts","sourceRoot":"","sources":["../../src/endpoints/mcp.ts"],"names":[],"mappings":"AACA,OAAO,EAAY,KAAK,cAAc,EAAc,MAAM,SAAS,CAAA;AAEnE,OAAO,KAAK,EAAqB,qBAAqB,EAAE,MAAM,aAAa,CAAA;AAK3E,eAAO,MAAM,oBAAoB,kBAAmB,qBAAqB,mBAmDxE,CAAA"}
|
package/dist/endpoints/mcp.js
CHANGED
|
@@ -30,11 +30,11 @@ export const initializeMCPHandler = (pluginOptions)=>{
|
|
|
30
30
|
if (docs.length === 0) {
|
|
31
31
|
throw new APIError('API Key is invalid', 401);
|
|
32
32
|
}
|
|
33
|
-
const
|
|
33
|
+
const mcpAccessSettings = docs[0];
|
|
34
34
|
if (useVerboseLogs) {
|
|
35
35
|
payload.logger.info('[payload-mcp] API Key is valid');
|
|
36
36
|
}
|
|
37
|
-
const handler = getMCPHandler(pluginOptions,
|
|
37
|
+
const handler = getMCPHandler(pluginOptions, mcpAccessSettings, req);
|
|
38
38
|
const request = createRequestFromPayloadRequest(req);
|
|
39
39
|
return await handler(request);
|
|
40
40
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/endpoints/mcp.ts"],"sourcesContent":["import crypto from 'crypto'\nimport { APIError, type PayloadHandler, type Where } from 'payload'\n\nimport type {
|
|
1
|
+
{"version":3,"sources":["../../src/endpoints/mcp.ts"],"sourcesContent":["import crypto from 'crypto'\nimport { APIError, type PayloadHandler, 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 apiKey = req.headers.get('Authorization')?.startsWith('Bearer ')\n ? req.headers.get('Authorization')?.replace('Bearer ', '').trim()\n : null\n\n if (apiKey === null) {\n throw new APIError('API Key is required', 401)\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 const where: Where = {\n or: apiKeyConstraints,\n }\n\n const { docs } = await payload.find({\n collection: 'payload-mcp-api-keys',\n where,\n })\n\n if (docs.length === 0) {\n throw new APIError('API Key is invalid', 401)\n }\n\n const mcpAccessSettings = docs[0] as MCPAccessSettings\n\n if (useVerboseLogs) {\n payload.logger.info('[payload-mcp] API Key is valid')\n }\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","APIError","createRequestFromPayloadRequest","getMCPHandler","initializeMCPHandler","pluginOptions","mcpHandler","req","payload","MCPOptions","mcp","MCPHandlerOptions","handlerOptions","useVerboseLogs","verboseLogs","apiKey","headers","get","startsWith","replace","trim","sha256APIKeyIndex","createHmac","secret","update","digest","apiKeyConstraints","apiKeyIndex","equals","where","or","docs","find","collection","length","mcpAccessSettings","logger","info","handler","request"],"mappings":"AAAA,OAAOA,YAAY,SAAQ;AAC3B,SAASC,QAAQ,QAAyC,UAAS;AAInE,SAASC,+BAA+B,QAAQ,0BAAyB;AACzE,SAASC,aAAa,QAAQ,0BAAyB;AAEvD,OAAO,MAAMC,uBAAuB,CAACC;IACnC,MAAMC,aAA6B,OAAOC;QACxC,MAAM,EAAEC,OAAO,EAAE,GAAGD;QACpB,MAAME,aAAaJ,cAAcK,GAAG,IAAI,CAAC;QACzC,MAAMC,oBAAoBF,WAAWG,cAAc,IAAI,CAAC;QACxD,MAAMC,iBAAiBF,kBAAkBG,WAAW,IAAI;QAExD,MAAMC,SAASR,IAAIS,OAAO,CAACC,GAAG,CAAC,kBAAkBC,WAAW,aACxDX,IAAIS,OAAO,CAACC,GAAG,CAAC,kBAAkBE,QAAQ,WAAW,IAAIC,SACzD;QAEJ,IAAIL,WAAW,MAAM;YACnB,MAAM,IAAId,SAAS,uBAAuB;QAC5C;QAEA,MAAMoB,oBAAoBrB,OACvBsB,UAAU,CAAC,UAAUd,QAAQe,MAAM,EACnCC,MAAM,CAACT,UAAU,IACjBU,MAAM,CAAC;QAEV,MAAMC,oBAAoB;YACxB;gBACEC,aAAa;oBACXC,QAAQP;gBACV;YACF;SACD;QACD,MAAMQ,QAAe;YACnBC,IAAIJ;QACN;QAEA,MAAM,EAAEK,IAAI,EAAE,GAAG,MAAMvB,QAAQwB,IAAI,CAAC;YAClCC,YAAY;YACZJ;QACF;QAEA,IAAIE,KAAKG,MAAM,KAAK,GAAG;YACrB,MAAM,IAAIjC,SAAS,sBAAsB;QAC3C;QAEA,MAAMkC,oBAAoBJ,IAAI,CAAC,EAAE;QAEjC,IAAIlB,gBAAgB;YAClBL,QAAQ4B,MAAM,CAACC,IAAI,CAAC;QACtB;QAEA,MAAMC,UAAUnC,cAAcE,eAAe8B,mBAAmB5B;QAChE,MAAMgC,UAAUrC,gCAAgCK;QAChD,OAAO,MAAM+B,QAAQC;IACvB;IACA,OAAOjC;AACT,EAAC"}
|
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;AAKvD;;;;;GAKG;AACH,eAAO,MAAM,SAAS,kBACJ,qBAAqB,cAC5B,MAAM,KAAG,
|
|
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;AAKvD;;;;;GAKG;AACH,eAAO,MAAM,SAAS,kBACJ,qBAAqB,cAC5B,MAAM,KAAG,MA2EjB,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -29,7 +29,7 @@ import { initializeMCPHandler } from './endpoints/mcp.js';
|
|
|
29
29
|
* - If a collection only has the find capability enabled, admins can only allow or disallow the find capability on that collection.
|
|
30
30
|
* - If a custom tool has gone haywire, admins can disallow that tool.
|
|
31
31
|
*
|
|
32
|
-
*/ const apiKeyCollection = createAPIKeysCollection(collections, customTools, experimentalTools);
|
|
32
|
+
*/ const apiKeyCollection = createAPIKeysCollection(collections, customTools, experimentalTools, pluginOptions);
|
|
33
33
|
if (pluginOptions.overrideApiKeyCollection) {
|
|
34
34
|
config.collections.push(pluginOptions.overrideApiKeyCollection(apiKeyCollection));
|
|
35
35
|
} else {
|
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(collections
|
|
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;AAEzD;;;;;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,4 +1,4 @@
|
|
|
1
1
|
import { type PayloadRequest } from 'payload';
|
|
2
|
-
import type {
|
|
3
|
-
export declare const getMCPHandler: (pluginOptions: PluginMCPServerConfig,
|
|
2
|
+
import type { MCPAccessSettings, PluginMCPServerConfig } from '../types.js';
|
|
3
|
+
export declare const getMCPHandler: (pluginOptions: PluginMCPServerConfig, mcpAccessSettings: MCPAccessSettings, req: PayloadRequest) => (request: Request) => Promise<Response>;
|
|
4
4
|
//# sourceMappingURL=getMcpHandler.d.ts.map
|
|
@@ -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,
|
|
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;AA4B3E,eAAO,MAAM,aAAa,kBACT,qBAAqB,qBACjB,iBAAiB,OAC/B,cAAc,4CA+ZpB,CAAA"}
|
|
@@ -24,11 +24,11 @@ import { updateConfigTool } from './tools/config/update.js';
|
|
|
24
24
|
import { createJobTool } from './tools/job/create.js';
|
|
25
25
|
import { runJobTool } from './tools/job/run.js';
|
|
26
26
|
import { updateJobTool } from './tools/job/update.js';
|
|
27
|
-
export const getMCPHandler = (pluginOptions,
|
|
27
|
+
export const getMCPHandler = (pluginOptions, mcpAccessSettings, req)=>{
|
|
28
28
|
const { payload } = req;
|
|
29
29
|
const configSchema = configToJSONSchema(payload.config);
|
|
30
30
|
// User
|
|
31
|
-
const user =
|
|
31
|
+
const user = mcpAccessSettings.user;
|
|
32
32
|
// MCP Server and Handler Options
|
|
33
33
|
const MCPOptions = pluginOptions.mcp || {};
|
|
34
34
|
const customMCPTools = MCPOptions.tools || [];
|
|
@@ -60,7 +60,7 @@ export const getMCPHandler = (pluginOptions, toolSettings, req)=>{
|
|
|
60
60
|
enabledCollectionSlugs.forEach((enabledCollectionSlug)=>{
|
|
61
61
|
try {
|
|
62
62
|
const schema = configSchema.definitions?.[enabledCollectionSlug];
|
|
63
|
-
const toolCapabilities =
|
|
63
|
+
const toolCapabilities = mcpAccessSettings?.[`${toCamelCase(enabledCollectionSlug)}`];
|
|
64
64
|
const allowCreate = toolCapabilities['create'];
|
|
65
65
|
const allowUpdate = toolCapabilities['update'];
|
|
66
66
|
const allowFind = toolCapabilities['find'];
|
|
@@ -84,80 +84,92 @@ export const getMCPHandler = (pluginOptions, toolSettings, req)=>{
|
|
|
84
84
|
// Custom tools
|
|
85
85
|
customMCPTools.forEach((tool)=>{
|
|
86
86
|
const camelCasedToolName = toCamelCase(tool.name);
|
|
87
|
-
const isToolEnabled =
|
|
87
|
+
const isToolEnabled = mcpAccessSettings['payload-mcp-tool']?.[camelCasedToolName] ?? true;
|
|
88
88
|
registerTool(isToolEnabled, tool.name, ()=>server.tool(tool.name, tool.description, tool.parameters, tool.handler), payload, useVerboseLogs);
|
|
89
89
|
});
|
|
90
90
|
// Custom prompts
|
|
91
91
|
customMCPPrompts.forEach((prompt)=>{
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
92
|
+
const camelCasedPromptName = toCamelCase(prompt.name);
|
|
93
|
+
const isPromptEnabled = mcpAccessSettings['payload-mcp-prompt']?.[camelCasedPromptName] ?? true;
|
|
94
|
+
if (isPromptEnabled) {
|
|
95
|
+
server.registerPrompt(prompt.name, {
|
|
96
|
+
argsSchema: prompt.argsSchema,
|
|
97
|
+
description: prompt.description,
|
|
98
|
+
title: prompt.title
|
|
99
|
+
}, prompt.handler);
|
|
100
|
+
if (useVerboseLogs) {
|
|
101
|
+
payload.logger.info(`[payload-mcp] ✅ Prompt: ${prompt.title} Registered.`);
|
|
102
|
+
}
|
|
103
|
+
} else if (useVerboseLogs) {
|
|
104
|
+
payload.logger.info(`[payload-mcp] ⏭️ Prompt: ${prompt.title} Skipped.`);
|
|
99
105
|
}
|
|
100
106
|
});
|
|
101
107
|
// Custom resources
|
|
102
108
|
customMCPResources.forEach((resource)=>{
|
|
103
|
-
|
|
104
|
-
resource
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
109
|
+
const camelCasedResourceName = toCamelCase(resource.name);
|
|
110
|
+
const isResourceEnabled = mcpAccessSettings['payload-mcp-resource']?.[camelCasedResourceName] ?? true;
|
|
111
|
+
if (isResourceEnabled) {
|
|
112
|
+
server.registerResource(resource.name, // @ts-expect-error - Overload type is not working however -- ResourceTemplate OR String is a valid type
|
|
113
|
+
resource.uri, {
|
|
114
|
+
description: resource.description,
|
|
115
|
+
mimeType: resource.mimeType,
|
|
116
|
+
title: resource.title
|
|
117
|
+
}, resource.handler);
|
|
118
|
+
if (useVerboseLogs) {
|
|
119
|
+
payload.logger.info(`[payload-mcp] ✅ Resource: ${resource.title} Registered.`);
|
|
120
|
+
}
|
|
121
|
+
} else if (useVerboseLogs) {
|
|
122
|
+
payload.logger.info(`[payload-mcp] ⏭️ Resource: ${resource.title} Skipped.`);
|
|
111
123
|
}
|
|
112
124
|
});
|
|
113
125
|
// Experimental - Collection Schema Modfication Tools
|
|
114
|
-
if (
|
|
115
|
-
registerTool(
|
|
126
|
+
if (mcpAccessSettings.collections?.create && experimentalTools.collections?.enabled && isDevelopment) {
|
|
127
|
+
registerTool(mcpAccessSettings.collections.create, 'Create Collection', ()=>createCollectionTool(server, req, useVerboseLogs, collectionsDirPath, configFilePath), payload, useVerboseLogs);
|
|
116
128
|
}
|
|
117
|
-
if (
|
|
118
|
-
registerTool(
|
|
129
|
+
if (mcpAccessSettings.collections?.delete && experimentalTools.collections?.enabled && isDevelopment) {
|
|
130
|
+
registerTool(mcpAccessSettings.collections.delete, 'Delete Collection', ()=>deleteCollectionTool(server, req, useVerboseLogs, collectionsDirPath, configFilePath), payload, useVerboseLogs);
|
|
119
131
|
}
|
|
120
|
-
if (
|
|
121
|
-
registerTool(
|
|
132
|
+
if (mcpAccessSettings.collections?.find && experimentalTools.collections?.enabled && isDevelopment) {
|
|
133
|
+
registerTool(mcpAccessSettings.collections.find, 'Find Collection', ()=>findCollectionTool(server, req, useVerboseLogs, collectionsDirPath), payload, useVerboseLogs);
|
|
122
134
|
}
|
|
123
|
-
if (
|
|
124
|
-
registerTool(
|
|
135
|
+
if (mcpAccessSettings.collections?.update && experimentalTools.collections?.enabled && isDevelopment) {
|
|
136
|
+
registerTool(mcpAccessSettings.collections.update, 'Update Collection', ()=>updateCollectionTool(server, req, useVerboseLogs, collectionsDirPath, configFilePath), payload, useVerboseLogs);
|
|
125
137
|
}
|
|
126
138
|
// Experimental - Payload Config Modification Tools
|
|
127
|
-
if (
|
|
128
|
-
registerTool(
|
|
139
|
+
if (mcpAccessSettings.config?.find && experimentalTools.config?.enabled && isDevelopment) {
|
|
140
|
+
registerTool(mcpAccessSettings.config.find, 'Find Config', ()=>findConfigTool(server, req, useVerboseLogs, configFilePath), payload, useVerboseLogs);
|
|
129
141
|
}
|
|
130
|
-
if (
|
|
131
|
-
registerTool(
|
|
142
|
+
if (mcpAccessSettings.config?.update && experimentalTools.config?.enabled && isDevelopment) {
|
|
143
|
+
registerTool(mcpAccessSettings.config.update, 'Update Config', ()=>updateConfigTool(server, req, useVerboseLogs, configFilePath), payload, useVerboseLogs);
|
|
132
144
|
}
|
|
133
145
|
// Experimental - Job Modification Tools
|
|
134
|
-
if (
|
|
135
|
-
registerTool(
|
|
146
|
+
if (mcpAccessSettings.jobs?.create && experimentalTools.jobs?.enabled && isDevelopment) {
|
|
147
|
+
registerTool(mcpAccessSettings.jobs.create, 'Create Job', ()=>createJobTool(server, req, useVerboseLogs, jobsDirPath), payload, useVerboseLogs);
|
|
136
148
|
}
|
|
137
|
-
if (
|
|
138
|
-
registerTool(
|
|
149
|
+
if (mcpAccessSettings.jobs?.update && experimentalTools.jobs?.enabled && isDevelopment) {
|
|
150
|
+
registerTool(mcpAccessSettings.jobs.update, 'Update Job', ()=>updateJobTool(server, req, useVerboseLogs, jobsDirPath), payload, useVerboseLogs);
|
|
139
151
|
}
|
|
140
|
-
if (
|
|
141
|
-
registerTool(
|
|
152
|
+
if (mcpAccessSettings.jobs?.run && experimentalTools.jobs?.enabled && isDevelopment) {
|
|
153
|
+
registerTool(mcpAccessSettings.jobs.run, 'Run Job', ()=>runJobTool(server, req, useVerboseLogs), payload, useVerboseLogs);
|
|
142
154
|
}
|
|
143
155
|
// Experimental - Auth Modification Tools
|
|
144
|
-
if (
|
|
145
|
-
registerTool(
|
|
156
|
+
if (mcpAccessSettings.auth?.auth && experimentalTools.auth?.enabled && isDevelopment) {
|
|
157
|
+
registerTool(mcpAccessSettings.auth.auth, 'Auth', ()=>authTool(server, req, useVerboseLogs), payload, useVerboseLogs);
|
|
146
158
|
}
|
|
147
|
-
if (
|
|
148
|
-
registerTool(
|
|
159
|
+
if (mcpAccessSettings.auth?.login && experimentalTools.auth?.enabled && isDevelopment) {
|
|
160
|
+
registerTool(mcpAccessSettings.auth.login, 'Login', ()=>loginTool(server, req, useVerboseLogs), payload, useVerboseLogs);
|
|
149
161
|
}
|
|
150
|
-
if (
|
|
151
|
-
registerTool(
|
|
162
|
+
if (mcpAccessSettings.auth?.verify && experimentalTools.auth?.enabled && isDevelopment) {
|
|
163
|
+
registerTool(mcpAccessSettings.auth.verify, 'Verify', ()=>verifyTool(server, req, useVerboseLogs), payload, useVerboseLogs);
|
|
152
164
|
}
|
|
153
|
-
if (
|
|
154
|
-
registerTool(
|
|
165
|
+
if (mcpAccessSettings.auth?.resetPassword && experimentalTools.auth?.enabled) {
|
|
166
|
+
registerTool(mcpAccessSettings.auth.resetPassword, 'Reset Password', ()=>resetPasswordTool(server, req, useVerboseLogs), payload, useVerboseLogs);
|
|
155
167
|
}
|
|
156
|
-
if (
|
|
157
|
-
registerTool(
|
|
168
|
+
if (mcpAccessSettings.auth?.forgotPassword && experimentalTools.auth?.enabled) {
|
|
169
|
+
registerTool(mcpAccessSettings.auth.forgotPassword, 'Forgot Password', ()=>forgotPasswordTool(server, req, useVerboseLogs), payload, useVerboseLogs);
|
|
158
170
|
}
|
|
159
|
-
if (
|
|
160
|
-
registerTool(
|
|
171
|
+
if (mcpAccessSettings.auth?.unlock && experimentalTools.auth?.enabled) {
|
|
172
|
+
registerTool(mcpAccessSettings.auth.unlock, 'Unlock', ()=>unlockTool(server, req, useVerboseLogs), payload, useVerboseLogs);
|
|
161
173
|
}
|
|
162
174
|
if (useVerboseLogs) {
|
|
163
175
|
payload.logger.info('[payload-mcp] 🚀 MCP Server Ready.');
|