@payloadcms/plugin-mcp 4.0.0-internal.e16cf59 → 4.0.0-internal.e38d3ac

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 (429) hide show
  1. package/LICENSE.md +1 -1
  2. package/bin.js +46 -0
  3. package/dist/defaultAccess.d.ts +3 -0
  4. package/dist/defaultAccess.d.ts.map +1 -0
  5. package/dist/defaultAccess.js +3 -0
  6. package/dist/defaultAccess.js.map +1 -0
  7. package/dist/defineTool.d.ts +26 -0
  8. package/dist/defineTool.d.ts.map +1 -0
  9. package/dist/defineTool.js +37 -0
  10. package/dist/defineTool.js.map +1 -0
  11. package/dist/endpoint/access.d.ts +17 -0
  12. package/dist/endpoint/access.d.ts.map +1 -0
  13. package/dist/endpoint/access.js +93 -0
  14. package/dist/endpoint/access.js.map +1 -0
  15. package/dist/endpoint/index.d.ts +3 -0
  16. package/dist/endpoint/index.d.ts.map +1 -0
  17. package/dist/endpoint/index.js +87 -0
  18. package/dist/endpoint/index.js.map +1 -0
  19. package/dist/exports/client.d.ts +2 -0
  20. package/dist/exports/client.d.ts.map +1 -0
  21. package/dist/exports/client.js +4 -0
  22. package/dist/exports/client.js.map +1 -0
  23. package/dist/exports/internal.d.ts +2 -0
  24. package/dist/exports/internal.d.ts.map +1 -0
  25. package/dist/exports/internal.js +3 -0
  26. package/dist/exports/internal.js.map +1 -0
  27. package/dist/index.d.ts +6 -9
  28. package/dist/index.d.ts.map +1 -1
  29. package/dist/index.js +39 -67
  30. package/dist/index.js.map +1 -1
  31. package/dist/mcp/buildMcpServer.d.ts +19 -0
  32. package/dist/mcp/buildMcpServer.d.ts.map +1 -0
  33. package/dist/mcp/buildMcpServer.js +223 -0
  34. package/dist/mcp/buildMcpServer.js.map +1 -0
  35. package/dist/mcp/builtin/collections/authTools.d.ts +7 -0
  36. package/dist/mcp/builtin/collections/authTools.d.ts.map +1 -0
  37. package/dist/mcp/builtin/collections/authTools.js +288 -0
  38. package/dist/mcp/builtin/collections/authTools.js.map +1 -0
  39. package/dist/mcp/builtin/collections/countTool.d.ts +2 -0
  40. package/dist/mcp/builtin/collections/countTool.d.ts.map +1 -0
  41. package/dist/mcp/builtin/collections/countTool.js +68 -0
  42. package/dist/mcp/builtin/collections/countTool.js.map +1 -0
  43. package/dist/mcp/builtin/collections/countVersionsTool.d.ts +2 -0
  44. package/dist/mcp/builtin/collections/countVersionsTool.d.ts.map +1 -0
  45. package/dist/mcp/builtin/collections/countVersionsTool.js +64 -0
  46. package/dist/mcp/builtin/collections/countVersionsTool.js.map +1 -0
  47. package/dist/mcp/builtin/collections/createTool.d.ts +2 -0
  48. package/dist/mcp/builtin/collections/createTool.d.ts.map +1 -0
  49. package/dist/mcp/builtin/collections/createTool.js +138 -0
  50. package/dist/mcp/builtin/collections/createTool.js.map +1 -0
  51. package/dist/mcp/builtin/collections/deleteTool.d.ts +2 -0
  52. package/dist/mcp/builtin/collections/deleteTool.d.ts.map +1 -0
  53. package/dist/mcp/builtin/collections/deleteTool.js +110 -0
  54. package/dist/mcp/builtin/collections/deleteTool.js.map +1 -0
  55. package/dist/mcp/builtin/collections/duplicateTool.d.ts +2 -0
  56. package/dist/mcp/builtin/collections/duplicateTool.d.ts.map +1 -0
  57. package/dist/mcp/builtin/collections/duplicateTool.js +96 -0
  58. package/dist/mcp/builtin/collections/duplicateTool.js.map +1 -0
  59. package/dist/mcp/builtin/collections/fileInput.d.ts +28 -0
  60. package/dist/mcp/builtin/collections/fileInput.d.ts.map +1 -0
  61. package/dist/mcp/builtin/collections/fileInput.js +124 -0
  62. package/dist/mcp/builtin/collections/fileInput.js.map +1 -0
  63. package/dist/mcp/builtin/collections/fileInput.spec.js +86 -0
  64. package/dist/mcp/builtin/collections/fileInput.spec.js.map +1 -0
  65. package/dist/mcp/builtin/collections/findDistinctTool.d.ts +2 -0
  66. package/dist/mcp/builtin/collections/findDistinctTool.d.ts.map +1 -0
  67. package/dist/mcp/builtin/collections/findDistinctTool.js +92 -0
  68. package/dist/mcp/builtin/collections/findDistinctTool.js.map +1 -0
  69. package/dist/mcp/builtin/collections/findTool.d.ts +2 -0
  70. package/dist/mcp/builtin/collections/findTool.d.ts.map +1 -0
  71. package/dist/mcp/builtin/collections/findTool.js +164 -0
  72. package/dist/mcp/builtin/collections/findTool.js.map +1 -0
  73. package/dist/mcp/builtin/collections/findVersionByIDTool.d.ts +2 -0
  74. package/dist/mcp/builtin/collections/findVersionByIDTool.d.ts.map +1 -0
  75. package/dist/mcp/builtin/collections/findVersionByIDTool.js +83 -0
  76. package/dist/mcp/builtin/collections/findVersionByIDTool.js.map +1 -0
  77. package/dist/mcp/builtin/collections/findVersionsTool.d.ts +2 -0
  78. package/dist/mcp/builtin/collections/findVersionsTool.d.ts.map +1 -0
  79. package/dist/mcp/builtin/collections/findVersionsTool.js +98 -0
  80. package/dist/mcp/builtin/collections/findVersionsTool.js.map +1 -0
  81. package/dist/mcp/builtin/collections/formatCollectionError.d.ts +9 -0
  82. package/dist/mcp/builtin/collections/formatCollectionError.d.ts.map +1 -0
  83. package/dist/mcp/builtin/collections/formatCollectionError.js +60 -0
  84. package/dist/mcp/builtin/collections/formatCollectionError.js.map +1 -0
  85. package/dist/mcp/builtin/collections/getCollectionSchemaTool.d.ts +2 -0
  86. package/dist/mcp/builtin/collections/getCollectionSchemaTool.d.ts.map +1 -0
  87. package/dist/mcp/builtin/collections/getCollectionSchemaTool.js +87 -0
  88. package/dist/mcp/builtin/collections/getCollectionSchemaTool.js.map +1 -0
  89. package/dist/mcp/builtin/collections/restoreVersionTool.d.ts +2 -0
  90. package/dist/mcp/builtin/collections/restoreVersionTool.d.ts.map +1 -0
  91. package/dist/mcp/builtin/collections/restoreVersionTool.js +81 -0
  92. package/dist/mcp/builtin/collections/restoreVersionTool.js.map +1 -0
  93. package/dist/mcp/builtin/collections/updateTool.d.ts +2 -0
  94. package/dist/mcp/builtin/collections/updateTool.d.ts.map +1 -0
  95. package/dist/mcp/builtin/collections/updateTool.js +204 -0
  96. package/dist/mcp/builtin/collections/updateTool.js.map +1 -0
  97. package/dist/mcp/builtin/collections/uploadInstructionsTool.d.ts +2 -0
  98. package/dist/mcp/builtin/collections/uploadInstructionsTool.d.ts.map +1 -0
  99. package/dist/mcp/builtin/collections/uploadInstructionsTool.js +55 -0
  100. package/dist/mcp/builtin/collections/uploadInstructionsTool.js.map +1 -0
  101. package/dist/mcp/builtin/getConfigInfoTool.d.ts +2 -0
  102. package/dist/mcp/builtin/getConfigInfoTool.d.ts.map +1 -0
  103. package/dist/mcp/builtin/getConfigInfoTool.js +68 -0
  104. package/dist/mcp/builtin/getConfigInfoTool.js.map +1 -0
  105. package/dist/mcp/builtin/globals/countVersionsTool.d.ts +2 -0
  106. package/dist/mcp/builtin/globals/countVersionsTool.d.ts.map +1 -0
  107. package/dist/mcp/builtin/globals/countVersionsTool.js +64 -0
  108. package/dist/mcp/builtin/globals/countVersionsTool.js.map +1 -0
  109. package/dist/mcp/builtin/globals/findTool.d.ts +2 -0
  110. package/dist/mcp/builtin/globals/findTool.d.ts.map +1 -0
  111. package/dist/mcp/builtin/globals/findTool.js +73 -0
  112. package/dist/mcp/builtin/globals/findTool.js.map +1 -0
  113. package/dist/mcp/builtin/globals/findVersionByIDTool.d.ts +2 -0
  114. package/dist/mcp/builtin/globals/findVersionByIDTool.d.ts.map +1 -0
  115. package/dist/mcp/builtin/globals/findVersionByIDTool.js +79 -0
  116. package/dist/mcp/builtin/globals/findVersionByIDTool.js.map +1 -0
  117. package/dist/mcp/builtin/globals/findVersionsTool.d.ts +2 -0
  118. package/dist/mcp/builtin/globals/findVersionsTool.d.ts.map +1 -0
  119. package/dist/mcp/builtin/globals/findVersionsTool.js +94 -0
  120. package/dist/mcp/builtin/globals/findVersionsTool.js.map +1 -0
  121. package/dist/mcp/builtin/globals/getGlobalSchemaTool.d.ts +2 -0
  122. package/dist/mcp/builtin/globals/getGlobalSchemaTool.d.ts.map +1 -0
  123. package/dist/mcp/builtin/globals/getGlobalSchemaTool.js +65 -0
  124. package/dist/mcp/builtin/globals/getGlobalSchemaTool.js.map +1 -0
  125. package/dist/mcp/builtin/globals/restoreVersionTool.d.ts +2 -0
  126. package/dist/mcp/builtin/globals/restoreVersionTool.d.ts.map +1 -0
  127. package/dist/mcp/builtin/globals/restoreVersionTool.js +77 -0
  128. package/dist/mcp/builtin/globals/restoreVersionTool.js.map +1 -0
  129. package/dist/mcp/builtin/globals/updateTool.d.ts +2 -0
  130. package/dist/mcp/builtin/globals/updateTool.d.ts.map +1 -0
  131. package/dist/mcp/builtin/globals/updateTool.js +87 -0
  132. package/dist/mcp/builtin/globals/updateTool.js.map +1 -0
  133. package/dist/mcp/builtin/validateEntityData.d.ts +14 -0
  134. package/dist/mcp/builtin/validateEntityData.d.ts.map +1 -0
  135. package/dist/mcp/builtin/validateEntityData.js +82 -0
  136. package/dist/mcp/builtin/validateEntityData.js.map +1 -0
  137. package/dist/mcp/builtinTools.d.ts +168 -0
  138. package/dist/mcp/builtinTools.d.ts.map +1 -0
  139. package/dist/mcp/builtinTools.js +169 -0
  140. package/dist/mcp/builtinTools.js.map +1 -0
  141. package/dist/mcp/sanitizeMCPConfig.d.ts +16 -0
  142. package/dist/mcp/sanitizeMCPConfig.d.ts.map +1 -0
  143. package/dist/mcp/sanitizeMCPConfig.js +233 -0
  144. package/dist/mcp/sanitizeMCPConfig.js.map +1 -0
  145. package/dist/stdio.d.ts +8 -0
  146. package/dist/stdio.d.ts.map +1 -0
  147. package/dist/stdio.js +127 -0
  148. package/dist/stdio.js.map +1 -0
  149. package/dist/types.d.ts +256 -447
  150. package/dist/types.d.ts.map +1 -1
  151. package/dist/types.js +4 -1
  152. package/dist/types.js.map +1 -1
  153. package/dist/utils/getLogger.d.ts +10 -0
  154. package/dist/utils/getLogger.d.ts.map +1 -0
  155. package/dist/utils/getLogger.js +22 -0
  156. package/dist/utils/getLogger.js.map +1 -0
  157. package/dist/utils/getPluginConfig.d.ts +12 -0
  158. package/dist/utils/getPluginConfig.d.ts.map +1 -0
  159. package/dist/utils/getPluginConfig.js +15 -0
  160. package/dist/utils/getPluginConfig.js.map +1 -0
  161. package/dist/utils/resolveProjectRoot.d.ts +7 -0
  162. package/dist/utils/resolveProjectRoot.d.ts.map +1 -0
  163. package/dist/utils/resolveProjectRoot.js +15 -0
  164. package/dist/utils/resolveProjectRoot.js.map +1 -0
  165. package/dist/utils/schemaConversion/filterFieldsByAccess.d.ts +28 -0
  166. package/dist/utils/schemaConversion/filterFieldsByAccess.d.ts.map +1 -0
  167. package/dist/utils/schemaConversion/filterFieldsByAccess.js +71 -0
  168. package/dist/utils/schemaConversion/filterFieldsByAccess.js.map +1 -0
  169. package/dist/utils/schemaConversion/getEntityInputSchema.d.ts +13 -0
  170. package/dist/utils/schemaConversion/getEntityInputSchema.d.ts.map +1 -0
  171. package/dist/utils/schemaConversion/getEntityInputSchema.js +66 -0
  172. package/dist/utils/schemaConversion/getEntityInputSchema.js.map +1 -0
  173. package/dist/utils/schemaConversion/sanitizeEntitySchema.d.ts +10 -0
  174. package/dist/utils/schemaConversion/sanitizeEntitySchema.d.ts.map +1 -0
  175. package/dist/utils/schemaConversion/sanitizeEntitySchema.js +384 -0
  176. package/dist/utils/schemaConversion/sanitizeEntitySchema.js.map +1 -0
  177. package/dist/utils/schemaConversion/sanitizeEntitySchema.spec.js +133 -0
  178. package/dist/utils/schemaConversion/sanitizeEntitySchema.spec.js.map +1 -0
  179. package/dist/utils/toStandardSchema.d.ts +5 -0
  180. package/dist/utils/toStandardSchema.d.ts.map +1 -0
  181. package/dist/utils/toStandardSchema.js +4 -0
  182. package/dist/utils/toStandardSchema.js.map +1 -0
  183. package/dist/utils/whereSchema.d.ts +9 -0
  184. package/dist/utils/whereSchema.d.ts.map +1 -0
  185. package/dist/utils/whereSchema.js +13 -0
  186. package/dist/utils/whereSchema.js.map +1 -0
  187. package/package.json +30 -10
  188. package/src/defaultAccess.ts +3 -0
  189. package/src/defineTool.ts +44 -0
  190. package/src/endpoint/access.ts +112 -0
  191. package/src/endpoint/index.ts +77 -0
  192. package/src/exports/client.ts +3 -0
  193. package/src/exports/internal.ts +1 -0
  194. package/src/index.ts +31 -89
  195. package/src/mcp/buildMcpServer.ts +284 -0
  196. package/src/mcp/builtin/collections/authTools.ts +269 -0
  197. package/src/mcp/builtin/collections/countTool.ts +73 -0
  198. package/src/mcp/builtin/collections/countVersionsTool.ts +69 -0
  199. package/src/mcp/builtin/collections/createTool.ts +168 -0
  200. package/src/mcp/builtin/collections/deleteTool.ts +125 -0
  201. package/src/mcp/builtin/collections/duplicateTool.ts +134 -0
  202. package/src/mcp/builtin/collections/fileInput.spec.ts +93 -0
  203. package/src/mcp/builtin/collections/fileInput.ts +164 -0
  204. package/src/mcp/builtin/collections/findDistinctTool.ts +119 -0
  205. package/src/mcp/builtin/collections/findTool.ts +216 -0
  206. package/src/mcp/builtin/collections/findVersionByIDTool.ts +109 -0
  207. package/src/mcp/builtin/collections/findVersionsTool.ts +154 -0
  208. package/src/mcp/builtin/collections/formatCollectionError.ts +84 -0
  209. package/src/mcp/builtin/collections/getCollectionSchemaTool.ts +80 -0
  210. package/src/mcp/builtin/collections/restoreVersionTool.ts +107 -0
  211. package/src/mcp/builtin/collections/updateTool.ts +227 -0
  212. package/src/mcp/builtin/collections/uploadInstructionsTool.ts +64 -0
  213. package/src/mcp/builtin/getConfigInfoTool.ts +67 -0
  214. package/src/mcp/builtin/globals/countVersionsTool.ts +68 -0
  215. package/src/mcp/builtin/globals/findTool.ts +105 -0
  216. package/src/mcp/builtin/globals/findVersionByIDTool.ts +103 -0
  217. package/src/mcp/builtin/globals/findVersionsTool.ts +147 -0
  218. package/src/mcp/builtin/globals/getGlobalSchemaTool.ts +63 -0
  219. package/src/mcp/builtin/globals/restoreVersionTool.ts +99 -0
  220. package/src/mcp/builtin/globals/updateTool.ts +115 -0
  221. package/src/mcp/builtin/validateEntityData.ts +132 -0
  222. package/src/mcp/builtinTools.ts +161 -0
  223. package/src/mcp/sanitizeMCPConfig.ts +281 -0
  224. package/src/stdio.ts +131 -0
  225. package/src/types.ts +304 -486
  226. package/src/utils/getLogger.ts +22 -0
  227. package/src/utils/getPluginConfig.ts +24 -0
  228. package/src/utils/resolveProjectRoot.ts +17 -0
  229. package/src/utils/schemaConversion/filterFieldsByAccess.ts +123 -0
  230. package/src/utils/schemaConversion/getEntityInputSchema.ts +96 -0
  231. package/src/utils/schemaConversion/sanitizeEntitySchema.spec.ts +96 -0
  232. package/src/utils/schemaConversion/sanitizeEntitySchema.ts +432 -0
  233. package/src/utils/toStandardSchema.ts +9 -0
  234. package/src/utils/whereSchema.ts +24 -0
  235. package/dist/collections/createApiKeysCollection.d.ts +0 -7
  236. package/dist/collections/createApiKeysCollection.d.ts.map +0 -1
  237. package/dist/collections/createApiKeysCollection.js +0 -317
  238. package/dist/collections/createApiKeysCollection.js.map +0 -1
  239. package/dist/defaults.d.ts +0 -4
  240. package/dist/defaults.d.ts.map +0 -1
  241. package/dist/defaults.js +0 -5
  242. package/dist/defaults.js.map +0 -1
  243. package/dist/endpoints/mcp.d.ts +0 -4
  244. package/dist/endpoints/mcp.d.ts.map +0 -1
  245. package/dist/endpoints/mcp.js +0 -71
  246. package/dist/endpoints/mcp.js.map +0 -1
  247. package/dist/mcp/createRequest.d.ts +0 -3
  248. package/dist/mcp/createRequest.d.ts.map +0 -1
  249. package/dist/mcp/createRequest.js +0 -14
  250. package/dist/mcp/createRequest.js.map +0 -1
  251. package/dist/mcp/getMcpHandler.d.ts +0 -4
  252. package/dist/mcp/getMcpHandler.d.ts.map +0 -1
  253. package/dist/mcp/getMcpHandler.js +0 -231
  254. package/dist/mcp/getMcpHandler.js.map +0 -1
  255. package/dist/mcp/helpers/config.d.ts +0 -22
  256. package/dist/mcp/helpers/config.d.ts.map +0 -1
  257. package/dist/mcp/helpers/config.js +0 -153
  258. package/dist/mcp/helpers/config.js.map +0 -1
  259. package/dist/mcp/helpers/fields.d.ts +0 -19
  260. package/dist/mcp/helpers/fields.d.ts.map +0 -1
  261. package/dist/mcp/helpers/fields.js +0 -102
  262. package/dist/mcp/helpers/fields.js.map +0 -1
  263. package/dist/mcp/helpers/fileValidation.d.ts +0 -67
  264. package/dist/mcp/helpers/fileValidation.d.ts.map +0 -1
  265. package/dist/mcp/helpers/fileValidation.js +0 -267
  266. package/dist/mcp/helpers/fileValidation.js.map +0 -1
  267. package/dist/mcp/registerTool.d.ts +0 -6
  268. package/dist/mcp/registerTool.d.ts.map +0 -1
  269. package/dist/mcp/registerTool.js +0 -18
  270. package/dist/mcp/registerTool.js.map +0 -1
  271. package/dist/mcp/tools/auth/auth.d.ts +0 -4
  272. package/dist/mcp/tools/auth/auth.d.ts.map +0 -1
  273. package/dist/mcp/tools/auth/auth.js +0 -57
  274. package/dist/mcp/tools/auth/auth.js.map +0 -1
  275. package/dist/mcp/tools/auth/forgotPassword.d.ts +0 -4
  276. package/dist/mcp/tools/auth/forgotPassword.d.ts.map +0 -1
  277. package/dist/mcp/tools/auth/forgotPassword.js +0 -48
  278. package/dist/mcp/tools/auth/forgotPassword.js.map +0 -1
  279. package/dist/mcp/tools/auth/login.d.ts +0 -4
  280. package/dist/mcp/tools/auth/login.d.ts.map +0 -1
  281. package/dist/mcp/tools/auth/login.js +0 -51
  282. package/dist/mcp/tools/auth/login.js.map +0 -1
  283. package/dist/mcp/tools/auth/resetPassword.d.ts +0 -4
  284. package/dist/mcp/tools/auth/resetPassword.d.ts.map +0 -1
  285. package/dist/mcp/tools/auth/resetPassword.js +0 -49
  286. package/dist/mcp/tools/auth/resetPassword.js.map +0 -1
  287. package/dist/mcp/tools/auth/unlock.d.ts +0 -4
  288. package/dist/mcp/tools/auth/unlock.d.ts.map +0 -1
  289. package/dist/mcp/tools/auth/unlock.js +0 -48
  290. package/dist/mcp/tools/auth/unlock.js.map +0 -1
  291. package/dist/mcp/tools/auth/verify.d.ts +0 -4
  292. package/dist/mcp/tools/auth/verify.d.ts.map +0 -1
  293. package/dist/mcp/tools/auth/verify.js +0 -45
  294. package/dist/mcp/tools/auth/verify.js.map +0 -1
  295. package/dist/mcp/tools/collection/create.d.ts +0 -10
  296. package/dist/mcp/tools/collection/create.d.ts.map +0 -1
  297. package/dist/mcp/tools/collection/create.js +0 -139
  298. package/dist/mcp/tools/collection/create.js.map +0 -1
  299. package/dist/mcp/tools/collection/delete.d.ts +0 -10
  300. package/dist/mcp/tools/collection/delete.d.ts.map +0 -1
  301. package/dist/mcp/tools/collection/delete.js +0 -154
  302. package/dist/mcp/tools/collection/delete.js.map +0 -1
  303. package/dist/mcp/tools/collection/find.d.ts +0 -10
  304. package/dist/mcp/tools/collection/find.d.ts.map +0 -1
  305. package/dist/mcp/tools/collection/find.js +0 -165
  306. package/dist/mcp/tools/collection/find.js.map +0 -1
  307. package/dist/mcp/tools/collection/update.d.ts +0 -10
  308. package/dist/mcp/tools/collection/update.d.ts.map +0 -1
  309. package/dist/mcp/tools/collection/update.js +0 -209
  310. package/dist/mcp/tools/collection/update.js.map +0 -1
  311. package/dist/mcp/tools/config/find.d.ts +0 -10
  312. package/dist/mcp/tools/config/find.d.ts.map +0 -1
  313. package/dist/mcp/tools/config/find.js +0 -97
  314. package/dist/mcp/tools/config/find.js.map +0 -1
  315. package/dist/mcp/tools/config/update.d.ts +0 -10
  316. package/dist/mcp/tools/config/update.d.ts.map +0 -1
  317. package/dist/mcp/tools/config/update.js +0 -215
  318. package/dist/mcp/tools/config/update.js.map +0 -1
  319. package/dist/mcp/tools/global/find.d.ts +0 -5
  320. package/dist/mcp/tools/global/find.d.ts.map +0 -1
  321. package/dist/mcp/tools/global/find.js +0 -82
  322. package/dist/mcp/tools/global/find.js.map +0 -1
  323. package/dist/mcp/tools/global/update.d.ts +0 -6
  324. package/dist/mcp/tools/global/update.d.ts.map +0 -1
  325. package/dist/mcp/tools/global/update.js +0 -124
  326. package/dist/mcp/tools/global/update.js.map +0 -1
  327. package/dist/mcp/tools/job/create.d.ts +0 -10
  328. package/dist/mcp/tools/job/create.d.ts.map +0 -1
  329. package/dist/mcp/tools/job/create.js +0 -293
  330. package/dist/mcp/tools/job/create.js.map +0 -1
  331. package/dist/mcp/tools/job/run.d.ts +0 -10
  332. package/dist/mcp/tools/job/run.d.ts.map +0 -1
  333. package/dist/mcp/tools/job/run.js +0 -129
  334. package/dist/mcp/tools/job/run.js.map +0 -1
  335. package/dist/mcp/tools/job/update.d.ts +0 -11
  336. package/dist/mcp/tools/job/update.d.ts.map +0 -1
  337. package/dist/mcp/tools/job/update.js +0 -186
  338. package/dist/mcp/tools/job/update.js.map +0 -1
  339. package/dist/mcp/tools/resource/create.d.ts +0 -6
  340. package/dist/mcp/tools/resource/create.d.ts.map +0 -1
  341. package/dist/mcp/tools/resource/create.js +0 -124
  342. package/dist/mcp/tools/resource/create.js.map +0 -1
  343. package/dist/mcp/tools/resource/delete.d.ts +0 -5
  344. package/dist/mcp/tools/resource/delete.d.ts.map +0 -1
  345. package/dist/mcp/tools/resource/delete.js +0 -151
  346. package/dist/mcp/tools/resource/delete.js.map +0 -1
  347. package/dist/mcp/tools/resource/find.d.ts +0 -5
  348. package/dist/mcp/tools/resource/find.d.ts.map +0 -1
  349. package/dist/mcp/tools/resource/find.js +0 -170
  350. package/dist/mcp/tools/resource/find.js.map +0 -1
  351. package/dist/mcp/tools/resource/update.d.ts +0 -6
  352. package/dist/mcp/tools/resource/update.d.ts.map +0 -1
  353. package/dist/mcp/tools/resource/update.js +0 -256
  354. package/dist/mcp/tools/resource/update.js.map +0 -1
  355. package/dist/mcp/tools/schemas.d.ts +0 -457
  356. package/dist/mcp/tools/schemas.d.ts.map +0 -1
  357. package/dist/mcp/tools/schemas.js +0 -243
  358. package/dist/mcp/tools/schemas.js.map +0 -1
  359. package/dist/utils/adminEntitySettings.d.ts +0 -17
  360. package/dist/utils/adminEntitySettings.d.ts.map +0 -1
  361. package/dist/utils/adminEntitySettings.js +0 -41
  362. package/dist/utils/adminEntitySettings.js.map +0 -1
  363. package/dist/utils/createApiKeyFields.d.ts +0 -15
  364. package/dist/utils/createApiKeyFields.d.ts.map +0 -1
  365. package/dist/utils/createApiKeyFields.js +0 -57
  366. package/dist/utils/createApiKeyFields.js.map +0 -1
  367. package/dist/utils/getEnabledSlugs.d.ts +0 -13
  368. package/dist/utils/getEnabledSlugs.d.ts.map +0 -1
  369. package/dist/utils/getEnabledSlugs.js +0 -32
  370. package/dist/utils/getEnabledSlugs.js.map +0 -1
  371. package/dist/utils/schemaConversion/convertCollectionSchemaToZod.d.ts +0 -3
  372. package/dist/utils/schemaConversion/convertCollectionSchemaToZod.d.ts.map +0 -1
  373. package/dist/utils/schemaConversion/convertCollectionSchemaToZod.js +0 -43
  374. package/dist/utils/schemaConversion/convertCollectionSchemaToZod.js.map +0 -1
  375. package/dist/utils/schemaConversion/removeVirtualFieldsFromSchema.d.ts +0 -7
  376. package/dist/utils/schemaConversion/removeVirtualFieldsFromSchema.d.ts.map +0 -1
  377. package/dist/utils/schemaConversion/removeVirtualFieldsFromSchema.js +0 -20
  378. package/dist/utils/schemaConversion/removeVirtualFieldsFromSchema.js.map +0 -1
  379. package/dist/utils/schemaConversion/sanitizeJsonSchema.d.ts +0 -13
  380. package/dist/utils/schemaConversion/sanitizeJsonSchema.d.ts.map +0 -1
  381. package/dist/utils/schemaConversion/sanitizeJsonSchema.js +0 -56
  382. package/dist/utils/schemaConversion/sanitizeJsonSchema.js.map +0 -1
  383. package/dist/utils/schemaConversion/simplifyRelationshipFields.d.ts +0 -20
  384. package/dist/utils/schemaConversion/simplifyRelationshipFields.d.ts.map +0 -1
  385. package/dist/utils/schemaConversion/simplifyRelationshipFields.js +0 -53
  386. package/dist/utils/schemaConversion/simplifyRelationshipFields.js.map +0 -1
  387. package/dist/utils/schemaConversion/transformPointFields.d.ts +0 -3
  388. package/dist/utils/schemaConversion/transformPointFields.d.ts.map +0 -1
  389. package/dist/utils/schemaConversion/transformPointFields.js +0 -51
  390. package/dist/utils/schemaConversion/transformPointFields.js.map +0 -1
  391. package/src/collections/createApiKeysCollection.ts +0 -373
  392. package/src/defaults.ts +0 -3
  393. package/src/endpoints/mcp.ts +0 -91
  394. package/src/mcp/createRequest.ts +0 -13
  395. package/src/mcp/getMcpHandler.ts +0 -545
  396. package/src/mcp/helpers/config.ts +0 -213
  397. package/src/mcp/helpers/fields.ts +0 -154
  398. package/src/mcp/helpers/fileValidation.ts +0 -362
  399. package/src/mcp/registerTool.ts +0 -22
  400. package/src/mcp/tools/auth/auth.ts +0 -71
  401. package/src/mcp/tools/auth/forgotPassword.ts +0 -70
  402. package/src/mcp/tools/auth/login.ts +0 -72
  403. package/src/mcp/tools/auth/resetPassword.ts +0 -61
  404. package/src/mcp/tools/auth/unlock.ts +0 -64
  405. package/src/mcp/tools/auth/verify.ts +0 -57
  406. package/src/mcp/tools/collection/create.ts +0 -210
  407. package/src/mcp/tools/collection/delete.ts +0 -211
  408. package/src/mcp/tools/collection/find.ts +0 -224
  409. package/src/mcp/tools/collection/update.ts +0 -290
  410. package/src/mcp/tools/config/find.ts +0 -128
  411. package/src/mcp/tools/config/update.ts +0 -280
  412. package/src/mcp/tools/global/find.ts +0 -128
  413. package/src/mcp/tools/global/update.ts +0 -207
  414. package/src/mcp/tools/job/create.ts +0 -416
  415. package/src/mcp/tools/job/run.ts +0 -167
  416. package/src/mcp/tools/job/update.ts +0 -274
  417. package/src/mcp/tools/resource/create.ts +0 -211
  418. package/src/mcp/tools/resource/delete.ts +0 -218
  419. package/src/mcp/tools/resource/find.ts +0 -246
  420. package/src/mcp/tools/resource/update.ts +0 -383
  421. package/src/mcp/tools/schemas.ts +0 -520
  422. package/src/utils/adminEntitySettings.ts +0 -40
  423. package/src/utils/createApiKeyFields.ts +0 -72
  424. package/src/utils/getEnabledSlugs.ts +0 -42
  425. package/src/utils/schemaConversion/convertCollectionSchemaToZod.ts +0 -52
  426. package/src/utils/schemaConversion/removeVirtualFieldsFromSchema.ts +0 -27
  427. package/src/utils/schemaConversion/sanitizeJsonSchema.ts +0 -62
  428. package/src/utils/schemaConversion/simplifyRelationshipFields.ts +0 -65
  429. package/src/utils/schemaConversion/transformPointFields.ts +0 -55
