@payloadcms/plugin-mcp 4.0.0-internal.38b7f1d → 4.0.0-internal.4804abd

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 (419) hide show
  1. package/bin.js +39 -0
  2. package/dist/@types/assets.d.js +2 -0
  3. package/dist/@types/assets.d.js.map +1 -0
  4. package/dist/defaultAccess.d.ts +3 -0
  5. package/dist/defaultAccess.d.ts.map +1 -0
  6. package/dist/defaultAccess.js +3 -0
  7. package/dist/defaultAccess.js.map +1 -0
  8. package/dist/defineTool.d.ts +26 -0
  9. package/dist/defineTool.d.ts.map +1 -0
  10. package/dist/defineTool.js +37 -0
  11. package/dist/defineTool.js.map +1 -0
  12. package/dist/endpoint/access.d.ts +22 -0
  13. package/dist/endpoint/access.d.ts.map +1 -0
  14. package/dist/endpoint/access.js +100 -0
  15. package/dist/endpoint/access.js.map +1 -0
  16. package/dist/endpoint/index.d.ts +3 -0
  17. package/dist/endpoint/index.d.ts.map +1 -0
  18. package/dist/endpoint/index.js +47 -0
  19. package/dist/endpoint/index.js.map +1 -0
  20. package/dist/exports/client.d.ts +2 -0
  21. package/dist/exports/client.d.ts.map +1 -0
  22. package/dist/exports/client.js +4 -0
  23. package/dist/exports/client.js.map +1 -0
  24. package/dist/exports/internal.d.ts +2 -0
  25. package/dist/exports/internal.d.ts.map +1 -0
  26. package/dist/exports/internal.js +3 -0
  27. package/dist/exports/internal.js.map +1 -0
  28. package/dist/index.d.ts +4 -7
  29. package/dist/index.d.ts.map +1 -1
  30. package/dist/index.js +39 -67
  31. package/dist/index.js.map +1 -1
  32. package/dist/mcp/buildMcpServer.d.ts +19 -0
  33. package/dist/mcp/buildMcpServer.d.ts.map +1 -0
  34. package/dist/mcp/buildMcpServer.js +201 -0
  35. package/dist/mcp/buildMcpServer.js.map +1 -0
  36. package/dist/mcp/builtin/collections/authTools.d.ts +7 -0
  37. package/dist/mcp/builtin/collections/authTools.d.ts.map +1 -0
  38. package/dist/mcp/builtin/collections/authTools.js +288 -0
  39. package/dist/mcp/builtin/collections/authTools.js.map +1 -0
  40. package/dist/mcp/builtin/collections/countTool.d.ts +2 -0
  41. package/dist/mcp/builtin/collections/countTool.d.ts.map +1 -0
  42. package/dist/mcp/builtin/collections/countTool.js +69 -0
  43. package/dist/mcp/builtin/collections/countTool.js.map +1 -0
  44. package/dist/mcp/builtin/collections/countVersionsTool.d.ts +2 -0
  45. package/dist/mcp/builtin/collections/countVersionsTool.d.ts.map +1 -0
  46. package/dist/mcp/builtin/collections/countVersionsTool.js +65 -0
  47. package/dist/mcp/builtin/collections/countVersionsTool.js.map +1 -0
  48. package/dist/mcp/builtin/collections/createTool.d.ts +2 -0
  49. package/dist/mcp/builtin/collections/createTool.d.ts.map +1 -0
  50. package/dist/mcp/builtin/collections/createTool.js +87 -0
  51. package/dist/mcp/builtin/collections/createTool.js.map +1 -0
  52. package/dist/mcp/builtin/collections/deleteTool.d.ts +2 -0
  53. package/dist/mcp/builtin/collections/deleteTool.d.ts.map +1 -0
  54. package/dist/mcp/builtin/collections/deleteTool.js +111 -0
  55. package/dist/mcp/builtin/collections/deleteTool.js.map +1 -0
  56. package/dist/mcp/builtin/collections/duplicateTool.d.ts +2 -0
  57. package/dist/mcp/builtin/collections/duplicateTool.d.ts.map +1 -0
  58. package/dist/mcp/builtin/collections/duplicateTool.js +97 -0
  59. package/dist/mcp/builtin/collections/duplicateTool.js.map +1 -0
  60. package/dist/mcp/builtin/collections/findDistinctTool.d.ts +2 -0
  61. package/dist/mcp/builtin/collections/findDistinctTool.d.ts.map +1 -0
  62. package/dist/mcp/builtin/collections/findDistinctTool.js +93 -0
  63. package/dist/mcp/builtin/collections/findDistinctTool.js.map +1 -0
  64. package/dist/mcp/builtin/collections/findTool.d.ts +2 -0
  65. package/dist/mcp/builtin/collections/findTool.d.ts.map +1 -0
  66. package/dist/mcp/builtin/collections/findTool.js +165 -0
  67. package/dist/mcp/builtin/collections/findTool.js.map +1 -0
  68. package/dist/mcp/builtin/collections/findVersionByIDTool.d.ts +2 -0
  69. package/dist/mcp/builtin/collections/findVersionByIDTool.d.ts.map +1 -0
  70. package/dist/mcp/builtin/collections/findVersionByIDTool.js +84 -0
  71. package/dist/mcp/builtin/collections/findVersionByIDTool.js.map +1 -0
  72. package/dist/mcp/builtin/collections/findVersionsTool.d.ts +2 -0
  73. package/dist/mcp/builtin/collections/findVersionsTool.d.ts.map +1 -0
  74. package/dist/mcp/builtin/collections/findVersionsTool.js +99 -0
  75. package/dist/mcp/builtin/collections/findVersionsTool.js.map +1 -0
  76. package/dist/mcp/builtin/collections/formatCollectionError.d.ts +9 -0
  77. package/dist/mcp/builtin/collections/formatCollectionError.d.ts.map +1 -0
  78. package/dist/mcp/builtin/collections/formatCollectionError.js +60 -0
  79. package/dist/mcp/builtin/collections/formatCollectionError.js.map +1 -0
  80. package/dist/mcp/builtin/collections/getCollectionSchemaTool.d.ts +2 -0
  81. package/dist/mcp/builtin/collections/getCollectionSchemaTool.d.ts.map +1 -0
  82. package/dist/mcp/builtin/collections/getCollectionSchemaTool.js +47 -0
  83. package/dist/mcp/builtin/collections/getCollectionSchemaTool.js.map +1 -0
  84. package/dist/mcp/builtin/collections/restoreVersionTool.d.ts +2 -0
  85. package/dist/mcp/builtin/collections/restoreVersionTool.d.ts.map +1 -0
  86. package/dist/mcp/builtin/collections/restoreVersionTool.js +82 -0
  87. package/dist/mcp/builtin/collections/restoreVersionTool.js.map +1 -0
  88. package/dist/mcp/builtin/collections/updateTool.d.ts +2 -0
  89. package/dist/mcp/builtin/collections/updateTool.d.ts.map +1 -0
  90. package/dist/mcp/builtin/collections/updateTool.js +192 -0
  91. package/dist/mcp/builtin/collections/updateTool.js.map +1 -0
  92. package/dist/mcp/builtin/getConfigInfoTool.d.ts +2 -0
  93. package/dist/mcp/builtin/getConfigInfoTool.d.ts.map +1 -0
  94. package/dist/mcp/builtin/getConfigInfoTool.js +71 -0
  95. package/dist/mcp/builtin/getConfigInfoTool.js.map +1 -0
  96. package/dist/mcp/builtin/globals/countVersionsTool.d.ts +2 -0
  97. package/dist/mcp/builtin/globals/countVersionsTool.d.ts.map +1 -0
  98. package/dist/mcp/builtin/globals/countVersionsTool.js +65 -0
  99. package/dist/mcp/builtin/globals/countVersionsTool.js.map +1 -0
  100. package/dist/mcp/builtin/globals/findTool.d.ts +2 -0
  101. package/dist/mcp/builtin/globals/findTool.d.ts.map +1 -0
  102. package/dist/mcp/builtin/globals/findTool.js +73 -0
  103. package/dist/mcp/builtin/globals/findTool.js.map +1 -0
  104. package/dist/mcp/builtin/globals/findVersionByIDTool.d.ts +2 -0
  105. package/dist/mcp/builtin/globals/findVersionByIDTool.d.ts.map +1 -0
  106. package/dist/mcp/builtin/globals/findVersionByIDTool.js +80 -0
  107. package/dist/mcp/builtin/globals/findVersionByIDTool.js.map +1 -0
  108. package/dist/mcp/builtin/globals/findVersionsTool.d.ts +2 -0
  109. package/dist/mcp/builtin/globals/findVersionsTool.d.ts.map +1 -0
  110. package/dist/mcp/builtin/globals/findVersionsTool.js +95 -0
  111. package/dist/mcp/builtin/globals/findVersionsTool.js.map +1 -0
  112. package/dist/mcp/builtin/globals/getGlobalSchemaTool.d.ts +2 -0
  113. package/dist/mcp/builtin/globals/getGlobalSchemaTool.d.ts.map +1 -0
  114. package/dist/mcp/builtin/globals/getGlobalSchemaTool.js +47 -0
  115. package/dist/mcp/builtin/globals/getGlobalSchemaTool.js.map +1 -0
  116. package/dist/mcp/builtin/globals/restoreVersionTool.d.ts +2 -0
  117. package/dist/mcp/builtin/globals/restoreVersionTool.d.ts.map +1 -0
  118. package/dist/mcp/builtin/globals/restoreVersionTool.js +78 -0
  119. package/dist/mcp/builtin/globals/restoreVersionTool.js.map +1 -0
  120. package/dist/mcp/builtin/globals/updateTool.d.ts +2 -0
  121. package/dist/mcp/builtin/globals/updateTool.d.ts.map +1 -0
  122. package/dist/mcp/builtin/globals/updateTool.js +87 -0
  123. package/dist/mcp/builtin/globals/updateTool.js.map +1 -0
  124. package/dist/mcp/builtin/validateEntityData.d.ts +14 -0
  125. package/dist/mcp/builtin/validateEntityData.d.ts.map +1 -0
  126. package/dist/mcp/builtin/validateEntityData.js +82 -0
  127. package/dist/mcp/builtin/validateEntityData.js.map +1 -0
  128. package/dist/mcp/builtinTools.d.ts +162 -0
  129. package/dist/mcp/builtinTools.d.ts.map +1 -0
  130. package/dist/mcp/builtinTools.js +163 -0
  131. package/dist/mcp/builtinTools.js.map +1 -0
  132. package/dist/mcp/sanitizeMCPConfig.d.ts +16 -0
  133. package/dist/mcp/sanitizeMCPConfig.d.ts.map +1 -0
  134. package/dist/mcp/sanitizeMCPConfig.js +229 -0
  135. package/dist/mcp/sanitizeMCPConfig.js.map +1 -0
  136. package/dist/stdio.d.ts +9 -0
  137. package/dist/stdio.d.ts.map +1 -0
  138. package/dist/stdio.js +108 -0
  139. package/dist/stdio.js.map +1 -0
  140. package/dist/types.d.ts +222 -461
  141. package/dist/types.d.ts.map +1 -1
  142. package/dist/types.js +6 -1
  143. package/dist/types.js.map +1 -1
  144. package/dist/utils/camelCase.d.ts.map +1 -1
  145. package/dist/utils/getLogger.d.ts +10 -0
  146. package/dist/utils/getLogger.d.ts.map +1 -0
  147. package/dist/utils/getLogger.js +22 -0
  148. package/dist/utils/getLogger.js.map +1 -0
  149. package/dist/utils/getPluginConfig.d.ts +12 -0
  150. package/dist/utils/getPluginConfig.d.ts.map +1 -0
  151. package/dist/utils/getPluginConfig.js +15 -0
  152. package/dist/utils/getPluginConfig.js.map +1 -0
  153. package/dist/utils/localAPIDefaults.d.ts +20 -0
  154. package/dist/utils/localAPIDefaults.d.ts.map +1 -0
  155. package/dist/utils/localAPIDefaults.js +19 -0
  156. package/dist/utils/localAPIDefaults.js.map +1 -0
  157. package/dist/utils/resolveProjectRoot.d.ts +7 -0
  158. package/dist/utils/resolveProjectRoot.d.ts.map +1 -0
  159. package/dist/utils/resolveProjectRoot.js +15 -0
  160. package/dist/utils/resolveProjectRoot.js.map +1 -0
  161. package/dist/utils/schemaConversion/getEntityInputSchema.d.ts +11 -0
  162. package/dist/utils/schemaConversion/getEntityInputSchema.d.ts.map +1 -0
  163. package/dist/utils/schemaConversion/getEntityInputSchema.js +32 -0
  164. package/dist/utils/schemaConversion/getEntityInputSchema.js.map +1 -0
  165. package/dist/utils/schemaConversion/sanitizeEntitySchema.d.ts +10 -0
  166. package/dist/utils/schemaConversion/sanitizeEntitySchema.d.ts.map +1 -0
  167. package/dist/utils/schemaConversion/sanitizeEntitySchema.js +384 -0
  168. package/dist/utils/schemaConversion/sanitizeEntitySchema.js.map +1 -0
  169. package/dist/utils/schemaConversion/sanitizeEntitySchema.spec.js +133 -0
  170. package/dist/utils/schemaConversion/sanitizeEntitySchema.spec.js.map +1 -0
  171. package/dist/utils/toStandardSchema.d.ts +5 -0
  172. package/dist/utils/toStandardSchema.d.ts.map +1 -0
  173. package/dist/utils/toStandardSchema.js +4 -0
  174. package/dist/utils/toStandardSchema.js.map +1 -0
  175. package/dist/utils/whereSchema.d.ts +9 -0
  176. package/dist/utils/whereSchema.d.ts.map +1 -0
  177. package/dist/utils/whereSchema.js +13 -0
  178. package/dist/utils/whereSchema.js.map +1 -0
  179. package/package.json +32 -10
  180. package/src/@types/assets.d.ts +3 -0
  181. package/src/defaultAccess.ts +3 -0
  182. package/src/defineTool.ts +44 -0
  183. package/src/endpoint/access.ts +119 -0
  184. package/src/endpoint/index.ts +48 -0
  185. package/src/exports/client.ts +3 -0
  186. package/src/exports/internal.ts +1 -0
  187. package/src/index.ts +29 -87
  188. package/src/mcp/buildMcpServer.ts +264 -0
  189. package/src/mcp/builtin/collections/authTools.ts +269 -0
  190. package/src/mcp/builtin/collections/countTool.ts +74 -0
  191. package/src/mcp/builtin/collections/countVersionsTool.ts +70 -0
  192. package/src/mcp/builtin/collections/createTool.ts +112 -0
  193. package/src/mcp/builtin/collections/deleteTool.ts +126 -0
  194. package/src/mcp/builtin/collections/duplicateTool.ts +135 -0
  195. package/src/mcp/builtin/collections/findDistinctTool.ts +120 -0
  196. package/src/mcp/builtin/collections/findTool.ts +217 -0
  197. package/src/mcp/builtin/collections/findVersionByIDTool.ts +110 -0
  198. package/src/mcp/builtin/collections/findVersionsTool.ts +155 -0
  199. package/src/mcp/builtin/collections/formatCollectionError.ts +84 -0
  200. package/src/mcp/builtin/collections/getCollectionSchemaTool.ts +46 -0
  201. package/src/mcp/builtin/collections/restoreVersionTool.ts +108 -0
  202. package/src/mcp/builtin/collections/updateTool.ts +211 -0
  203. package/src/mcp/builtin/getConfigInfoTool.ts +69 -0
  204. package/src/mcp/builtin/globals/countVersionsTool.ts +69 -0
  205. package/src/mcp/builtin/globals/findTool.ts +105 -0
  206. package/src/mcp/builtin/globals/findVersionByIDTool.ts +104 -0
  207. package/src/mcp/builtin/globals/findVersionsTool.ts +148 -0
  208. package/src/mcp/builtin/globals/getGlobalSchemaTool.ts +41 -0
  209. package/src/mcp/builtin/globals/restoreVersionTool.ts +100 -0
  210. package/src/mcp/builtin/globals/updateTool.ts +115 -0
  211. package/src/mcp/builtin/validateEntityData.ts +132 -0
  212. package/src/mcp/builtinTools.ts +154 -0
  213. package/src/mcp/sanitizeMCPConfig.ts +277 -0
  214. package/src/stdio.ts +113 -0
  215. package/src/types.ts +263 -493
  216. package/src/utils/getLogger.ts +22 -0
  217. package/src/utils/getPluginConfig.ts +24 -0
  218. package/src/utils/localAPIDefaults.ts +22 -0
  219. package/src/utils/resolveProjectRoot.ts +17 -0
  220. package/src/utils/schemaConversion/getEntityInputSchema.ts +62 -0
  221. package/src/utils/schemaConversion/sanitizeEntitySchema.spec.ts +96 -0
  222. package/src/utils/schemaConversion/sanitizeEntitySchema.ts +432 -0
  223. package/src/utils/toStandardSchema.ts +9 -0
  224. package/src/utils/whereSchema.ts +24 -0
  225. package/dist/collections/createApiKeysCollection.d.ts +0 -7
  226. package/dist/collections/createApiKeysCollection.d.ts.map +0 -1
  227. package/dist/collections/createApiKeysCollection.js +0 -317
  228. package/dist/collections/createApiKeysCollection.js.map +0 -1
  229. package/dist/defaults.d.ts +0 -4
  230. package/dist/defaults.d.ts.map +0 -1
  231. package/dist/defaults.js +0 -5
  232. package/dist/defaults.js.map +0 -1
  233. package/dist/endpoints/mcp.d.ts +0 -4
  234. package/dist/endpoints/mcp.d.ts.map +0 -1
  235. package/dist/endpoints/mcp.js +0 -71
  236. package/dist/endpoints/mcp.js.map +0 -1
  237. package/dist/mcp/createRequest.d.ts +0 -3
  238. package/dist/mcp/createRequest.d.ts.map +0 -1
  239. package/dist/mcp/createRequest.js +0 -14
  240. package/dist/mcp/createRequest.js.map +0 -1
  241. package/dist/mcp/getMcpHandler.d.ts +0 -4
  242. package/dist/mcp/getMcpHandler.d.ts.map +0 -1
  243. package/dist/mcp/getMcpHandler.js +0 -231
  244. package/dist/mcp/getMcpHandler.js.map +0 -1
  245. package/dist/mcp/helpers/config.d.ts +0 -22
  246. package/dist/mcp/helpers/config.d.ts.map +0 -1
  247. package/dist/mcp/helpers/config.js +0 -153
  248. package/dist/mcp/helpers/config.js.map +0 -1
  249. package/dist/mcp/helpers/fields.d.ts +0 -19
  250. package/dist/mcp/helpers/fields.d.ts.map +0 -1
  251. package/dist/mcp/helpers/fields.js +0 -102
  252. package/dist/mcp/helpers/fields.js.map +0 -1
  253. package/dist/mcp/helpers/fileValidation.d.ts +0 -67
  254. package/dist/mcp/helpers/fileValidation.d.ts.map +0 -1
  255. package/dist/mcp/helpers/fileValidation.js +0 -267
  256. package/dist/mcp/helpers/fileValidation.js.map +0 -1
  257. package/dist/mcp/registerTool.d.ts +0 -6
  258. package/dist/mcp/registerTool.d.ts.map +0 -1
  259. package/dist/mcp/registerTool.js +0 -18
  260. package/dist/mcp/registerTool.js.map +0 -1
  261. package/dist/mcp/tools/auth/auth.d.ts +0 -4
  262. package/dist/mcp/tools/auth/auth.d.ts.map +0 -1
  263. package/dist/mcp/tools/auth/auth.js +0 -57
  264. package/dist/mcp/tools/auth/auth.js.map +0 -1
  265. package/dist/mcp/tools/auth/forgotPassword.d.ts +0 -4
  266. package/dist/mcp/tools/auth/forgotPassword.d.ts.map +0 -1
  267. package/dist/mcp/tools/auth/forgotPassword.js +0 -48
  268. package/dist/mcp/tools/auth/forgotPassword.js.map +0 -1
  269. package/dist/mcp/tools/auth/login.d.ts +0 -4
  270. package/dist/mcp/tools/auth/login.d.ts.map +0 -1
  271. package/dist/mcp/tools/auth/login.js +0 -51
  272. package/dist/mcp/tools/auth/login.js.map +0 -1
  273. package/dist/mcp/tools/auth/resetPassword.d.ts +0 -4
  274. package/dist/mcp/tools/auth/resetPassword.d.ts.map +0 -1
  275. package/dist/mcp/tools/auth/resetPassword.js +0 -49
  276. package/dist/mcp/tools/auth/resetPassword.js.map +0 -1
  277. package/dist/mcp/tools/auth/unlock.d.ts +0 -4
  278. package/dist/mcp/tools/auth/unlock.d.ts.map +0 -1
  279. package/dist/mcp/tools/auth/unlock.js +0 -48
  280. package/dist/mcp/tools/auth/unlock.js.map +0 -1
  281. package/dist/mcp/tools/auth/verify.d.ts +0 -4
  282. package/dist/mcp/tools/auth/verify.d.ts.map +0 -1
  283. package/dist/mcp/tools/auth/verify.js +0 -45
  284. package/dist/mcp/tools/auth/verify.js.map +0 -1
  285. package/dist/mcp/tools/collection/create.d.ts +0 -10
  286. package/dist/mcp/tools/collection/create.d.ts.map +0 -1
  287. package/dist/mcp/tools/collection/create.js +0 -139
  288. package/dist/mcp/tools/collection/create.js.map +0 -1
  289. package/dist/mcp/tools/collection/delete.d.ts +0 -10
  290. package/dist/mcp/tools/collection/delete.d.ts.map +0 -1
  291. package/dist/mcp/tools/collection/delete.js +0 -154
  292. package/dist/mcp/tools/collection/delete.js.map +0 -1
  293. package/dist/mcp/tools/collection/find.d.ts +0 -10
  294. package/dist/mcp/tools/collection/find.d.ts.map +0 -1
  295. package/dist/mcp/tools/collection/find.js +0 -165
  296. package/dist/mcp/tools/collection/find.js.map +0 -1
  297. package/dist/mcp/tools/collection/update.d.ts +0 -10
  298. package/dist/mcp/tools/collection/update.d.ts.map +0 -1
  299. package/dist/mcp/tools/collection/update.js +0 -209
  300. package/dist/mcp/tools/collection/update.js.map +0 -1
  301. package/dist/mcp/tools/config/find.d.ts +0 -10
  302. package/dist/mcp/tools/config/find.d.ts.map +0 -1
  303. package/dist/mcp/tools/config/find.js +0 -97
  304. package/dist/mcp/tools/config/find.js.map +0 -1
  305. package/dist/mcp/tools/config/update.d.ts +0 -10
  306. package/dist/mcp/tools/config/update.d.ts.map +0 -1
  307. package/dist/mcp/tools/config/update.js +0 -215
  308. package/dist/mcp/tools/config/update.js.map +0 -1
  309. package/dist/mcp/tools/global/find.d.ts +0 -5
  310. package/dist/mcp/tools/global/find.d.ts.map +0 -1
  311. package/dist/mcp/tools/global/find.js +0 -82
  312. package/dist/mcp/tools/global/find.js.map +0 -1
  313. package/dist/mcp/tools/global/update.d.ts +0 -6
  314. package/dist/mcp/tools/global/update.d.ts.map +0 -1
  315. package/dist/mcp/tools/global/update.js +0 -124
  316. package/dist/mcp/tools/global/update.js.map +0 -1
  317. package/dist/mcp/tools/job/create.d.ts +0 -10
  318. package/dist/mcp/tools/job/create.d.ts.map +0 -1
  319. package/dist/mcp/tools/job/create.js +0 -293
  320. package/dist/mcp/tools/job/create.js.map +0 -1
  321. package/dist/mcp/tools/job/run.d.ts +0 -10
  322. package/dist/mcp/tools/job/run.d.ts.map +0 -1
  323. package/dist/mcp/tools/job/run.js +0 -129
  324. package/dist/mcp/tools/job/run.js.map +0 -1
  325. package/dist/mcp/tools/job/update.d.ts +0 -11
  326. package/dist/mcp/tools/job/update.d.ts.map +0 -1
  327. package/dist/mcp/tools/job/update.js +0 -186
  328. package/dist/mcp/tools/job/update.js.map +0 -1
  329. package/dist/mcp/tools/resource/create.d.ts +0 -6
  330. package/dist/mcp/tools/resource/create.d.ts.map +0 -1
  331. package/dist/mcp/tools/resource/create.js +0 -124
  332. package/dist/mcp/tools/resource/create.js.map +0 -1
  333. package/dist/mcp/tools/resource/delete.d.ts +0 -5
  334. package/dist/mcp/tools/resource/delete.d.ts.map +0 -1
  335. package/dist/mcp/tools/resource/delete.js +0 -151
  336. package/dist/mcp/tools/resource/delete.js.map +0 -1
  337. package/dist/mcp/tools/resource/find.d.ts +0 -5
  338. package/dist/mcp/tools/resource/find.d.ts.map +0 -1
  339. package/dist/mcp/tools/resource/find.js +0 -170
  340. package/dist/mcp/tools/resource/find.js.map +0 -1
  341. package/dist/mcp/tools/resource/update.d.ts +0 -6
  342. package/dist/mcp/tools/resource/update.d.ts.map +0 -1
  343. package/dist/mcp/tools/resource/update.js +0 -256
  344. package/dist/mcp/tools/resource/update.js.map +0 -1
  345. package/dist/mcp/tools/schemas.d.ts +0 -457
  346. package/dist/mcp/tools/schemas.d.ts.map +0 -1
  347. package/dist/mcp/tools/schemas.js +0 -243
  348. package/dist/mcp/tools/schemas.js.map +0 -1
  349. package/dist/utils/adminEntitySettings.d.ts +0 -17
  350. package/dist/utils/adminEntitySettings.d.ts.map +0 -1
  351. package/dist/utils/adminEntitySettings.js +0 -41
  352. package/dist/utils/adminEntitySettings.js.map +0 -1
  353. package/dist/utils/createApiKeyFields.d.ts +0 -15
  354. package/dist/utils/createApiKeyFields.d.ts.map +0 -1
  355. package/dist/utils/createApiKeyFields.js +0 -57
  356. package/dist/utils/createApiKeyFields.js.map +0 -1
  357. package/dist/utils/getEnabledSlugs.d.ts +0 -13
  358. package/dist/utils/getEnabledSlugs.d.ts.map +0 -1
  359. package/dist/utils/getEnabledSlugs.js +0 -32
  360. package/dist/utils/getEnabledSlugs.js.map +0 -1
  361. package/dist/utils/schemaConversion/convertCollectionSchemaToZod.d.ts +0 -3
  362. package/dist/utils/schemaConversion/convertCollectionSchemaToZod.d.ts.map +0 -1
  363. package/dist/utils/schemaConversion/convertCollectionSchemaToZod.js +0 -43
  364. package/dist/utils/schemaConversion/convertCollectionSchemaToZod.js.map +0 -1
  365. package/dist/utils/schemaConversion/removeVirtualFieldsFromSchema.d.ts +0 -7
  366. package/dist/utils/schemaConversion/removeVirtualFieldsFromSchema.d.ts.map +0 -1
  367. package/dist/utils/schemaConversion/removeVirtualFieldsFromSchema.js +0 -20
  368. package/dist/utils/schemaConversion/removeVirtualFieldsFromSchema.js.map +0 -1
  369. package/dist/utils/schemaConversion/sanitizeJsonSchema.d.ts +0 -13
  370. package/dist/utils/schemaConversion/sanitizeJsonSchema.d.ts.map +0 -1
  371. package/dist/utils/schemaConversion/sanitizeJsonSchema.js +0 -56
  372. package/dist/utils/schemaConversion/sanitizeJsonSchema.js.map +0 -1
  373. package/dist/utils/schemaConversion/simplifyRelationshipFields.d.ts +0 -20
  374. package/dist/utils/schemaConversion/simplifyRelationshipFields.d.ts.map +0 -1
  375. package/dist/utils/schemaConversion/simplifyRelationshipFields.js +0 -53
  376. package/dist/utils/schemaConversion/simplifyRelationshipFields.js.map +0 -1
  377. package/dist/utils/schemaConversion/transformPointFields.d.ts +0 -3
  378. package/dist/utils/schemaConversion/transformPointFields.d.ts.map +0 -1
  379. package/dist/utils/schemaConversion/transformPointFields.js +0 -51
  380. package/dist/utils/schemaConversion/transformPointFields.js.map +0 -1
  381. package/src/collections/createApiKeysCollection.ts +0 -373
  382. package/src/defaults.ts +0 -3
  383. package/src/endpoints/mcp.ts +0 -91
  384. package/src/mcp/createRequest.ts +0 -13
  385. package/src/mcp/getMcpHandler.ts +0 -545
  386. package/src/mcp/helpers/config.ts +0 -213
  387. package/src/mcp/helpers/fields.ts +0 -154
  388. package/src/mcp/helpers/fileValidation.ts +0 -362
  389. package/src/mcp/registerTool.ts +0 -22
  390. package/src/mcp/tools/auth/auth.ts +0 -71
  391. package/src/mcp/tools/auth/forgotPassword.ts +0 -70
  392. package/src/mcp/tools/auth/login.ts +0 -72
  393. package/src/mcp/tools/auth/resetPassword.ts +0 -61
  394. package/src/mcp/tools/auth/unlock.ts +0 -64
  395. package/src/mcp/tools/auth/verify.ts +0 -57
  396. package/src/mcp/tools/collection/create.ts +0 -210
  397. package/src/mcp/tools/collection/delete.ts +0 -211
  398. package/src/mcp/tools/collection/find.ts +0 -224
  399. package/src/mcp/tools/collection/update.ts +0 -290
  400. package/src/mcp/tools/config/find.ts +0 -128
  401. package/src/mcp/tools/config/update.ts +0 -280
  402. package/src/mcp/tools/global/find.ts +0 -128
  403. package/src/mcp/tools/global/update.ts +0 -207
  404. package/src/mcp/tools/job/create.ts +0 -416
  405. package/src/mcp/tools/job/run.ts +0 -167
  406. package/src/mcp/tools/job/update.ts +0 -274
  407. package/src/mcp/tools/resource/create.ts +0 -211
  408. package/src/mcp/tools/resource/delete.ts +0 -218
  409. package/src/mcp/tools/resource/find.ts +0 -246
  410. package/src/mcp/tools/resource/update.ts +0 -383
  411. package/src/mcp/tools/schemas.ts +0 -520
  412. package/src/utils/adminEntitySettings.ts +0 -40
  413. package/src/utils/createApiKeyFields.ts +0 -72
  414. package/src/utils/getEnabledSlugs.ts +0 -42
  415. package/src/utils/schemaConversion/convertCollectionSchemaToZod.ts +0 -52
  416. package/src/utils/schemaConversion/removeVirtualFieldsFromSchema.ts +0 -27
  417. package/src/utils/schemaConversion/sanitizeJsonSchema.ts +0 -62
  418. package/src/utils/schemaConversion/simplifyRelationshipFields.ts +0 -65
  419. package/src/utils/schemaConversion/transformPointFields.ts +0 -55
