@payloadcms/plugin-mcp 3.85.0 → 4.0.0-canary.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 (329) hide show
  1. package/README.md +2 -2
  2. package/bin.js +39 -0
  3. package/dist/collection/getAccessField.d.ts +12 -0
  4. package/dist/collection/getAccessField.d.ts.map +1 -0
  5. package/dist/collection/getAccessField.js +57 -0
  6. package/dist/collection/getAccessField.js.map +1 -0
  7. package/dist/collection/index.d.ts +6 -0
  8. package/dist/collection/index.d.ts.map +1 -0
  9. package/dist/collection/index.js +59 -0
  10. package/dist/collection/index.js.map +1 -0
  11. package/dist/components/AccessField/index.client.d.ts +10 -0
  12. package/dist/components/AccessField/index.client.d.ts.map +1 -0
  13. package/dist/components/AccessField/index.client.js +305 -0
  14. package/dist/components/AccessField/index.client.js.map +1 -0
  15. package/dist/components/AccessField/index.css +93 -0
  16. package/dist/defineTool.d.ts +26 -0
  17. package/dist/defineTool.d.ts.map +1 -0
  18. package/dist/defineTool.js +37 -0
  19. package/dist/defineTool.js.map +1 -0
  20. package/dist/endpoint/access.d.ts +10 -0
  21. package/dist/endpoint/access.d.ts.map +1 -0
  22. package/dist/endpoint/access.js +106 -0
  23. package/dist/endpoint/access.js.map +1 -0
  24. package/dist/endpoint/index.d.ts +3 -0
  25. package/dist/endpoint/index.d.ts.map +1 -0
  26. package/dist/endpoint/index.js +36 -0
  27. package/dist/endpoint/index.js.map +1 -0
  28. package/dist/exports/client.d.ts +2 -0
  29. package/dist/exports/client.d.ts.map +1 -0
  30. package/dist/exports/client.js +4 -0
  31. package/dist/exports/client.js.map +1 -0
  32. package/dist/index.d.ts +4 -7
  33. package/dist/index.d.ts.map +1 -1
  34. package/dist/index.js +44 -67
  35. package/dist/index.js.map +1 -1
  36. package/dist/mcp/buildMcpServer.d.ts +19 -0
  37. package/dist/mcp/buildMcpServer.d.ts.map +1 -0
  38. package/dist/mcp/buildMcpServer.js +163 -0
  39. package/dist/mcp/buildMcpServer.js.map +1 -0
  40. package/dist/mcp/builtin/collections/authTools.d.ts +7 -0
  41. package/dist/mcp/builtin/collections/authTools.d.ts.map +1 -0
  42. package/dist/mcp/builtin/collections/authTools.js +250 -0
  43. package/dist/mcp/builtin/collections/authTools.js.map +1 -0
  44. package/dist/mcp/builtin/collections/createTool.d.ts +2 -0
  45. package/dist/mcp/builtin/collections/createTool.d.ts.map +1 -0
  46. package/dist/mcp/builtin/collections/createTool.js +87 -0
  47. package/dist/mcp/builtin/collections/createTool.js.map +1 -0
  48. package/dist/mcp/builtin/collections/deleteTool.d.ts +2 -0
  49. package/dist/mcp/builtin/collections/deleteTool.d.ts.map +1 -0
  50. package/dist/mcp/builtin/collections/deleteTool.js +117 -0
  51. package/dist/mcp/builtin/collections/deleteTool.js.map +1 -0
  52. package/dist/mcp/builtin/collections/findTool.d.ts +2 -0
  53. package/dist/mcp/builtin/collections/findTool.d.ts.map +1 -0
  54. package/dist/mcp/builtin/collections/findTool.js +159 -0
  55. package/dist/mcp/builtin/collections/findTool.js.map +1 -0
  56. package/dist/mcp/builtin/collections/updateTool.d.ts +2 -0
  57. package/dist/mcp/builtin/collections/updateTool.d.ts.map +1 -0
  58. package/dist/mcp/builtin/collections/updateTool.js +187 -0
  59. package/dist/mcp/builtin/collections/updateTool.js.map +1 -0
  60. package/dist/mcp/builtin/globals/findTool.d.ts +2 -0
  61. package/dist/mcp/builtin/globals/findTool.d.ts.map +1 -0
  62. package/dist/mcp/builtin/globals/findTool.js +76 -0
  63. package/dist/mcp/builtin/globals/findTool.js.map +1 -0
  64. package/dist/mcp/builtin/globals/updateTool.d.ts +2 -0
  65. package/dist/mcp/builtin/globals/updateTool.d.ts.map +1 -0
  66. package/dist/mcp/builtin/globals/updateTool.js +92 -0
  67. package/dist/mcp/builtin/globals/updateTool.js.map +1 -0
  68. package/dist/mcp/builtinTools.d.ts +37 -0
  69. package/dist/mcp/builtinTools.d.ts.map +1 -0
  70. package/dist/mcp/builtinTools.js +64 -0
  71. package/dist/mcp/builtinTools.js.map +1 -0
  72. package/dist/mcp/sanitizeMCPConfig.d.ts +17 -0
  73. package/dist/mcp/sanitizeMCPConfig.d.ts.map +1 -0
  74. package/dist/mcp/sanitizeMCPConfig.js +167 -0
  75. package/dist/mcp/sanitizeMCPConfig.js.map +1 -0
  76. package/dist/stdio.d.ts +8 -0
  77. package/dist/stdio.d.ts.map +1 -0
  78. package/dist/stdio.js +89 -0
  79. package/dist/stdio.js.map +1 -0
  80. package/dist/types.d.ts +262 -455
  81. package/dist/types.d.ts.map +1 -1
  82. package/dist/types.js +6 -1
  83. package/dist/types.js.map +1 -1
  84. package/dist/utils/camelCase.d.ts.map +1 -1
  85. package/dist/utils/getLogger.d.ts +10 -0
  86. package/dist/utils/getLogger.d.ts.map +1 -0
  87. package/dist/utils/getLogger.js +22 -0
  88. package/dist/utils/getLogger.js.map +1 -0
  89. package/dist/utils/getPluginConfig.d.ts +12 -0
  90. package/dist/utils/getPluginConfig.d.ts.map +1 -0
  91. package/dist/utils/getPluginConfig.js +15 -0
  92. package/dist/utils/getPluginConfig.js.map +1 -0
  93. package/dist/utils/localAPIDefaults.d.ts +20 -0
  94. package/dist/utils/localAPIDefaults.d.ts.map +1 -0
  95. package/dist/utils/localAPIDefaults.js +19 -0
  96. package/dist/utils/localAPIDefaults.js.map +1 -0
  97. package/dist/utils/resolveProjectRoot.d.ts +7 -0
  98. package/dist/utils/resolveProjectRoot.d.ts.map +1 -0
  99. package/dist/utils/resolveProjectRoot.js +15 -0
  100. package/dist/utils/resolveProjectRoot.js.map +1 -0
  101. package/dist/utils/schemaConversion/prepareCollectionSchema.d.ts +7 -0
  102. package/dist/utils/schemaConversion/prepareCollectionSchema.d.ts.map +1 -0
  103. package/dist/utils/schemaConversion/prepareCollectionSchema.js +37 -0
  104. package/dist/utils/schemaConversion/prepareCollectionSchema.js.map +1 -0
  105. package/dist/utils/schemaConversion/removeVirtualFieldsFromSchema.d.ts +2 -2
  106. package/dist/utils/schemaConversion/removeVirtualFieldsFromSchema.d.ts.map +1 -1
  107. package/dist/utils/schemaConversion/removeVirtualFieldsFromSchema.js.map +1 -1
  108. package/dist/utils/schemaConversion/sanitizeJsonSchema.d.ts +2 -2
  109. package/dist/utils/schemaConversion/sanitizeJsonSchema.d.ts.map +1 -1
  110. package/dist/utils/schemaConversion/sanitizeJsonSchema.js.map +1 -1
  111. package/dist/utils/schemaConversion/simplifyRelationshipFields.d.ts +2 -2
  112. package/dist/utils/schemaConversion/simplifyRelationshipFields.d.ts.map +1 -1
  113. package/dist/utils/schemaConversion/simplifyRelationshipFields.js +7 -4
  114. package/dist/utils/schemaConversion/simplifyRelationshipFields.js.map +1 -1
  115. package/dist/utils/schemaConversion/transformPointFields.d.ts +2 -2
  116. package/dist/utils/schemaConversion/transformPointFields.d.ts.map +1 -1
  117. package/dist/utils/schemaConversion/transformPointFields.js +7 -1
  118. package/dist/utils/schemaConversion/transformPointFields.js.map +1 -1
  119. package/dist/utils/toStandardSchema.d.ts +5 -0
  120. package/dist/utils/toStandardSchema.d.ts.map +1 -0
  121. package/dist/utils/toStandardSchema.js +4 -0
  122. package/dist/utils/toStandardSchema.js.map +1 -0
  123. package/package.json +35 -10
  124. package/src/collection/getAccessField.ts +64 -0
  125. package/src/collection/index.ts +63 -0
  126. package/src/components/AccessField/index.client.tsx +344 -0
  127. package/src/components/AccessField/index.css +93 -0
  128. package/src/defineTool.ts +44 -0
  129. package/src/endpoint/access.ts +132 -0
  130. package/src/endpoint/index.ts +35 -0
  131. package/src/exports/client.ts +2 -0
  132. package/src/index.ts +35 -85
  133. package/src/mcp/buildMcpServer.ts +224 -0
  134. package/src/mcp/builtin/collections/authTools.ts +233 -0
  135. package/src/mcp/builtin/collections/createTool.ts +116 -0
  136. package/src/mcp/builtin/collections/deleteTool.ts +123 -0
  137. package/src/mcp/builtin/collections/findTool.ts +187 -0
  138. package/src/mcp/builtin/collections/updateTool.ts +205 -0
  139. package/src/mcp/builtin/globals/findTool.ts +96 -0
  140. package/src/mcp/builtin/globals/updateTool.ts +118 -0
  141. package/src/mcp/builtinTools.ts +84 -0
  142. package/src/mcp/sanitizeMCPConfig.ts +239 -0
  143. package/src/stdio.ts +98 -0
  144. package/src/types.ts +295 -490
  145. package/src/utils/getLogger.ts +22 -0
  146. package/src/utils/getPluginConfig.ts +24 -0
  147. package/src/utils/localAPIDefaults.ts +22 -0
  148. package/src/utils/resolveProjectRoot.ts +17 -0
  149. package/src/utils/schemaConversion/prepareCollectionSchema.ts +39 -0
  150. package/src/utils/schemaConversion/removeVirtualFieldsFromSchema.ts +3 -3
  151. package/src/utils/schemaConversion/sanitizeJsonSchema.ts +4 -4
  152. package/src/utils/schemaConversion/simplifyRelationshipFields.ts +11 -6
  153. package/src/utils/schemaConversion/transformPointFields.ts +6 -5
  154. package/src/utils/toStandardSchema.ts +9 -0
  155. package/dist/collections/createApiKeysCollection.d.ts +0 -7
  156. package/dist/collections/createApiKeysCollection.d.ts.map +0 -1
  157. package/dist/collections/createApiKeysCollection.js +0 -317
  158. package/dist/collections/createApiKeysCollection.js.map +0 -1
  159. package/dist/defaults.d.ts +0 -4
  160. package/dist/defaults.d.ts.map +0 -1
  161. package/dist/defaults.js +0 -5
  162. package/dist/defaults.js.map +0 -1
  163. package/dist/endpoints/mcp.d.ts +0 -4
  164. package/dist/endpoints/mcp.d.ts.map +0 -1
  165. package/dist/endpoints/mcp.js +0 -71
  166. package/dist/endpoints/mcp.js.map +0 -1
  167. package/dist/mcp/createRequest.d.ts +0 -3
  168. package/dist/mcp/createRequest.d.ts.map +0 -1
  169. package/dist/mcp/createRequest.js +0 -14
  170. package/dist/mcp/createRequest.js.map +0 -1
  171. package/dist/mcp/getMcpHandler.d.ts +0 -4
  172. package/dist/mcp/getMcpHandler.d.ts.map +0 -1
  173. package/dist/mcp/getMcpHandler.js +0 -231
  174. package/dist/mcp/getMcpHandler.js.map +0 -1
  175. package/dist/mcp/helpers/config.d.ts +0 -22
  176. package/dist/mcp/helpers/config.d.ts.map +0 -1
  177. package/dist/mcp/helpers/config.js +0 -153
  178. package/dist/mcp/helpers/config.js.map +0 -1
  179. package/dist/mcp/helpers/fields.d.ts +0 -19
  180. package/dist/mcp/helpers/fields.d.ts.map +0 -1
  181. package/dist/mcp/helpers/fields.js +0 -102
  182. package/dist/mcp/helpers/fields.js.map +0 -1
  183. package/dist/mcp/helpers/fileValidation.d.ts +0 -67
  184. package/dist/mcp/helpers/fileValidation.d.ts.map +0 -1
  185. package/dist/mcp/helpers/fileValidation.js +0 -267
  186. package/dist/mcp/helpers/fileValidation.js.map +0 -1
  187. package/dist/mcp/registerTool.d.ts +0 -6
  188. package/dist/mcp/registerTool.d.ts.map +0 -1
  189. package/dist/mcp/registerTool.js +0 -18
  190. package/dist/mcp/registerTool.js.map +0 -1
  191. package/dist/mcp/tools/auth/auth.d.ts +0 -4
  192. package/dist/mcp/tools/auth/auth.d.ts.map +0 -1
  193. package/dist/mcp/tools/auth/auth.js +0 -57
  194. package/dist/mcp/tools/auth/auth.js.map +0 -1
  195. package/dist/mcp/tools/auth/forgotPassword.d.ts +0 -4
  196. package/dist/mcp/tools/auth/forgotPassword.d.ts.map +0 -1
  197. package/dist/mcp/tools/auth/forgotPassword.js +0 -48
  198. package/dist/mcp/tools/auth/forgotPassword.js.map +0 -1
  199. package/dist/mcp/tools/auth/login.d.ts +0 -4
  200. package/dist/mcp/tools/auth/login.d.ts.map +0 -1
  201. package/dist/mcp/tools/auth/login.js +0 -51
  202. package/dist/mcp/tools/auth/login.js.map +0 -1
  203. package/dist/mcp/tools/auth/resetPassword.d.ts +0 -4
  204. package/dist/mcp/tools/auth/resetPassword.d.ts.map +0 -1
  205. package/dist/mcp/tools/auth/resetPassword.js +0 -49
  206. package/dist/mcp/tools/auth/resetPassword.js.map +0 -1
  207. package/dist/mcp/tools/auth/unlock.d.ts +0 -4
  208. package/dist/mcp/tools/auth/unlock.d.ts.map +0 -1
  209. package/dist/mcp/tools/auth/unlock.js +0 -48
  210. package/dist/mcp/tools/auth/unlock.js.map +0 -1
  211. package/dist/mcp/tools/auth/verify.d.ts +0 -4
  212. package/dist/mcp/tools/auth/verify.d.ts.map +0 -1
  213. package/dist/mcp/tools/auth/verify.js +0 -45
  214. package/dist/mcp/tools/auth/verify.js.map +0 -1
  215. package/dist/mcp/tools/collection/create.d.ts +0 -10
  216. package/dist/mcp/tools/collection/create.d.ts.map +0 -1
  217. package/dist/mcp/tools/collection/create.js +0 -139
  218. package/dist/mcp/tools/collection/create.js.map +0 -1
  219. package/dist/mcp/tools/collection/delete.d.ts +0 -10
  220. package/dist/mcp/tools/collection/delete.d.ts.map +0 -1
  221. package/dist/mcp/tools/collection/delete.js +0 -154
  222. package/dist/mcp/tools/collection/delete.js.map +0 -1
  223. package/dist/mcp/tools/collection/find.d.ts +0 -10
  224. package/dist/mcp/tools/collection/find.d.ts.map +0 -1
  225. package/dist/mcp/tools/collection/find.js +0 -165
  226. package/dist/mcp/tools/collection/find.js.map +0 -1
  227. package/dist/mcp/tools/collection/update.d.ts +0 -10
  228. package/dist/mcp/tools/collection/update.d.ts.map +0 -1
  229. package/dist/mcp/tools/collection/update.js +0 -209
  230. package/dist/mcp/tools/collection/update.js.map +0 -1
  231. package/dist/mcp/tools/config/find.d.ts +0 -10
  232. package/dist/mcp/tools/config/find.d.ts.map +0 -1
  233. package/dist/mcp/tools/config/find.js +0 -97
  234. package/dist/mcp/tools/config/find.js.map +0 -1
  235. package/dist/mcp/tools/config/update.d.ts +0 -10
  236. package/dist/mcp/tools/config/update.d.ts.map +0 -1
  237. package/dist/mcp/tools/config/update.js +0 -215
  238. package/dist/mcp/tools/config/update.js.map +0 -1
  239. package/dist/mcp/tools/global/find.d.ts +0 -5
  240. package/dist/mcp/tools/global/find.d.ts.map +0 -1
  241. package/dist/mcp/tools/global/find.js +0 -82
  242. package/dist/mcp/tools/global/find.js.map +0 -1
  243. package/dist/mcp/tools/global/update.d.ts +0 -6
  244. package/dist/mcp/tools/global/update.d.ts.map +0 -1
  245. package/dist/mcp/tools/global/update.js +0 -124
  246. package/dist/mcp/tools/global/update.js.map +0 -1
  247. package/dist/mcp/tools/job/create.d.ts +0 -10
  248. package/dist/mcp/tools/job/create.d.ts.map +0 -1
  249. package/dist/mcp/tools/job/create.js +0 -293
  250. package/dist/mcp/tools/job/create.js.map +0 -1
  251. package/dist/mcp/tools/job/run.d.ts +0 -10
  252. package/dist/mcp/tools/job/run.d.ts.map +0 -1
  253. package/dist/mcp/tools/job/run.js +0 -129
  254. package/dist/mcp/tools/job/run.js.map +0 -1
  255. package/dist/mcp/tools/job/update.d.ts +0 -11
  256. package/dist/mcp/tools/job/update.d.ts.map +0 -1
  257. package/dist/mcp/tools/job/update.js +0 -186
  258. package/dist/mcp/tools/job/update.js.map +0 -1
  259. package/dist/mcp/tools/resource/create.d.ts +0 -6
  260. package/dist/mcp/tools/resource/create.d.ts.map +0 -1
  261. package/dist/mcp/tools/resource/create.js +0 -124
  262. package/dist/mcp/tools/resource/create.js.map +0 -1
  263. package/dist/mcp/tools/resource/delete.d.ts +0 -5
  264. package/dist/mcp/tools/resource/delete.d.ts.map +0 -1
  265. package/dist/mcp/tools/resource/delete.js +0 -151
  266. package/dist/mcp/tools/resource/delete.js.map +0 -1
  267. package/dist/mcp/tools/resource/find.d.ts +0 -5
  268. package/dist/mcp/tools/resource/find.d.ts.map +0 -1
  269. package/dist/mcp/tools/resource/find.js +0 -170
  270. package/dist/mcp/tools/resource/find.js.map +0 -1
  271. package/dist/mcp/tools/resource/update.d.ts +0 -6
  272. package/dist/mcp/tools/resource/update.d.ts.map +0 -1
  273. package/dist/mcp/tools/resource/update.js +0 -256
  274. package/dist/mcp/tools/resource/update.js.map +0 -1
  275. package/dist/mcp/tools/schemas.d.ts +0 -457
  276. package/dist/mcp/tools/schemas.d.ts.map +0 -1
  277. package/dist/mcp/tools/schemas.js +0 -243
  278. package/dist/mcp/tools/schemas.js.map +0 -1
  279. package/dist/utils/adminEntitySettings.d.ts +0 -17
  280. package/dist/utils/adminEntitySettings.d.ts.map +0 -1
  281. package/dist/utils/adminEntitySettings.js +0 -41
  282. package/dist/utils/adminEntitySettings.js.map +0 -1
  283. package/dist/utils/createApiKeyFields.d.ts +0 -15
  284. package/dist/utils/createApiKeyFields.d.ts.map +0 -1
  285. package/dist/utils/createApiKeyFields.js +0 -57
  286. package/dist/utils/createApiKeyFields.js.map +0 -1
  287. package/dist/utils/getEnabledSlugs.d.ts +0 -13
  288. package/dist/utils/getEnabledSlugs.d.ts.map +0 -1
  289. package/dist/utils/getEnabledSlugs.js +0 -32
  290. package/dist/utils/getEnabledSlugs.js.map +0 -1
  291. package/dist/utils/schemaConversion/convertCollectionSchemaToZod.d.ts +0 -3
  292. package/dist/utils/schemaConversion/convertCollectionSchemaToZod.d.ts.map +0 -1
  293. package/dist/utils/schemaConversion/convertCollectionSchemaToZod.js +0 -43
  294. package/dist/utils/schemaConversion/convertCollectionSchemaToZod.js.map +0 -1
  295. package/src/collections/createApiKeysCollection.ts +0 -373
  296. package/src/defaults.ts +0 -3
  297. package/src/endpoints/mcp.ts +0 -91
  298. package/src/mcp/createRequest.ts +0 -13
  299. package/src/mcp/getMcpHandler.ts +0 -545
  300. package/src/mcp/helpers/config.ts +0 -213
  301. package/src/mcp/helpers/fields.ts +0 -154
  302. package/src/mcp/helpers/fileValidation.ts +0 -362
  303. package/src/mcp/registerTool.ts +0 -22
  304. package/src/mcp/tools/auth/auth.ts +0 -71
  305. package/src/mcp/tools/auth/forgotPassword.ts +0 -70
  306. package/src/mcp/tools/auth/login.ts +0 -72
  307. package/src/mcp/tools/auth/resetPassword.ts +0 -61
  308. package/src/mcp/tools/auth/unlock.ts +0 -64
  309. package/src/mcp/tools/auth/verify.ts +0 -57
  310. package/src/mcp/tools/collection/create.ts +0 -210
  311. package/src/mcp/tools/collection/delete.ts +0 -211
  312. package/src/mcp/tools/collection/find.ts +0 -224
  313. package/src/mcp/tools/collection/update.ts +0 -290
  314. package/src/mcp/tools/config/find.ts +0 -128
  315. package/src/mcp/tools/config/update.ts +0 -280
  316. package/src/mcp/tools/global/find.ts +0 -128
  317. package/src/mcp/tools/global/update.ts +0 -207
  318. package/src/mcp/tools/job/create.ts +0 -416
  319. package/src/mcp/tools/job/run.ts +0 -167
  320. package/src/mcp/tools/job/update.ts +0 -274
  321. package/src/mcp/tools/resource/create.ts +0 -211
  322. package/src/mcp/tools/resource/delete.ts +0 -218
  323. package/src/mcp/tools/resource/find.ts +0 -246
  324. package/src/mcp/tools/resource/update.ts +0 -383
  325. package/src/mcp/tools/schemas.ts +0 -520
  326. package/src/utils/adminEntitySettings.ts +0 -40
  327. package/src/utils/createApiKeyFields.ts +0 -72
  328. package/src/utils/getEnabledSlugs.ts +0 -42
  329. package/src/utils/schemaConversion/convertCollectionSchemaToZod.ts +0 -52
