@payloadcms/plugin-mcp 0.0.1-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (173) hide show
  1. package/LICENSE.md +22 -0
  2. package/README.md +7 -0
  3. package/dist/collections/createApiKeysCollection.d.ts +7 -0
  4. package/dist/collections/createApiKeysCollection.d.ts.map +1 -0
  5. package/dist/collections/createApiKeysCollection.js +315 -0
  6. package/dist/collections/createApiKeysCollection.js.map +1 -0
  7. package/dist/endpoints/mcp.d.ts +4 -0
  8. package/dist/endpoints/mcp.d.ts.map +1 -0
  9. package/dist/endpoints/mcp.js +44 -0
  10. package/dist/endpoints/mcp.js.map +1 -0
  11. package/dist/index.d.ts +10 -0
  12. package/dist/index.d.ts.map +1 -0
  13. package/dist/index.js +67 -0
  14. package/dist/index.js.map +1 -0
  15. package/dist/mcp/createRequest.d.ts +3 -0
  16. package/dist/mcp/createRequest.d.ts.map +1 -0
  17. package/dist/mcp/createRequest.js +14 -0
  18. package/dist/mcp/createRequest.js.map +1 -0
  19. package/dist/mcp/getMcpHandler.d.ts +4 -0
  20. package/dist/mcp/getMcpHandler.d.ts.map +1 -0
  21. package/dist/mcp/getMcpHandler.js +179 -0
  22. package/dist/mcp/getMcpHandler.js.map +1 -0
  23. package/dist/mcp/helpers/config.d.ts +30 -0
  24. package/dist/mcp/helpers/config.d.ts.map +1 -0
  25. package/dist/mcp/helpers/config.js +217 -0
  26. package/dist/mcp/helpers/config.js.map +1 -0
  27. package/dist/mcp/helpers/conversion.d.ts +2 -0
  28. package/dist/mcp/helpers/conversion.d.ts.map +1 -0
  29. package/dist/mcp/helpers/conversion.js +5 -0
  30. package/dist/mcp/helpers/conversion.js.map +1 -0
  31. package/dist/mcp/helpers/fields.d.ts +38 -0
  32. package/dist/mcp/helpers/fields.d.ts.map +1 -0
  33. package/dist/mcp/helpers/fields.js +96 -0
  34. package/dist/mcp/helpers/fields.js.map +1 -0
  35. package/dist/mcp/helpers/fileValidation.d.ts +69 -0
  36. package/dist/mcp/helpers/fileValidation.d.ts.map +1 -0
  37. package/dist/mcp/helpers/fileValidation.js +305 -0
  38. package/dist/mcp/helpers/fileValidation.js.map +1 -0
  39. package/dist/mcp/helpers/validation.d.ts +9 -0
  40. package/dist/mcp/helpers/validation.d.ts.map +1 -0
  41. package/dist/mcp/helpers/validation.js +22 -0
  42. package/dist/mcp/helpers/validation.js.map +1 -0
  43. package/dist/mcp/registerTool.d.ts +6 -0
  44. package/dist/mcp/registerTool.d.ts.map +1 -0
  45. package/dist/mcp/registerTool.js +18 -0
  46. package/dist/mcp/registerTool.js.map +1 -0
  47. package/dist/mcp/tools/auth/auth.d.ts +4 -0
  48. package/dist/mcp/tools/auth/auth.d.ts.map +1 -0
  49. package/dist/mcp/tools/auth/auth.js +54 -0
  50. package/dist/mcp/tools/auth/auth.js.map +1 -0
  51. package/dist/mcp/tools/auth/forgotPassword.d.ts +4 -0
  52. package/dist/mcp/tools/auth/forgotPassword.d.ts.map +1 -0
  53. package/dist/mcp/tools/auth/forgotPassword.js +45 -0
  54. package/dist/mcp/tools/auth/forgotPassword.js.map +1 -0
  55. package/dist/mcp/tools/auth/login.d.ts +4 -0
  56. package/dist/mcp/tools/auth/login.d.ts.map +1 -0
  57. package/dist/mcp/tools/auth/login.js +48 -0
  58. package/dist/mcp/tools/auth/login.js.map +1 -0
  59. package/dist/mcp/tools/auth/resetPassword.d.ts +4 -0
  60. package/dist/mcp/tools/auth/resetPassword.d.ts.map +1 -0
  61. package/dist/mcp/tools/auth/resetPassword.js +46 -0
  62. package/dist/mcp/tools/auth/resetPassword.js.map +1 -0
  63. package/dist/mcp/tools/auth/unlock.d.ts +4 -0
  64. package/dist/mcp/tools/auth/unlock.d.ts.map +1 -0
  65. package/dist/mcp/tools/auth/unlock.js +45 -0
  66. package/dist/mcp/tools/auth/unlock.js.map +1 -0
  67. package/dist/mcp/tools/auth/verify.d.ts +4 -0
  68. package/dist/mcp/tools/auth/verify.d.ts.map +1 -0
  69. package/dist/mcp/tools/auth/verify.js +42 -0
  70. package/dist/mcp/tools/auth/verify.js.map +1 -0
  71. package/dist/mcp/tools/collection/create.d.ts +10 -0
  72. package/dist/mcp/tools/collection/create.d.ts.map +1 -0
  73. package/dist/mcp/tools/collection/create.js +159 -0
  74. package/dist/mcp/tools/collection/create.js.map +1 -0
  75. package/dist/mcp/tools/collection/delete.d.ts +10 -0
  76. package/dist/mcp/tools/collection/delete.d.ts.map +1 -0
  77. package/dist/mcp/tools/collection/delete.js +162 -0
  78. package/dist/mcp/tools/collection/delete.js.map +1 -0
  79. package/dist/mcp/tools/collection/find.d.ts +10 -0
  80. package/dist/mcp/tools/collection/find.d.ts.map +1 -0
  81. package/dist/mcp/tools/collection/find.js +162 -0
  82. package/dist/mcp/tools/collection/find.js.map +1 -0
  83. package/dist/mcp/tools/collection/update.d.ts +10 -0
  84. package/dist/mcp/tools/collection/update.d.ts.map +1 -0
  85. package/dist/mcp/tools/collection/update.js +206 -0
  86. package/dist/mcp/tools/collection/update.js.map +1 -0
  87. package/dist/mcp/tools/config/find.d.ts +10 -0
  88. package/dist/mcp/tools/config/find.d.ts.map +1 -0
  89. package/dist/mcp/tools/config/find.js +94 -0
  90. package/dist/mcp/tools/config/find.js.map +1 -0
  91. package/dist/mcp/tools/config/update.d.ts +10 -0
  92. package/dist/mcp/tools/config/update.d.ts.map +1 -0
  93. package/dist/mcp/tools/config/update.js +212 -0
  94. package/dist/mcp/tools/config/update.js.map +1 -0
  95. package/dist/mcp/tools/job/create.d.ts +10 -0
  96. package/dist/mcp/tools/job/create.d.ts.map +1 -0
  97. package/dist/mcp/tools/job/create.js +293 -0
  98. package/dist/mcp/tools/job/create.js.map +1 -0
  99. package/dist/mcp/tools/job/run.d.ts +10 -0
  100. package/dist/mcp/tools/job/run.d.ts.map +1 -0
  101. package/dist/mcp/tools/job/run.js +147 -0
  102. package/dist/mcp/tools/job/run.js.map +1 -0
  103. package/dist/mcp/tools/job/update.d.ts +11 -0
  104. package/dist/mcp/tools/job/update.d.ts.map +1 -0
  105. package/dist/mcp/tools/job/update.js +211 -0
  106. package/dist/mcp/tools/job/update.js.map +1 -0
  107. package/dist/mcp/tools/resource/create.d.ts +6 -0
  108. package/dist/mcp/tools/resource/create.d.ts.map +1 -0
  109. package/dist/mcp/tools/resource/create.js +75 -0
  110. package/dist/mcp/tools/resource/create.js.map +1 -0
  111. package/dist/mcp/tools/resource/delete.d.ts +5 -0
  112. package/dist/mcp/tools/resource/delete.d.ts.map +1 -0
  113. package/dist/mcp/tools/resource/delete.js +140 -0
  114. package/dist/mcp/tools/resource/delete.js.map +1 -0
  115. package/dist/mcp/tools/resource/find.d.ts +5 -0
  116. package/dist/mcp/tools/resource/find.d.ts.map +1 -0
  117. package/dist/mcp/tools/resource/find.js +119 -0
  118. package/dist/mcp/tools/resource/find.js.map +1 -0
  119. package/dist/mcp/tools/resource/update.d.ts +6 -0
  120. package/dist/mcp/tools/resource/update.d.ts.map +1 -0
  121. package/dist/mcp/tools/resource/update.js +201 -0
  122. package/dist/mcp/tools/resource/update.js.map +1 -0
  123. package/dist/mcp/tools/schemas.d.ts +374 -0
  124. package/dist/mcp/tools/schemas.d.ts.map +1 -0
  125. package/dist/mcp/tools/schemas.js +201 -0
  126. package/dist/mcp/tools/schemas.js.map +1 -0
  127. package/dist/types.d.ts +379 -0
  128. package/dist/types.d.ts.map +1 -0
  129. package/dist/types.js +3 -0
  130. package/dist/types.js.map +1 -0
  131. package/dist/utils/camelCase.d.ts +9 -0
  132. package/dist/utils/camelCase.d.ts.map +1 -0
  133. package/dist/utils/camelCase.js +11 -0
  134. package/dist/utils/camelCase.js.map +1 -0
  135. package/dist/utils/convertCollectionSchemaToZod.d.ts +3 -0
  136. package/dist/utils/convertCollectionSchemaToZod.d.ts.map +1 -0
  137. package/dist/utils/convertCollectionSchemaToZod.js +30 -0
  138. package/dist/utils/convertCollectionSchemaToZod.js.map +1 -0
  139. package/package.json +64 -0
  140. package/src/collections/createApiKeysCollection.ts +393 -0
  141. package/src/endpoints/mcp.ts +60 -0
  142. package/src/index.ts +86 -0
  143. package/src/mcp/createRequest.ts +13 -0
  144. package/src/mcp/getMcpHandler.ts +433 -0
  145. package/src/mcp/helpers/config.ts +326 -0
  146. package/src/mcp/helpers/conversion.ts +3 -0
  147. package/src/mcp/helpers/fields.ts +158 -0
  148. package/src/mcp/helpers/fileValidation.ts +417 -0
  149. package/src/mcp/helpers/validation.ts +32 -0
  150. package/src/mcp/registerTool.ts +22 -0
  151. package/src/mcp/tools/auth/auth.ts +69 -0
  152. package/src/mcp/tools/auth/forgotPassword.ts +68 -0
  153. package/src/mcp/tools/auth/login.ts +70 -0
  154. package/src/mcp/tools/auth/resetPassword.ts +59 -0
  155. package/src/mcp/tools/auth/unlock.ts +62 -0
  156. package/src/mcp/tools/auth/verify.ts +55 -0
  157. package/src/mcp/tools/collection/create.ts +236 -0
  158. package/src/mcp/tools/collection/delete.ts +227 -0
  159. package/src/mcp/tools/collection/find.ts +222 -0
  160. package/src/mcp/tools/collection/update.ts +288 -0
  161. package/src/mcp/tools/config/find.ts +126 -0
  162. package/src/mcp/tools/config/update.ts +282 -0
  163. package/src/mcp/tools/job/create.ts +420 -0
  164. package/src/mcp/tools/job/run.ts +189 -0
  165. package/src/mcp/tools/job/update.ts +319 -0
  166. package/src/mcp/tools/resource/create.ts +121 -0
  167. package/src/mcp/tools/resource/delete.ts +210 -0
  168. package/src/mcp/tools/resource/find.ts +194 -0
  169. package/src/mcp/tools/resource/update.ts +314 -0
  170. package/src/mcp/tools/schemas.ts +373 -0
  171. package/src/types.ts +405 -0
  172. package/src/utils/camelCase.ts +12 -0
  173. package/src/utils/convertCollectionSchemaToZod.ts +35 -0
