@payloadcms/plugin-mcp 3.86.0-internal.ac46214 → 4.0.0-canary.1

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 (368) 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 +60 -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 +199 -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 +94 -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 +102 -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 +144 -0
  55. package/dist/mcp/builtin/collections/findTool.js.map +1 -0
  56. package/dist/mcp/builtin/collections/formatCollectionError.d.ts +9 -0
  57. package/dist/mcp/builtin/collections/formatCollectionError.d.ts.map +1 -0
  58. package/dist/mcp/builtin/collections/formatCollectionError.js +60 -0
  59. package/dist/mcp/builtin/collections/formatCollectionError.js.map +1 -0
  60. package/dist/mcp/builtin/collections/getCollectionSchemaTool.d.ts +2 -0
  61. package/dist/mcp/builtin/collections/getCollectionSchemaTool.d.ts.map +1 -0
  62. package/dist/mcp/builtin/collections/getCollectionSchemaTool.js +35 -0
  63. package/dist/mcp/builtin/collections/getCollectionSchemaTool.js.map +1 -0
  64. package/dist/mcp/builtin/collections/updateTool.d.ts +2 -0
  65. package/dist/mcp/builtin/collections/updateTool.d.ts.map +1 -0
  66. package/dist/mcp/builtin/collections/updateTool.js +199 -0
  67. package/dist/mcp/builtin/collections/updateTool.js.map +1 -0
  68. package/dist/mcp/builtin/getConfigInfoTool.d.ts +2 -0
  69. package/dist/mcp/builtin/getConfigInfoTool.d.ts.map +1 -0
  70. package/dist/mcp/builtin/getConfigInfoTool.js +49 -0
  71. package/dist/mcp/builtin/getConfigInfoTool.js.map +1 -0
  72. package/dist/mcp/builtin/globals/findTool.d.ts +2 -0
  73. package/dist/mcp/builtin/globals/findTool.d.ts.map +1 -0
  74. package/dist/mcp/builtin/globals/findTool.js +76 -0
  75. package/dist/mcp/builtin/globals/findTool.js.map +1 -0
  76. package/dist/mcp/builtin/globals/getGlobalSchemaTool.d.ts +2 -0
  77. package/dist/mcp/builtin/globals/getGlobalSchemaTool.d.ts.map +1 -0
  78. package/dist/mcp/builtin/globals/getGlobalSchemaTool.js +35 -0
  79. package/dist/mcp/builtin/globals/getGlobalSchemaTool.js.map +1 -0
  80. package/dist/mcp/builtin/globals/updateTool.d.ts +2 -0
  81. package/dist/mcp/builtin/globals/updateTool.d.ts.map +1 -0
  82. package/dist/mcp/builtin/globals/updateTool.js +94 -0
  83. package/dist/mcp/builtin/globals/updateTool.js.map +1 -0
  84. package/dist/mcp/builtin/validateEntityData.d.ts +14 -0
  85. package/dist/mcp/builtin/validateEntityData.d.ts.map +1 -0
  86. package/dist/mcp/builtin/validateEntityData.js +82 -0
  87. package/dist/mcp/builtin/validateEntityData.js.map +1 -0
  88. package/dist/mcp/builtinTools.d.ts +105 -0
  89. package/dist/mcp/builtinTools.d.ts.map +1 -0
  90. package/dist/mcp/builtinTools.js +107 -0
  91. package/dist/mcp/builtinTools.js.map +1 -0
  92. package/dist/mcp/sanitizeMCPConfig.d.ts +17 -0
  93. package/dist/mcp/sanitizeMCPConfig.d.ts.map +1 -0
  94. package/dist/mcp/sanitizeMCPConfig.js +188 -0
  95. package/dist/mcp/sanitizeMCPConfig.js.map +1 -0
  96. package/dist/stdio.d.ts +8 -0
  97. package/dist/stdio.d.ts.map +1 -0
  98. package/dist/stdio.js +89 -0
  99. package/dist/stdio.js.map +1 -0
  100. package/dist/types.d.ts +251 -455
  101. package/dist/types.d.ts.map +1 -1
  102. package/dist/types.js +6 -1
  103. package/dist/types.js.map +1 -1
  104. package/dist/utils/camelCase.d.ts.map +1 -1
  105. package/dist/utils/getLogger.d.ts +10 -0
  106. package/dist/utils/getLogger.d.ts.map +1 -0
  107. package/dist/utils/getLogger.js +22 -0
  108. package/dist/utils/getLogger.js.map +1 -0
  109. package/dist/utils/getPluginConfig.d.ts +12 -0
  110. package/dist/utils/getPluginConfig.d.ts.map +1 -0
  111. package/dist/utils/getPluginConfig.js +15 -0
  112. package/dist/utils/getPluginConfig.js.map +1 -0
  113. package/dist/utils/localAPIDefaults.d.ts +20 -0
  114. package/dist/utils/localAPIDefaults.d.ts.map +1 -0
  115. package/dist/utils/localAPIDefaults.js +19 -0
  116. package/dist/utils/localAPIDefaults.js.map +1 -0
  117. package/dist/utils/resolveProjectRoot.d.ts +7 -0
  118. package/dist/utils/resolveProjectRoot.d.ts.map +1 -0
  119. package/dist/utils/resolveProjectRoot.js +15 -0
  120. package/dist/utils/resolveProjectRoot.js.map +1 -0
  121. package/dist/utils/schemaConversion/getEntityInputSchema.d.ts +11 -0
  122. package/dist/utils/schemaConversion/getEntityInputSchema.d.ts.map +1 -0
  123. package/dist/utils/schemaConversion/getEntityInputSchema.js +34 -0
  124. package/dist/utils/schemaConversion/getEntityInputSchema.js.map +1 -0
  125. package/dist/utils/schemaConversion/removeVirtualFieldsFromSchema.d.ts +2 -2
  126. package/dist/utils/schemaConversion/removeVirtualFieldsFromSchema.d.ts.map +1 -1
  127. package/dist/utils/schemaConversion/removeVirtualFieldsFromSchema.js.map +1 -1
  128. package/dist/utils/schemaConversion/sanitizeEntitySchema.d.ts +15 -0
  129. package/dist/utils/schemaConversion/sanitizeEntitySchema.d.ts.map +1 -0
  130. package/dist/utils/schemaConversion/sanitizeEntitySchema.js +464 -0
  131. package/dist/utils/schemaConversion/sanitizeEntitySchema.js.map +1 -0
  132. package/dist/utils/schemaConversion/sanitizeEntitySchema.spec.js +158 -0
  133. package/dist/utils/schemaConversion/sanitizeEntitySchema.spec.js.map +1 -0
  134. package/dist/utils/toStandardSchema.d.ts +5 -0
  135. package/dist/utils/toStandardSchema.d.ts.map +1 -0
  136. package/dist/utils/toStandardSchema.js +4 -0
  137. package/dist/utils/toStandardSchema.js.map +1 -0
  138. package/dist/utils/whereSchema.d.ts +9 -0
  139. package/dist/utils/whereSchema.d.ts.map +1 -0
  140. package/dist/utils/whereSchema.js +13 -0
  141. package/dist/utils/whereSchema.js.map +1 -0
  142. package/package.json +35 -10
  143. package/src/collection/getAccessField.ts +64 -0
  144. package/src/collection/index.ts +64 -0
  145. package/src/components/AccessField/index.client.tsx +347 -0
  146. package/src/components/AccessField/index.css +93 -0
  147. package/src/defineTool.ts +44 -0
  148. package/src/endpoint/access.ts +132 -0
  149. package/src/endpoint/index.ts +35 -0
  150. package/src/exports/client.ts +2 -0
  151. package/src/index.ts +35 -85
  152. package/src/mcp/buildMcpServer.ts +257 -0
  153. package/src/mcp/builtin/collections/authTools.ts +233 -0
  154. package/src/mcp/builtin/collections/createTool.ts +112 -0
  155. package/src/mcp/builtin/collections/deleteTool.ts +116 -0
  156. package/src/mcp/builtin/collections/findTool.ts +177 -0
  157. package/src/mcp/builtin/collections/formatCollectionError.ts +84 -0
  158. package/src/mcp/builtin/collections/getCollectionSchemaTool.ts +28 -0
  159. package/src/mcp/builtin/collections/updateTool.ts +211 -0
  160. package/src/mcp/builtin/getConfigInfoTool.ts +44 -0
  161. package/src/mcp/builtin/globals/findTool.ts +96 -0
  162. package/src/mcp/builtin/globals/getGlobalSchemaTool.ts +28 -0
  163. package/src/mcp/builtin/globals/updateTool.ts +115 -0
  164. package/src/mcp/builtin/validateEntityData.ts +132 -0
  165. package/src/mcp/builtinTools.ts +98 -0
  166. package/src/mcp/sanitizeMCPConfig.ts +260 -0
  167. package/src/stdio.ts +98 -0
  168. package/src/types.ts +290 -490
  169. package/src/utils/getLogger.ts +22 -0
  170. package/src/utils/getPluginConfig.ts +24 -0
  171. package/src/utils/localAPIDefaults.ts +22 -0
  172. package/src/utils/resolveProjectRoot.ts +17 -0
  173. package/src/utils/schemaConversion/getEntityInputSchema.ts +78 -0
  174. package/src/utils/schemaConversion/removeVirtualFieldsFromSchema.ts +3 -3
  175. package/src/utils/schemaConversion/sanitizeEntitySchema.spec.ts +103 -0
  176. package/src/utils/schemaConversion/sanitizeEntitySchema.ts +529 -0
  177. package/src/utils/toStandardSchema.ts +9 -0
  178. package/src/utils/whereSchema.ts +24 -0
  179. package/dist/collections/createApiKeysCollection.d.ts +0 -7
  180. package/dist/collections/createApiKeysCollection.d.ts.map +0 -1
  181. package/dist/collections/createApiKeysCollection.js +0 -317
  182. package/dist/collections/createApiKeysCollection.js.map +0 -1
  183. package/dist/defaults.d.ts +0 -4
  184. package/dist/defaults.d.ts.map +0 -1
  185. package/dist/defaults.js +0 -5
  186. package/dist/defaults.js.map +0 -1
  187. package/dist/endpoints/mcp.d.ts +0 -4
  188. package/dist/endpoints/mcp.d.ts.map +0 -1
  189. package/dist/endpoints/mcp.js +0 -71
  190. package/dist/endpoints/mcp.js.map +0 -1
  191. package/dist/mcp/createRequest.d.ts +0 -3
  192. package/dist/mcp/createRequest.d.ts.map +0 -1
  193. package/dist/mcp/createRequest.js +0 -14
  194. package/dist/mcp/createRequest.js.map +0 -1
  195. package/dist/mcp/getMcpHandler.d.ts +0 -4
  196. package/dist/mcp/getMcpHandler.d.ts.map +0 -1
  197. package/dist/mcp/getMcpHandler.js +0 -231
  198. package/dist/mcp/getMcpHandler.js.map +0 -1
  199. package/dist/mcp/helpers/config.d.ts +0 -22
  200. package/dist/mcp/helpers/config.d.ts.map +0 -1
  201. package/dist/mcp/helpers/config.js +0 -153
  202. package/dist/mcp/helpers/config.js.map +0 -1
  203. package/dist/mcp/helpers/fields.d.ts +0 -19
  204. package/dist/mcp/helpers/fields.d.ts.map +0 -1
  205. package/dist/mcp/helpers/fields.js +0 -102
  206. package/dist/mcp/helpers/fields.js.map +0 -1
  207. package/dist/mcp/helpers/fileValidation.d.ts +0 -67
  208. package/dist/mcp/helpers/fileValidation.d.ts.map +0 -1
  209. package/dist/mcp/helpers/fileValidation.js +0 -267
  210. package/dist/mcp/helpers/fileValidation.js.map +0 -1
  211. package/dist/mcp/registerTool.d.ts +0 -6
  212. package/dist/mcp/registerTool.d.ts.map +0 -1
  213. package/dist/mcp/registerTool.js +0 -18
  214. package/dist/mcp/registerTool.js.map +0 -1
  215. package/dist/mcp/tools/auth/auth.d.ts +0 -4
  216. package/dist/mcp/tools/auth/auth.d.ts.map +0 -1
  217. package/dist/mcp/tools/auth/auth.js +0 -57
  218. package/dist/mcp/tools/auth/auth.js.map +0 -1
  219. package/dist/mcp/tools/auth/forgotPassword.d.ts +0 -4
  220. package/dist/mcp/tools/auth/forgotPassword.d.ts.map +0 -1
  221. package/dist/mcp/tools/auth/forgotPassword.js +0 -48
  222. package/dist/mcp/tools/auth/forgotPassword.js.map +0 -1
  223. package/dist/mcp/tools/auth/login.d.ts +0 -4
  224. package/dist/mcp/tools/auth/login.d.ts.map +0 -1
  225. package/dist/mcp/tools/auth/login.js +0 -51
  226. package/dist/mcp/tools/auth/login.js.map +0 -1
  227. package/dist/mcp/tools/auth/resetPassword.d.ts +0 -4
  228. package/dist/mcp/tools/auth/resetPassword.d.ts.map +0 -1
  229. package/dist/mcp/tools/auth/resetPassword.js +0 -49
  230. package/dist/mcp/tools/auth/resetPassword.js.map +0 -1
  231. package/dist/mcp/tools/auth/unlock.d.ts +0 -4
  232. package/dist/mcp/tools/auth/unlock.d.ts.map +0 -1
  233. package/dist/mcp/tools/auth/unlock.js +0 -48
  234. package/dist/mcp/tools/auth/unlock.js.map +0 -1
  235. package/dist/mcp/tools/auth/verify.d.ts +0 -4
  236. package/dist/mcp/tools/auth/verify.d.ts.map +0 -1
  237. package/dist/mcp/tools/auth/verify.js +0 -45
  238. package/dist/mcp/tools/auth/verify.js.map +0 -1
  239. package/dist/mcp/tools/collection/create.d.ts +0 -10
  240. package/dist/mcp/tools/collection/create.d.ts.map +0 -1
  241. package/dist/mcp/tools/collection/create.js +0 -139
  242. package/dist/mcp/tools/collection/create.js.map +0 -1
  243. package/dist/mcp/tools/collection/delete.d.ts +0 -10
  244. package/dist/mcp/tools/collection/delete.d.ts.map +0 -1
  245. package/dist/mcp/tools/collection/delete.js +0 -154
  246. package/dist/mcp/tools/collection/delete.js.map +0 -1
  247. package/dist/mcp/tools/collection/find.d.ts +0 -10
  248. package/dist/mcp/tools/collection/find.d.ts.map +0 -1
  249. package/dist/mcp/tools/collection/find.js +0 -165
  250. package/dist/mcp/tools/collection/find.js.map +0 -1
  251. package/dist/mcp/tools/collection/update.d.ts +0 -10
  252. package/dist/mcp/tools/collection/update.d.ts.map +0 -1
  253. package/dist/mcp/tools/collection/update.js +0 -209
  254. package/dist/mcp/tools/collection/update.js.map +0 -1
  255. package/dist/mcp/tools/config/find.d.ts +0 -10
  256. package/dist/mcp/tools/config/find.d.ts.map +0 -1
  257. package/dist/mcp/tools/config/find.js +0 -97
  258. package/dist/mcp/tools/config/find.js.map +0 -1
  259. package/dist/mcp/tools/config/update.d.ts +0 -10
  260. package/dist/mcp/tools/config/update.d.ts.map +0 -1
  261. package/dist/mcp/tools/config/update.js +0 -215
  262. package/dist/mcp/tools/config/update.js.map +0 -1
  263. package/dist/mcp/tools/global/find.d.ts +0 -5
  264. package/dist/mcp/tools/global/find.d.ts.map +0 -1
  265. package/dist/mcp/tools/global/find.js +0 -82
  266. package/dist/mcp/tools/global/find.js.map +0 -1
  267. package/dist/mcp/tools/global/update.d.ts +0 -6
  268. package/dist/mcp/tools/global/update.d.ts.map +0 -1
  269. package/dist/mcp/tools/global/update.js +0 -124
  270. package/dist/mcp/tools/global/update.js.map +0 -1
  271. package/dist/mcp/tools/job/create.d.ts +0 -10
  272. package/dist/mcp/tools/job/create.d.ts.map +0 -1
  273. package/dist/mcp/tools/job/create.js +0 -293
  274. package/dist/mcp/tools/job/create.js.map +0 -1
  275. package/dist/mcp/tools/job/run.d.ts +0 -10
  276. package/dist/mcp/tools/job/run.d.ts.map +0 -1
  277. package/dist/mcp/tools/job/run.js +0 -129
  278. package/dist/mcp/tools/job/run.js.map +0 -1
  279. package/dist/mcp/tools/job/update.d.ts +0 -11
  280. package/dist/mcp/tools/job/update.d.ts.map +0 -1
  281. package/dist/mcp/tools/job/update.js +0 -186
  282. package/dist/mcp/tools/job/update.js.map +0 -1
  283. package/dist/mcp/tools/resource/create.d.ts +0 -6
  284. package/dist/mcp/tools/resource/create.d.ts.map +0 -1
  285. package/dist/mcp/tools/resource/create.js +0 -124
  286. package/dist/mcp/tools/resource/create.js.map +0 -1
  287. package/dist/mcp/tools/resource/delete.d.ts +0 -5
  288. package/dist/mcp/tools/resource/delete.d.ts.map +0 -1
  289. package/dist/mcp/tools/resource/delete.js +0 -151
  290. package/dist/mcp/tools/resource/delete.js.map +0 -1
  291. package/dist/mcp/tools/resource/find.d.ts +0 -5
  292. package/dist/mcp/tools/resource/find.d.ts.map +0 -1
  293. package/dist/mcp/tools/resource/find.js +0 -170
  294. package/dist/mcp/tools/resource/find.js.map +0 -1
  295. package/dist/mcp/tools/resource/update.d.ts +0 -6
  296. package/dist/mcp/tools/resource/update.d.ts.map +0 -1
  297. package/dist/mcp/tools/resource/update.js +0 -256
  298. package/dist/mcp/tools/resource/update.js.map +0 -1
  299. package/dist/mcp/tools/schemas.d.ts +0 -457
  300. package/dist/mcp/tools/schemas.d.ts.map +0 -1
  301. package/dist/mcp/tools/schemas.js +0 -243
  302. package/dist/mcp/tools/schemas.js.map +0 -1
  303. package/dist/utils/adminEntitySettings.d.ts +0 -17
  304. package/dist/utils/adminEntitySettings.d.ts.map +0 -1
  305. package/dist/utils/adminEntitySettings.js +0 -41
  306. package/dist/utils/adminEntitySettings.js.map +0 -1
  307. package/dist/utils/createApiKeyFields.d.ts +0 -15
  308. package/dist/utils/createApiKeyFields.d.ts.map +0 -1
  309. package/dist/utils/createApiKeyFields.js +0 -57
  310. package/dist/utils/createApiKeyFields.js.map +0 -1
  311. package/dist/utils/getEnabledSlugs.d.ts +0 -13
  312. package/dist/utils/getEnabledSlugs.d.ts.map +0 -1
  313. package/dist/utils/getEnabledSlugs.js +0 -32
  314. package/dist/utils/getEnabledSlugs.js.map +0 -1
  315. package/dist/utils/schemaConversion/convertCollectionSchemaToZod.d.ts +0 -3
  316. package/dist/utils/schemaConversion/convertCollectionSchemaToZod.d.ts.map +0 -1
  317. package/dist/utils/schemaConversion/convertCollectionSchemaToZod.js +0 -43
  318. package/dist/utils/schemaConversion/convertCollectionSchemaToZod.js.map +0 -1
  319. package/dist/utils/schemaConversion/sanitizeJsonSchema.d.ts +0 -13
  320. package/dist/utils/schemaConversion/sanitizeJsonSchema.d.ts.map +0 -1
  321. package/dist/utils/schemaConversion/sanitizeJsonSchema.js +0 -56
  322. package/dist/utils/schemaConversion/sanitizeJsonSchema.js.map +0 -1
  323. package/dist/utils/schemaConversion/simplifyRelationshipFields.d.ts +0 -20
  324. package/dist/utils/schemaConversion/simplifyRelationshipFields.d.ts.map +0 -1
  325. package/dist/utils/schemaConversion/simplifyRelationshipFields.js +0 -53
  326. package/dist/utils/schemaConversion/simplifyRelationshipFields.js.map +0 -1
  327. package/dist/utils/schemaConversion/transformPointFields.d.ts +0 -3
  328. package/dist/utils/schemaConversion/transformPointFields.d.ts.map +0 -1
  329. package/dist/utils/schemaConversion/transformPointFields.js +0 -51
  330. package/dist/utils/schemaConversion/transformPointFields.js.map +0 -1
  331. package/src/collections/createApiKeysCollection.ts +0 -373
  332. package/src/defaults.ts +0 -3
  333. package/src/endpoints/mcp.ts +0 -91
  334. package/src/mcp/createRequest.ts +0 -13
  335. package/src/mcp/getMcpHandler.ts +0 -545
  336. package/src/mcp/helpers/config.ts +0 -213
  337. package/src/mcp/helpers/fields.ts +0 -154
  338. package/src/mcp/helpers/fileValidation.ts +0 -362
  339. package/src/mcp/registerTool.ts +0 -22
  340. package/src/mcp/tools/auth/auth.ts +0 -71
  341. package/src/mcp/tools/auth/forgotPassword.ts +0 -70
  342. package/src/mcp/tools/auth/login.ts +0 -72
  343. package/src/mcp/tools/auth/resetPassword.ts +0 -61
  344. package/src/mcp/tools/auth/unlock.ts +0 -64
  345. package/src/mcp/tools/auth/verify.ts +0 -57
  346. package/src/mcp/tools/collection/create.ts +0 -210
  347. package/src/mcp/tools/collection/delete.ts +0 -211
  348. package/src/mcp/tools/collection/find.ts +0 -224
  349. package/src/mcp/tools/collection/update.ts +0 -290
  350. package/src/mcp/tools/config/find.ts +0 -128
  351. package/src/mcp/tools/config/update.ts +0 -280
  352. package/src/mcp/tools/global/find.ts +0 -128
  353. package/src/mcp/tools/global/update.ts +0 -207
  354. package/src/mcp/tools/job/create.ts +0 -416
  355. package/src/mcp/tools/job/run.ts +0 -167
  356. package/src/mcp/tools/job/update.ts +0 -274
  357. package/src/mcp/tools/resource/create.ts +0 -211
  358. package/src/mcp/tools/resource/delete.ts +0 -218
  359. package/src/mcp/tools/resource/find.ts +0 -246
  360. package/src/mcp/tools/resource/update.ts +0 -383
  361. package/src/mcp/tools/schemas.ts +0 -520
  362. package/src/utils/adminEntitySettings.ts +0 -40
  363. package/src/utils/createApiKeyFields.ts +0 -72
  364. package/src/utils/getEnabledSlugs.ts +0 -42
  365. package/src/utils/schemaConversion/convertCollectionSchemaToZod.ts +0 -52
  366. package/src/utils/schemaConversion/sanitizeJsonSchema.ts +0 -62
  367. package/src/utils/schemaConversion/simplifyRelationshipFields.ts +0 -65
  368. package/src/utils/schemaConversion/transformPointFields.ts +0 -55