@@ -0,0 +1,132 @@
1
+ import type { CollectionSlug, GlobalSlug, PayloadRequest, SanitizedConfig } from 'payload'
2
+
3
+ import { CfWorkerJsonSchemaValidator } from '@modelcontextprotocol/server/validators/cf-worker'
4
+
5
+ import type { JsonSchemaType, MCPToolResponse } from '../../types.js'
6
+
7
+ import {
8
+ getCollectionInputSchema,
9
+ getGlobalInputSchema,
10
+ } from '../../utils/schemaConversion/getEntityInputSchema.js'
11
+
12
+ /**
13
+ * Keep the default `shortcircuit: true` - `false` makes validating nested rich text exponentially slow.
14
+ */
15
+ const validator = new CfWorkerJsonSchemaValidator({ shortcircuit: true })
16
+
17
+ type EntityValidator = {
18
+ schema: JsonSchemaType
19
+ validate: ReturnType<(typeof validator)['getValidator']>
20
+ }
21
+
22
+ /**
23
+ * - Caches each entity's schema and validator, so both are only built on the first request.
24
+ * - Keyed by payload config, then by entity type, slug, partial and language.
25
+ */
26
+ const validatorCache = new WeakMap<SanitizedConfig, Map<string, EntityValidator>>()
27
+
28
+ export const validateCollectionData = ({
29
+ collectionSlug,
30
+ data,
31
+ partial,
32
+ req,
33
+ }: {
34
+ collectionSlug: CollectionSlug
35
+ data: Record<string, unknown>
36
+ partial?: boolean
37
+ req: PayloadRequest
38
+ }): MCPToolResponse | null =>
39
+ validateData({
40
+ slug: collectionSlug,
41
+ buildSchema: () => getCollectionInputSchema({ collectionSlug, req }),
42
+ data,
43
+ entity: 'collection',
44
+ partial,
45
+ req,
46
+ })
47
+
48
+ export const validateGlobalData = ({
49
+ data,
50
+ globalSlug,
51
+ req,
52
+ }: {
53
+ data: Record<string, unknown>
54
+ globalSlug: GlobalSlug
55
+ req: PayloadRequest
56
+ }): MCPToolResponse | null =>
57
+ validateData({
58
+ slug: globalSlug,
59
+ buildSchema: () => getGlobalInputSchema({ globalSlug, req }),
60
+ data,
61
+ entity: 'global',
62
+ partial: true,
63
+ req,
64
+ })
65
+
66
+ const validateData = ({
67
+ slug,
68
+ buildSchema,
69
+ data,
70
+ entity,
71
+ partial,
72
+ req,
73
+ }: {
74
+ buildSchema: () => JsonSchemaType | null
75
+ data: Record<string, unknown>
76
+ entity: 'collection' | 'global'
77
+ partial?: boolean
78
+ req: PayloadRequest
79
+ slug: string
80
+ }): MCPToolResponse | null => {
81
+ let cache = validatorCache.get(req.payload.config)
82
+ if (!cache) {
83
+ cache = new Map()
84
+ validatorCache.set(req.payload.config, cache)
85
+ }
86
+
87
+ const cacheKey = `${entity}:${slug}:${partial ? 'partial' : 'full'}:${req.i18n.language}`
88
+ let entityValidator = cache.get(cacheKey)
89
+
90
+ if (!entityValidator) {
91
+ const schema = buildSchema()
92
+
93
+ if (!schema) {
94
+ return null
95
+ }
96
+
97
+ entityValidator = {
98
+ schema,
99
+ validate: validator.getValidator(partial ? withoutRequired(schema) : schema),
100
+ }
101
+ cache.set(cacheKey, entityValidator)
102
+ }
103
+
104
+ const result = entityValidator.validate(data)
105
+
106
+ if (result.valid) {
107
+ return null
108
+ }
109
+
110
+ const { schema } = entityValidator
111
+
112
+ return {
113
+ content: [
114
+ {
115
+ type: 'text',
116
+ text: `Invalid data for ${entity} "${slug}": ${result.errorMessage}\n\nUse this schema for data:\n\`\`\`json\n${JSON.stringify(schema)}\n\`\`\``,
117
+ },
118
+ ],
119
+ isError: true,
120
+ structuredContent: {
121
+ [`${entity}Slug`]: slug,
122
+ errors: [{ message: result.errorMessage }],
123
+ schema,
124
+ },
125
+ }
126
+ }
127
+
128
+ /** Updates are partial — drop the schema's top-level `required` before validating. */
129
+ const withoutRequired = (schema: JsonSchemaType): JsonSchemaType => {
130
+ const { required: _required, ...rest } = schema
131
+ return rest
132
+ }
@@ -0,0 +1,161 @@
1
+ import type { CollectionTool, GlobalTool, Tool } from '../types.js'
2
+
3
+ import {
4
+ authCollectionTool,
5
+ forgotPasswordCollectionTool,
6
+ loginCollectionTool,
7
+ resetPasswordCollectionTool,
8
+ unlockCollectionTool,
9
+ verifyCollectionTool,
10
+ } from './builtin/collections/authTools.js'
11
+ import { countDocumentsTool } from './builtin/collections/countTool.js'
12
+ import { countVersionsTool } from './builtin/collections/countVersionsTool.js'
13
+ import { createDocumentsTool } from './builtin/collections/createTool.js'
14
+ import { deleteDocumentsTool } from './builtin/collections/deleteTool.js'
15
+ import { duplicateDocumentTool } from './builtin/collections/duplicateTool.js'
16
+ import { findDistinctTool } from './builtin/collections/findDistinctTool.js'
17
+ import { findDocumentsTool } from './builtin/collections/findTool.js'
18
+ import { findVersionByIDTool } from './builtin/collections/findVersionByIDTool.js'
19
+ import { findVersionsTool } from './builtin/collections/findVersionsTool.js'
20
+ import { getCollectionSchemaTool } from './builtin/collections/getCollectionSchemaTool.js'
21
+ import { restoreVersionTool } from './builtin/collections/restoreVersionTool.js'
22
+ import { updateDocumentTool } from './builtin/collections/updateTool.js'
23
+ import { getUploadInstructionsTool } from './builtin/collections/uploadInstructionsTool.js'
24
+ import { getConfigInfoTool } from './builtin/getConfigInfoTool.js'
25
+ import { countGlobalVersionsTool } from './builtin/globals/countVersionsTool.js'
26
+ import { findGlobalTool } from './builtin/globals/findTool.js'
27
+ import { findGlobalVersionByIDTool } from './builtin/globals/findVersionByIDTool.js'
28
+ import { findGlobalVersionsTool } from './builtin/globals/findVersionsTool.js'
29
+ import { getGlobalSchemaTool } from './builtin/globals/getGlobalSchemaTool.js'
30
+ import { restoreGlobalVersionTool } from './builtin/globals/restoreVersionTool.js'
31
+ import { updateGlobalTool } from './builtin/globals/updateTool.js'
32
+
33
+ type CollectionBuiltin = {
34
+ mcpName: string
35
+ requiresDuplicateEnabled?: boolean
36
+ requiresUpload?: boolean
37
+ requiresVersions?: boolean
38
+ tool: CollectionTool
39
+ }
40
+
41
+ type GlobalBuiltin = {
42
+ mcpName: string
43
+ requiresVersions?: boolean
44
+ tool: GlobalTool
45
+ }
46
+
47
+ export const TOOL_BUILTINS = {
48
+ getConfigInfo: { mcpName: 'getConfigInfo', tool: getConfigInfoTool },
49
+ } satisfies Record<string, { mcpName: string; tool: Tool }>
50
+
51
+ /**
52
+ * The static built-in collection CRUD tools. Keys here are the source of truth
53
+ * for `MCPCollectionBuiltinName` — adding/removing an entry updates the type
54
+ * automatically.
55
+ */
56
+ export const COLLECTION_BUILTINS = {
57
+ count: { mcpName: 'countDocuments', tool: countDocumentsTool },
58
+ countVersions: { mcpName: 'countVersions', requiresVersions: true, tool: countVersionsTool },
59
+ create: { mcpName: 'createDocuments', tool: createDocumentsTool },
60
+ delete: { mcpName: 'deleteDocuments', tool: deleteDocumentsTool },
61
+ duplicate: {
62
+ mcpName: 'duplicateDocument',
63
+ requiresDuplicateEnabled: true,
64
+ tool: duplicateDocumentTool,
65
+ },
66
+ find: { mcpName: 'findDocuments', tool: findDocumentsTool },
67
+ findDistinct: { mcpName: 'findDistinct', tool: findDistinctTool },
68
+ findVersionByID: {
69
+ mcpName: 'findVersionByID',
70
+ requiresVersions: true,
71
+ tool: findVersionByIDTool,
72
+ },
73
+ findVersions: { mcpName: 'findVersions', requiresVersions: true, tool: findVersionsTool },
74
+ getCollectionSchema: { mcpName: 'getCollectionSchema', tool: getCollectionSchemaTool },
75
+ getUploadInstructions: {
76
+ mcpName: 'getUploadInstructions',
77
+ requiresUpload: true,
78
+ tool: getUploadInstructionsTool,
79
+ },
80
+ restoreVersion: { mcpName: 'restoreVersion', requiresVersions: true, tool: restoreVersionTool },
81
+ update: { mcpName: 'updateDocument', tool: updateDocumentTool },
82
+ } satisfies Record<string, CollectionBuiltin>
83
+
84
+ /**
85
+ * The static auth tools surfaced under auth-enabled collections. Keys are the
86
+ * source of truth for `MCPCollectionAuthToolName`.
87
+ */
88
+ export const COLLECTION_AUTH_BUILTINS = {
89
+ auth: { mcpName: 'auth', tool: authCollectionTool },
90
+ forgotPassword: {
91
+ mcpName: 'forgotPassword',
92
+ tool: forgotPasswordCollectionTool,
93
+ },
94
+ login: { mcpName: 'login', tool: loginCollectionTool },
95
+ resetPassword: {
96
+ mcpName: 'resetPassword',
97
+ tool: resetPasswordCollectionTool,
98
+ },
99
+ unlock: { mcpName: 'unlock', tool: unlockCollectionTool },
100
+ verify: { mcpName: 'verify', tool: verifyCollectionTool },
101
+ } satisfies Record<string, { mcpName: string; tool: CollectionTool }>
102
+
103
+ /**
104
+ * The static built-in global tools. Keys are the source of truth for
105
+ * `MCPGlobalBuiltinName`.
106
+ */
107
+ export const GLOBAL_BUILTINS = {
108
+ countGlobalVersions: {
109
+ mcpName: 'countGlobalVersions',
110
+ requiresVersions: true,
111
+ tool: countGlobalVersionsTool,
112
+ },
113
+ find: { mcpName: 'findGlobal', tool: findGlobalTool },
114
+ findGlobalVersionByID: {
115
+ mcpName: 'findGlobalVersionByID',
116
+ requiresVersions: true,
117
+ tool: findGlobalVersionByIDTool,
118
+ },
119
+ findGlobalVersions: {
120
+ mcpName: 'findGlobalVersions',
121
+ requiresVersions: true,
122
+ tool: findGlobalVersionsTool,
123
+ },
124
+ getGlobalSchema: { mcpName: 'getGlobalSchema', tool: getGlobalSchemaTool },
125
+ restoreGlobalVersion: {
126
+ mcpName: 'restoreGlobalVersion',
127
+ requiresVersions: true,
128
+ tool: restoreGlobalVersionTool,
129
+ },
130
+ update: { mcpName: 'updateGlobal', tool: updateGlobalTool },
131
+ } satisfies Record<string, GlobalBuiltin>
132
+
133
+ export type MCPCollectionBuiltinName = keyof typeof COLLECTION_BUILTINS
134
+
135
+ export type MCPCollectionAuthToolName = keyof typeof COLLECTION_AUTH_BUILTINS
136
+
137
+ export type MCPGlobalBuiltinName = keyof typeof GLOBAL_BUILTINS
138
+
139
+ export type MCPTopLevelBuiltinName = keyof typeof TOOL_BUILTINS
140
+
141
+ /**
142
+ * Pre-typed `Object.entries` for each registry. The cast from `string` to the
143
+ * literal key union lives here once so consumers can iterate without their own
144
+ * cast — TypeScript's `Object.entries` always widens keys to `string`, which
145
+ * defeats the narrow type lookups on `MCPCollectionToolsMap`.
146
+ */
147
+ export const TOOL_BUILTIN_ENTRIES = Object.entries(TOOL_BUILTINS) as Array<
148
+ [MCPTopLevelBuiltinName, (typeof TOOL_BUILTINS)[MCPTopLevelBuiltinName]]
149
+ >
150
+
151
+ export const COLLECTION_BUILTIN_ENTRIES = Object.entries(COLLECTION_BUILTINS) as Array<
152
+ [MCPCollectionBuiltinName, CollectionBuiltin]
153
+ >
154
+
155
+ export const COLLECTION_AUTH_BUILTIN_ENTRIES = Object.entries(COLLECTION_AUTH_BUILTINS) as Array<
156
+ [MCPCollectionAuthToolName, (typeof COLLECTION_AUTH_BUILTINS)[MCPCollectionAuthToolName]]
157
+ >
158
+
159
+ export const GLOBAL_BUILTIN_ENTRIES = Object.entries(GLOBAL_BUILTINS) as Array<
160
+ [MCPGlobalBuiltinName, GlobalBuiltin]
161
+ >
@@ -0,0 +1,281 @@
1
+ import type {
2
+ CollectionConfig,
3
+ Config,
4
+ GlobalConfig,
5
+ SanitizedCollectionConfig,
6
+ SanitizedConfig,
7
+ SanitizedGlobalConfig,
8
+ } from 'payload'
9
+
10
+ import type {
11
+ CollectionMCPItem,
12
+ CollectionTool,
13
+ GlobalMCPItem,
14
+ GlobalTool,
15
+ MCPItem,
16
+ MCPPluginConfig,
17
+ SanitizedMCPPluginConfig,
18
+ } from '../types.js'
19
+
20
+ import { defaultAccess } from '../defaultAccess.js'
21
+ import {
22
+ COLLECTION_AUTH_BUILTIN_ENTRIES,
23
+ COLLECTION_AUTH_BUILTINS,
24
+ COLLECTION_BUILTIN_ENTRIES,
25
+ COLLECTION_BUILTINS,
26
+ GLOBAL_BUILTIN_ENTRIES,
27
+ GLOBAL_BUILTINS,
28
+ TOOL_BUILTIN_ENTRIES,
29
+ TOOL_BUILTINS,
30
+ } from './builtinTools.js'
31
+
32
+ /**
33
+ * Converts the user-configured `MCPPluginConfig` into a `SanitizedMCPPluginConfig`:
34
+ * - Flattens `tools` / `prompts` / `resources` / per-collection / per-global
35
+ * tool maps into a single `items` array.
36
+ * - Applies built-in tools for collections and globals, respecting opt-out user overrides.
37
+ *
38
+ * Called once during plugin init. After that, `plugins['@payloadcms/plugin-mcp']
39
+ * ?.options` holds the sanitized result
40
+ */
41
+ export const sanitizeMCPConfig = ({
42
+ config,
43
+ pluginConfig,
44
+ }: {
45
+ config: Config | SanitizedConfig
46
+ pluginConfig: MCPPluginConfig
47
+ }): SanitizedMCPPluginConfig => {
48
+ const items: MCPItem[] = []
49
+
50
+ for (const collection of config.collections ?? []) {
51
+ items.push(...sanitizeCollectionConfig({ collection, pluginConfig }))
52
+ }
53
+
54
+ for (const global of config.globals ?? []) {
55
+ items.push(...sanitizeGlobalConfig({ global, pluginConfig }))
56
+ }
57
+
58
+ for (const [configKey, { mcpName, tool }] of TOOL_BUILTIN_ENTRIES) {
59
+ items.push({
60
+ type: 'tool',
61
+ configKey,
62
+ label: tool.annotations?.title ?? configKey,
63
+ mcpName,
64
+ tool: { ...tool, access: tool.access ?? defaultAccess },
65
+ })
66
+ }
67
+
68
+ for (const [configKey, tool] of Object.entries(pluginConfig.tools ?? {})) {
69
+ if (configKey in TOOL_BUILTINS) {
70
+ continue
71
+ }
72
+ items.push({
73
+ type: 'tool',
74
+ configKey,
75
+ label: tool.annotations?.title ?? configKey,
76
+ mcpName: configKey,
77
+ tool: { ...tool, access: tool.access ?? defaultAccess },
78
+ })
79
+ }
80
+
81
+ for (const [configKey, prompt] of Object.entries(pluginConfig.prompts ?? {})) {
82
+ items.push({
83
+ type: 'prompt',
84
+ configKey,
85
+ label: prompt.title ?? configKey,
86
+ mcpName: configKey,
87
+ prompt: { ...prompt, access: prompt.access ?? defaultAccess },
88
+ })
89
+ }
90
+
91
+ for (const [configKey, resource] of Object.entries(pluginConfig.resources ?? {})) {
92
+ items.push({
93
+ type: 'resource',
94
+ configKey,
95
+ label: resource.title ?? configKey,
96
+ mcpName: configKey,
97
+ resource: { ...resource, access: resource.access ?? defaultAccess },
98
+ })
99
+ }
100
+
101
+ return {
102
+ disabled: pluginConfig.disabled,
103
+ hooks: pluginConfig.hooks,
104
+ items,
105
+ mcp: pluginConfig.mcp,
106
+ overrideGetAuthorizedMCP: pluginConfig.overrideGetAuthorizedMCP,
107
+ }
108
+ }
109
+
110
+ const sanitizeCollectionConfig = ({
111
+ collection,
112
+ pluginConfig,
113
+ }: {
114
+ collection: CollectionConfig | SanitizedCollectionConfig
115
+ pluginConfig: MCPPluginConfig
116
+ }): CollectionMCPItem[] => {
117
+ const slug = collection.slug
118
+ const collectionPluginConfig = pluginConfig.collections?.[slug]
119
+ const items: CollectionMCPItem[] = []
120
+ /**
121
+ * Payload disables duplicate for auth collections by default unless the
122
+ * collection explicitly opts back in with `disableDuplicate: false`.
123
+ */
124
+ const isDuplicateDisabled =
125
+ collection.disableDuplicate === true ||
126
+ (Boolean(collection.auth) && collection.disableDuplicate !== false)
127
+
128
+ for (const [
129
+ toolKey,
130
+ { mcpName, requiresDuplicateEnabled, requiresUpload, requiresVersions, tool },
131
+ ] of COLLECTION_BUILTIN_ENTRIES) {
132
+ if (requiresVersions && !collection.versions) {
133
+ continue
134
+ }
135
+ if (requiresDuplicateEnabled && isDuplicateDisabled) {
136
+ continue
137
+ }
138
+ if (requiresUpload && !collection.upload) {
139
+ continue
140
+ }
141
+ const matchedConfigEntry = collectionPluginConfig?.tools?.[toolKey]
142
+ if (matchedConfigEntry === false) {
143
+ continue
144
+ }
145
+ const override = typeof matchedConfigEntry === 'object' ? matchedConfigEntry : undefined
146
+ const annotations = { ...tool.annotations, ...override?.annotations }
147
+ items.push({
148
+ type: 'collectionTool',
149
+ collectionSlug: slug,
150
+ configKey: toolKey,
151
+ label: annotations.title ?? toolKey,
152
+ mcpName,
153
+ tool: {
154
+ ...tool,
155
+ access: override?.access ?? tool.access ?? defaultAccess,
156
+ annotations,
157
+ description: override?.description ?? tool.description,
158
+ overrideResponse:
159
+ override?.overrideResponse ??
160
+ collectionPluginConfig?.overrideResponse ??
161
+ tool.overrideResponse,
162
+ },
163
+ })
164
+ }
165
+
166
+ if (collection.auth) {
167
+ for (const [authToolKey, { mcpName, tool }] of COLLECTION_AUTH_BUILTIN_ENTRIES) {
168
+ const matchedConfigEntry = collectionPluginConfig?.tools?.[authToolKey]
169
+ if (!matchedConfigEntry) {
170
+ continue
171
+ }
172
+ // `true` means "enable, no override"; only the object form carries fields.
173
+ const override = typeof matchedConfigEntry === 'object' ? matchedConfigEntry : undefined
174
+ const annotations = { ...tool.annotations, ...override?.annotations }
175
+ items.push({
176
+ type: 'collectionTool',
177
+ collectionSlug: slug,
178
+ configKey: authToolKey,
179
+ label: annotations.title ?? authToolKey,
180
+ mcpName,
181
+ tool: {
182
+ ...tool,
183
+ access: override?.access ?? tool.access ?? defaultAccess,
184
+ annotations,
185
+ description: override?.description ?? tool.description,
186
+ overrideResponse:
187
+ override?.overrideResponse ??
188
+ collectionPluginConfig?.overrideResponse ??
189
+ tool.overrideResponse,
190
+ },
191
+ })
192
+ }
193
+ }
194
+
195
+ // Cast: builtin keys are filtered out below, so the remaining values are
196
+ // always custom tools (`CollectionTool`) or undefined
197
+ const customEntries = Object.entries(collectionPluginConfig?.tools ?? {}) as Array<
198
+ [string, CollectionTool | undefined]
199
+ >
200
+ for (const [configKey, customTool] of customEntries) {
201
+ if (configKey in COLLECTION_BUILTINS || configKey in COLLECTION_AUTH_BUILTINS) {
202
+ continue
203
+ }
204
+ if (!customTool) {
205
+ continue
206
+ }
207
+ items.push({
208
+ type: 'collectionTool',
209
+ collectionSlug: slug,
210
+ configKey,
211
+ label: customTool.annotations?.title ?? configKey,
212
+ mcpName: configKey,
213
+ tool: { ...customTool, access: customTool.access ?? defaultAccess },
214
+ })
215
+ }
216
+
217
+ return items
218
+ }
219
+
220
+ const sanitizeGlobalConfig = ({
221
+ global,
222
+ pluginConfig,
223
+ }: {
224
+ global: GlobalConfig | SanitizedGlobalConfig
225
+ pluginConfig: MCPPluginConfig
226
+ }): GlobalMCPItem[] => {
227
+ const slug = global.slug
228
+ const globalPluginConfig = pluginConfig.globals?.[slug]
229
+ const items: GlobalMCPItem[] = []
230
+
231
+ for (const [toolKey, { mcpName, requiresVersions, tool }] of GLOBAL_BUILTIN_ENTRIES) {
232
+ if (requiresVersions && !global.versions) {
233
+ continue
234
+ }
235
+ const matchedConfigEntry = globalPluginConfig?.tools?.[toolKey]
236
+ if (matchedConfigEntry === false) {
237
+ continue
238
+ }
239
+ const override = typeof matchedConfigEntry === 'object' ? matchedConfigEntry : undefined
240
+ const annotations = { ...tool.annotations, ...override?.annotations }
241
+ items.push({
242
+ type: 'globalTool',
243
+ configKey: toolKey,
244
+ globalSlug: slug,
245
+ label: annotations.title ?? toolKey,
246
+ mcpName,
247
+ tool: {
248
+ ...tool,
249
+ access: override?.access ?? tool.access ?? defaultAccess,
250
+ annotations,
251
+ description: override?.description ?? tool.description,
252
+ overrideResponse:
253
+ override?.overrideResponse ??
254
+ globalPluginConfig?.overrideResponse ??
255
+ tool.overrideResponse,
256
+ },
257
+ })
258
+ }
259
+
260
+ const customEntries = Object.entries(globalPluginConfig?.tools ?? {}) as Array<
261
+ [string, GlobalTool | undefined]
262
+ >
263
+ for (const [configKey, customTool] of customEntries) {
264
+ if (configKey in GLOBAL_BUILTINS) {
265
+ continue
266
+ }
267
+ if (!customTool) {
268
+ continue
269
+ }
270
+ items.push({
271
+ type: 'globalTool',
272
+ configKey,
273
+ globalSlug: slug,
274
+ label: customTool.annotations?.title ?? configKey,
275
+ mcpName: configKey,
276
+ tool: { ...customTool, access: customTool.access ?? defaultAccess },
277
+ })
278
+ }
279
+
280
+ return items
281
+ }
package/src/stdio.ts ADDED
@@ -0,0 +1,131 @@
1
+ import type { Config, Plugin, SanitizedConfig } from 'payload'
2
+
3
+ /* eslint-disable no-console */
4
+ import { serveStdio } from '@modelcontextprotocol/server/stdio'
5
+ import { fileURLToPath, pathToFileURL } from 'node:url'
6
+ import { createLocalReq, getPayload } from 'payload'
7
+ import { findConfig, loadEnv } from 'payload/node'
8
+
9
+ import type { SanitizedMCPPluginConfig } from './types.js'
10
+
11
+ import { getAuthorizedMCP } from './endpoint/access.js'
12
+ import { buildMcpServer } from './mcp/buildMcpServer.js'
13
+ import { sanitizeMCPConfig } from './mcp/sanitizeMCPConfig.js'
14
+ import { getPluginConfig } from './utils/getPluginConfig.js'
15
+ import { resolveProjectRoot } from './utils/resolveProjectRoot.js'
16
+
17
+ /**
18
+ * Starts Payload's MCP server over stdin and stdout.
19
+ *
20
+ * Set `PAYLOAD_MCP_AUTHORIZATION` to authenticate. In development,
21
+ * `PAYLOAD_MCP_OVERRIDE_ACCESS=true` skips access checks.
22
+ */
23
+ export const runMcpStdio = async (): Promise<void> => {
24
+ // MCP clients may start this command from another folder. Move to the Payload
25
+ // project so findConfig() can find the config.
26
+ const projectRoot = resolveProjectRoot(fileURLToPath(import.meta.url))
27
+ if (projectRoot) {
28
+ process.chdir(projectRoot)
29
+ }
30
+
31
+ loadEnv()
32
+ const configPath = findConfig()
33
+ const configModule = await import(pathToFileURL(configPath).toString())
34
+ const config = (await (configModule.default ?? configModule)) as SanitizedConfig
35
+
36
+ /**
37
+ * stdout is only for MCP messages. The spec says the server must not write
38
+ * logs there and may write them to stderr instead.
39
+ *
40
+ * The 2.0 client library recovers from stray stdout logs, but that behavior is not
41
+ * guaranteed. Move Payload logs to stderr so Payload does not add invalid data
42
+ * to stdout. Keep options from configurable loggers. Replace pre-built loggers
43
+ * because their output cannot be redirected.
44
+ *
45
+ * @see https://modelcontextprotocol.io/specification/2025-11-25/basic/transports#stdio
46
+ */
47
+ const loggerConfig: { logger?: Config['logger'] } = config
48
+ if (
49
+ loggerConfig.logger &&
50
+ typeof loggerConfig.logger === 'object' &&
51
+ 'options' in loggerConfig.logger
52
+ ) {
53
+ loggerConfig.logger.destination = process.stderr
54
+ } else {
55
+ loggerConfig.logger = { destination: process.stderr, options: {} }
56
+ }
57
+
58
+ const payload = await getPayload({ config, cron: false, disableOnInit: true })
59
+
60
+ let pluginConfig: SanitizedMCPPluginConfig
61
+ try {
62
+ pluginConfig = getPluginConfig({ config: payload.config })
63
+ } catch {
64
+ // The command also works when mcpPlugin() is not in the Payload config.
65
+ pluginConfig = sanitizeMCPConfig({ config: payload.config, pluginConfig: {} })
66
+
67
+ const fallbackPlugin: Plugin = (config) => config
68
+ Object.assign(fallbackPlugin, {
69
+ slug: '@payloadcms/plugin-mcp',
70
+ sanitizedOptions: pluginConfig,
71
+ })
72
+ payload.config.plugins ??= []
73
+ payload.config.plugins.push(fallbackPlugin)
74
+ }
75
+
76
+ const overrideAccessEnv = process.env.PAYLOAD_MCP_OVERRIDE_ACCESS
77
+ let overrideAccess = false
78
+
79
+ if (overrideAccessEnv === 'true') {
80
+ overrideAccess = true
81
+ } else if (overrideAccessEnv && overrideAccessEnv !== 'false') {
82
+ throw new Error('PAYLOAD_MCP_OVERRIDE_ACCESS must be "true" or "false".')
83
+ }
84
+
85
+ if (overrideAccess && process.env.NODE_ENV !== 'development') {
86
+ throw new Error('PAYLOAD_MCP_OVERRIDE_ACCESS is only available in development.')
87
+ }
88
+
89
+ const headers = new Headers()
90
+ if (process.env.PAYLOAD_MCP_AUTHORIZATION) {
91
+ headers.set('Authorization', process.env.PAYLOAD_MCP_AUTHORIZATION)
92
+ }
93
+
94
+ const req = await createLocalReq({ req: { headers } }, payload)
95
+ req.payloadAPI = 'MCP' as const
96
+ const authorizedMCP = await getAuthorizedMCP({ overrideAccess, req })
97
+
98
+ const stdioServer = serveStdio(() => buildMcpServer({ authorizedMCP, pluginConfig, req }), {
99
+ onerror: (err) => {
100
+ // MCP messages use stdout, so write SDK errors to stderr.
101
+ console.error('[payload-mcp] error serving MCP over stdio:', err)
102
+ },
103
+ })
104
+
105
+ // Close the MCP server and Payload when the client disconnects or the process stops.
106
+ let isShuttingDown = false
107
+ const shutdown = async () => {
108
+ if (isShuttingDown) {
109
+ return
110
+ }
111
+ isShuttingDown = true
112
+
113
+ try {
114
+ await stdioServer.close()
115
+ } catch (err) {
116
+ console.error('[payload-mcp] error closing server:', err)
117
+ }
118
+
119
+ try {
120
+ await payload.destroy()
121
+ } catch (err) {
122
+ console.error('[payload-mcp] error destroying payload:', err)
123
+ }
124
+
125
+ process.exit(0)
126
+ }
127
+
128
+ process.once('SIGINT', () => void shutdown())
129
+ process.once('SIGTERM', () => void shutdown())
130
+ process.stdin.once('close', () => void shutdown())
131
+ }