@@ -0,0 +1,148 @@
1
+ import type { PopulateType, SelectType } from 'payload'
2
+
3
+ import { z } from 'zod'
4
+
5
+ import { defaultAccess } from '../../../defaultAccess.js'
6
+ import { defineGlobalTool } from '../../../defineTool.js'
7
+ import { getLogger } from '../../../utils/getLogger.js'
8
+ import { localAPIDefaults } from '../../../utils/localAPIDefaults.js'
9
+ import { whereSchema } from '../../../utils/whereSchema.js'
10
+
11
+ const DEFAULT_DESCRIPTION =
12
+ 'Find global versions in any version-enabled global by passing the global slug and optional where clause.'
13
+
14
+ export const findGlobalVersionsTool = defineGlobalTool({
15
+ access: (args) =>
16
+ defaultAccess(args) && Boolean(args.permissions?.globals?.[args.globalSlug]?.readVersions),
17
+ annotations: {
18
+ destructiveHint: false,
19
+ idempotentHint: true,
20
+ openWorldHint: false,
21
+ readOnlyHint: true,
22
+ title: 'Find Global Versions',
23
+ },
24
+ description: DEFAULT_DESCRIPTION,
25
+ input: z.object({
26
+ depth: z
27
+ .number()
28
+ .int()
29
+ .min(0)
30
+ .max(10)
31
+ .describe('How many levels deep to populate relationships in global version documents')
32
+ .optional()
33
+ .default(0),
34
+ fallbackLocale: z
35
+ .string()
36
+ .describe('Optional: fallback locale code to use when requested locale is not available')
37
+ .optional(),
38
+ limit: z
39
+ .number()
40
+ .int()
41
+ .min(1)
42
+ .max(100)
43
+ .describe('Maximum number of versions to return (default: 10, max: 100)')
44
+ .optional()
45
+ .default(10),
46
+ locale: z
47
+ .string()
48
+ .describe(
49
+ 'Optional: locale code to retrieve data in (e.g., "en", "es"). Use "all" to retrieve all locales for localized fields',
50
+ )
51
+ .optional(),
52
+ page: z
53
+ .number()
54
+ .int()
55
+ .min(1)
56
+ .describe('Page number for pagination (default: 1)')
57
+ .optional()
58
+ .default(1),
59
+ pagination: z
60
+ .boolean()
61
+ .describe('Optional: set to false to skip the count query overhead')
62
+ .optional(),
63
+ populate: z
64
+ .record(z.string(), z.unknown())
65
+ .describe(
66
+ 'Optional: control which fields to include from populated relationship or upload documents.',
67
+ )
68
+ .optional(),
69
+ select: z
70
+ .record(z.string(), z.unknown())
71
+ .describe(
72
+ 'Optional: define exactly which fields you\'d like to return in the response, e.g., {"version.siteName": true}',
73
+ )
74
+ .optional(),
75
+ showHiddenFields: z
76
+ .boolean()
77
+ .describe('Optional: include hidden fields in returned global version documents')
78
+ .optional(),
79
+ sort: z
80
+ .string()
81
+ .describe('Field to sort by (e.g., "-updatedAt", "-version.updatedAt" for descending)')
82
+ .optional(),
83
+ where: whereSchema
84
+ .describe(
85
+ 'Optional: where clause for filtering versions. Version document fields are usually under "version". Example: {"version.siteName":{"contains":"test"}}',
86
+ )
87
+ .optional(),
88
+ }),
89
+ }).handler(async ({ authorizedMCP, globalSlug, input, req }) => {
90
+ const payload = req.payload
91
+ const logger = getLogger({ payload })
92
+ const {
93
+ depth,
94
+ fallbackLocale,
95
+ limit,
96
+ locale,
97
+ page,
98
+ pagination,
99
+ populate,
100
+ select,
101
+ showHiddenFields,
102
+ sort,
103
+ where,
104
+ } = input
105
+
106
+ logger.info(`Finding versions for global: ${globalSlug}, limit: ${limit}, page: ${page}`)
107
+
108
+ try {
109
+ const result = await payload.findGlobalVersions({
110
+ slug: globalSlug,
111
+ depth,
112
+ limit,
113
+ page,
114
+ req,
115
+ ...localAPIDefaults(authorizedMCP),
116
+ ...(fallbackLocale ? { fallbackLocale } : {}),
117
+ ...(locale ? { locale } : {}),
118
+ ...(pagination !== undefined ? { pagination } : {}),
119
+ ...(populate ? { populate: populate as PopulateType } : {}),
120
+ ...(select ? { select: select as SelectType } : {}),
121
+ ...(showHiddenFields !== undefined ? { showHiddenFields } : {}),
122
+ ...(sort ? { sort } : {}),
123
+ ...(where ? { where } : {}),
124
+ })
125
+
126
+ return {
127
+ content: [
128
+ {
129
+ type: 'text',
130
+ text: `Versions for global "${globalSlug}":\n\`\`\`json\n${JSON.stringify(result)}\n\`\`\``,
131
+ },
132
+ ],
133
+ doc: result as unknown as Record<string, unknown>,
134
+ }
135
+ } catch (error) {
136
+ const errorMessage = error instanceof Error ? error.message : 'Unknown error'
137
+ logger.error(`Error finding versions for global ${globalSlug}: ${errorMessage}`)
138
+ return {
139
+ content: [
140
+ {
141
+ type: 'text',
142
+ text: `❌ **Error finding versions for global "${globalSlug}":** ${errorMessage}`,
143
+ },
144
+ ],
145
+ isError: true,
146
+ }
147
+ }
148
+ })
@@ -0,0 +1,41 @@
1
+ import { defaultAccess } from '../../../defaultAccess.js'
2
+ import { defineGlobalTool } from '../../../defineTool.js'
3
+ import { getGlobalInputSchema } from '../../../utils/schemaConversion/getEntityInputSchema.js'
4
+
5
+ export const getGlobalSchemaTool = defineGlobalTool({
6
+ access: (args) => {
7
+ const permissions = args.permissions?.globals?.[args.globalSlug]
8
+
9
+ return defaultAccess(args) && Boolean(permissions?.read || permissions?.update)
10
+ },
11
+ annotations: {
12
+ destructiveHint: false,
13
+ idempotentHint: true,
14
+ openWorldHint: false,
15
+ readOnlyHint: true,
16
+ title: 'Get Global Schema',
17
+ },
18
+ description: 'Get the input schema for updating a global.',
19
+ }).handler(({ globalSlug, req }) => {
20
+ const inputSchema = getGlobalInputSchema({ globalSlug, req })
21
+
22
+ if (!inputSchema) {
23
+ return {
24
+ content: [{ type: 'text', text: `Error: Global "${globalSlug}" not found` }],
25
+ isError: true,
26
+ }
27
+ }
28
+
29
+ return {
30
+ content: [
31
+ {
32
+ type: 'text',
33
+ text: `Schema for global "${globalSlug}":\n\`\`\`json\n${JSON.stringify(inputSchema)}\n\`\`\``,
34
+ },
35
+ ],
36
+ structuredContent: {
37
+ globalSlug,
38
+ schema: inputSchema,
39
+ },
40
+ }
41
+ })
@@ -0,0 +1,100 @@
1
+ import type { PopulateType } from 'payload'
2
+
3
+ import { z } from 'zod'
4
+
5
+ import { defaultAccess } from '../../../defaultAccess.js'
6
+ import { defineGlobalTool } from '../../../defineTool.js'
7
+ import { getLogger } from '../../../utils/getLogger.js'
8
+ import { localAPIDefaults } from '../../../utils/localAPIDefaults.js'
9
+
10
+ const DEFAULT_DESCRIPTION =
11
+ 'Restore a global from a previous version in any version-enabled global.'
12
+
13
+ export const restoreGlobalVersionTool = defineGlobalTool({
14
+ access: (args) =>
15
+ defaultAccess(args) && Boolean(args.permissions?.globals?.[args.globalSlug]?.update),
16
+ annotations: {
17
+ destructiveHint: true,
18
+ idempotentHint: false,
19
+ openWorldHint: false,
20
+ readOnlyHint: false,
21
+ title: 'Restore Global Version',
22
+ },
23
+ description: DEFAULT_DESCRIPTION,
24
+ input: z.object({
25
+ id: z.string().describe('The ID of the global version to restore'),
26
+ depth: z
27
+ .number()
28
+ .int()
29
+ .min(0)
30
+ .max(10)
31
+ .describe('How many levels deep to populate relationships in response')
32
+ .optional()
33
+ .default(0),
34
+ fallbackLocale: z
35
+ .string()
36
+ .describe('Optional: fallback locale code to use when requested locale is not available')
37
+ .optional(),
38
+ locale: z
39
+ .string()
40
+ .describe('Optional: locale code to restore in (e.g., "en", "es")')
41
+ .optional(),
42
+ populate: z
43
+ .record(z.string(), z.unknown())
44
+ .describe(
45
+ 'Optional: control which fields to include from populated relationship or upload documents.',
46
+ )
47
+ .optional(),
48
+ showHiddenFields: z
49
+ .boolean()
50
+ .describe('Optional: include hidden fields in the restored global response')
51
+ .optional(),
52
+ }),
53
+ }).handler(async ({ authorizedMCP, globalSlug, input, req }) => {
54
+ const payload = req.payload
55
+ const logger = getLogger({ payload })
56
+ const { id, depth, fallbackLocale, locale, populate, showHiddenFields } = input
57
+
58
+ logger.info(`Restoring version for global: ${globalSlug} with ID: ${id}`)
59
+
60
+ try {
61
+ const result = await payload.restoreGlobalVersion({
62
+ id,
63
+ slug: globalSlug,
64
+ depth,
65
+ req,
66
+ ...localAPIDefaults(authorizedMCP),
67
+ ...(fallbackLocale ? { fallbackLocale } : {}),
68
+ ...(locale ? { locale } : {}),
69
+ ...(populate ? { populate: populate as PopulateType } : {}),
70
+ ...(showHiddenFields !== undefined ? { showHiddenFields } : {}),
71
+ })
72
+ const resultObject = result as Record<string, unknown>
73
+ const restoredGlobal =
74
+ resultObject.version && typeof resultObject.version === 'object'
75
+ ? (resultObject.version as Record<string, unknown>)
76
+ : resultObject
77
+
78
+ return {
79
+ content: [
80
+ {
81
+ type: 'text',
82
+ text: `Version "${id}" restored successfully for global "${globalSlug}"!\nRestored global:\n\`\`\`json\n${JSON.stringify(restoredGlobal)}\n\`\`\``,
83
+ },
84
+ ],
85
+ doc: restoredGlobal,
86
+ }
87
+ } catch (error) {
88
+ const errorMessage = error instanceof Error ? error.message : 'Unknown error'
89
+ logger.error(`Error restoring version ${id} for global ${globalSlug}: ${errorMessage}`)
90
+ return {
91
+ content: [
92
+ {
93
+ type: 'text',
94
+ text: `❌ **Error restoring version "${id}" for global "${globalSlug}":** ${errorMessage}`,
95
+ },
96
+ ],
97
+ isError: true,
98
+ }
99
+ }
100
+ })
@@ -0,0 +1,115 @@
1
+ import type { SelectType } from 'payload'
2
+
3
+ import { z } from 'zod'
4
+
5
+ import { defaultAccess } from '../../../defaultAccess.js'
6
+ import { defineGlobalTool } from '../../../defineTool.js'
7
+ import { getLogger } from '../../../utils/getLogger.js'
8
+ import {
9
+ getGlobalVirtualFieldNames,
10
+ stripVirtualFields,
11
+ } from '../../../utils/getVirtualFieldNames.js'
12
+ import { localAPIDefaults } from '../../../utils/localAPIDefaults.js'
13
+ import { transformPointDataToPayload } from '../../../utils/transformPointDataToPayload.js'
14
+ import { validateGlobalData } from '../validateEntityData.js'
15
+
16
+ const DEFAULT_DESCRIPTION = 'Update any Payload global by passing the global slug and data.'
17
+
18
+ export const updateGlobalTool = defineGlobalTool({
19
+ access: (args) =>
20
+ defaultAccess(args) && Boolean(args.permissions?.globals?.[args.globalSlug]?.update),
21
+ annotations: {
22
+ destructiveHint: true,
23
+ idempotentHint: false,
24
+ openWorldHint: false,
25
+ readOnlyHint: false,
26
+ title: 'Update Global',
27
+ },
28
+ description: DEFAULT_DESCRIPTION,
29
+ input: z.object({
30
+ data: z.record(z.string(), z.unknown()).describe('The global fields to update'),
31
+ depth: z
32
+ .number()
33
+ .describe('Optional: Depth of relationships to populate')
34
+ .optional()
35
+ .default(0),
36
+ draft: z
37
+ .boolean()
38
+ .describe('Optional: Whether to save as draft (default: false)')
39
+ .optional()
40
+ .default(false),
41
+ fallbackLocale: z
42
+ .string()
43
+ .describe('Optional: fallback locale code to use when requested locale is not available')
44
+ .optional(),
45
+ locale: z
46
+ .string()
47
+ .describe(
48
+ 'Optional: locale code to update data in (e.g., "en", "es"). Use "all" to update all locales for localized fields',
49
+ )
50
+ .optional(),
51
+ select: z
52
+ .record(z.string(), z.unknown())
53
+ .describe(
54
+ 'Optional: define exactly which fields you\'d like to return in the response, e.g., {"siteName": true}',
55
+ )
56
+ .optional(),
57
+ }),
58
+ }).handler(async ({ authorizedMCP, globalSlug, input, req }) => {
59
+ const payload = req.payload
60
+ const logger = getLogger({ payload })
61
+
62
+ const { data, depth, draft, fallbackLocale, locale, select } = input
63
+
64
+ logger.info(
65
+ `Updating global: ${globalSlug}, draft: ${draft}${locale ? `, locale: ${locale}` : ''}`,
66
+ )
67
+
68
+ try {
69
+ const virtualFieldNames = getGlobalVirtualFieldNames(payload.config, globalSlug)
70
+ const inputData = stripVirtualFields(data, virtualFieldNames)
71
+ const validationError = validateGlobalData({ data: inputData, globalSlug, req })
72
+
73
+ if (validationError) {
74
+ return validationError
75
+ }
76
+
77
+ const parsedData = transformPointDataToPayload(inputData)
78
+
79
+ const updateOptions: Parameters<typeof payload.updateGlobal>[0] = {
80
+ slug: globalSlug,
81
+ data: parsedData,
82
+ depth,
83
+ draft,
84
+ ...localAPIDefaults(authorizedMCP),
85
+ }
86
+
87
+ if (locale) {
88
+ updateOptions.locale = locale
89
+ }
90
+ if (fallbackLocale) {
91
+ updateOptions.fallbackLocale = fallbackLocale
92
+ }
93
+ if (select) {
94
+ updateOptions.select = select as SelectType
95
+ }
96
+
97
+ const result = await payload.updateGlobal(updateOptions)
98
+
99
+ return {
100
+ content: [
101
+ {
102
+ type: 'text',
103
+ text: `Global "${globalSlug}" updated successfully!\n\`\`\`json\n${JSON.stringify(result)}\n\`\`\``,
104
+ },
105
+ ],
106
+ doc: result as Record<string, unknown>,
107
+ }
108
+ } catch (error) {
109
+ const errorMessage = error instanceof Error ? error.message : 'Unknown error'
110
+ logger.error(`Error updating global ${globalSlug}: ${errorMessage}`)
111
+ return {
112
+ content: [{ type: 'text', text: `Error updating global "${globalSlug}": ${errorMessage}` }],
113
+ }
114
+ }
115
+ })
@@ -0,0 +1,132 @@
1
+ import type { CollectionSlug, GlobalSlug, PayloadRequest, SanitizedConfig } from 'payload'
2
+
3
+ import { CfWorkerJsonSchemaValidator } from '@modelcontextprotocol/server'
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,154 @@
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 { createDocumentTool } 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 { getConfigInfoTool } from './builtin/getConfigInfoTool.js'
24
+ import { countGlobalVersionsTool } from './builtin/globals/countVersionsTool.js'
25
+ import { findGlobalTool } from './builtin/globals/findTool.js'
26
+ import { findGlobalVersionByIDTool } from './builtin/globals/findVersionByIDTool.js'
27
+ import { findGlobalVersionsTool } from './builtin/globals/findVersionsTool.js'
28
+ import { getGlobalSchemaTool } from './builtin/globals/getGlobalSchemaTool.js'
29
+ import { restoreGlobalVersionTool } from './builtin/globals/restoreVersionTool.js'
30
+ import { updateGlobalTool } from './builtin/globals/updateTool.js'
31
+
32
+ type CollectionBuiltin = {
33
+ mcpName: string
34
+ requiresDuplicateEnabled?: boolean
35
+ requiresVersions?: boolean
36
+ tool: CollectionTool
37
+ }
38
+
39
+ type GlobalBuiltin = {
40
+ mcpName: string
41
+ requiresVersions?: boolean
42
+ tool: GlobalTool
43
+ }
44
+
45
+ export const TOOL_BUILTINS = {
46
+ getConfigInfo: { mcpName: 'getConfigInfo', tool: getConfigInfoTool },
47
+ } satisfies Record<string, { mcpName: string; tool: Tool }>
48
+
49
+ /**
50
+ * The static built-in collection CRUD tools. Keys here are the source of truth
51
+ * for `MCPCollectionBuiltinName` — adding/removing an entry updates the type
52
+ * automatically.
53
+ */
54
+ export const COLLECTION_BUILTINS = {
55
+ count: { mcpName: 'countDocuments', tool: countDocumentsTool },
56
+ countVersions: { mcpName: 'countVersions', requiresVersions: true, tool: countVersionsTool },
57
+ create: { mcpName: 'createDocument', tool: createDocumentTool },
58
+ delete: { mcpName: 'deleteDocuments', tool: deleteDocumentsTool },
59
+ duplicate: {
60
+ mcpName: 'duplicateDocument',
61
+ requiresDuplicateEnabled: true,
62
+ tool: duplicateDocumentTool,
63
+ },
64
+ find: { mcpName: 'findDocuments', tool: findDocumentsTool },
65
+ findDistinct: { mcpName: 'findDistinct', tool: findDistinctTool },
66
+ findVersionByID: {
67
+ mcpName: 'findVersionByID',
68
+ requiresVersions: true,
69
+ tool: findVersionByIDTool,
70
+ },
71
+ findVersions: { mcpName: 'findVersions', requiresVersions: true, tool: findVersionsTool },
72
+ getCollectionSchema: { mcpName: 'getCollectionSchema', tool: getCollectionSchemaTool },
73
+ restoreVersion: { mcpName: 'restoreVersion', requiresVersions: true, tool: restoreVersionTool },
74
+ update: { mcpName: 'updateDocument', tool: updateDocumentTool },
75
+ } satisfies Record<string, CollectionBuiltin>
76
+
77
+ /**
78
+ * The static auth tools surfaced under auth-enabled collections. Keys are the
79
+ * source of truth for `MCPCollectionAuthToolName`.
80
+ */
81
+ export const COLLECTION_AUTH_BUILTINS = {
82
+ auth: { mcpName: 'auth', tool: authCollectionTool },
83
+ forgotPassword: {
84
+ mcpName: 'forgotPassword',
85
+ tool: forgotPasswordCollectionTool,
86
+ },
87
+ login: { mcpName: 'login', tool: loginCollectionTool },
88
+ resetPassword: {
89
+ mcpName: 'resetPassword',
90
+ tool: resetPasswordCollectionTool,
91
+ },
92
+ unlock: { mcpName: 'unlock', tool: unlockCollectionTool },
93
+ verify: { mcpName: 'verify', tool: verifyCollectionTool },
94
+ } satisfies Record<string, { mcpName: string; tool: CollectionTool }>
95
+
96
+ /**
97
+ * The static built-in global tools. Keys are the source of truth for
98
+ * `MCPGlobalBuiltinName`.
99
+ */
100
+ export const GLOBAL_BUILTINS = {
101
+ countGlobalVersions: {
102
+ mcpName: 'countGlobalVersions',
103
+ requiresVersions: true,
104
+ tool: countGlobalVersionsTool,
105
+ },
106
+ find: { mcpName: 'findGlobal', tool: findGlobalTool },
107
+ findGlobalVersionByID: {
108
+ mcpName: 'findGlobalVersionByID',
109
+ requiresVersions: true,
110
+ tool: findGlobalVersionByIDTool,
111
+ },
112
+ findGlobalVersions: {
113
+ mcpName: 'findGlobalVersions',
114
+ requiresVersions: true,
115
+ tool: findGlobalVersionsTool,
116
+ },
117
+ getGlobalSchema: { mcpName: 'getGlobalSchema', tool: getGlobalSchemaTool },
118
+ restoreGlobalVersion: {
119
+ mcpName: 'restoreGlobalVersion',
120
+ requiresVersions: true,
121
+ tool: restoreGlobalVersionTool,
122
+ },
123
+ update: { mcpName: 'updateGlobal', tool: updateGlobalTool },
124
+ } satisfies Record<string, GlobalBuiltin>
125
+
126
+ export type MCPCollectionBuiltinName = keyof typeof COLLECTION_BUILTINS
127
+
128
+ export type MCPCollectionAuthToolName = keyof typeof COLLECTION_AUTH_BUILTINS
129
+
130
+ export type MCPGlobalBuiltinName = keyof typeof GLOBAL_BUILTINS
131
+
132
+ export type MCPTopLevelBuiltinName = keyof typeof TOOL_BUILTINS
133
+
134
+ /**
135
+ * Pre-typed `Object.entries` for each registry. The cast from `string` to the
136
+ * literal key union lives here once so consumers can iterate without their own
137
+ * cast — TypeScript's `Object.entries` always widens keys to `string`, which
138
+ * defeats the narrow type lookups on `MCPCollectionToolsMap`.
139
+ */
140
+ export const TOOL_BUILTIN_ENTRIES = Object.entries(TOOL_BUILTINS) as Array<
141
+ [MCPTopLevelBuiltinName, (typeof TOOL_BUILTINS)[MCPTopLevelBuiltinName]]
142
+ >
143
+
144
+ export const COLLECTION_BUILTIN_ENTRIES = Object.entries(COLLECTION_BUILTINS) as Array<
145
+ [MCPCollectionBuiltinName, CollectionBuiltin]
146
+ >
147
+
148
+ export const COLLECTION_AUTH_BUILTIN_ENTRIES = Object.entries(COLLECTION_AUTH_BUILTINS) as Array<
149
+ [MCPCollectionAuthToolName, (typeof COLLECTION_AUTH_BUILTINS)[MCPCollectionAuthToolName]]
150
+ >
151
+
152
+ export const GLOBAL_BUILTIN_ENTRIES = Object.entries(GLOBAL_BUILTINS) as Array<
153
+ [MCPGlobalBuiltinName, GlobalBuiltin]
154
+ >