package/LICENSE.md ADDED
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2018-2024 Payload CMS, Inc. <info@payloadcms.com>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ 'Software'), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,7 @@
1
+ # Payload MCP Plugin
2
+
3
+ A plugin for [Payload](https://github.com/payloadcms/payload). This plugin adds [Model Context Protocol](https://modelcontextprotocol.io/docs/getting-started/intro) capabilities.
4
+
5
+ - [Source code](https://github.com/payloadcms/payload/tree/main/packages/plugin-mcp)
6
+ - [Documentation](https://payloadcms.com/docs/plugins/mcp)
7
+ - [Documentation source](https://github.com/payloadcms/payload/tree/main/docs/plugins/mcp.mdx)
@@ -0,0 +1,7 @@
1
+ import type { CollectionConfig } from 'payload';
2
+ import type { PluginMCPServerConfig } from '../types.js';
3
+ export declare const createAPIKeysCollection: (collections: PluginMCPServerConfig["collections"], customTools?: Array<{
4
+ description: string;
5
+ name: string;
6
+ }>, experimentalTools?: NonNullable<PluginMCPServerConfig["experimental"]>["tools"]) => CollectionConfig;
7
+ //# sourceMappingURL=createApiKeysCollection.d.ts.map
@@ -0,0 +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;AAgHxD,eAAO,MAAM,uBAAuB,gBACrB,qBAAqB,CAAC,aAAa,CAAC,gBACpC,KAAK,CAAC;IAAE,WAAW,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC,sBACtC,WAAW,CAAC,qBAAqB,CAAC,cAAc,CAAC,CAAC,CAAC,OAAO,CAAC,KAC7E,gBAkRF,CAAA"}
@@ -0,0 +1,315 @@
1
+ import { toCamelCase } from '../utils/camelCase.js';
2
+ const addEnabledCollectionTools = (collections)=>{
3
+ const enabledCollectionSlugs = Object.keys(collections || {}).filter((collection)=>{
4
+ const fullyEnabled = typeof collections?.[collection]?.enabled === 'boolean' && collections?.[collection]?.enabled;
5
+ if (fullyEnabled) {
6
+ return true;
7
+ }
8
+ const partiallyEnabled = typeof collections?.[collection]?.enabled !== 'boolean' && (typeof collections?.[collection]?.enabled?.find === 'boolean' && collections?.[collection]?.enabled?.find === true || typeof collections?.[collection]?.enabled?.create === 'boolean' && collections?.[collection]?.enabled?.create === true || typeof collections?.[collection]?.enabled?.update === 'boolean' && collections?.[collection]?.enabled?.update === true || typeof collections?.[collection]?.enabled?.delete === 'boolean' && collections?.[collection]?.enabled?.delete === true);
9
+ if (partiallyEnabled) {
10
+ return true;
11
+ }
12
+ });
13
+ return enabledCollectionSlugs.map((enabledCollectionSlug)=>({
14
+ type: 'collapsible',
15
+ admin: {
16
+ position: 'sidebar'
17
+ },
18
+ fields: [
19
+ {
20
+ name: `${toCamelCase(enabledCollectionSlug)}`,
21
+ type: 'group',
22
+ fields: [
23
+ ...collections?.[enabledCollectionSlug]?.enabled === true || typeof collections?.[enabledCollectionSlug]?.enabled !== 'boolean' && typeof collections?.[enabledCollectionSlug]?.enabled?.find === 'boolean' && collections?.[enabledCollectionSlug]?.enabled?.find === true ? [
24
+ {
25
+ name: `find`,
26
+ type: 'checkbox',
27
+ admin: {
28
+ description: `Allow clients to find ${enabledCollectionSlug}.`
29
+ },
30
+ defaultValue: false,
31
+ label: 'Find'
32
+ }
33
+ ] : [],
34
+ ...collections?.[enabledCollectionSlug]?.enabled === true || typeof collections?.[enabledCollectionSlug]?.enabled !== 'boolean' && typeof collections?.[enabledCollectionSlug]?.enabled?.create === 'boolean' && collections?.[enabledCollectionSlug]?.enabled?.create === true ? [
35
+ {
36
+ name: `create`,
37
+ type: 'checkbox',
38
+ admin: {
39
+ description: `Allow clients to create ${enabledCollectionSlug}.`
40
+ },
41
+ defaultValue: false,
42
+ label: 'Create'
43
+ }
44
+ ] : [],
45
+ ...collections?.[enabledCollectionSlug]?.enabled === true || typeof collections?.[enabledCollectionSlug]?.enabled !== 'boolean' && typeof collections?.[enabledCollectionSlug]?.enabled?.update === 'boolean' && collections?.[enabledCollectionSlug]?.enabled?.update === true ? [
46
+ {
47
+ name: `update`,
48
+ type: 'checkbox',
49
+ admin: {
50
+ description: `Allow clients to update ${enabledCollectionSlug}.`
51
+ },
52
+ defaultValue: false,
53
+ label: 'Update'
54
+ }
55
+ ] : [],
56
+ ...collections?.[enabledCollectionSlug]?.enabled === true || typeof collections?.[enabledCollectionSlug]?.enabled !== 'boolean' && typeof collections?.[enabledCollectionSlug]?.enabled?.delete === 'boolean' && collections?.[enabledCollectionSlug]?.enabled?.delete === true ? [
57
+ {
58
+ name: `delete`,
59
+ type: 'checkbox',
60
+ admin: {
61
+ description: `Allow clients to delete ${enabledCollectionSlug}.`
62
+ },
63
+ defaultValue: false,
64
+ label: 'Delete'
65
+ }
66
+ ] : []
67
+ ]
68
+ }
69
+ ],
70
+ label: `${enabledCollectionSlug.charAt(0).toUpperCase() + toCamelCase(enabledCollectionSlug).slice(1)}`
71
+ }));
72
+ };
73
+ export const createAPIKeysCollection = (collections, customTools = [], experimentalTools = {})=>{
74
+ const customToolsFields = customTools.map((tool)=>{
75
+ const camelCasedName = toCamelCase(tool.name);
76
+ return {
77
+ name: camelCasedName,
78
+ type: 'checkbox',
79
+ admin: {
80
+ description: tool.description
81
+ },
82
+ defaultValue: true,
83
+ label: camelCasedName
84
+ };
85
+ });
86
+ return {
87
+ slug: 'payload-mcp-api-keys',
88
+ admin: {
89
+ group: 'MCP',
90
+ useAsTitle: 'label'
91
+ },
92
+ auth: {
93
+ disableLocalStrategy: true,
94
+ useAPIKey: true
95
+ },
96
+ fields: [
97
+ {
98
+ name: 'user',
99
+ type: 'relationship',
100
+ admin: {
101
+ description: 'The user that the API key is associated with.'
102
+ },
103
+ relationTo: 'users',
104
+ required: true
105
+ },
106
+ {
107
+ name: 'label',
108
+ type: 'text',
109
+ admin: {
110
+ description: 'A useful label for the API key.'
111
+ }
112
+ },
113
+ {
114
+ name: 'description',
115
+ type: 'text',
116
+ admin: {
117
+ description: 'The purpose of the API key.'
118
+ }
119
+ },
120
+ ...addEnabledCollectionTools(collections),
121
+ ...customTools.length > 0 ? [
122
+ {
123
+ type: 'collapsible',
124
+ admin: {
125
+ position: 'sidebar'
126
+ },
127
+ fields: [
128
+ {
129
+ name: 'custom',
130
+ type: 'group',
131
+ fields: customToolsFields
132
+ }
133
+ ],
134
+ label: 'Custom Tools'
135
+ }
136
+ ] : [],
137
+ // Experimental Tools
138
+ ...process.env.NODE_ENV === 'development' && (experimentalTools?.collections?.enabled || experimentalTools?.jobs?.enabled || experimentalTools?.config?.enabled || experimentalTools?.auth?.enabled) ? [
139
+ {
140
+ type: 'collapsible',
141
+ admin: {
142
+ position: 'sidebar'
143
+ },
144
+ fields: [
145
+ ...experimentalTools?.collections?.enabled ? [
146
+ {
147
+ name: 'collections',
148
+ type: 'group',
149
+ fields: [
150
+ {
151
+ name: 'find',
152
+ type: 'checkbox',
153
+ admin: {
154
+ description: 'Allow LLMs to find and list Payload collections with optional content and document counts.'
155
+ },
156
+ defaultValue: false
157
+ },
158
+ {
159
+ name: 'create',
160
+ type: 'checkbox',
161
+ admin: {
162
+ description: 'Allow LLMs to create new Payload collections with specified fields and configuration.'
163
+ },
164
+ defaultValue: false
165
+ },
166
+ {
167
+ name: 'update',
168
+ type: 'checkbox',
169
+ admin: {
170
+ description: 'Allow LLMs to update existing Payload collections with new fields, modifications, or configuration changes.'
171
+ },
172
+ defaultValue: false
173
+ },
174
+ {
175
+ name: 'delete',
176
+ type: 'checkbox',
177
+ admin: {
178
+ description: 'Allow LLMs to delete Payload collections and optionally update the configuration.'
179
+ },
180
+ defaultValue: false
181
+ }
182
+ ]
183
+ }
184
+ ] : [],
185
+ ...experimentalTools?.jobs?.enabled ? [
186
+ {
187
+ name: 'jobs',
188
+ type: 'group',
189
+ fields: [
190
+ {
191
+ name: 'create',
192
+ type: 'checkbox',
193
+ admin: {
194
+ description: 'Allow LLMs to create new Payload jobs (tasks and workflows) with custom schemas and configuration.'
195
+ },
196
+ defaultValue: false
197
+ },
198
+ {
199
+ name: 'run',
200
+ type: 'checkbox',
201
+ admin: {
202
+ description: 'Allow LLMs to execute Payload jobs with custom input data and queue options.'
203
+ },
204
+ defaultValue: false
205
+ },
206
+ {
207
+ name: 'update',
208
+ type: 'checkbox',
209
+ admin: {
210
+ description: 'Allow LLMs to update existing Payload jobs with new schemas, configuration, or handler code.'
211
+ },
212
+ defaultValue: false
213
+ }
214
+ ]
215
+ }
216
+ ] : [],
217
+ ...experimentalTools?.config?.enabled ? [
218
+ {
219
+ name: 'config',
220
+ type: 'group',
221
+ fields: [
222
+ {
223
+ name: 'find',
224
+ type: 'checkbox',
225
+ admin: {
226
+ description: 'Allow LLMs to read and display a Payload configuration file.'
227
+ },
228
+ defaultValue: false
229
+ },
230
+ {
231
+ name: 'update',
232
+ type: 'checkbox',
233
+ admin: {
234
+ description: 'Allow LLMs to update a Payload configuration file with various modifications.'
235
+ },
236
+ defaultValue: false
237
+ }
238
+ ]
239
+ }
240
+ ] : [],
241
+ ...experimentalTools?.auth?.enabled ? [
242
+ {
243
+ name: 'auth',
244
+ type: 'group',
245
+ fields: [
246
+ {
247
+ name: 'auth',
248
+ type: 'checkbox',
249
+ admin: {
250
+ description: 'Allow LLMs to check authentication status for a user by setting custom headers. (e.g. {"Authorization": "Bearer <token>"})'
251
+ },
252
+ defaultValue: false,
253
+ label: 'Check Auth Status'
254
+ },
255
+ {
256
+ name: 'login',
257
+ type: 'checkbox',
258
+ admin: {
259
+ description: 'Allow LLMs to authenticate a user with email and password.'
260
+ },
261
+ defaultValue: false,
262
+ label: 'User Login'
263
+ },
264
+ {
265
+ name: 'verify',
266
+ type: 'checkbox',
267
+ admin: {
268
+ description: 'Allow LLMs to verify a user email with a verification token.'
269
+ },
270
+ defaultValue: false,
271
+ label: 'Email Verification'
272
+ },
273
+ {
274
+ name: 'resetPassword',
275
+ type: 'checkbox',
276
+ admin: {
277
+ description: 'Allow LLMs to reset a user password with a reset token.'
278
+ },
279
+ defaultValue: false,
280
+ label: 'Reset Password'
281
+ },
282
+ {
283
+ name: 'forgotPassword',
284
+ type: 'checkbox',
285
+ admin: {
286
+ description: 'Allow LLMs to send a password reset email to a user.'
287
+ },
288
+ defaultValue: false,
289
+ label: 'Forgot Password'
290
+ },
291
+ {
292
+ name: 'unlock',
293
+ type: 'checkbox',
294
+ admin: {
295
+ description: 'Allow LLMs to unlock a user account that has been locked due to failed login attempts.'
296
+ },
297
+ defaultValue: false,
298
+ label: 'Unlock Account'
299
+ }
300
+ ]
301
+ }
302
+ ] : []
303
+ ],
304
+ label: 'Experimental Tools'
305
+ }
306
+ ] : []
307
+ ],
308
+ labels: {
309
+ plural: 'API Keys',
310
+ singular: 'API Key'
311
+ }
312
+ };
313
+ };
314
+
315
+ //# sourceMappingURL=createApiKeysCollection.js.map
@@ -0,0 +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,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,CA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,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,mBAAmBO,MAAM5B,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;QACDwB,QAAQ;YACNC,QAAQ;YACRC,UAAU;QACZ;IACF;AACF,EAAC"}
@@ -0,0 +1,4 @@
1
+ import { type PayloadHandler } from 'payload';
2
+ import type { PluginMCPServerConfig } from '../types.js';
3
+ export declare const initializeMCPHandler: (pluginOptions: PluginMCPServerConfig) => PayloadHandler;
4
+ //# sourceMappingURL=mcp.d.ts.map
@@ -0,0 +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,EAAE,qBAAqB,EAAgB,MAAM,aAAa,CAAA;AAKtE,eAAO,MAAM,oBAAoB,kBAAmB,qBAAqB,mBAmDxE,CAAA"}
@@ -0,0 +1,44 @@
1
+ import crypto from 'crypto';
2
+ import { APIError } from 'payload';
3
+ import { createRequestFromPayloadRequest } from '../mcp/createRequest.js';
4
+ import { getMCPHandler } from '../mcp/getMcpHandler.js';
5
+ export const initializeMCPHandler = (pluginOptions)=>{
6
+ const mcpHandler = async (req)=>{
7
+ const { payload } = req;
8
+ const MCPOptions = pluginOptions.mcp || {};
9
+ const MCPHandlerOptions = MCPOptions.handlerOptions || {};
10
+ const useVerboseLogs = MCPHandlerOptions.verboseLogs ?? false;
11
+ const apiKey = req.headers.get('Authorization')?.startsWith('Bearer ') ? req.headers.get('Authorization')?.replace('Bearer ', '').trim() : null;
12
+ if (apiKey === null) {
13
+ throw new APIError('API Key is required', 401);
14
+ }
15
+ const sha256APIKeyIndex = crypto.createHmac('sha256', payload.secret).update(apiKey || '').digest('hex');
16
+ const apiKeyConstraints = [
17
+ {
18
+ apiKeyIndex: {
19
+ equals: sha256APIKeyIndex
20
+ }
21
+ }
22
+ ];
23
+ const where = {
24
+ or: apiKeyConstraints
25
+ };
26
+ const { docs } = await payload.find({
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 toolSettings = docs[0];
34
+ if (useVerboseLogs) {
35
+ payload.logger.info('[payload-mcp] API Key is valid');
36
+ }
37
+ const handler = getMCPHandler(pluginOptions, toolSettings, req);
38
+ const request = createRequestFromPayloadRequest(req);
39
+ return await handler(request);
40
+ };
41
+ return mcpHandler;
42
+ };
43
+
44
+ //# sourceMappingURL=mcp.js.map
@@ -0,0 +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 { PluginMCPServerConfig, ToolSettings } 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 toolSettings = docs[0] as ToolSettings\n\n if (useVerboseLogs) {\n payload.logger.info('[payload-mcp] API Key is valid')\n }\n\n const handler = getMCPHandler(pluginOptions, toolSettings, 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","toolSettings","logger","info","handler","request"],"mappings":"AAAA,OAAOA,YAAY,SAAQ;AAC3B,SAASC,QA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CPServerConfig } from './types.js';
3
+ /**
4
+ * The MCP Plugin for Payload. This plugin allows you to add MCP capabilities to your Payload project.
5
+ *
6
+ * @param pluginOptions - The options for the MCP plugin.
7
+ * @experimental This plugin is experimental and may change in the future.
8
+ */
9
+ export declare const mcpPlugin: (pluginOptions: PluginMCPServerConfig) => (config: Config) => Config;
10
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +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,MAsEjB,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,67 @@
1
+ import { createAPIKeysCollection } from './collections/createApiKeysCollection.js';
2
+ import { initializeMCPHandler } from './endpoints/mcp.js';
3
+ /**
4
+ * The MCP Plugin for Payload. This plugin allows you to add MCP capabilities to your Payload project.
5
+ *
6
+ * @param pluginOptions - The options for the MCP plugin.
7
+ * @experimental This plugin is experimental and may change in the future.
8
+ */ export const mcpPlugin = (pluginOptions)=>(config)=>{
9
+ if (!config.collections) {
10
+ config.collections = [];
11
+ }
12
+ // Collections
13
+ const collections = pluginOptions.collections || {};
14
+ // Extract custom tools for the global config
15
+ const customTools = pluginOptions.mcp?.tools?.map((tool)=>({
16
+ name: tool.name,
17
+ description: tool.description
18
+ })) || [];
19
+ const experimentalTools = pluginOptions?.experimental?.tools || {};
20
+ /**
21
+ * API Keys
22
+ * --------
23
+ * High resolution control over MCP capabilities is crucial when using Payload with LLMs.
24
+ *
25
+ * This API Keys collection has ways for admins to create API keys and allow or disallow the MCP capabilities.
26
+ * This is useful when Admins want to allow or disallow the use of the MCP capabilities in real time.
27
+ * For example:
28
+ * - If a collection has all of its capabilities enabled, admins can allow or disallow the create, update, delete, and find capabilities on that collection.
29
+ * - If a collection only has the find capability enabled, admins can only allow or disallow the find capability on that collection.
30
+ * - If a custom tool has gone haywire, admins can disallow that tool.
31
+ *
32
+ */ const apiKeyCollection = createAPIKeysCollection(collections, customTools, experimentalTools);
33
+ if (pluginOptions.overrideApiKeyCollection) {
34
+ config.collections.push(pluginOptions.overrideApiKeyCollection(apiKeyCollection));
35
+ } else {
36
+ config.collections.push(apiKeyCollection);
37
+ }
38
+ /**
39
+ * If the plugin is disabled, we still want to keep added collections/fields so the database schema is consistent which is important for migrations.
40
+ * If your plugin heavily modifies the database schema, you may want to remove this property.
41
+ */ if (pluginOptions.disabled) {
42
+ return config;
43
+ }
44
+ if (!config.endpoints) {
45
+ config.endpoints = [];
46
+ }
47
+ /**
48
+ * This is the primary MCP Server Endpoint.
49
+ * Payload will automatically add the /api prefix to the path, so the full path is `/api/mcp`
50
+ * NOTE: This is only transport method until we add full support for SSE which will be another endpoint at `/api/sse`
51
+ */ config.endpoints.push({
52
+ handler: initializeMCPHandler(pluginOptions),
53
+ method: 'post',
54
+ path: '/mcp'
55
+ });
56
+ /**
57
+ * The GET response is always: {"jsonrpc":"2.0","error":{"code":-32000,"message":"Method not allowed."},"id":null} -- even with an API key
58
+ * This is expected behavior and MCP clients should always use the POST endpoint.
59
+ */ config.endpoints.push({
60
+ handler: initializeMCPHandler(pluginOptions),
61
+ method: 'get',
62
+ path: '/mcp'
63
+ });
64
+ return config;
65
+ };
66
+
67
+ //# sourceMappingURL=index.js.map
@@ -0,0 +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, customTools, experimentalTools)\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,wBAAwBK,aAAaC,aAAaO;QAC3E,IAAIV,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"}
@@ -0,0 +1,3 @@
1
+ import { type PayloadRequest } from 'payload';
2
+ export declare const createRequestFromPayloadRequest: (req: PayloadRequest) => Request;
3
+ //# sourceMappingURL=createRequest.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createRequest.d.ts","sourceRoot":"","sources":["../../src/mcp/createRequest.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,KAAK,cAAc,EAAE,MAAM,SAAS,CAAA;AAEvD,eAAO,MAAM,+BAA+B,QAAS,cAAc,YAUlE,CAAA"}
@@ -0,0 +1,14 @@
1
+ import { APIError } from 'payload';
2
+ export const createRequestFromPayloadRequest = (req)=>{
3
+ if (!req.url) {
4
+ throw new APIError('Request URL is required', 500);
5
+ }
6
+ return new Request(req.url, {
7
+ body: req.body,
8
+ duplex: 'half',
9
+ headers: req.headers,
10
+ method: req.method
11
+ });
12
+ };
13
+
14
+ //# sourceMappingURL=createRequest.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/mcp/createRequest.ts"],"sourcesContent":["import { APIError, type PayloadRequest } from 'payload'\n\nexport const createRequestFromPayloadRequest = (req: PayloadRequest) => {\n if (!req.url) {\n throw new APIError('Request URL is required', 500)\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":["APIError","createRequestFromPayloadRequest","req","url","Request","body","duplex","headers","method"],"mappings":"AAAA,SAASA,QAAQ,QAA6B,UAAS;AAEvD,OAAO,MAAMC,kCAAkC,CAACC;IAC9C,IAAI,CAACA,IAAIC,GAAG,EAAE;QACZ,MAAM,IAAIH,SAAS,2BAA2B;IAChD;IACA,OAAO,IAAII,QAAQF,IAAIC,GAAG,EAAE;QAC1BE,MAAMH,IAAIG,IAAI;QACdC,QAAQ;QACRC,SAASL,IAAIK,OAAO;QACpBC,QAAQN,IAAIM,MAAM;IACpB;AACF,EAAC"}
@@ -0,0 +1,4 @@
1
+ import { type PayloadRequest } from 'payload';
2
+ import type { PluginMCPServerConfig, ToolSettings } from '../types.js';
3
+ export declare const getMCPHandler: (pluginOptions: PluginMCPServerConfig, toolSettings: ToolSettings, req: PayloadRequest) => (request: Request) => Promise<Response>;
4
+ //# sourceMappingURL=getMcpHandler.d.ts.map
@@ -0,0 +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,qBAAqB,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AA4BtE,eAAO,MAAM,aAAa,kBACT,qBAAqB,gBACtB,YAAY,OACrB,cAAc,4CA2YpB,CAAA"}