@@ -0,0 +1,107 @@
1
+ import { authCollectionTool, forgotPasswordCollectionTool, loginCollectionTool, resetPasswordCollectionTool, unlockCollectionTool, verifyCollectionTool } from './builtin/collections/authTools.js';
2
+ import { createDocumentTool } from './builtin/collections/createTool.js';
3
+ import { deleteDocumentsTool } from './builtin/collections/deleteTool.js';
4
+ import { findDocumentsTool } from './builtin/collections/findTool.js';
5
+ import { getCollectionSchemaTool } from './builtin/collections/getCollectionSchemaTool.js';
6
+ import { updateDocumentTool } from './builtin/collections/updateTool.js';
7
+ import { getConfigInfoTool } from './builtin/getConfigInfoTool.js';
8
+ import { findGlobalTool } from './builtin/globals/findTool.js';
9
+ import { getGlobalSchemaTool } from './builtin/globals/getGlobalSchemaTool.js';
10
+ import { updateGlobalTool } from './builtin/globals/updateTool.js';
11
+ export const TOOL_BUILTINS = {
12
+ getConfigInfo: {
13
+ label: 'Config Info',
14
+ mcpName: 'getConfigInfo',
15
+ tool: getConfigInfoTool
16
+ }
17
+ };
18
+ /**
19
+ * The static built-in collection CRUD tools. Keys here are the source of truth
20
+ * for `MCPCollectionBuiltinName` — adding/removing an entry updates the type
21
+ * automatically.
22
+ */ export const COLLECTION_BUILTINS = {
23
+ create: {
24
+ mcpName: 'createDocument',
25
+ tool: createDocumentTool
26
+ },
27
+ delete: {
28
+ mcpName: 'deleteDocuments',
29
+ tool: deleteDocumentsTool
30
+ },
31
+ find: {
32
+ mcpName: 'findDocuments',
33
+ tool: findDocumentsTool
34
+ },
35
+ getCollectionSchema: {
36
+ mcpName: 'getCollectionSchema',
37
+ tool: getCollectionSchemaTool
38
+ },
39
+ update: {
40
+ mcpName: 'updateDocument',
41
+ tool: updateDocumentTool
42
+ }
43
+ };
44
+ /**
45
+ * The static auth tools surfaced under auth-enabled collections. Each entry
46
+ * carries the admin-UI label alongside the tool. Keys are the source of truth
47
+ * for `MCPCollectionAuthToolName`.
48
+ */ export const COLLECTION_AUTH_BUILTINS = {
49
+ auth: {
50
+ label: 'Check Auth Status',
51
+ mcpName: 'auth',
52
+ tool: authCollectionTool
53
+ },
54
+ forgotPassword: {
55
+ label: 'Forgot Password',
56
+ mcpName: 'forgotPassword',
57
+ tool: forgotPasswordCollectionTool
58
+ },
59
+ login: {
60
+ label: 'User Login',
61
+ mcpName: 'login',
62
+ tool: loginCollectionTool
63
+ },
64
+ resetPassword: {
65
+ label: 'Reset Password',
66
+ mcpName: 'resetPassword',
67
+ tool: resetPasswordCollectionTool
68
+ },
69
+ unlock: {
70
+ label: 'Unlock Account',
71
+ mcpName: 'unlock',
72
+ tool: unlockCollectionTool
73
+ },
74
+ verify: {
75
+ label: 'Email Verification',
76
+ mcpName: 'verify',
77
+ tool: verifyCollectionTool
78
+ }
79
+ };
80
+ /**
81
+ * The static built-in global tools. Keys are the source of truth for
82
+ * `MCPGlobalBuiltinName`.
83
+ */ export const GLOBAL_BUILTINS = {
84
+ find: {
85
+ mcpName: 'findGlobal',
86
+ tool: findGlobalTool
87
+ },
88
+ getGlobalSchema: {
89
+ mcpName: 'getGlobalSchema',
90
+ tool: getGlobalSchemaTool
91
+ },
92
+ update: {
93
+ mcpName: 'updateGlobal',
94
+ tool: updateGlobalTool
95
+ }
96
+ };
97
+ /**
98
+ * Pre-typed `Object.entries` for each registry. The cast from `string` to the
99
+ * literal key union lives here once so consumers can iterate without their own
100
+ * cast — TypeScript's `Object.entries` always widens keys to `string`, which
101
+ * defeats the narrow type lookups on `MCPCollectionToolsMap`.
102
+ */ export const TOOL_BUILTIN_ENTRIES = Object.entries(TOOL_BUILTINS);
103
+ export const COLLECTION_BUILTIN_ENTRIES = Object.entries(COLLECTION_BUILTINS);
104
+ export const COLLECTION_AUTH_BUILTIN_ENTRIES = Object.entries(COLLECTION_AUTH_BUILTINS);
105
+ export const GLOBAL_BUILTIN_ENTRIES = Object.entries(GLOBAL_BUILTINS);
106
+
107
+ //# sourceMappingURL=builtinTools.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/mcp/builtinTools.ts"],"sourcesContent":["import type { CollectionTool, GlobalTool, Tool } from '../types.js'\n\nimport {\n authCollectionTool,\n forgotPasswordCollectionTool,\n loginCollectionTool,\n resetPasswordCollectionTool,\n unlockCollectionTool,\n verifyCollectionTool,\n} from './builtin/collections/authTools.js'\nimport { createDocumentTool } from './builtin/collections/createTool.js'\nimport { deleteDocumentsTool } from './builtin/collections/deleteTool.js'\nimport { findDocumentsTool } from './builtin/collections/findTool.js'\nimport { getCollectionSchemaTool } from './builtin/collections/getCollectionSchemaTool.js'\nimport { updateDocumentTool } from './builtin/collections/updateTool.js'\nimport { getConfigInfoTool } from './builtin/getConfigInfoTool.js'\nimport { findGlobalTool } from './builtin/globals/findTool.js'\nimport { getGlobalSchemaTool } from './builtin/globals/getGlobalSchemaTool.js'\nimport { updateGlobalTool } from './builtin/globals/updateTool.js'\n\nexport const TOOL_BUILTINS = {\n getConfigInfo: { label: 'Config Info', mcpName: 'getConfigInfo', tool: getConfigInfoTool },\n} satisfies Record<string, { label: string; mcpName: string; tool: Tool }>\n\n/**\n * The static built-in collection CRUD tools. Keys here are the source of truth\n * for `MCPCollectionBuiltinName` — adding/removing an entry updates the type\n * automatically.\n */\nexport const COLLECTION_BUILTINS = {\n create: { mcpName: 'createDocument', tool: createDocumentTool },\n delete: { mcpName: 'deleteDocuments', tool: deleteDocumentsTool },\n find: { mcpName: 'findDocuments', tool: findDocumentsTool },\n getCollectionSchema: { mcpName: 'getCollectionSchema', tool: getCollectionSchemaTool },\n update: { mcpName: 'updateDocument', tool: updateDocumentTool },\n} satisfies Record<string, { mcpName: string; tool: CollectionTool }>\n\n/**\n * The static auth tools surfaced under auth-enabled collections. Each entry\n * carries the admin-UI label alongside the tool. Keys are the source of truth\n * for `MCPCollectionAuthToolName`.\n */\nexport const COLLECTION_AUTH_BUILTINS = {\n auth: { label: 'Check Auth Status', mcpName: 'auth', tool: authCollectionTool },\n forgotPassword: {\n label: 'Forgot Password',\n mcpName: 'forgotPassword',\n tool: forgotPasswordCollectionTool,\n },\n login: { label: 'User Login', mcpName: 'login', tool: loginCollectionTool },\n resetPassword: {\n label: 'Reset Password',\n mcpName: 'resetPassword',\n tool: resetPasswordCollectionTool,\n },\n unlock: { label: 'Unlock Account', mcpName: 'unlock', tool: unlockCollectionTool },\n verify: { label: 'Email Verification', mcpName: 'verify', tool: verifyCollectionTool },\n} satisfies Record<string, { label: string; mcpName: string; tool: CollectionTool }>\n\n/**\n * The static built-in global tools. Keys are the source of truth for\n * `MCPGlobalBuiltinName`.\n */\nexport const GLOBAL_BUILTINS = {\n find: { mcpName: 'findGlobal', tool: findGlobalTool },\n getGlobalSchema: { mcpName: 'getGlobalSchema', tool: getGlobalSchemaTool },\n update: { mcpName: 'updateGlobal', tool: updateGlobalTool },\n} satisfies Record<string, { mcpName: string; tool: GlobalTool }>\n\nexport type MCPCollectionBuiltinName = keyof typeof COLLECTION_BUILTINS\n\nexport type MCPCollectionAuthToolName = keyof typeof COLLECTION_AUTH_BUILTINS\n\nexport type MCPGlobalBuiltinName = keyof typeof GLOBAL_BUILTINS\n\nexport type MCPTopLevelBuiltinName = keyof typeof TOOL_BUILTINS\n\n/**\n * Pre-typed `Object.entries` for each registry. The cast from `string` to the\n * literal key union lives here once so consumers can iterate without their own\n * cast — TypeScript's `Object.entries` always widens keys to `string`, which\n * defeats the narrow type lookups on `MCPCollectionToolsMap`.\n */\nexport const TOOL_BUILTIN_ENTRIES = Object.entries(TOOL_BUILTINS) as Array<\n [MCPTopLevelBuiltinName, (typeof TOOL_BUILTINS)[MCPTopLevelBuiltinName]]\n>\n\nexport const COLLECTION_BUILTIN_ENTRIES = Object.entries(COLLECTION_BUILTINS) as Array<\n [MCPCollectionBuiltinName, (typeof COLLECTION_BUILTINS)[MCPCollectionBuiltinName]]\n>\n\nexport const COLLECTION_AUTH_BUILTIN_ENTRIES = Object.entries(COLLECTION_AUTH_BUILTINS) as Array<\n [MCPCollectionAuthToolName, (typeof COLLECTION_AUTH_BUILTINS)[MCPCollectionAuthToolName]]\n>\n\nexport const GLOBAL_BUILTIN_ENTRIES = Object.entries(GLOBAL_BUILTINS) as Array<\n [MCPGlobalBuiltinName, (typeof GLOBAL_BUILTINS)[MCPGlobalBuiltinName]]\n>\n"],"names":["authCollectionTool","forgotPasswordCollectionTool","loginCollectionTool","resetPasswordCollectionTool","unlockCollectionTool","verifyCollectionTool","createDocumentTool","deleteDocumentsTool","findDocumentsTool","getCollectionSchemaTool","updateDocumentTool","getConfigInfoTool","findGlobalTool","getGlobalSchemaTool","updateGlobalTool","TOOL_BUILTINS","getConfigInfo","label","mcpName","tool","COLLECTION_BUILTINS","create","delete","find","getCollectionSchema","update","COLLECTION_AUTH_BUILTINS","auth","forgotPassword","login","resetPassword","unlock","verify","GLOBAL_BUILTINS","getGlobalSchema","TOOL_BUILTIN_ENTRIES","Object","entries","COLLECTION_BUILTIN_ENTRIES","COLLECTION_AUTH_BUILTIN_ENTRIES","GLOBAL_BUILTIN_ENTRIES"],"mappings":"AAEA,SACEA,kBAAkB,EAClBC,4BAA4B,EAC5BC,mBAAmB,EACnBC,2BAA2B,EAC3BC,oBAAoB,EACpBC,oBAAoB,QACf,qCAAoC;AAC3C,SAASC,kBAAkB,QAAQ,sCAAqC;AACxE,SAASC,mBAAmB,QAAQ,sCAAqC;AACzE,SAASC,iBAAiB,QAAQ,oCAAmC;AACrE,SAASC,uBAAuB,QAAQ,mDAAkD;AAC1F,SAASC,kBAAkB,QAAQ,sCAAqC;AACxE,SAASC,iBAAiB,QAAQ,iCAAgC;AAClE,SAASC,cAAc,QAAQ,gCAA+B;AAC9D,SAASC,mBAAmB,QAAQ,2CAA0C;AAC9E,SAASC,gBAAgB,QAAQ,kCAAiC;AAElE,OAAO,MAAMC,gBAAgB;IAC3BC,eAAe;QAAEC,OAAO;QAAeC,SAAS;QAAiBC,MAAMR;IAAkB;AAC3F,EAA0E;AAE1E;;;;CAIC,GACD,OAAO,MAAMS,sBAAsB;IACjCC,QAAQ;QAAEH,SAAS;QAAkBC,MAAMb;IAAmB;IAC9DgB,QAAQ;QAAEJ,SAAS;QAAmBC,MAAMZ;IAAoB;IAChEgB,MAAM;QAAEL,SAAS;QAAiBC,MAAMX;IAAkB;IAC1DgB,qBAAqB;QAAEN,SAAS;QAAuBC,MAAMV;IAAwB;IACrFgB,QAAQ;QAAEP,SAAS;QAAkBC,MAAMT;IAAmB;AAChE,EAAqE;AAErE;;;;CAIC,GACD,OAAO,MAAMgB,2BAA2B;IACtCC,MAAM;QAAEV,OAAO;QAAqBC,SAAS;QAAQC,MAAMnB;IAAmB;IAC9E4B,gBAAgB;QACdX,OAAO;QACPC,SAAS;QACTC,MAAMlB;IACR;IACA4B,OAAO;QAAEZ,OAAO;QAAcC,SAAS;QAASC,MAAMjB;IAAoB;IAC1E4B,eAAe;QACbb,OAAO;QACPC,SAAS;QACTC,MAAMhB;IACR;IACA4B,QAAQ;QAAEd,OAAO;QAAkBC,SAAS;QAAUC,MAAMf;IAAqB;IACjF4B,QAAQ;QAAEf,OAAO;QAAsBC,SAAS;QAAUC,MAAMd;IAAqB;AACvF,EAAoF;AAEpF;;;CAGC,GACD,OAAO,MAAM4B,kBAAkB;IAC7BV,MAAM;QAAEL,SAAS;QAAcC,MAAMP;IAAe;IACpDsB,iBAAiB;QAAEhB,SAAS;QAAmBC,MAAMN;IAAoB;IACzEY,QAAQ;QAAEP,SAAS;QAAgBC,MAAML;IAAiB;AAC5D,EAAiE;AAUjE;;;;;CAKC,GACD,OAAO,MAAMqB,uBAAuBC,OAAOC,OAAO,CAACtB,eAElD;AAED,OAAO,MAAMuB,6BAA6BF,OAAOC,OAAO,CAACjB,qBAExD;AAED,OAAO,MAAMmB,kCAAkCH,OAAOC,OAAO,CAACX,0BAE7D;AAED,OAAO,MAAMc,yBAAyBJ,OAAOC,OAAO,CAACJ,iBAEpD"}
@@ -0,0 +1,17 @@
1
+ import type { Config, SanitizedConfig } from 'payload';
2
+ import type { MCPPluginConfig, SanitizedMCPPluginConfig } from '../types.js';
3
+ /**
4
+ * Converts the user-configured `MCPPluginConfig` into a `SanitizedMCPPluginConfig`:
5
+ * - Flattens `tools` / `prompts` / `resources` / per-collection / per-global
6
+ * tool maps into a single `items` array.
7
+ * - Applies built-in tools for collections and globals, respecting opt-out user overrides.
8
+ * - Applies the `userCollection` default
9
+ *
10
+ * Called once during plugin init. After that, `plugins['@payloadcms/plugin-mcp']
11
+ * ?.options` holds the sanitized result
12
+ */
13
+ export declare const sanitizeMCPConfig: ({ config, pluginConfig, }: {
14
+ config: Config | SanitizedConfig;
15
+ pluginConfig: MCPPluginConfig;
16
+ }) => SanitizedMCPPluginConfig;
17
+ //# sourceMappingURL=sanitizeMCPConfig.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sanitizeMCPConfig.d.ts","sourceRoot":"","sources":["../../src/mcp/sanitizeMCPConfig.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,MAAM,EAGN,eAAe,EAEhB,MAAM,SAAS,CAAA;AAEhB,OAAO,KAAK,EAMV,eAAe,EACf,wBAAwB,EACzB,MAAM,aAAa,CAAA;AAapB;;;;;;;;;GASG;AACH,eAAO,MAAM,iBAAiB,GAAI,2BAG/B;IACD,MAAM,EAAE,MAAM,GAAG,eAAe,CAAA;IAChC,YAAY,EAAE,eAAe,CAAA;CAC9B,KAAG,wBAkEH,CAAA"}
@@ -0,0 +1,188 @@
1
+ import { COLLECTION_AUTH_BUILTIN_ENTRIES, COLLECTION_AUTH_BUILTINS, COLLECTION_BUILTIN_ENTRIES, COLLECTION_BUILTINS, GLOBAL_BUILTIN_ENTRIES, GLOBAL_BUILTINS, TOOL_BUILTIN_ENTRIES, TOOL_BUILTINS } from './builtinTools.js';
2
+ /**
3
+ * Converts the user-configured `MCPPluginConfig` into a `SanitizedMCPPluginConfig`:
4
+ * - Flattens `tools` / `prompts` / `resources` / per-collection / per-global
5
+ * tool maps into a single `items` array.
6
+ * - Applies built-in tools for collections and globals, respecting opt-out user overrides.
7
+ * - Applies the `userCollection` default
8
+ *
9
+ * Called once during plugin init. After that, `plugins['@payloadcms/plugin-mcp']
10
+ * ?.options` holds the sanitized result
11
+ */ export const sanitizeMCPConfig = ({ config, pluginConfig })=>{
12
+ const items = [];
13
+ for (const collection of config.collections ?? []){
14
+ items.push(...sanitizeCollectionConfig({
15
+ collection,
16
+ pluginConfig
17
+ }));
18
+ }
19
+ for (const global of config.globals ?? []){
20
+ items.push(...sanitizeGlobalConfig({
21
+ global,
22
+ pluginConfig
23
+ }));
24
+ }
25
+ for (const [configKey, { label, mcpName, tool }] of TOOL_BUILTIN_ENTRIES){
26
+ items.push({
27
+ type: 'tool',
28
+ configKey,
29
+ label,
30
+ mcpName,
31
+ tool
32
+ });
33
+ }
34
+ for (const [configKey, tool] of Object.entries(pluginConfig.tools ?? {})){
35
+ if (configKey in TOOL_BUILTINS) {
36
+ continue;
37
+ }
38
+ items.push({
39
+ type: 'tool',
40
+ configKey,
41
+ label: configKey,
42
+ mcpName: configKey,
43
+ tool
44
+ });
45
+ }
46
+ for (const [configKey, prompt] of Object.entries(pluginConfig.prompts ?? {})){
47
+ items.push({
48
+ type: 'prompt',
49
+ configKey,
50
+ label: prompt.title ?? configKey,
51
+ mcpName: configKey,
52
+ prompt
53
+ });
54
+ }
55
+ for (const [configKey, resource] of Object.entries(pluginConfig.resources ?? {})){
56
+ items.push({
57
+ type: 'resource',
58
+ configKey,
59
+ label: resource.title ?? configKey,
60
+ mcpName: configKey,
61
+ resource
62
+ });
63
+ }
64
+ // Mirror Payload's own admin.user detection (sanitize.ts) since plugins run first.
65
+ const firstCollectionWithAuth = config.collections.find(({ auth })=>Boolean(auth));
66
+ return {
67
+ disabled: pluginConfig.disabled,
68
+ items,
69
+ mcp: pluginConfig.mcp,
70
+ overrideApiKeyCollection: pluginConfig.overrideApiKeyCollection,
71
+ overrideAuth: pluginConfig.overrideAuth,
72
+ userCollection: pluginConfig.userCollection ?? config.admin?.user ?? firstCollectionWithAuth?.slug ?? 'users'
73
+ };
74
+ };
75
+ const sanitizeCollectionConfig = ({ collection, pluginConfig })=>{
76
+ if (collection.slug === 'payload-mcp-api-keys') {
77
+ return [];
78
+ }
79
+ const slug = collection.slug;
80
+ const collectionPluginConfig = pluginConfig.collections?.[slug];
81
+ const items = [];
82
+ for (const [toolKey, { mcpName, tool }] of COLLECTION_BUILTIN_ENTRIES){
83
+ const matchedConfigEntry = collectionPluginConfig?.tools?.[toolKey];
84
+ if (matchedConfigEntry === false) {
85
+ continue;
86
+ }
87
+ const override = typeof matchedConfigEntry === 'object' ? matchedConfigEntry : undefined;
88
+ items.push({
89
+ type: 'collectionTool',
90
+ collectionSlug: slug,
91
+ configKey: toolKey,
92
+ label: capitalize(toolKey),
93
+ mcpName,
94
+ tool: {
95
+ ...tool,
96
+ description: override?.description ?? tool.description,
97
+ overrideResponse: override?.overrideResponse ?? collectionPluginConfig?.overrideResponse ?? tool.overrideResponse
98
+ }
99
+ });
100
+ }
101
+ if (collection.auth) {
102
+ for (const [authToolKey, { label, mcpName, tool }] of COLLECTION_AUTH_BUILTIN_ENTRIES){
103
+ const matchedConfigEntry = collectionPluginConfig?.tools?.[authToolKey];
104
+ if (!matchedConfigEntry) {
105
+ continue;
106
+ }
107
+ // `true` means "enable, no override"; only the object form carries fields.
108
+ const override = typeof matchedConfigEntry === 'object' ? matchedConfigEntry : undefined;
109
+ items.push({
110
+ type: 'collectionTool',
111
+ collectionSlug: slug,
112
+ configKey: authToolKey,
113
+ label,
114
+ mcpName,
115
+ tool: {
116
+ ...tool,
117
+ description: override?.description ?? tool.description,
118
+ overrideResponse: override?.overrideResponse ?? collectionPluginConfig?.overrideResponse ?? tool.overrideResponse
119
+ }
120
+ });
121
+ }
122
+ }
123
+ // Cast: builtin keys are filtered out below, so the remaining values are
124
+ // always custom tools (`CollectionTool`) or undefined
125
+ const customEntries = Object.entries(collectionPluginConfig?.tools ?? {});
126
+ for (const [configKey, customTool] of customEntries){
127
+ if (configKey in COLLECTION_BUILTINS || configKey in COLLECTION_AUTH_BUILTINS) {
128
+ continue;
129
+ }
130
+ if (!customTool) {
131
+ continue;
132
+ }
133
+ items.push({
134
+ type: 'collectionTool',
135
+ collectionSlug: slug,
136
+ configKey,
137
+ label: configKey,
138
+ mcpName: configKey,
139
+ tool: customTool
140
+ });
141
+ }
142
+ return items;
143
+ };
144
+ const sanitizeGlobalConfig = ({ global, pluginConfig })=>{
145
+ const slug = global.slug;
146
+ const globalPluginConfig = pluginConfig.globals?.[slug];
147
+ const items = [];
148
+ for (const [toolKey, { mcpName, tool }] of GLOBAL_BUILTIN_ENTRIES){
149
+ const matchedConfigEntry = globalPluginConfig?.tools?.[toolKey];
150
+ if (matchedConfigEntry === false) {
151
+ continue;
152
+ }
153
+ const override = typeof matchedConfigEntry === 'object' ? matchedConfigEntry : undefined;
154
+ items.push({
155
+ type: 'globalTool',
156
+ configKey: toolKey,
157
+ globalSlug: slug,
158
+ label: capitalize(toolKey),
159
+ mcpName,
160
+ tool: {
161
+ ...tool,
162
+ description: override?.description ?? tool.description,
163
+ overrideResponse: override?.overrideResponse ?? globalPluginConfig?.overrideResponse ?? tool.overrideResponse
164
+ }
165
+ });
166
+ }
167
+ const customEntries = Object.entries(globalPluginConfig?.tools ?? {});
168
+ for (const [configKey, customTool] of customEntries){
169
+ if (configKey in GLOBAL_BUILTINS) {
170
+ continue;
171
+ }
172
+ if (!customTool) {
173
+ continue;
174
+ }
175
+ items.push({
176
+ type: 'globalTool',
177
+ configKey,
178
+ globalSlug: slug,
179
+ label: configKey,
180
+ mcpName: configKey,
181
+ tool: customTool
182
+ });
183
+ }
184
+ return items;
185
+ };
186
+ const capitalize = (s)=>s.charAt(0).toUpperCase() + s.slice(1);
187
+
188
+ //# sourceMappingURL=sanitizeMCPConfig.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/mcp/sanitizeMCPConfig.ts"],"sourcesContent":["import type {\n CollectionConfig,\n Config,\n GlobalConfig,\n SanitizedCollectionConfig,\n SanitizedConfig,\n SanitizedGlobalConfig,\n} from 'payload'\n\nimport type {\n CollectionMCPItem,\n CollectionTool,\n GlobalMCPItem,\n GlobalTool,\n MCPItem,\n MCPPluginConfig,\n SanitizedMCPPluginConfig,\n} from '../types.js'\n\nimport {\n COLLECTION_AUTH_BUILTIN_ENTRIES,\n COLLECTION_AUTH_BUILTINS,\n COLLECTION_BUILTIN_ENTRIES,\n COLLECTION_BUILTINS,\n GLOBAL_BUILTIN_ENTRIES,\n GLOBAL_BUILTINS,\n TOOL_BUILTIN_ENTRIES,\n TOOL_BUILTINS,\n} from './builtinTools.js'\n\n/**\n * Converts the user-configured `MCPPluginConfig` into a `SanitizedMCPPluginConfig`:\n * - Flattens `tools` / `prompts` / `resources` / per-collection / per-global\n * tool maps into a single `items` array.\n * - Applies built-in tools for collections and globals, respecting opt-out user overrides.\n * - Applies the `userCollection` default\n *\n * Called once during plugin init. After that, `plugins['@payloadcms/plugin-mcp']\n * ?.options` holds the sanitized result\n */\nexport const sanitizeMCPConfig = ({\n config,\n pluginConfig,\n}: {\n config: Config | SanitizedConfig\n pluginConfig: MCPPluginConfig\n}): SanitizedMCPPluginConfig => {\n const items: MCPItem[] = []\n\n for (const collection of config.collections ?? []) {\n items.push(...sanitizeCollectionConfig({ collection, pluginConfig }))\n }\n\n for (const global of config.globals ?? []) {\n items.push(...sanitizeGlobalConfig({ global, pluginConfig }))\n }\n\n for (const [configKey, { label, mcpName, tool }] of TOOL_BUILTIN_ENTRIES) {\n items.push({\n type: 'tool',\n configKey,\n label,\n mcpName,\n tool,\n })\n }\n\n for (const [configKey, tool] of Object.entries(pluginConfig.tools ?? {})) {\n if (configKey in TOOL_BUILTINS) {\n continue\n }\n items.push({\n type: 'tool',\n configKey,\n label: configKey,\n mcpName: configKey,\n tool,\n })\n }\n\n for (const [configKey, prompt] of Object.entries(pluginConfig.prompts ?? {})) {\n items.push({\n type: 'prompt',\n configKey,\n label: prompt.title ?? configKey,\n mcpName: configKey,\n prompt,\n })\n }\n\n for (const [configKey, resource] of Object.entries(pluginConfig.resources ?? {})) {\n items.push({\n type: 'resource',\n configKey,\n label: resource.title ?? configKey,\n mcpName: configKey,\n resource,\n })\n }\n\n // Mirror Payload's own admin.user detection (sanitize.ts) since plugins run first.\n const firstCollectionWithAuth = config.collections!.find(({ auth }) => Boolean(auth))\n\n return {\n disabled: pluginConfig.disabled,\n items,\n mcp: pluginConfig.mcp,\n overrideApiKeyCollection: pluginConfig.overrideApiKeyCollection,\n overrideAuth: pluginConfig.overrideAuth,\n userCollection:\n pluginConfig.userCollection ?? config.admin?.user ?? firstCollectionWithAuth?.slug ?? 'users',\n }\n}\n\nconst sanitizeCollectionConfig = ({\n collection,\n pluginConfig,\n}: {\n collection: CollectionConfig | SanitizedCollectionConfig\n pluginConfig: MCPPluginConfig\n}): CollectionMCPItem[] => {\n if (collection.slug === 'payload-mcp-api-keys') {\n return []\n }\n const slug = collection.slug\n const collectionPluginConfig = pluginConfig.collections?.[slug]\n const items: CollectionMCPItem[] = []\n\n for (const [toolKey, { mcpName, tool }] of COLLECTION_BUILTIN_ENTRIES) {\n const matchedConfigEntry = collectionPluginConfig?.tools?.[toolKey]\n if (matchedConfigEntry === false) {\n continue\n }\n const override = typeof matchedConfigEntry === 'object' ? matchedConfigEntry : undefined\n items.push({\n type: 'collectionTool',\n collectionSlug: slug,\n configKey: toolKey,\n label: capitalize(toolKey),\n mcpName,\n tool: {\n ...tool,\n description: override?.description ?? tool.description,\n overrideResponse:\n override?.overrideResponse ??\n collectionPluginConfig?.overrideResponse ??\n tool.overrideResponse,\n },\n })\n }\n\n if (collection.auth) {\n for (const [authToolKey, { label, mcpName, tool }] of COLLECTION_AUTH_BUILTIN_ENTRIES) {\n const matchedConfigEntry = collectionPluginConfig?.tools?.[authToolKey]\n if (!matchedConfigEntry) {\n continue\n }\n // `true` means \"enable, no override\"; only the object form carries fields.\n const override = typeof matchedConfigEntry === 'object' ? matchedConfigEntry : undefined\n items.push({\n type: 'collectionTool',\n collectionSlug: slug,\n configKey: authToolKey,\n label,\n mcpName,\n tool: {\n ...tool,\n description: override?.description ?? tool.description,\n overrideResponse:\n override?.overrideResponse ??\n collectionPluginConfig?.overrideResponse ??\n tool.overrideResponse,\n },\n })\n }\n }\n\n // Cast: builtin keys are filtered out below, so the remaining values are\n // always custom tools (`CollectionTool`) or undefined\n const customEntries = Object.entries(collectionPluginConfig?.tools ?? {}) as Array<\n [string, CollectionTool | undefined]\n >\n for (const [configKey, customTool] of customEntries) {\n if (configKey in COLLECTION_BUILTINS || configKey in COLLECTION_AUTH_BUILTINS) {\n continue\n }\n if (!customTool) {\n continue\n }\n items.push({\n type: 'collectionTool',\n collectionSlug: slug,\n configKey,\n label: configKey,\n mcpName: configKey,\n tool: customTool,\n })\n }\n\n return items\n}\n\nconst sanitizeGlobalConfig = ({\n global,\n pluginConfig,\n}: {\n global: GlobalConfig | SanitizedGlobalConfig\n pluginConfig: MCPPluginConfig\n}): GlobalMCPItem[] => {\n const slug = global.slug\n const globalPluginConfig = pluginConfig.globals?.[slug]\n const items: GlobalMCPItem[] = []\n\n for (const [toolKey, { mcpName, tool }] of GLOBAL_BUILTIN_ENTRIES) {\n const matchedConfigEntry = globalPluginConfig?.tools?.[toolKey]\n if (matchedConfigEntry === false) {\n continue\n }\n const override = typeof matchedConfigEntry === 'object' ? matchedConfigEntry : undefined\n items.push({\n type: 'globalTool',\n configKey: toolKey,\n globalSlug: slug,\n label: capitalize(toolKey),\n mcpName,\n tool: {\n ...tool,\n description: override?.description ?? tool.description,\n overrideResponse:\n override?.overrideResponse ??\n globalPluginConfig?.overrideResponse ??\n tool.overrideResponse,\n },\n })\n }\n\n const customEntries = Object.entries(globalPluginConfig?.tools ?? {}) as Array<\n [string, GlobalTool | undefined]\n >\n for (const [configKey, customTool] of customEntries) {\n if (configKey in GLOBAL_BUILTINS) {\n continue\n }\n if (!customTool) {\n continue\n }\n items.push({\n type: 'globalTool',\n configKey,\n globalSlug: slug,\n label: configKey,\n mcpName: configKey,\n tool: customTool,\n })\n }\n\n return items\n}\n\nconst capitalize = (s: string): string => s.charAt(0).toUpperCase() + s.slice(1)\n"],"names":["COLLECTION_AUTH_BUILTIN_ENTRIES","COLLECTION_AUTH_BUILTINS","COLLECTION_BUILTIN_ENTRIES","COLLECTION_BUILTINS","GLOBAL_BUILTIN_ENTRIES","GLOBAL_BUILTINS","TOOL_BUILTIN_ENTRIES","TOOL_BUILTINS","sanitizeMCPConfig","config","pluginConfig","items","collection","collections","push","sanitizeCollectionConfig","global","globals","sanitizeGlobalConfig","configKey","label","mcpName","tool","type","Object","entries","tools","prompt","prompts","title","resource","resources","firstCollectionWithAuth","find","auth","Boolean","disabled","mcp","overrideApiKeyCollection","overrideAuth","userCollection","admin","user","slug","collectionPluginConfig","toolKey","matchedConfigEntry","override","undefined","collectionSlug","capitalize","description","overrideResponse","authToolKey","customEntries","customTool","globalPluginConfig","globalSlug","s","charAt","toUpperCase","slice"],"mappings":"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"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Stdio adapter for the Payload MCP server.
3
+ *
4
+ * Do not use in production. There's no auth; whoever can spawn the process gets
5
+ * full access to your local data.
6
+ */
7
+ export declare const runMcpStdio: () => Promise<void>;
8
+ //# sourceMappingURL=stdio.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stdio.d.ts","sourceRoot":"","sources":["../src/stdio.ts"],"names":[],"mappings":"AAeA;;;;;GAKG;AACH,eAAO,MAAM,WAAW,QAAa,OAAO,CAAC,IAAI,CA4EhD,CAAA"}
package/dist/stdio.js ADDED
@@ -0,0 +1,89 @@
1
+ /* eslint-disable no-console */ import { StdioServerTransport } from '@modelcontextprotocol/server';
2
+ import { fileURLToPath, pathToFileURL } from 'node:url';
3
+ import { createLocalReq, getPayload } from 'payload';
4
+ import { findConfig } from 'payload/node';
5
+ import { buildMcpServer } from './mcp/buildMcpServer.js';
6
+ import { sanitizeMCPConfig } from './mcp/sanitizeMCPConfig.js';
7
+ import { getPluginConfig } from './utils/getPluginConfig.js';
8
+ import { resolveProjectRoot } from './utils/resolveProjectRoot.js';
9
+ /**
10
+ * Stdio adapter for the Payload MCP server.
11
+ *
12
+ * Do not use in production. There's no auth; whoever can spawn the process gets
13
+ * full access to your local data.
14
+ */ export const runMcpStdio = async ()=>{
15
+ /**
16
+ * If MCP clients spawn stdio servers from an arbitrary working directory,
17
+ * Payload's cwd-anchored `findConfig()` can't locate the project on
18
+ * its own. This module always lives inside the project's `node_modules`, so
19
+ * we derive the project root from its own path and `chdir` into it.
20
+ *
21
+ * An absolute `PAYLOAD_CONFIG_PATH` still overrides everything; unusual
22
+ * layouts (e.g. a monorepo where the package is hoisted above the app) can
23
+ * fall back to it. See the implementation of findConfig for details.
24
+ */ const projectRoot = resolveProjectRoot(fileURLToPath(import.meta.url));
25
+ if (projectRoot) {
26
+ process.chdir(projectRoot);
27
+ }
28
+ const configPath = findConfig();
29
+ const configModule = await import(pathToFileURL(configPath).toString());
30
+ const config = await (configModule.default ?? configModule);
31
+ const payload = await getPayload({
32
+ config
33
+ });
34
+ /**
35
+ * If the user added `mcpPlugin({...})` to their `plugins` array, read the
36
+ * sanitized config they registered. Otherwise fall back to the defaults. That way,
37
+ * the mcp works on any project that has `@payloadcms/plugin-mcp` installed,
38
+ * even if the plugin is not added to the plugins array.
39
+ */ let pluginConfig;
40
+ try {
41
+ pluginConfig = getPluginConfig({
42
+ config: payload.config
43
+ });
44
+ } catch {
45
+ pluginConfig = sanitizeMCPConfig({
46
+ config: payload.config,
47
+ pluginConfig: {}
48
+ });
49
+ const fakePluginFn = (config)=>config;
50
+ fakePluginFn.slug = '@payloadcms/plugin-mcp';
51
+ // @ts-expect-error
52
+ fakePluginFn.sanitizedOptions = pluginConfig;
53
+ (payload.config.plugins ??= []).push(fakePluginFn);
54
+ }
55
+ const authorizedMCP = {
56
+ items: pluginConfig.items,
57
+ overrideAccess: true,
58
+ user: null
59
+ };
60
+ const req = await createLocalReq({}, payload);
61
+ req.payloadAPI = 'MCP';
62
+ const server = buildMcpServer({
63
+ authorizedMCP,
64
+ pluginConfig,
65
+ req
66
+ });
67
+ const transport = new StdioServerTransport();
68
+ await server.connect(transport);
69
+ // Process now lives until stdin closes. Wire graceful shutdown so DB
70
+ // connections (and any other Payload-managed resources) get released.
71
+ const shutdown = async (code = 0)=>{
72
+ try {
73
+ await server.close();
74
+ } catch (err) {
75
+ console.error('[payload-mcp] error closing server:', err);
76
+ }
77
+ try {
78
+ await payload.destroy();
79
+ } catch (err) {
80
+ console.error('[payload-mcp] error destroying payload:', err);
81
+ }
82
+ process.exit(code);
83
+ };
84
+ process.on('SIGINT', ()=>void shutdown(0));
85
+ process.on('SIGTERM', ()=>void shutdown(0));
86
+ process.stdin.on('close', ()=>void shutdown(0));
87
+ };
88
+
89
+ //# sourceMappingURL=stdio.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/stdio.ts"],"sourcesContent":["import type { MaybePromise, Plugin, SanitizedConfig } from 'payload'\n\n/* eslint-disable no-console */\nimport { StdioServerTransport } from '@modelcontextprotocol/server'\nimport { fileURLToPath, pathToFileURL } from 'node:url'\nimport { createLocalReq, getPayload } from 'payload'\nimport { findConfig } from 'payload/node'\n\nimport type { AuthorizedMCP, SanitizedMCPPluginConfig } from './types.js'\n\nimport { buildMcpServer } from './mcp/buildMcpServer.js'\nimport { sanitizeMCPConfig } from './mcp/sanitizeMCPConfig.js'\nimport { getPluginConfig } from './utils/getPluginConfig.js'\nimport { resolveProjectRoot } from './utils/resolveProjectRoot.js'\n\n/**\n * Stdio adapter for the Payload MCP server.\n *\n * Do not use in production. There's no auth; whoever can spawn the process gets\n * full access to your local data.\n */\nexport const runMcpStdio = async (): Promise<void> => {\n /**\n * If MCP clients spawn stdio servers from an arbitrary working directory,\n * Payload's cwd-anchored `findConfig()` can't locate the project on\n * its own. This module always lives inside the project's `node_modules`, so\n * we derive the project root from its own path and `chdir` into it.\n *\n * An absolute `PAYLOAD_CONFIG_PATH` still overrides everything; unusual\n * layouts (e.g. a monorepo where the package is hoisted above the app) can\n * fall back to it. See the implementation of findConfig for details.\n */\n const projectRoot = resolveProjectRoot(fileURLToPath(import.meta.url))\n if (projectRoot) {\n process.chdir(projectRoot)\n }\n\n const configPath = findConfig()\n const configModule = await import(pathToFileURL(configPath).toString())\n const config = (await (configModule.default ?? configModule)) as MaybePromise<SanitizedConfig>\n\n const payload = await getPayload({ config })\n\n /**\n * If the user added `mcpPlugin({...})` to their `plugins` array, read the\n * sanitized config they registered. Otherwise fall back to the defaults. That way,\n * the mcp works on any project that has `@payloadcms/plugin-mcp` installed,\n * even if the plugin is not added to the plugins array.\n */\n let pluginConfig: SanitizedMCPPluginConfig\n try {\n pluginConfig = getPluginConfig({ config: payload.config })\n } catch {\n pluginConfig = sanitizeMCPConfig({ config: payload.config, pluginConfig: {} })\n\n const fakePluginFn: Plugin = (config) => config\n fakePluginFn.slug = '@payloadcms/plugin-mcp'\n // @ts-expect-error\n fakePluginFn.sanitizedOptions = pluginConfig\n\n // Push to payload config, to ensure consecutive calls to `getPluginConfig()` work\n ;(payload.config.plugins ??= []).push(fakePluginFn)\n }\n\n const authorizedMCP: AuthorizedMCP = {\n items: pluginConfig.items,\n overrideAccess: true,\n user: null,\n }\n\n const req = await createLocalReq({}, payload)\n req.payloadAPI = 'MCP' as const\n\n const server = buildMcpServer({ authorizedMCP, pluginConfig, req })\n\n const transport = new StdioServerTransport()\n await server.connect(transport)\n\n // Process now lives until stdin closes. Wire graceful shutdown so DB\n // connections (and any other Payload-managed resources) get released.\n const shutdown = async (code = 0) => {\n try {\n await server.close()\n } catch (err) {\n console.error('[payload-mcp] error closing server:', err)\n }\n try {\n await payload.destroy()\n } catch (err) {\n console.error('[payload-mcp] error destroying payload:', err)\n }\n process.exit(code)\n }\n\n process.on('SIGINT', () => void shutdown(0))\n process.on('SIGTERM', () => void shutdown(0))\n process.stdin.on('close', () => void shutdown(0))\n}\n"],"names":["StdioServerTransport","fileURLToPath","pathToFileURL","createLocalReq","getPayload","findConfig","buildMcpServer","sanitizeMCPConfig","getPluginConfig","resolveProjectRoot","runMcpStdio","projectRoot","url","process","chdir","configPath","configModule","toString","config","default","payload","pluginConfig","fakePluginFn","slug","sanitizedOptions","plugins","push","authorizedMCP","items","overrideAccess","user","req","payloadAPI","server","transport","connect","shutdown","code","close","err","console","error","destroy","exit","on","stdin"],"mappings":"AAEA,6BAA6B,GAC7B,SAASA,oBAAoB,QAAQ,+BAA8B;AACnE,SAASC,aAAa,EAAEC,aAAa,QAAQ,WAAU;AACvD,SAASC,cAAc,EAAEC,UAAU,QAAQ,UAAS;AACpD,SAASC,UAAU,QAAQ,eAAc;AAIzC,SAASC,cAAc,QAAQ,0BAAyB;AACxD,SAASC,iBAAiB,QAAQ,6BAA4B;AAC9D,SAASC,eAAe,QAAQ,6BAA4B;AAC5D,SAASC,kBAAkB,QAAQ,gCAA+B;AAElE;;;;;CAKC,GACD,OAAO,MAAMC,cAAc;IACzB;;;;;;;;;GASC,GACD,MAAMC,cAAcF,mBAAmBR,cAAc,YAAYW,GAAG;IACpE,IAAID,aAAa;QACfE,QAAQC,KAAK,CAACH;IAChB;IAEA,MAAMI,aAAaV;IACnB,MAAMW,eAAe,MAAM,MAAM,CAACd,cAAca,YAAYE,QAAQ;IACpE,MAAMC,SAAU,MAAOF,CAAAA,aAAaG,OAAO,IAAIH,YAAW;IAE1D,MAAMI,UAAU,MAAMhB,WAAW;QAAEc;IAAO;IAE1C;;;;;GAKC,GACD,IAAIG;IACJ,IAAI;QACFA,eAAeb,gBAAgB;YAAEU,QAAQE,QAAQF,MAAM;QAAC;IAC1D,EAAE,OAAM;QACNG,eAAed,kBAAkB;YAAEW,QAAQE,QAAQF,MAAM;YAAEG,cAAc,CAAC;QAAE;QAE5E,MAAMC,eAAuB,CAACJ,SAAWA;QACzCI,aAAaC,IAAI,GAAG;QACpB,mBAAmB;QACnBD,aAAaE,gBAAgB,GAAGH;QAG9BD,CAAAA,QAAQF,MAAM,CAACO,OAAO,KAAK,EAAE,AAAD,EAAGC,IAAI,CAACJ;IACxC;IAEA,MAAMK,gBAA+B;QACnCC,OAAOP,aAAaO,KAAK;QACzBC,gBAAgB;QAChBC,MAAM;IACR;IAEA,MAAMC,MAAM,MAAM5B,eAAe,CAAC,GAAGiB;IACrCW,IAAIC,UAAU,GAAG;IAEjB,MAAMC,SAAS3B,eAAe;QAAEqB;QAAeN;QAAcU;IAAI;IAEjE,MAAMG,YAAY,IAAIlC;IACtB,MAAMiC,OAAOE,OAAO,CAACD;IAErB,qEAAqE;IACrE,sEAAsE;IACtE,MAAME,WAAW,OAAOC,OAAO,CAAC;QAC9B,IAAI;YACF,MAAMJ,OAAOK,KAAK;QACpB,EAAE,OAAOC,KAAK;YACZC,QAAQC,KAAK,CAAC,uCAAuCF;QACvD;QACA,IAAI;YACF,MAAMnB,QAAQsB,OAAO;QACvB,EAAE,OAAOH,KAAK;YACZC,QAAQC,KAAK,CAAC,2CAA2CF;QAC3D;QACA1B,QAAQ8B,IAAI,CAACN;IACf;IAEAxB,QAAQ+B,EAAE,CAAC,UAAU,IAAM,KAAKR,SAAS;IACzCvB,QAAQ+B,EAAE,CAAC,WAAW,IAAM,KAAKR,SAAS;IAC1CvB,QAAQgC,KAAK,CAACD,EAAE,CAAC,SAAS,IAAM,KAAKR,SAAS;AAChD,EAAC"}