@@ -1,64 +0,0 @@
1
- import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'
2
- import type { PayloadRequest } from 'payload'
3
-
4
- import { toolSchemas } from '../schemas.js'
5
-
6
- export const unlockTool = (server: McpServer, req: PayloadRequest, verboseLogs: boolean) => {
7
- const tool = async (collection: string, email: string) => {
8
- const payload = req.payload
9
-
10
- if (verboseLogs) {
11
- payload.logger.info(
12
- `[payload-mcp] Unlocking user account for user: ${email} in collection: ${collection}`,
13
- )
14
- }
15
-
16
- try {
17
- const result = await payload.unlock({
18
- collection,
19
- data: {
20
- email,
21
- },
22
- overrideAccess: true,
23
- })
24
-
25
- if (verboseLogs) {
26
- payload.logger.info(`[payload-mcp] User account unlocked successfully for user: ${email}`)
27
- }
28
-
29
- return {
30
- content: [
31
- {
32
- type: 'text' as const,
33
- text: `# User Account Unlocked\n\n**User:** ${email}\n**Collection:** ${collection}\n\n\`\`\`json\n${JSON.stringify(result)}\n\`\`\``,
34
- },
35
- ],
36
- }
37
- } catch (error) {
38
- const errorMessage = error instanceof Error ? error.message : 'Unknown error'
39
- payload.logger.error(
40
- `[payload-mcp] Error unlocking user account for user ${email}: ${errorMessage}`,
41
- )
42
-
43
- return {
44
- content: [
45
- {
46
- type: 'text' as const,
47
- text: `❌ **Error unlocking user account for user "${email}"**: ${errorMessage}`,
48
- },
49
- ],
50
- }
51
- }
52
- }
53
-
54
- server.registerTool(
55
- 'unlock',
56
- {
57
- description: toolSchemas.unlock.description,
58
- inputSchema: toolSchemas.unlock.parameters.shape,
59
- },
60
- async ({ collection, email }) => {
61
- return await tool(collection, email)
62
- },
63
- )
64
- }
@@ -1,57 +0,0 @@
1
- import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'
2
- import type { PayloadRequest } from 'payload'
3
-
4
- import { toolSchemas } from '../schemas.js'
5
-
6
- export const verifyTool = (server: McpServer, req: PayloadRequest, verboseLogs: boolean) => {
7
- const tool = async (collection: string, token: string) => {
8
- const payload = req.payload
9
-
10
- if (verboseLogs) {
11
- payload.logger.info(`[payload-mcp] Verifying user account for collection: ${collection}`)
12
- }
13
-
14
- try {
15
- const result = await payload.verifyEmail({
16
- collection,
17
- token,
18
- })
19
-
20
- if (verboseLogs) {
21
- payload.logger.info('[payload-mcp] Email verification completed successfully')
22
- }
23
-
24
- return {
25
- content: [
26
- {
27
- type: 'text' as const,
28
- text: `# Email Verification Successful\n\n**Collection:** ${collection}\n**Token:** ${token}\n**Result:** ${result ? 'Success' : 'Failed'}`,
29
- },
30
- ],
31
- }
32
- } catch (error) {
33
- const errorMessage = error instanceof Error ? error.message : 'Unknown error'
34
- payload.logger.error(`[payload-mcp] Error verifying email: ${errorMessage}`)
35
-
36
- return {
37
- content: [
38
- {
39
- type: 'text' as const,
40
- text: `❌ **Error verifying email**: ${errorMessage}`,
41
- },
42
- ],
43
- }
44
- }
45
- }
46
-
47
- server.registerTool(
48
- 'verify',
49
- {
50
- description: toolSchemas.verify.description,
51
- inputSchema: toolSchemas.verify.parameters.shape,
52
- },
53
- async ({ collection, token }) => {
54
- return await tool(collection, token)
55
- },
56
- )
57
- }
@@ -1,210 +0,0 @@
1
- import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'
2
- import type { PayloadRequest } from 'payload'
3
-
4
- import { writeFileSync } from 'fs'
5
- import { join } from 'path'
6
-
7
- import { generateFieldDefinitionString } from '../../helpers/fields.js'
8
- import { validateCollectionFile } from '../../helpers/fileValidation.js'
9
- import { toolSchemas } from '../schemas.js'
10
-
11
- export const createCollection = async (
12
- req: PayloadRequest,
13
- verboseLogs: boolean,
14
- collectionsDirPath: string,
15
- configFilePath: string,
16
- collectionName: string,
17
- collectionDescription: string | undefined,
18
- fields: any[],
19
- hasUpload: boolean | undefined,
20
- ) => {
21
- const payload = req.payload
22
- if (verboseLogs) {
23
- payload.logger.info(
24
- `[payload-mcp] Creating collection: ${collectionName} with ${fields.length} fields`,
25
- )
26
- }
27
-
28
- const capitalizedName = collectionName.charAt(0).toUpperCase() + collectionName.slice(1)
29
- const slug = collectionName
30
- .replace(/([A-Z])/g, '-$1')
31
- .toLowerCase()
32
- .replace(/^-/, '')
33
-
34
- if (verboseLogs) {
35
- payload.logger.info(`[payload-mcp] Generated slug: ${slug} for collection: ${collectionName}`)
36
- }
37
-
38
- const fieldDefinitions = fields.map(generateFieldDefinitionString).join('\n')
39
-
40
- // Generate collection file content
41
- const collectionContent = `import type { CollectionConfig } from 'payload'
42
-
43
- export const ${capitalizedName}: CollectionConfig = {
44
- slug: '${slug}',${
45
- collectionDescription
46
- ? `
47
- admin: {
48
- description: '${collectionDescription}',
49
- },`
50
- : ''
51
- }${
52
- hasUpload
53
- ? `
54
- upload: true,`
55
- : ''
56
- }
57
- fields: [
58
- ${fieldDefinitions}
59
- ],
60
- }
61
- `
62
-
63
- try {
64
- // Validate the collection name and path
65
- const fileName = `${capitalizedName}.ts`
66
- const filePath = join(collectionsDirPath, fileName)
67
-
68
- // Security check: ensure we're working with the collections directory
69
- if (!filePath.startsWith(collectionsDirPath)) {
70
- payload.logger.error(`[payload-mcp] Invalid collection path attempted: ${filePath}`)
71
- return {
72
- content: [
73
- {
74
- type: 'text' as const,
75
- text: '❌ **Error**: Invalid collection path',
76
- },
77
- ],
78
- }
79
- }
80
-
81
- // Check if file already exists
82
- try {
83
- const fs = await import('fs')
84
- if (fs.existsSync(filePath)) {
85
- return {
86
- content: [
87
- {
88
- type: 'text' as const,
89
- text: `❌ **Error**: Collection file already exists: ${fileName}`,
90
- },
91
- ],
92
- }
93
- }
94
- } catch (_ignore) {
95
- // File doesn't exist, which is what we want
96
- }
97
-
98
- // Write the collection file
99
- writeFileSync(filePath, collectionContent, 'utf8')
100
- if (verboseLogs) {
101
- payload.logger.info(`[payload-mcp] Successfully created collection file: ${filePath}`)
102
- }
103
-
104
- // Validate the generated file
105
- const validationResult = await validateCollectionFile(fileName)
106
- if (validationResult.error) {
107
- return {
108
- content: [
109
- {
110
- type: 'text' as const,
111
- text: `❌ **Error**: Generated collection has validation issues:\n\n${validationResult.error}`,
112
- },
113
- ],
114
- }
115
- }
116
-
117
- return {
118
- content: [
119
- {
120
- type: 'text' as const,
121
- text: `✅ **Collection created successfully!**
122
- **File**: \`${fileName}\`
123
- **Collection Config:**
124
- \`\`\`typescript
125
- ${collectionContent}
126
- \`\`\``,
127
- },
128
- ],
129
- }
130
- } catch (error) {
131
- const errorMessage = (error as Error).message
132
- payload.logger.error(`[payload-mcp] Error creating collection: ${errorMessage}`)
133
-
134
- return {
135
- content: [
136
- {
137
- type: 'text' as const,
138
- text: `❌ **Error creating collection**: ${errorMessage}`,
139
- },
140
- ],
141
- }
142
- }
143
- }
144
-
145
- export const createCollectionTool = (
146
- server: McpServer,
147
- req: PayloadRequest,
148
- verboseLogs: boolean,
149
- collectionsDirPath: string,
150
- configFilePath: string,
151
- ) => {
152
- const tool = async (
153
- collectionName: string,
154
- collectionDescription?: string,
155
- fields: any[] = [],
156
- hasUpload?: boolean,
157
- ) => {
158
- const payload = req.payload
159
-
160
- if (verboseLogs) {
161
- payload.logger.info(
162
- `[payload-mcp] Creating collection: ${collectionName}, fields: ${fields.length}, upload: ${hasUpload}`,
163
- )
164
- }
165
-
166
- try {
167
- const result = await createCollection(
168
- req,
169
- verboseLogs,
170
- collectionsDirPath,
171
- configFilePath,
172
- collectionName,
173
- collectionDescription,
174
- fields,
175
- hasUpload,
176
- )
177
-
178
- if (verboseLogs) {
179
- payload.logger.info(`[payload-mcp] Collection creation completed for: ${collectionName}`)
180
- }
181
-
182
- return result
183
- } catch (error) {
184
- const errorMessage = error instanceof Error ? error.message : 'Unknown error'
185
- payload.logger.error(
186
- `[payload-mcp] Error creating collection ${collectionName}: ${errorMessage}`,
187
- )
188
-
189
- return {
190
- content: [
191
- {
192
- type: 'text' as const,
193
- text: `Error creating collection "${collectionName}": ${errorMessage}`,
194
- },
195
- ],
196
- }
197
- }
198
- }
199
-
200
- server.registerTool(
201
- 'createCollection',
202
- {
203
- description: toolSchemas.createCollection.description,
204
- inputSchema: toolSchemas.createCollection.parameters.shape,
205
- },
206
- async ({ collectionDescription, collectionName, fields, hasUpload }) => {
207
- return await tool(collectionName, collectionDescription, fields, hasUpload)
208
- },
209
- )
210
- }
@@ -1,211 +0,0 @@
1
- import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'
2
- import type { PayloadRequest } from 'payload'
3
-
4
- import { readFileSync, unlinkSync, writeFileSync } from 'fs'
5
- import { join } from 'path'
6
-
7
- import { removeCollectionFromConfig } from '../../helpers/config.js'
8
- import { toolSchemas } from '../schemas.js'
9
-
10
- export const deleteCollection = (
11
- req: PayloadRequest,
12
- verboseLogs: boolean,
13
- collectionsDirPath: string,
14
- configFilePath: string,
15
- collectionName: string,
16
- confirmDeletion: boolean,
17
- updateConfig: boolean,
18
- ) => {
19
- const payload = req.payload
20
-
21
- if (verboseLogs) {
22
- payload.logger.info(`[payload-mcp] Attempting to delete collection: ${collectionName}`)
23
- }
24
-
25
- if (!confirmDeletion) {
26
- payload.logger.warn(`[payload-mcp] Deletion cancelled for collection: ${collectionName}`)
27
- return {
28
- content: [
29
- {
30
- type: 'text' as const,
31
- text: `❌ **Deletion cancelled**. Set confirmDeletion to true to proceed with deleting collection "${collectionName}".`,
32
- },
33
- ],
34
- }
35
- }
36
-
37
- const capitalizedName = collectionName.charAt(0).toUpperCase() + collectionName.slice(1)
38
- const collectionFilePath = join(collectionsDirPath, `${capitalizedName}.ts`)
39
-
40
- // Security check: ensure we're working with the collections directory
41
- if (!collectionFilePath.startsWith(collectionsDirPath)) {
42
- payload.logger.error(`[payload-mcp] Invalid collection path attempted: ${collectionFilePath}`)
43
- return {
44
- content: [
45
- {
46
- type: 'text' as const,
47
- text: '❌ **Error**: Invalid collection path',
48
- },
49
- ],
50
- }
51
- }
52
-
53
- try {
54
- // Check if collection file exists
55
- let fileExists = false
56
- try {
57
- readFileSync(collectionFilePath, 'utf8')
58
- fileExists = true
59
- } catch {
60
- payload.logger.warn(`[payload-mcp] Collection file does not exist: ${collectionFilePath}`)
61
- }
62
-
63
- // Read current config if we need to update it
64
- let configContent = ''
65
- let configExists = false
66
- if (updateConfig) {
67
- try {
68
- configContent = readFileSync(configFilePath, 'utf8')
69
- configExists = true
70
- } catch {
71
- payload.logger.warn(`[payload-mcp] Config file does not exist: ${configFilePath}`)
72
- }
73
- }
74
-
75
- let responseText = ''
76
- let operationsPerformed = 0
77
-
78
- // Delete the collection file
79
- if (fileExists) {
80
- try {
81
- unlinkSync(collectionFilePath)
82
- if (verboseLogs) {
83
- payload.logger.info(
84
- `[payload-mcp] Successfully deleted collection file: ${collectionFilePath}`,
85
- )
86
- }
87
- responseText += `✅ Deleted collection file: \`${capitalizedName}.ts\`\n`
88
- operationsPerformed++
89
- } catch (error) {
90
- const errorMessage = (error as Error).message
91
- payload.logger.error(`[payload-mcp] Error deleting collection file: ${errorMessage}`)
92
- responseText += `❌ Error deleting collection file: ${errorMessage}\n`
93
- }
94
- } else {
95
- responseText += `⚠️ Collection file not found: \`${capitalizedName}.ts\`\n`
96
- }
97
-
98
- // Update the config file if requested and it exists
99
- if (updateConfig && configExists) {
100
- try {
101
- const updatedConfigContent = removeCollectionFromConfig(configContent, capitalizedName)
102
- writeFileSync(configFilePath, updatedConfigContent, 'utf8')
103
- if (verboseLogs) {
104
- payload.logger.info(`[payload-mcp] Successfully updated config file: ${configFilePath}`)
105
- }
106
- responseText += `✅ Updated payload.config.ts to remove collection reference\n`
107
- operationsPerformed++
108
- } catch (error) {
109
- const errorMessage = (error as Error).message
110
- payload.logger.error(`[payload-mcp] Error updating config file: ${errorMessage}`)
111
- responseText += `❌ Error updating config file: ${errorMessage}\n`
112
- }
113
- } else if (updateConfig && !configExists) {
114
- responseText += `⚠️ Config file not found: payload.config.ts\n`
115
- }
116
-
117
- // Summary
118
- if (operationsPerformed > 0) {
119
- responseText += `\n✅ **Collection deletion completed!**`
120
- } else {
121
- responseText += `\n⚠️ **No operations performed**
122
-
123
- The collection file may not have existed or there were errors during deletion.`
124
- }
125
-
126
- return {
127
- content: [
128
- {
129
- type: 'text' as const,
130
- text: responseText,
131
- },
132
- ],
133
- }
134
- } catch (error) {
135
- const errorMessage = (error as Error).message
136
- payload.logger.error(`[payload-mcp] Error during collection deletion: ${errorMessage}`)
137
- return {
138
- content: [
139
- {
140
- type: 'text' as const,
141
- text: `❌ **Error during collection deletion**: ${errorMessage}`,
142
- },
143
- ],
144
- }
145
- }
146
- }
147
-
148
- export const deleteCollectionTool = (
149
- server: McpServer,
150
- req: PayloadRequest,
151
- verboseLogs: boolean,
152
- collectionsDirPath: string,
153
- configFilePath: string,
154
- ) => {
155
- const tool = (
156
- collectionName: string,
157
- confirmDeletion: boolean,
158
- updateConfig: boolean = false,
159
- ) => {
160
- const payload = req.payload
161
-
162
- if (verboseLogs) {
163
- payload.logger.info(
164
- `[payload-mcp] Deleting collection: ${collectionName}, confirmDeletion: ${confirmDeletion}, updateConfig: ${updateConfig}`,
165
- )
166
- }
167
-
168
- try {
169
- const result = deleteCollection(
170
- req,
171
- verboseLogs,
172
- collectionsDirPath,
173
- configFilePath,
174
- collectionName,
175
- confirmDeletion,
176
- updateConfig,
177
- )
178
-
179
- if (verboseLogs) {
180
- payload.logger.info(`[payload-mcp] Collection deletion completed for: ${collectionName}`)
181
- }
182
-
183
- return result
184
- } catch (error) {
185
- const errorMessage = error instanceof Error ? error.message : 'Unknown error'
186
- payload.logger.error(
187
- `[payload-mcp] Error deleting collection ${collectionName}: ${errorMessage}`,
188
- )
189
-
190
- return {
191
- content: [
192
- {
193
- type: 'text' as const,
194
- text: `Error deleting collection "${collectionName}": ${errorMessage}`,
195
- },
196
- ],
197
- }
198
- }
199
- }
200
-
201
- server.registerTool(
202
- 'deleteCollection',
203
- {
204
- description: toolSchemas.deleteCollection.description,
205
- inputSchema: toolSchemas.deleteCollection.parameters.shape,
206
- },
207
- ({ collectionName, confirmDeletion, updateConfig }) => {
208
- return tool(collectionName, confirmDeletion, updateConfig)
209
- },
210
- )
211
- }