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

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 (424) 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 +96 -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 +20 -0
  60. package/dist/mcp/builtin/collections/fileInput.d.ts.map +1 -0
  61. package/dist/mcp/builtin/collections/fileInput.js +100 -0
  62. package/dist/mcp/builtin/collections/fileInput.js.map +1 -0
  63. package/dist/mcp/builtin/collections/fileInput.spec.js +72 -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 +86 -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/getConfigInfoTool.d.ts +2 -0
  98. package/dist/mcp/builtin/getConfigInfoTool.d.ts.map +1 -0
  99. package/dist/mcp/builtin/getConfigInfoTool.js +68 -0
  100. package/dist/mcp/builtin/getConfigInfoTool.js.map +1 -0
  101. package/dist/mcp/builtin/globals/countVersionsTool.d.ts +2 -0
  102. package/dist/mcp/builtin/globals/countVersionsTool.d.ts.map +1 -0
  103. package/dist/mcp/builtin/globals/countVersionsTool.js +64 -0
  104. package/dist/mcp/builtin/globals/countVersionsTool.js.map +1 -0
  105. package/dist/mcp/builtin/globals/findTool.d.ts +2 -0
  106. package/dist/mcp/builtin/globals/findTool.d.ts.map +1 -0
  107. package/dist/mcp/builtin/globals/findTool.js +73 -0
  108. package/dist/mcp/builtin/globals/findTool.js.map +1 -0
  109. package/dist/mcp/builtin/globals/findVersionByIDTool.d.ts +2 -0
  110. package/dist/mcp/builtin/globals/findVersionByIDTool.d.ts.map +1 -0
  111. package/dist/mcp/builtin/globals/findVersionByIDTool.js +79 -0
  112. package/dist/mcp/builtin/globals/findVersionByIDTool.js.map +1 -0
  113. package/dist/mcp/builtin/globals/findVersionsTool.d.ts +2 -0
  114. package/dist/mcp/builtin/globals/findVersionsTool.d.ts.map +1 -0
  115. package/dist/mcp/builtin/globals/findVersionsTool.js +94 -0
  116. package/dist/mcp/builtin/globals/findVersionsTool.js.map +1 -0
  117. package/dist/mcp/builtin/globals/getGlobalSchemaTool.d.ts +2 -0
  118. package/dist/mcp/builtin/globals/getGlobalSchemaTool.d.ts.map +1 -0
  119. package/dist/mcp/builtin/globals/getGlobalSchemaTool.js +65 -0
  120. package/dist/mcp/builtin/globals/getGlobalSchemaTool.js.map +1 -0
  121. package/dist/mcp/builtin/globals/restoreVersionTool.d.ts +2 -0
  122. package/dist/mcp/builtin/globals/restoreVersionTool.d.ts.map +1 -0
  123. package/dist/mcp/builtin/globals/restoreVersionTool.js +77 -0
  124. package/dist/mcp/builtin/globals/restoreVersionTool.js.map +1 -0
  125. package/dist/mcp/builtin/globals/updateTool.d.ts +2 -0
  126. package/dist/mcp/builtin/globals/updateTool.d.ts.map +1 -0
  127. package/dist/mcp/builtin/globals/updateTool.js +87 -0
  128. package/dist/mcp/builtin/globals/updateTool.js.map +1 -0
  129. package/dist/mcp/builtin/validateEntityData.d.ts +14 -0
  130. package/dist/mcp/builtin/validateEntityData.d.ts.map +1 -0
  131. package/dist/mcp/builtin/validateEntityData.js +82 -0
  132. package/dist/mcp/builtin/validateEntityData.js.map +1 -0
  133. package/dist/mcp/builtinTools.d.ts +162 -0
  134. package/dist/mcp/builtinTools.d.ts.map +1 -0
  135. package/dist/mcp/builtinTools.js +163 -0
  136. package/dist/mcp/builtinTools.js.map +1 -0
  137. package/dist/mcp/sanitizeMCPConfig.d.ts +16 -0
  138. package/dist/mcp/sanitizeMCPConfig.d.ts.map +1 -0
  139. package/dist/mcp/sanitizeMCPConfig.js +230 -0
  140. package/dist/mcp/sanitizeMCPConfig.js.map +1 -0
  141. package/dist/stdio.d.ts +8 -0
  142. package/dist/stdio.d.ts.map +1 -0
  143. package/dist/stdio.js +126 -0
  144. package/dist/stdio.js.map +1 -0
  145. package/dist/types.d.ts +256 -447
  146. package/dist/types.d.ts.map +1 -1
  147. package/dist/types.js +4 -1
  148. package/dist/types.js.map +1 -1
  149. package/dist/utils/getLogger.d.ts +10 -0
  150. package/dist/utils/getLogger.d.ts.map +1 -0
  151. package/dist/utils/getLogger.js +22 -0
  152. package/dist/utils/getLogger.js.map +1 -0
  153. package/dist/utils/getPluginConfig.d.ts +12 -0
  154. package/dist/utils/getPluginConfig.d.ts.map +1 -0
  155. package/dist/utils/getPluginConfig.js +15 -0
  156. package/dist/utils/getPluginConfig.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/filterFieldsByAccess.d.ts +28 -0
  162. package/dist/utils/schemaConversion/filterFieldsByAccess.d.ts.map +1 -0
  163. package/dist/utils/schemaConversion/filterFieldsByAccess.js +71 -0
  164. package/dist/utils/schemaConversion/filterFieldsByAccess.js.map +1 -0
  165. package/dist/utils/schemaConversion/getEntityInputSchema.d.ts +13 -0
  166. package/dist/utils/schemaConversion/getEntityInputSchema.d.ts.map +1 -0
  167. package/dist/utils/schemaConversion/getEntityInputSchema.js +66 -0
  168. package/dist/utils/schemaConversion/getEntityInputSchema.js.map +1 -0
  169. package/dist/utils/schemaConversion/sanitizeEntitySchema.d.ts +10 -0
  170. package/dist/utils/schemaConversion/sanitizeEntitySchema.d.ts.map +1 -0
  171. package/dist/utils/schemaConversion/sanitizeEntitySchema.js +384 -0
  172. package/dist/utils/schemaConversion/sanitizeEntitySchema.js.map +1 -0
  173. package/dist/utils/schemaConversion/sanitizeEntitySchema.spec.js +133 -0
  174. package/dist/utils/schemaConversion/sanitizeEntitySchema.spec.js.map +1 -0
  175. package/dist/utils/toStandardSchema.d.ts +5 -0
  176. package/dist/utils/toStandardSchema.d.ts.map +1 -0
  177. package/dist/utils/toStandardSchema.js +4 -0
  178. package/dist/utils/toStandardSchema.js.map +1 -0
  179. package/dist/utils/whereSchema.d.ts +9 -0
  180. package/dist/utils/whereSchema.d.ts.map +1 -0
  181. package/dist/utils/whereSchema.js +13 -0
  182. package/dist/utils/whereSchema.js.map +1 -0
  183. package/package.json +30 -10
  184. package/src/defaultAccess.ts +3 -0
  185. package/src/defineTool.ts +44 -0
  186. package/src/endpoint/access.ts +112 -0
  187. package/src/endpoint/index.ts +77 -0
  188. package/src/exports/client.ts +3 -0
  189. package/src/exports/internal.ts +1 -0
  190. package/src/index.ts +31 -89
  191. package/src/mcp/buildMcpServer.ts +284 -0
  192. package/src/mcp/builtin/collections/authTools.ts +269 -0
  193. package/src/mcp/builtin/collections/countTool.ts +73 -0
  194. package/src/mcp/builtin/collections/countVersionsTool.ts +69 -0
  195. package/src/mcp/builtin/collections/createTool.ts +121 -0
  196. package/src/mcp/builtin/collections/deleteTool.ts +125 -0
  197. package/src/mcp/builtin/collections/duplicateTool.ts +134 -0
  198. package/src/mcp/builtin/collections/fileInput.spec.ts +79 -0
  199. package/src/mcp/builtin/collections/fileInput.ts +139 -0
  200. package/src/mcp/builtin/collections/findDistinctTool.ts +119 -0
  201. package/src/mcp/builtin/collections/findTool.ts +216 -0
  202. package/src/mcp/builtin/collections/findVersionByIDTool.ts +109 -0
  203. package/src/mcp/builtin/collections/findVersionsTool.ts +154 -0
  204. package/src/mcp/builtin/collections/formatCollectionError.ts +84 -0
  205. package/src/mcp/builtin/collections/getCollectionSchemaTool.ts +76 -0
  206. package/src/mcp/builtin/collections/restoreVersionTool.ts +107 -0
  207. package/src/mcp/builtin/collections/updateTool.ts +227 -0
  208. package/src/mcp/builtin/getConfigInfoTool.ts +67 -0
  209. package/src/mcp/builtin/globals/countVersionsTool.ts +68 -0
  210. package/src/mcp/builtin/globals/findTool.ts +105 -0
  211. package/src/mcp/builtin/globals/findVersionByIDTool.ts +103 -0
  212. package/src/mcp/builtin/globals/findVersionsTool.ts +147 -0
  213. package/src/mcp/builtin/globals/getGlobalSchemaTool.ts +63 -0
  214. package/src/mcp/builtin/globals/restoreVersionTool.ts +99 -0
  215. package/src/mcp/builtin/globals/updateTool.ts +115 -0
  216. package/src/mcp/builtin/validateEntityData.ts +132 -0
  217. package/src/mcp/builtinTools.ts +154 -0
  218. package/src/mcp/sanitizeMCPConfig.ts +278 -0
  219. package/src/stdio.ts +130 -0
  220. package/src/types.ts +304 -486
  221. package/src/utils/getLogger.ts +22 -0
  222. package/src/utils/getPluginConfig.ts +24 -0
  223. package/src/utils/resolveProjectRoot.ts +17 -0
  224. package/src/utils/schemaConversion/filterFieldsByAccess.ts +123 -0
  225. package/src/utils/schemaConversion/getEntityInputSchema.ts +96 -0
  226. package/src/utils/schemaConversion/sanitizeEntitySchema.spec.ts +96 -0
  227. package/src/utils/schemaConversion/sanitizeEntitySchema.ts +432 -0
  228. package/src/utils/toStandardSchema.ts +9 -0
  229. package/src/utils/whereSchema.ts +24 -0
  230. package/dist/collections/createApiKeysCollection.d.ts +0 -7
  231. package/dist/collections/createApiKeysCollection.d.ts.map +0 -1
  232. package/dist/collections/createApiKeysCollection.js +0 -317
  233. package/dist/collections/createApiKeysCollection.js.map +0 -1
  234. package/dist/defaults.d.ts +0 -4
  235. package/dist/defaults.d.ts.map +0 -1
  236. package/dist/defaults.js +0 -5
  237. package/dist/defaults.js.map +0 -1
  238. package/dist/endpoints/mcp.d.ts +0 -4
  239. package/dist/endpoints/mcp.d.ts.map +0 -1
  240. package/dist/endpoints/mcp.js +0 -71
  241. package/dist/endpoints/mcp.js.map +0 -1
  242. package/dist/mcp/createRequest.d.ts +0 -3
  243. package/dist/mcp/createRequest.d.ts.map +0 -1
  244. package/dist/mcp/createRequest.js +0 -14
  245. package/dist/mcp/createRequest.js.map +0 -1
  246. package/dist/mcp/getMcpHandler.d.ts +0 -4
  247. package/dist/mcp/getMcpHandler.d.ts.map +0 -1
  248. package/dist/mcp/getMcpHandler.js +0 -231
  249. package/dist/mcp/getMcpHandler.js.map +0 -1
  250. package/dist/mcp/helpers/config.d.ts +0 -22
  251. package/dist/mcp/helpers/config.d.ts.map +0 -1
  252. package/dist/mcp/helpers/config.js +0 -153
  253. package/dist/mcp/helpers/config.js.map +0 -1
  254. package/dist/mcp/helpers/fields.d.ts +0 -19
  255. package/dist/mcp/helpers/fields.d.ts.map +0 -1
  256. package/dist/mcp/helpers/fields.js +0 -102
  257. package/dist/mcp/helpers/fields.js.map +0 -1
  258. package/dist/mcp/helpers/fileValidation.d.ts +0 -67
  259. package/dist/mcp/helpers/fileValidation.d.ts.map +0 -1
  260. package/dist/mcp/helpers/fileValidation.js +0 -267
  261. package/dist/mcp/helpers/fileValidation.js.map +0 -1
  262. package/dist/mcp/registerTool.d.ts +0 -6
  263. package/dist/mcp/registerTool.d.ts.map +0 -1
  264. package/dist/mcp/registerTool.js +0 -18
  265. package/dist/mcp/registerTool.js.map +0 -1
  266. package/dist/mcp/tools/auth/auth.d.ts +0 -4
  267. package/dist/mcp/tools/auth/auth.d.ts.map +0 -1
  268. package/dist/mcp/tools/auth/auth.js +0 -57
  269. package/dist/mcp/tools/auth/auth.js.map +0 -1
  270. package/dist/mcp/tools/auth/forgotPassword.d.ts +0 -4
  271. package/dist/mcp/tools/auth/forgotPassword.d.ts.map +0 -1
  272. package/dist/mcp/tools/auth/forgotPassword.js +0 -48
  273. package/dist/mcp/tools/auth/forgotPassword.js.map +0 -1
  274. package/dist/mcp/tools/auth/login.d.ts +0 -4
  275. package/dist/mcp/tools/auth/login.d.ts.map +0 -1
  276. package/dist/mcp/tools/auth/login.js +0 -51
  277. package/dist/mcp/tools/auth/login.js.map +0 -1
  278. package/dist/mcp/tools/auth/resetPassword.d.ts +0 -4
  279. package/dist/mcp/tools/auth/resetPassword.d.ts.map +0 -1
  280. package/dist/mcp/tools/auth/resetPassword.js +0 -49
  281. package/dist/mcp/tools/auth/resetPassword.js.map +0 -1
  282. package/dist/mcp/tools/auth/unlock.d.ts +0 -4
  283. package/dist/mcp/tools/auth/unlock.d.ts.map +0 -1
  284. package/dist/mcp/tools/auth/unlock.js +0 -48
  285. package/dist/mcp/tools/auth/unlock.js.map +0 -1
  286. package/dist/mcp/tools/auth/verify.d.ts +0 -4
  287. package/dist/mcp/tools/auth/verify.d.ts.map +0 -1
  288. package/dist/mcp/tools/auth/verify.js +0 -45
  289. package/dist/mcp/tools/auth/verify.js.map +0 -1
  290. package/dist/mcp/tools/collection/create.d.ts +0 -10
  291. package/dist/mcp/tools/collection/create.d.ts.map +0 -1
  292. package/dist/mcp/tools/collection/create.js +0 -139
  293. package/dist/mcp/tools/collection/create.js.map +0 -1
  294. package/dist/mcp/tools/collection/delete.d.ts +0 -10
  295. package/dist/mcp/tools/collection/delete.d.ts.map +0 -1
  296. package/dist/mcp/tools/collection/delete.js +0 -154
  297. package/dist/mcp/tools/collection/delete.js.map +0 -1
  298. package/dist/mcp/tools/collection/find.d.ts +0 -10
  299. package/dist/mcp/tools/collection/find.d.ts.map +0 -1
  300. package/dist/mcp/tools/collection/find.js +0 -165
  301. package/dist/mcp/tools/collection/find.js.map +0 -1
  302. package/dist/mcp/tools/collection/update.d.ts +0 -10
  303. package/dist/mcp/tools/collection/update.d.ts.map +0 -1
  304. package/dist/mcp/tools/collection/update.js +0 -209
  305. package/dist/mcp/tools/collection/update.js.map +0 -1
  306. package/dist/mcp/tools/config/find.d.ts +0 -10
  307. package/dist/mcp/tools/config/find.d.ts.map +0 -1
  308. package/dist/mcp/tools/config/find.js +0 -97
  309. package/dist/mcp/tools/config/find.js.map +0 -1
  310. package/dist/mcp/tools/config/update.d.ts +0 -10
  311. package/dist/mcp/tools/config/update.d.ts.map +0 -1
  312. package/dist/mcp/tools/config/update.js +0 -215
  313. package/dist/mcp/tools/config/update.js.map +0 -1
  314. package/dist/mcp/tools/global/find.d.ts +0 -5
  315. package/dist/mcp/tools/global/find.d.ts.map +0 -1
  316. package/dist/mcp/tools/global/find.js +0 -82
  317. package/dist/mcp/tools/global/find.js.map +0 -1
  318. package/dist/mcp/tools/global/update.d.ts +0 -6
  319. package/dist/mcp/tools/global/update.d.ts.map +0 -1
  320. package/dist/mcp/tools/global/update.js +0 -124
  321. package/dist/mcp/tools/global/update.js.map +0 -1
  322. package/dist/mcp/tools/job/create.d.ts +0 -10
  323. package/dist/mcp/tools/job/create.d.ts.map +0 -1
  324. package/dist/mcp/tools/job/create.js +0 -293
  325. package/dist/mcp/tools/job/create.js.map +0 -1
  326. package/dist/mcp/tools/job/run.d.ts +0 -10
  327. package/dist/mcp/tools/job/run.d.ts.map +0 -1
  328. package/dist/mcp/tools/job/run.js +0 -129
  329. package/dist/mcp/tools/job/run.js.map +0 -1
  330. package/dist/mcp/tools/job/update.d.ts +0 -11
  331. package/dist/mcp/tools/job/update.d.ts.map +0 -1
  332. package/dist/mcp/tools/job/update.js +0 -186
  333. package/dist/mcp/tools/job/update.js.map +0 -1
  334. package/dist/mcp/tools/resource/create.d.ts +0 -6
  335. package/dist/mcp/tools/resource/create.d.ts.map +0 -1
  336. package/dist/mcp/tools/resource/create.js +0 -124
  337. package/dist/mcp/tools/resource/create.js.map +0 -1
  338. package/dist/mcp/tools/resource/delete.d.ts +0 -5
  339. package/dist/mcp/tools/resource/delete.d.ts.map +0 -1
  340. package/dist/mcp/tools/resource/delete.js +0 -151
  341. package/dist/mcp/tools/resource/delete.js.map +0 -1
  342. package/dist/mcp/tools/resource/find.d.ts +0 -5
  343. package/dist/mcp/tools/resource/find.d.ts.map +0 -1
  344. package/dist/mcp/tools/resource/find.js +0 -170
  345. package/dist/mcp/tools/resource/find.js.map +0 -1
  346. package/dist/mcp/tools/resource/update.d.ts +0 -6
  347. package/dist/mcp/tools/resource/update.d.ts.map +0 -1
  348. package/dist/mcp/tools/resource/update.js +0 -256
  349. package/dist/mcp/tools/resource/update.js.map +0 -1
  350. package/dist/mcp/tools/schemas.d.ts +0 -457
  351. package/dist/mcp/tools/schemas.d.ts.map +0 -1
  352. package/dist/mcp/tools/schemas.js +0 -243
  353. package/dist/mcp/tools/schemas.js.map +0 -1
  354. package/dist/utils/adminEntitySettings.d.ts +0 -17
  355. package/dist/utils/adminEntitySettings.d.ts.map +0 -1
  356. package/dist/utils/adminEntitySettings.js +0 -41
  357. package/dist/utils/adminEntitySettings.js.map +0 -1
  358. package/dist/utils/createApiKeyFields.d.ts +0 -15
  359. package/dist/utils/createApiKeyFields.d.ts.map +0 -1
  360. package/dist/utils/createApiKeyFields.js +0 -57
  361. package/dist/utils/createApiKeyFields.js.map +0 -1
  362. package/dist/utils/getEnabledSlugs.d.ts +0 -13
  363. package/dist/utils/getEnabledSlugs.d.ts.map +0 -1
  364. package/dist/utils/getEnabledSlugs.js +0 -32
  365. package/dist/utils/getEnabledSlugs.js.map +0 -1
  366. package/dist/utils/schemaConversion/convertCollectionSchemaToZod.d.ts +0 -3
  367. package/dist/utils/schemaConversion/convertCollectionSchemaToZod.d.ts.map +0 -1
  368. package/dist/utils/schemaConversion/convertCollectionSchemaToZod.js +0 -43
  369. package/dist/utils/schemaConversion/convertCollectionSchemaToZod.js.map +0 -1
  370. package/dist/utils/schemaConversion/removeVirtualFieldsFromSchema.d.ts +0 -7
  371. package/dist/utils/schemaConversion/removeVirtualFieldsFromSchema.d.ts.map +0 -1
  372. package/dist/utils/schemaConversion/removeVirtualFieldsFromSchema.js +0 -20
  373. package/dist/utils/schemaConversion/removeVirtualFieldsFromSchema.js.map +0 -1
  374. package/dist/utils/schemaConversion/sanitizeJsonSchema.d.ts +0 -13
  375. package/dist/utils/schemaConversion/sanitizeJsonSchema.d.ts.map +0 -1
  376. package/dist/utils/schemaConversion/sanitizeJsonSchema.js +0 -56
  377. package/dist/utils/schemaConversion/sanitizeJsonSchema.js.map +0 -1
  378. package/dist/utils/schemaConversion/simplifyRelationshipFields.d.ts +0 -20
  379. package/dist/utils/schemaConversion/simplifyRelationshipFields.d.ts.map +0 -1
  380. package/dist/utils/schemaConversion/simplifyRelationshipFields.js +0 -53
  381. package/dist/utils/schemaConversion/simplifyRelationshipFields.js.map +0 -1
  382. package/dist/utils/schemaConversion/transformPointFields.d.ts +0 -3
  383. package/dist/utils/schemaConversion/transformPointFields.d.ts.map +0 -1
  384. package/dist/utils/schemaConversion/transformPointFields.js +0 -51
  385. package/dist/utils/schemaConversion/transformPointFields.js.map +0 -1
  386. package/src/collections/createApiKeysCollection.ts +0 -373
  387. package/src/defaults.ts +0 -3
  388. package/src/endpoints/mcp.ts +0 -91
  389. package/src/mcp/createRequest.ts +0 -13
  390. package/src/mcp/getMcpHandler.ts +0 -545
  391. package/src/mcp/helpers/config.ts +0 -213
  392. package/src/mcp/helpers/fields.ts +0 -154
  393. package/src/mcp/helpers/fileValidation.ts +0 -362
  394. package/src/mcp/registerTool.ts +0 -22
  395. package/src/mcp/tools/auth/auth.ts +0 -71
  396. package/src/mcp/tools/auth/forgotPassword.ts +0 -70
  397. package/src/mcp/tools/auth/login.ts +0 -72
  398. package/src/mcp/tools/auth/resetPassword.ts +0 -61
  399. package/src/mcp/tools/auth/unlock.ts +0 -64
  400. package/src/mcp/tools/auth/verify.ts +0 -57
  401. package/src/mcp/tools/collection/create.ts +0 -210
  402. package/src/mcp/tools/collection/delete.ts +0 -211
  403. package/src/mcp/tools/collection/find.ts +0 -224
  404. package/src/mcp/tools/collection/update.ts +0 -290
  405. package/src/mcp/tools/config/find.ts +0 -128
  406. package/src/mcp/tools/config/update.ts +0 -280
  407. package/src/mcp/tools/global/find.ts +0 -128
  408. package/src/mcp/tools/global/update.ts +0 -207
  409. package/src/mcp/tools/job/create.ts +0 -416
  410. package/src/mcp/tools/job/run.ts +0 -167
  411. package/src/mcp/tools/job/update.ts +0 -274
  412. package/src/mcp/tools/resource/create.ts +0 -211
  413. package/src/mcp/tools/resource/delete.ts +0 -218
  414. package/src/mcp/tools/resource/find.ts +0 -246
  415. package/src/mcp/tools/resource/update.ts +0 -383
  416. package/src/mcp/tools/schemas.ts +0 -520
  417. package/src/utils/adminEntitySettings.ts +0 -40
  418. package/src/utils/createApiKeyFields.ts +0 -72
  419. package/src/utils/getEnabledSlugs.ts +0 -42
  420. package/src/utils/schemaConversion/convertCollectionSchemaToZod.ts +0 -52
  421. package/src/utils/schemaConversion/removeVirtualFieldsFromSchema.ts +0 -27
  422. package/src/utils/schemaConversion/sanitizeJsonSchema.ts +0 -62
  423. package/src/utils/schemaConversion/simplifyRelationshipFields.ts +0 -65
  424. package/src/utils/schemaConversion/transformPointFields.ts +0 -55
@@ -0,0 +1,100 @@
1
+ import { APIError } from 'payload';
2
+ import { getExternalFile, isURLAllowed } from 'payload/internal';
3
+ import { sanitizeFilename } from 'payload/shared';
4
+ import { z } from 'zod';
5
+ const mimeTypeSchema = z.string().regex(/^[!#$%&'*+.^`|~\w-]+\/[!#$%&'*+.^`|~\w-]+$/, 'MIME type must use the type/subtype format');
6
+ export const fileInputSchema = z.discriminatedUnion('source', [
7
+ z.object({
8
+ name: z.string().min(1).describe('The file name, including its extension'),
9
+ data: z.string().describe('The base64-encoded file bytes, without a data URL prefix'),
10
+ mimeType: mimeTypeSchema.describe('The file MIME type, for example image/png'),
11
+ source: z.literal('base64')
12
+ }),
13
+ z.object({
14
+ name: z.string().min(1).describe('Optional file name override').optional(),
15
+ source: z.literal('url'),
16
+ url: z.url().describe('The http or https URL to download')
17
+ })
18
+ ]).describe('A file for an upload collection. Use only a source listed by getCollectionSchema: url for an online file or base64 for a local file.');
19
+ export async function resolveFileInput({ collectionSlug, input, req }) {
20
+ if (!input) {
21
+ return undefined;
22
+ }
23
+ const uploadConfig = req.payload.collections[collectionSlug]?.config.upload;
24
+ if (!uploadConfig) {
25
+ throw new APIError(`Collection "${collectionSlug}" does not support file uploads.`, 400);
26
+ }
27
+ const maxFileSize = req.payload.config.upload.limits?.fileSize;
28
+ let file;
29
+ if (input.source === 'base64') {
30
+ const data = decodeBase64({
31
+ maxFileSize,
32
+ value: input.data
33
+ });
34
+ file = {
35
+ name: sanitizeFilename(input.name),
36
+ data,
37
+ mimetype: input.mimeType,
38
+ size: data.length
39
+ };
40
+ } else {
41
+ if (uploadConfig.pasteURL === false) {
42
+ throw new APIError(`Uploading files from URLs is disabled for collection "${collectionSlug}".`, 400);
43
+ }
44
+ const url = new URL(input.url);
45
+ if (![
46
+ 'http:',
47
+ 'https:'
48
+ ].includes(url.protocol)) {
49
+ throw new APIError('File URLs must use http or https.', 400);
50
+ }
51
+ if (typeof uploadConfig.pasteURL === 'object' && !isURLAllowed(input.url, uploadConfig.pasteURL.allowList)) {
52
+ throw new APIError('The provided file URL is not allowed.', 400);
53
+ }
54
+ file = await getExternalFile({
55
+ data: {
56
+ filename: sanitizeFilename(input.name || getURLFilename(url)),
57
+ url: input.url
58
+ },
59
+ req,
60
+ uploadConfig: {
61
+ ...uploadConfig,
62
+ externalFileHeaderFilter: uploadConfig.externalFileHeaderFilter ?? (()=>({}))
63
+ }
64
+ });
65
+ file.mimetype = file.mimetype?.split(';')[0] || 'application/octet-stream';
66
+ file.size = file.data.length;
67
+ }
68
+ if (maxFileSize !== undefined && Number.isFinite(maxFileSize) && file.size > maxFileSize) {
69
+ throw new APIError(`File exceeds the ${maxFileSize} byte upload limit.`, 400);
70
+ }
71
+ return file;
72
+ }
73
+ function decodeBase64({ maxFileSize, value }) {
74
+ const normalized = value.replace(/\s/g, '');
75
+ if (!/^[a-z0-9+/]*={0,2}$/i.test(normalized) || normalized.length % 4 === 1) {
76
+ throw new APIError('File data must be valid base64.', 400);
77
+ }
78
+ if (maxFileSize !== undefined && Number.isFinite(maxFileSize)) {
79
+ const paddingLength = normalized.endsWith('==') ? 2 : normalized.endsWith('=') ? 1 : 0;
80
+ const decodedSize = Math.floor(normalized.length * 3 / 4) - paddingLength;
81
+ if (decodedSize > maxFileSize) {
82
+ throw new APIError(`File exceeds the ${maxFileSize} byte upload limit.`, 400);
83
+ }
84
+ }
85
+ const data = Buffer.from(normalized, 'base64');
86
+ if (data.toString('base64').replace(/=+$/, '') !== normalized.replace(/=+$/, '')) {
87
+ throw new APIError('File data must be valid base64.', 400);
88
+ }
89
+ return data;
90
+ }
91
+ function getURLFilename(url) {
92
+ const pathSegment = url.pathname.split('/').pop() || 'upload';
93
+ try {
94
+ return decodeURIComponent(pathSegment);
95
+ } catch {
96
+ return pathSegment;
97
+ }
98
+ }
99
+
100
+ //# sourceMappingURL=fileInput.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/mcp/builtin/collections/fileInput.ts"],"sourcesContent":["import type { CollectionSlug, File, FileData, PayloadRequest } from 'payload'\n\nimport { APIError } from 'payload'\nimport { getExternalFile, isURLAllowed } from 'payload/internal'\nimport { sanitizeFilename } from 'payload/shared'\nimport { z } from 'zod'\n\nconst mimeTypeSchema = z\n .string()\n .regex(/^[!#$%&'*+.^`|~\\w-]+\\/[!#$%&'*+.^`|~\\w-]+$/, 'MIME type must use the type/subtype format')\n\nexport const fileInputSchema = z\n .discriminatedUnion('source', [\n z.object({\n name: z.string().min(1).describe('The file name, including its extension'),\n data: z.string().describe('The base64-encoded file bytes, without a data URL prefix'),\n mimeType: mimeTypeSchema.describe('The file MIME type, for example image/png'),\n source: z.literal('base64'),\n }),\n z.object({\n name: z.string().min(1).describe('Optional file name override').optional(),\n source: z.literal('url'),\n url: z.url().describe('The http or https URL to download'),\n }),\n ])\n .describe(\n 'A file for an upload collection. Use only a source listed by getCollectionSchema: url for an online file or base64 for a local file.',\n )\n\ntype FileInput = z.infer<typeof fileInputSchema>\n\nexport async function resolveFileInput({\n collectionSlug,\n input,\n req,\n}: {\n collectionSlug: CollectionSlug\n input?: FileInput\n req: PayloadRequest\n}): Promise<File | undefined> {\n if (!input) {\n return undefined\n }\n\n const uploadConfig = req.payload.collections[collectionSlug]?.config.upload\n\n if (!uploadConfig) {\n throw new APIError(`Collection \"${collectionSlug}\" does not support file uploads.`, 400)\n }\n\n const maxFileSize = req.payload.config.upload.limits?.fileSize\n let file: File\n\n if (input.source === 'base64') {\n const data = decodeBase64({ maxFileSize, value: input.data })\n\n file = {\n name: sanitizeFilename(input.name),\n data,\n mimetype: input.mimeType,\n size: data.length,\n }\n } else {\n if (uploadConfig.pasteURL === false) {\n throw new APIError(\n `Uploading files from URLs is disabled for collection \"${collectionSlug}\".`,\n 400,\n )\n }\n\n const url = new URL(input.url)\n\n if (!['http:', 'https:'].includes(url.protocol)) {\n throw new APIError('File URLs must use http or https.', 400)\n }\n\n if (\n typeof uploadConfig.pasteURL === 'object' &&\n !isURLAllowed(input.url, uploadConfig.pasteURL.allowList)\n ) {\n throw new APIError('The provided file URL is not allowed.', 400)\n }\n\n file = await getExternalFile({\n data: {\n filename: sanitizeFilename(input.name || getURLFilename(url)),\n url: input.url,\n } as FileData,\n req,\n uploadConfig: {\n ...uploadConfig,\n externalFileHeaderFilter: uploadConfig.externalFileHeaderFilter ?? (() => ({})),\n },\n })\n file.mimetype = file.mimetype?.split(';')[0] || 'application/octet-stream'\n file.size = file.data.length\n }\n\n if (maxFileSize !== undefined && Number.isFinite(maxFileSize) && file.size > maxFileSize) {\n throw new APIError(`File exceeds the ${maxFileSize} byte upload limit.`, 400)\n }\n\n return file\n}\n\nfunction decodeBase64({ maxFileSize, value }: { maxFileSize?: number; value: string }): Buffer {\n const normalized = value.replace(/\\s/g, '')\n\n if (!/^[a-z0-9+/]*={0,2}$/i.test(normalized) || normalized.length % 4 === 1) {\n throw new APIError('File data must be valid base64.', 400)\n }\n\n if (maxFileSize !== undefined && Number.isFinite(maxFileSize)) {\n const paddingLength = normalized.endsWith('==') ? 2 : normalized.endsWith('=') ? 1 : 0\n const decodedSize = Math.floor((normalized.length * 3) / 4) - paddingLength\n\n if (decodedSize > maxFileSize) {\n throw new APIError(`File exceeds the ${maxFileSize} byte upload limit.`, 400)\n }\n }\n\n const data = Buffer.from(normalized, 'base64')\n\n if (data.toString('base64').replace(/=+$/, '') !== normalized.replace(/=+$/, '')) {\n throw new APIError('File data must be valid base64.', 400)\n }\n\n return data\n}\n\nfunction getURLFilename(url: URL): string {\n const pathSegment = url.pathname.split('/').pop() || 'upload'\n\n try {\n return decodeURIComponent(pathSegment)\n } catch {\n return pathSegment\n }\n}\n"],"names":["APIError","getExternalFile","isURLAllowed","sanitizeFilename","z","mimeTypeSchema","string","regex","fileInputSchema","discriminatedUnion","object","name","min","describe","data","mimeType","source","literal","optional","url","resolveFileInput","collectionSlug","input","req","undefined","uploadConfig","payload","collections","config","upload","maxFileSize","limits","fileSize","file","decodeBase64","value","mimetype","size","length","pasteURL","URL","includes","protocol","allowList","filename","getURLFilename","externalFileHeaderFilter","split","Number","isFinite","normalized","replace","test","paddingLength","endsWith","decodedSize","Math","floor","Buffer","from","toString","pathSegment","pathname","pop","decodeURIComponent"],"mappings":"AAEA,SAASA,QAAQ,QAAQ,UAAS;AAClC,SAASC,eAAe,EAAEC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AI,CAACF,eAAeA,WAAWZ,MAAM,GAAG,MAAM,GAAG;QAC3E,MAAM,IAAItC,SAAS,mCAAmC;IACxD;IAEA,IAAI8B,gBAAgBN,aAAawB,OAAOC,QAAQ,CAACnB,cAAc;QAC7D,MAAMuB,gBAAgBH,WAAWI,QAAQ,CAAC,QAAQ,IAAIJ,WAAWI,QAAQ,CAAC,OAAO,IAAI;QACrF,MAAMC,cAAcC,KAAKC,KAAK,CAAC,AAACP,WAAWZ,MAAM,GAAG,IAAK,KAAKe;QAE9D,IAAIE,cAAczB,aAAa;YAC7B,MAAM,IAAI9B,SAAS,CAAC,iBAAiB,EAAE8B,YAAY,mBAAmB,CAAC,EAAE;QAC3E;IACF;IAEA,MAAMhB,OAAO4C,OAAOC,IAAI,CAACT,YAAY;IAErC,IAAIpC,KAAK8C,QAAQ,CAAC,UAAUT,OAAO,CAAC,OAAO,QAAQD,WAAWC,OAAO,CAAC,OAAO,KAAK;QAChF,MAAM,IAAInD,SAAS,mCAAmC;IACxD;IAEA,OAAOc;AACT;AAEA,SAAS+B,eAAe1B,GAAQ;IAC9B,MAAM0C,cAAc1C,IAAI2C,QAAQ,CAACf,KAAK,CAAC,KAAKgB,GAAG,MAAM;IAErD,IAAI;QACF,OAAOC,mBAAmBH;IAC5B,EAAE,OAAM;QACN,OAAOA;IACT;AACF"}
@@ -0,0 +1,72 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import { fileInputSchema, resolveFileInput } from './fileInput.js';
3
+ describe('MCP file input', ()=>{
4
+ it('should reject malformed MIME types', ()=>{
5
+ const result = fileInputSchema.safeParse({
6
+ data: 'aGVsbG8=',
7
+ mimeType: 'text/plain\r\nx-test: value',
8
+ name: 'hello.txt',
9
+ source: 'base64'
10
+ });
11
+ expect(result.success).toBe(false);
12
+ });
13
+ it('should reject oversized base64 files', async ()=>{
14
+ const req = createRequest({
15
+ maxFileSize: 4
16
+ });
17
+ await expect(resolveFileInput({
18
+ collectionSlug: 'media',
19
+ input: {
20
+ data: Buffer.from('hello').toString('base64'),
21
+ mimeType: 'text/plain',
22
+ name: 'hello.txt',
23
+ source: 'base64'
24
+ },
25
+ req
26
+ })).rejects.toThrow('File exceeds the 4 byte upload limit.');
27
+ });
28
+ it('should reject URLs outside the collection allowlist', async ()=>{
29
+ const req = createRequest({
30
+ allowList: [
31
+ {
32
+ hostname: 'assets.example.com',
33
+ protocol: 'https'
34
+ }
35
+ ]
36
+ });
37
+ await expect(resolveFileInput({
38
+ collectionSlug: 'media',
39
+ input: {
40
+ source: 'url',
41
+ url: 'https://example.com/image.png'
42
+ },
43
+ req
44
+ })).rejects.toThrow('The provided file URL is not allowed.');
45
+ });
46
+ });
47
+ function createRequest({ allowList, maxFileSize }) {
48
+ return {
49
+ payload: {
50
+ collections: {
51
+ media: {
52
+ config: {
53
+ upload: allowList ? {
54
+ pasteURL: {
55
+ allowList
56
+ }
57
+ } : {}
58
+ }
59
+ }
60
+ },
61
+ config: {
62
+ upload: {
63
+ limits: {
64
+ fileSize: maxFileSize
65
+ }
66
+ }
67
+ }
68
+ }
69
+ };
70
+ }
71
+
72
+ //# sourceMappingURL=fileInput.spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/mcp/builtin/collections/fileInput.spec.ts"],"sourcesContent":["import type { PayloadRequest } from 'payload'\n\nimport { describe, expect, it } from 'vitest'\n\nimport { fileInputSchema, resolveFileInput } from './fileInput.js'\n\ndescribe('MCP file input', () => {\n it('should reject malformed MIME types', () => {\n const result = fileInputSchema.safeParse({\n data: 'aGVsbG8=',\n mimeType: 'text/plain\\r\\nx-test: value',\n name: 'hello.txt',\n source: 'base64',\n })\n\n expect(result.success).toBe(false)\n })\n\n it('should reject oversized base64 files', async () => {\n const req = createRequest({ maxFileSize: 4 })\n\n await expect(\n resolveFileInput({\n collectionSlug: 'media',\n input: {\n data: Buffer.from('hello').toString('base64'),\n mimeType: 'text/plain',\n name: 'hello.txt',\n source: 'base64',\n },\n req,\n }),\n ).rejects.toThrow('File exceeds the 4 byte upload limit.')\n })\n\n it('should reject URLs outside the collection allowlist', async () => {\n const req = createRequest({\n allowList: [{ hostname: 'assets.example.com', protocol: 'https' }],\n })\n\n await expect(\n resolveFileInput({\n collectionSlug: 'media',\n input: {\n source: 'url',\n url: 'https://example.com/image.png',\n },\n req,\n }),\n ).rejects.toThrow('The provided file URL is not allowed.')\n })\n})\n\nfunction createRequest({\n allowList,\n maxFileSize,\n}: {\n allowList?: Array<{ hostname: string; protocol: 'http' | 'https' }>\n maxFileSize?: number\n}): PayloadRequest {\n return {\n payload: {\n collections: {\n media: {\n config: {\n upload: allowList ? { pasteURL: { allowList } } : {},\n },\n },\n },\n config: {\n upload: {\n limits: {\n fileSize: maxFileSize,\n },\n },\n },\n },\n } as unknown as PayloadRequest\n}\n"],"names":["describe","expect","it","fileInputSchema","resolveFileInput","result","safeParse","data","mimeType","name","source","success","toBe","req","createRequest","maxFileSize","collectionSlug","input","Buffer","from","toString","rejects","toThrow","allowList","hostname","protocol","url","payload","collections","media","config","upload","pasteURL","limits","fileSize"],"mappings":"AAEA,SAASA,QAAQ,EAAEC,MAAM,EAAEC,EAAE,QAAQ,SAAQ;AAE7C,SAASC,eAAe,EAAEC,gBAAgB,QAAQ,iBAAgB;AAElEJ,SAAS,kBAAkB;IACzBE,GAAG,sCAAsC;QACvC,MAAMG,SAASF,gBAAgBG,SAAS,CAAC;YACvCC,MAAM;YACNC,UAAU;YACVC,MAAM;YACNC,QAAQ;QACV;QAEAT,OAAOI,OAAOM,OAAO,EAAEC,IAAI,CAAC;IAC9B;IAEAV,GAAG,wCAAwC;QACzC,MAAMW,MAAMC,cAAc;YAAEC,aAAa;QAAE;QAE3C,MAAMd,OACJG,iBAAiB;YACfY,gBAAgB;YAChBC,OAAO;gBACLV,MAAMW,OAAOC,IAAI,CAAC,SAASC,QAAQ,CAAC;gBACpCZ,UAAU;gBACVC,MAAM;gBACNC,QAAQ;YACV;YACAG;QACF,IACAQ,OAAO,CAACC,OAAO,CAAC;IACpB;IAEApB,GAAG,uDAAuD;QACxD,MAAMW,MAAMC,cAAc;YACxBS,WAAW;gBAAC;oBAAEC,UAAU;oBAAsBC,UAAU;gBAAQ;aAAE;QACpE;QAEA,MAAMxB,OACJG,iBAAiB;YACfY,gBAAgB;YAChBC,OAAO;gBACLP,QAAQ;gBACRgB,KAAK;YACP;YACAb;QACF,IACAQ,OAAO,CAACC,OAAO,CAAC;IACpB;AACF;AAEA,SAASR,cAAc,EACrBS,SAAS,EACTR,WAAW,EAIZ;IACC,OAAO;QACLY,SAAS;YACPC,aAAa;gBACXC,OAAO;oBACLC,QAAQ;wBACNC,QAAQR,YAAY;4BAAES,UAAU;gCAAET;4BAAU;wBAAE,IAAI,CAAC;oBACrD;gBACF;YACF;YACAO,QAAQ;gBACNC,QAAQ;oBACNE,QAAQ;wBACNC,UAAUnB;oBACZ;gBACF;YACF;QACF;IACF;AACF"}
@@ -0,0 +1,2 @@
1
+ export declare const findDistinctTool: import("../../../types.js").CollectionTool;
2
+ //# sourceMappingURL=findDistinctTool.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"findDistinctTool.d.ts","sourceRoot":"","sources":["../../../../src/mcp/builtin/collections/findDistinctTool.ts"],"names":[],"mappings":"AAYA,eAAO,MAAM,gBAAgB,4CA0G3B,CAAA"}
@@ -0,0 +1,92 @@
1
+ import { z } from 'zod';
2
+ import { defaultAccess } from '../../../defaultAccess.js';
3
+ import { defineCollectionTool } from '../../../defineTool.js';
4
+ import { getLogger } from '../../../utils/getLogger.js';
5
+ import { whereSchema } from '../../../utils/whereSchema.js';
6
+ const DEFAULT_DESCRIPTION = 'Find distinct values for a field in any collection by passing the collection slug and field path.';
7
+ export const findDistinctTool = defineCollectionTool({
8
+ access: (args)=>defaultAccess(args) && Boolean(args.permissions?.collections?.[args.collectionSlug]?.read),
9
+ annotations: {
10
+ destructiveHint: false,
11
+ idempotentHint: true,
12
+ openWorldHint: false,
13
+ readOnlyHint: true,
14
+ title: 'Find Distinct'
15
+ },
16
+ description: DEFAULT_DESCRIPTION,
17
+ input: z.object({
18
+ depth: z.number().int().min(0).max(10).describe('How many levels deep to populate relationships in distinct values').optional().default(0),
19
+ field: z.string().describe('The field path to get distinct values for'),
20
+ limit: z.number().int().min(1).max(100).describe('Maximum number of distinct values to return (max: 100)').optional(),
21
+ locale: z.string().describe('Optional: locale code to retrieve data in (e.g., "en", "es"). Use "all" to retrieve all locales for localized fields').optional(),
22
+ page: z.number().int().min(1).describe('Page number for pagination').optional(),
23
+ populate: z.record(z.string(), z.unknown()).describe('Optional: control which fields to include from populated relationship or upload documents.').optional(),
24
+ showHiddenFields: z.boolean().describe('Optional: include hidden fields in the distinct query').optional(),
25
+ sort: z.string().describe('Field to sort by (e.g., "createdAt", "-updatedAt" for descending)').optional(),
26
+ trash: z.boolean().describe('Optional: include soft-deleted documents when trash is enabled on the collection').optional(),
27
+ where: whereSchema.describe('Optional: where clause for filtering. Use field names with Payload operators, and/or arrays for grouping. Example: {"title":{"contains":"test"}}').optional()
28
+ })
29
+ }).handler(async ({ authorizedMCP, collectionSlug, input, req })=>{
30
+ const payload = req.payload;
31
+ const logger = getLogger({
32
+ payload
33
+ });
34
+ const { depth, field, limit, locale, page, populate, showHiddenFields, sort, trash, where } = input;
35
+ logger.info(`Finding distinct values in collection: ${collectionSlug}, field: ${field}`);
36
+ try {
37
+ const result = await payload.findDistinct({
38
+ collection: collectionSlug,
39
+ depth,
40
+ field,
41
+ overrideAccess: authorizedMCP.overrideAccess,
42
+ req,
43
+ ...limit ? {
44
+ limit
45
+ } : {},
46
+ ...locale ? {
47
+ locale
48
+ } : {},
49
+ ...page ? {
50
+ page
51
+ } : {},
52
+ ...populate ? {
53
+ populate: populate
54
+ } : {},
55
+ ...showHiddenFields !== undefined ? {
56
+ showHiddenFields
57
+ } : {},
58
+ ...sort ? {
59
+ sort
60
+ } : {},
61
+ ...trash !== undefined ? {
62
+ trash
63
+ } : {},
64
+ ...where ? {
65
+ where
66
+ } : {}
67
+ });
68
+ return {
69
+ content: [
70
+ {
71
+ type: 'text',
72
+ text: `Distinct values for "${field}" in collection "${collectionSlug}":\n\`\`\`json\n${JSON.stringify(result)}\n\`\`\``
73
+ }
74
+ ],
75
+ doc: result
76
+ };
77
+ } catch (error) {
78
+ const errorMessage = error instanceof Error ? error.message : 'Unknown error';
79
+ logger.error(`Error finding distinct values in ${collectionSlug}: ${errorMessage}`);
80
+ return {
81
+ content: [
82
+ {
83
+ type: 'text',
84
+ text: `❌ **Error finding distinct values in collection "${collectionSlug}":** ${errorMessage}`
85
+ }
86
+ ],
87
+ isError: true
88
+ };
89
+ }
90
+ });
91
+
92
+ //# sourceMappingURL=findDistinctTool.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/mcp/builtin/collections/findDistinctTool.ts"],"sourcesContent":["import type { PopulateType } from 'payload'\n\nimport { z } from 'zod'\n\nimport { defaultAccess } from '../../../defaultAccess.js'\nimport { defineCollectionTool } from '../../../defineTool.js'\nimport { getLogger } from '../../../utils/getLogger.js'\nimport { whereSchema } from '../../../utils/whereSchema.js'\n\nconst DEFAULT_DESCRIPTION =\n 'Find distinct values for a field in any collection by passing the collection slug and field path.'\n\nexport const findDistinctTool = defineCollectionTool({\n access: (args) =>\n defaultAccess(args) && Boolean(args.permissions?.collections?.[args.collectionSlug]?.read),\n annotations: {\n destructiveHint: false,\n idempotentHint: true,\n openWorldHint: false,\n readOnlyHint: true,\n title: 'Find Distinct',\n },\n description: DEFAULT_DESCRIPTION,\n input: z.object({\n depth: z\n .number()\n .int()\n .min(0)\n .max(10)\n .describe('How many levels deep to populate relationships in distinct values')\n .optional()\n .default(0),\n field: z.string().describe('The field path to get distinct values for'),\n limit: z\n .number()\n .int()\n .min(1)\n .max(100)\n .describe('Maximum number of distinct values to return (max: 100)')\n .optional(),\n locale: z\n .string()\n .describe(\n 'Optional: locale code to retrieve data in (e.g., \"en\", \"es\"). Use \"all\" to retrieve all locales for localized fields',\n )\n .optional(),\n page: z.number().int().min(1).describe('Page number for pagination').optional(),\n populate: z\n .record(z.string(), z.unknown())\n .describe(\n 'Optional: control which fields to include from populated relationship or upload documents.',\n )\n .optional(),\n showHiddenFields: z\n .boolean()\n .describe('Optional: include hidden fields in the distinct query')\n .optional(),\n sort: z\n .string()\n .describe('Field to sort by (e.g., \"createdAt\", \"-updatedAt\" for descending)')\n .optional(),\n trash: z\n .boolean()\n .describe('Optional: include soft-deleted documents when trash is enabled on the collection')\n .optional(),\n where: whereSchema\n .describe(\n 'Optional: where clause for filtering. Use field names with Payload operators, and/or arrays for grouping. Example: {\"title\":{\"contains\":\"test\"}}',\n )\n .optional(),\n }),\n}).handler(async ({ authorizedMCP, collectionSlug, input, req }) => {\n const payload = req.payload\n const logger = getLogger({ payload })\n const { depth, field, limit, locale, page, populate, showHiddenFields, sort, trash, where } =\n input\n\n logger.info(`Finding distinct values in collection: ${collectionSlug}, field: ${field}`)\n\n try {\n const result = await payload.findDistinct({\n collection: collectionSlug,\n depth,\n field,\n overrideAccess: authorizedMCP.overrideAccess,\n req,\n ...(limit ? { limit } : {}),\n ...(locale ? { locale } : {}),\n ...(page ? { page } : {}),\n ...(populate ? { populate: populate as PopulateType } : {}),\n ...(showHiddenFields !== undefined ? { showHiddenFields } : {}),\n ...(sort ? { sort } : {}),\n ...(trash !== undefined ? { trash } : {}),\n ...(where ? { where } : {}),\n })\n\n return {\n content: [\n {\n type: 'text',\n text: `Distinct values for \"${field}\" in collection \"${collectionSlug}\":\\n\\`\\`\\`json\\n${JSON.stringify(result)}\\n\\`\\`\\``,\n },\n ],\n doc: result as unknown as Record<string, unknown>,\n }\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : 'Unknown error'\n logger.error(`Error finding distinct values in ${collectionSlug}: ${errorMessage}`)\n return {\n content: [\n {\n type: 'text',\n text: `❌ **Error finding distinct values in collection \"${collectionSlug}\":** ${errorMessage}`,\n },\n ],\n isError: true,\n }\n }\n})\n"],"names":["z","defaultAccess","defineCollectionTool","getLogger","whereSchema","DEFAULT_DESCRIPTION","findDistinctTool","access","args","Boolean","permissions","collections","collectionSlug","read","annotations","destructiveHint","idempotentHint","openWorldHint","readOnlyHint","title","description","input","object","depth","number","int","min","max","describe","optional","default","field","string","limit","locale","page","populate","record","unknown","showHiddenFields","boolean","sort","trash","where","handler","authorizedMCP","req","payload","logger","info","result","findDistinct","collection","overrideAccess","undefined","content","type","text","JSON","stringify","doc","error","errorMessage","Error","message","isError"],"mappings":"AAEA,SAASA,CAAC,QAAQ,MAAK;AAEvB,SAASC,aAAa,QAAQ,4BAA2B;AACzD,SAASC,oBAAoB,QAAQ,yBAAwB;AAC7D,SAASC,SAAS,QAAQ,8BAA6B;AACvD,SAASC,WAAW,QAAQ,gCAA+B;AAE3D,MAAMC,sBACJ;AAEF,OAAO,MAAMC,mBAAmBJ,qBAAqB;IACnDK,QAAQ,CAACC,OACPP,cAAcO,SAASC,QAAQD,KAAKE,WAAW,EAAEC,aAAa,CAACH,KAAKI,cAAc,CAAC,EAAEC;IACvFC,aAAa;QACXC,iBAAiB;QACjBC,gBAAgB;QAChBC,eAAe;QACfC,cAAc;QACdC,OAAO;IACT;IACAC,aAAaf;IACbgB,OAAOrB,EAAEsB,MAAM,CAAC;QACdC,OAAOvB,EACJwB,MAAM,GACNC,GAAG,GACHC,GAAG,CAAC,GACJC,GAAG,CAAC,IACJC,QAAQ,CAAC,qEACTC,QAAQ,GACRC,OAAO,CAAC;QACXC,OAAO/B,EAAEgC,MAAM,GAAGJ,QAAQ,CAAC;QAC3BK,OAAOjC,EACJwB,MAAM,GACNC,GAAG,GACHC,GAAG,CAAC,GACJC,GAAG,CAAC,KACJC,QAAQ,CAAC,0DACTC,QAAQ;QACXK,QAAQlC,EACLgC,MAAM,GACNJ,QAAQ,CACP,wHAEDC,QAAQ;QACXM,MAAMnC,EAAEwB,MAAM,GAAGC,GAAG,GAAGC,GAAG,CAAC,GAAGE,QAAQ,CAAC,8BAA8BC,QAAQ;QAC7EO,UAA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Y,YAAY;gBAAEZ;YAAM,IAAI,CAAC,CAAC;YACxC,GAAIC,QAAQ;gBAAEA;YAAM,IAAI,CAAC,CAAC;QAC5B;QAEA,OAAO;YACLY,SAAS;gBACP;oBACEC,MAAM;oBACNC,MAAM,CAAC,qBAAqB,EAAE1B,MAAM,iBAAiB,EAAEnB,eAAe,gBAAgB,EAAE8C,KAAKC,SAAS,CAACT,QAAQ,QAAQ,CAAC;gBAC1H;aACD;YACDU,KAAKV;QACP;IACF,EAAE,OAAOW,OAAO;QACd,MAAMC,eAAeD,iBAAiBE,QAAQF,MAAMG,OAAO,GAAG;QAC9DhB,OAAOa,KAAK,CAAC,CAAC,iCAAiC,EAAEjD,eAAe,EAAE,EAAEkD,cAAc;QAClF,OAAO;YACLP,SAAS;gBACP;oBACEC,MAAM;oBACNC,MAAM,CAAC,iDAAiD,EAAE7C,eAAe,KAAK,EAAEkD,cAAc;gBAChG;aACD;YACDG,SAAS;QACX;IACF;AACF,GAAE"}
@@ -0,0 +1,2 @@
1
+ export declare const findDocumentsTool: import("../../../types.js").CollectionTool;
2
+ //# sourceMappingURL=findTool.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"findTool.d.ts","sourceRoot":"","sources":["../../../../src/mcp/builtin/collections/findTool.ts"],"names":[],"mappings":"AAYA,eAAO,MAAM,iBAAiB,4CA2M5B,CAAA"}
@@ -0,0 +1,164 @@
1
+ import { z } from 'zod';
2
+ import { defaultAccess } from '../../../defaultAccess.js';
3
+ import { defineCollectionTool } from '../../../defineTool.js';
4
+ import { getLogger } from '../../../utils/getLogger.js';
5
+ import { whereSchema } from '../../../utils/whereSchema.js';
6
+ const DEFAULT_DESCRIPTION = 'Find documents in any collection by passing the collection slug and optional ID or where clause.';
7
+ export const findDocumentsTool = defineCollectionTool({
8
+ access: (args)=>defaultAccess(args) && Boolean(args.permissions?.collections?.[args.collectionSlug]?.read),
9
+ annotations: {
10
+ destructiveHint: false,
11
+ idempotentHint: true,
12
+ openWorldHint: false,
13
+ readOnlyHint: true,
14
+ title: 'Find Documents'
15
+ },
16
+ description: DEFAULT_DESCRIPTION,
17
+ input: z.object({
18
+ id: z.union([
19
+ z.string(),
20
+ z.number()
21
+ ]).describe('Optional: specific document ID to retrieve. If not provided, returns all documents').optional(),
22
+ depth: z.number().int().min(0).max(10).describe('How many levels deep to populate relationships (default: 0)').optional().default(0),
23
+ draft: z.boolean().describe('For versioned collections, true returns the latest draft version when available. False reads the main document.').optional(),
24
+ fallbackLocale: z.string().describe('Optional: fallback locale code to use when requested locale is not available').optional(),
25
+ joins: z.union([
26
+ z.record(z.string(), z.unknown()),
27
+ z.literal(false)
28
+ ]).describe('Optional: configure join field queries, or pass false to disable all join fields.').optional(),
29
+ limit: z.number().int().min(1).max(100).describe('Maximum number of documents to return (default: 10, max: 100)').optional().default(10),
30
+ locale: z.string().describe('Optional: locale code to retrieve data in (e.g., "en", "es"). Use "all" to retrieve all locales for localized fields').optional(),
31
+ page: z.number().int().min(1).describe('Page number for pagination (default: 1)').optional().default(1),
32
+ pagination: z.boolean().describe('Optional: set to false to skip the count query overhead').optional(),
33
+ populate: z.record(z.string(), z.unknown()).describe('Optional: control which fields to include from populated relationship or upload documents.').optional(),
34
+ select: z.record(z.string(), z.unknown()).describe('Optional: define exactly which fields you\'d like to return in the response, e.g., {"title": true}').optional(),
35
+ sort: z.string().describe('Field to sort by (e.g., "createdAt", "-updatedAt" for descending)').optional(),
36
+ trash: z.boolean().describe('Optional: include soft-deleted documents when trash is enabled on the collection').optional(),
37
+ where: whereSchema.describe('Optional: where clause for filtering. Use field names with Payload operators, and/or arrays for grouping. Example: {"title":{"contains":"test"}}').optional()
38
+ })
39
+ }).handler(async ({ authorizedMCP, collectionSlug, input, req })=>{
40
+ const payload = req.payload;
41
+ const logger = getLogger({
42
+ payload
43
+ });
44
+ const { id, depth, draft, fallbackLocale, joins, limit, locale, page, pagination, populate, select, sort, trash, where } = input;
45
+ logger.info(`Reading document from collection: ${collectionSlug}${id ? ` with ID: ${id}` : ''}, limit: ${limit}, page: ${page}${locale ? `, locale: ${locale}` : ''}`);
46
+ try {
47
+ if (id) {
48
+ try {
49
+ const doc = await payload.findByID({
50
+ id,
51
+ collection: collectionSlug,
52
+ depth,
53
+ overrideAccess: authorizedMCP.overrideAccess,
54
+ req,
55
+ ...select && {
56
+ select: select
57
+ },
58
+ ...populate && {
59
+ populate: populate
60
+ },
61
+ ...joins !== undefined && {
62
+ joins: joins
63
+ },
64
+ ...locale && {
65
+ locale
66
+ },
67
+ ...fallbackLocale && {
68
+ fallbackLocale
69
+ },
70
+ ...draft !== undefined && {
71
+ draft
72
+ },
73
+ ...trash !== undefined && {
74
+ trash
75
+ }
76
+ });
77
+ return {
78
+ content: [
79
+ {
80
+ type: 'text',
81
+ text: `Document from collection "${collectionSlug}":\n${JSON.stringify(doc)}`
82
+ }
83
+ ],
84
+ doc: doc
85
+ };
86
+ } catch {
87
+ logger.warn(`Document not found with ID: ${id} in collection: ${collectionSlug}`);
88
+ return {
89
+ content: [
90
+ {
91
+ type: 'text',
92
+ text: `Error: Document with ID "${id}" not found in collection "${collectionSlug}"`
93
+ }
94
+ ]
95
+ };
96
+ }
97
+ }
98
+ const findOptions = {
99
+ collection: collectionSlug,
100
+ depth,
101
+ limit,
102
+ overrideAccess: authorizedMCP.overrideAccess,
103
+ page,
104
+ req,
105
+ ...select && {
106
+ select: select
107
+ },
108
+ ...populate && {
109
+ populate: populate
110
+ },
111
+ ...joins !== undefined && {
112
+ joins: joins
113
+ },
114
+ ...locale && {
115
+ locale
116
+ },
117
+ ...fallbackLocale && {
118
+ fallbackLocale
119
+ },
120
+ ...draft !== undefined && {
121
+ draft
122
+ },
123
+ ...pagination !== undefined && {
124
+ pagination
125
+ },
126
+ ...trash !== undefined && {
127
+ trash
128
+ }
129
+ };
130
+ if (sort) {
131
+ findOptions.sort = sort;
132
+ }
133
+ if (where) {
134
+ findOptions.where = where;
135
+ }
136
+ const result = await payload.find(findOptions);
137
+ let responseText = `Collection: "${collectionSlug}"\nTotal: ${result.totalDocs} documents\nPage: ${result.page} of ${result.totalPages}\n`;
138
+ for (const doc of result.docs){
139
+ responseText += `\n\`\`\`json\n${JSON.stringify(doc)}\n\`\`\``;
140
+ }
141
+ return {
142
+ content: [
143
+ {
144
+ type: 'text',
145
+ text: responseText
146
+ }
147
+ ],
148
+ doc: result
149
+ };
150
+ } catch (error) {
151
+ const errorMessage = error instanceof Error ? error.message : 'Unknown error';
152
+ logger.error(`Error reading documents from collection ${collectionSlug}: ${errorMessage}`);
153
+ return {
154
+ content: [
155
+ {
156
+ type: 'text',
157
+ text: `❌ **Error reading documents from collection "${collectionSlug}":** ${errorMessage}`
158
+ }
159
+ ]
160
+ };
161
+ }
162
+ });
163
+
164
+ //# sourceMappingURL=findTool.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/mcp/builtin/collections/findTool.ts"],"sourcesContent":["import type { JoinQuery, PopulateType, SelectType } from 'payload'\n\nimport { z } from 'zod'\n\nimport { defaultAccess } from '../../../defaultAccess.js'\nimport { defineCollectionTool } from '../../../defineTool.js'\nimport { getLogger } from '../../../utils/getLogger.js'\nimport { whereSchema } from '../../../utils/whereSchema.js'\n\nconst DEFAULT_DESCRIPTION =\n 'Find documents in any collection by passing the collection slug and optional ID or where clause.'\n\nexport const findDocumentsTool = defineCollectionTool({\n access: (args) =>\n defaultAccess(args) && Boolean(args.permissions?.collections?.[args.collectionSlug]?.read),\n annotations: {\n destructiveHint: false,\n idempotentHint: true,\n openWorldHint: false,\n readOnlyHint: true,\n title: 'Find Documents',\n },\n description: DEFAULT_DESCRIPTION,\n input: z.object({\n id: z\n .union([z.string(), z.number()])\n .describe(\n 'Optional: specific document ID to retrieve. If not provided, returns all documents',\n )\n .optional(),\n depth: z\n .number()\n .int()\n .min(0)\n .max(10)\n .describe('How many levels deep to populate relationships (default: 0)')\n .optional()\n .default(0),\n draft: z\n .boolean()\n .describe(\n 'For versioned collections, true returns the latest draft version when available. False reads the main document.',\n )\n .optional(),\n fallbackLocale: z\n .string()\n .describe('Optional: fallback locale code to use when requested locale is not available')\n .optional(),\n joins: z\n .union([z.record(z.string(), z.unknown()), z.literal(false)])\n .describe('Optional: configure join field queries, or pass false to disable all join fields.')\n .optional(),\n limit: z\n .number()\n .int()\n .min(1)\n .max(100)\n .describe('Maximum number of documents to return (default: 10, max: 100)')\n .optional()\n .default(10),\n locale: z\n .string()\n .describe(\n 'Optional: locale code to retrieve data in (e.g., \"en\", \"es\"). Use \"all\" to retrieve all locales for localized fields',\n )\n .optional(),\n page: z\n .number()\n .int()\n .min(1)\n .describe('Page number for pagination (default: 1)')\n .optional()\n .default(1),\n pagination: z\n .boolean()\n .describe('Optional: set to false to skip the count query overhead')\n .optional(),\n populate: z\n .record(z.string(), z.unknown())\n .describe(\n 'Optional: control which fields to include from populated relationship or upload documents.',\n )\n .optional(),\n select: z\n .record(z.string(), z.unknown())\n .describe(\n 'Optional: define exactly which fields you\\'d like to return in the response, e.g., {\"title\": true}',\n )\n .optional(),\n sort: z\n .string()\n .describe('Field to sort by (e.g., \"createdAt\", \"-updatedAt\" for descending)')\n .optional(),\n trash: z\n .boolean()\n .describe('Optional: include soft-deleted documents when trash is enabled on the collection')\n .optional(),\n where: whereSchema\n .describe(\n 'Optional: where clause for filtering. Use field names with Payload operators, and/or arrays for grouping. Example: {\"title\":{\"contains\":\"test\"}}',\n )\n .optional(),\n }),\n}).handler(async ({ authorizedMCP, collectionSlug, input, req }) => {\n const payload = req.payload\n const logger = getLogger({ payload })\n\n const {\n id,\n depth,\n draft,\n fallbackLocale,\n joins,\n limit,\n locale,\n page,\n pagination,\n populate,\n select,\n sort,\n trash,\n where,\n } = input\n\n logger.info(\n `Reading document from collection: ${collectionSlug}${id ? ` with ID: ${id}` : ''}, limit: ${limit}, page: ${page}${locale ? `, locale: ${locale}` : ''}`,\n )\n\n try {\n if (id) {\n try {\n const doc = await payload.findByID({\n id,\n collection: collectionSlug,\n depth,\n overrideAccess: authorizedMCP.overrideAccess,\n req,\n ...(select && { select: select as SelectType }),\n ...(populate && { populate: populate as PopulateType }),\n ...(joins !== undefined && { joins: joins as JoinQuery }),\n ...(locale && { locale }),\n ...(fallbackLocale && { fallbackLocale }),\n ...(draft !== undefined && { draft }),\n ...(trash !== undefined && { trash }),\n })\n\n return {\n content: [\n {\n type: 'text',\n text: `Document from collection \"${collectionSlug}\":\\n${JSON.stringify(doc)}`,\n },\n ],\n doc: doc as Record<string, unknown>,\n }\n } catch {\n logger.warn(`Document not found with ID: ${id} in collection: ${collectionSlug}`)\n return {\n content: [\n {\n type: 'text',\n text: `Error: Document with ID \"${id}\" not found in collection \"${collectionSlug}\"`,\n },\n ],\n }\n }\n }\n\n const findOptions: Parameters<typeof payload.find>[0] = {\n collection: collectionSlug,\n depth,\n limit,\n overrideAccess: authorizedMCP.overrideAccess,\n page,\n req,\n ...(select && { select: select as SelectType }),\n ...(populate && { populate: populate as PopulateType }),\n ...(joins !== undefined && { joins: joins as JoinQuery }),\n ...(locale && { locale }),\n ...(fallbackLocale && { fallbackLocale }),\n ...(draft !== undefined && { draft }),\n ...(pagination !== undefined && { pagination }),\n ...(trash !== undefined && { trash }),\n }\n\n if (sort) {\n findOptions.sort = sort\n }\n if (where) {\n findOptions.where = where\n }\n\n const result = await payload.find(findOptions)\n\n let responseText = `Collection: \"${collectionSlug}\"\\nTotal: ${result.totalDocs} documents\\nPage: ${result.page} of ${result.totalPages}\\n`\n for (const doc of result.docs) {\n responseText += `\\n\\`\\`\\`json\\n${JSON.stringify(doc)}\\n\\`\\`\\``\n }\n\n return {\n content: [{ type: 'text', text: responseText }],\n doc: result as unknown as Record<string, unknown>,\n }\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : 'Unknown error'\n logger.error(`Error reading documents from collection ${collectionSlug}: ${errorMessage}`)\n return {\n content: [\n {\n type: 'text',\n text: `❌ **Error reading documents from collection \"${collectionSlug}\":** ${errorMessage}`,\n },\n ],\n }\n }\n})\n"],"names":["z","defaultAccess","defineCollectionTool","getLogger","whereSchema","DEFAULT_DESCRIPTION","findDocumentsTool","access","args","Boolean","permissions","collections","collectionSlug","read","annotations","destructiveHint","idempotentHint","openWorldHint","readOnlyHint","title","description","input","object","id","union","string","number","describe","optional","depth","int","min","max","default","draft","boolean","fallbackLocale","joins","record","unknown","literal","limit","locale","page","pagination","populate","select","sort","trash","where","handler","authorizedMCP","req","payload","logger","info","doc","findByID","collection","overrideAccess","undefined","content","type","text","JSON","stringify","warn","findOptions","result","find","responseText","totalDocs","totalPages","docs","error","errorMessage","Error","message"],"mappings":"AAEA,SAASA,CAAC,QAAQ,MAAK;AAEvB,SAASC,aAAa,QAAQ,4BAA2B;AACzD,SAASC,oBAAoB,QAAQ,yBAAwB;AAC7D,SAASC,SAAS,QAAQ,8BAA6B;AACvD,SAASC,WAAW,QAAQ,gCAA+B;AAE3D,MAAMC,sBACJ;AAEF,OAAO,MAAMC,oBAAoBJ,qBAAqB;IACpDK,QAAQ,CAACC,OACPP,cAAcO,SAASC,QAAQD,KAAKE,WAAW,EAAEC,aAAa,CAACH,KAAKI,cAAc,CAAC,EAAEC;IACvFC,aAAa;QACXC,iBAAiB;QACjBC,gBAAgB;QAChBC,eAAe;QACfC,cAAc;QACdC,OAAO;IACT;IACAC,aAAaf;IACbgB,OAAOrB,EAAEsB,MAAM,CAAC;QACdC,IAAIvB,EACDwB,KAAK,CAAC;YAACxB,EAAEyB,MAAM;YAAIzB,EAAE0B,MAAM;SAAG,EAC9BC,QAAQ,CACP,sFAEDC,QAAQ;QACXC,OAAO7B,EACJ0B,MAAM,GACNI,GAAG,GACHC,GAAG,CAAC,GACJC,GAAG,CAAC,IACJL,QAAQ,CAAC,+DACTC,QAAQ,GACRK,OAAO,CAAC;QACXC,OAAOlC,EACJmC,OAAO,GACPR,QAAQ,CACP,mHAEDC,QAAQ;QACXQ,gBAAgBpC,EACbyB,MAAM,GACNE,QAAQ,CAAC,gFACTC,QAAQ;QACXS,OAAOrC,EACJwB,KAAK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aACD;QACH;IACF;AACF,GAAE"}
@@ -0,0 +1,2 @@
1
+ export declare const findVersionByIDTool: import("../../../types.js").CollectionTool;
2
+ //# sourceMappingURL=findVersionByIDTool.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"findVersionByIDTool.d.ts","sourceRoot":"","sources":["../../../../src/mcp/builtin/collections/findVersionByIDTool.ts"],"names":[],"mappings":"AAWA,eAAO,MAAM,mBAAmB,4CAiG9B,CAAA"}
@@ -0,0 +1,83 @@
1
+ import { z } from 'zod';
2
+ import { defaultAccess } from '../../../defaultAccess.js';
3
+ import { defineCollectionTool } from '../../../defineTool.js';
4
+ import { getLogger } from '../../../utils/getLogger.js';
5
+ const DEFAULT_DESCRIPTION = 'Find a specific document version in any version-enabled collection by passing the collection slug and version ID.';
6
+ export const findVersionByIDTool = defineCollectionTool({
7
+ access: (args)=>defaultAccess(args) && Boolean(args.permissions?.collections?.[args.collectionSlug]?.readVersions),
8
+ annotations: {
9
+ destructiveHint: false,
10
+ idempotentHint: true,
11
+ openWorldHint: false,
12
+ readOnlyHint: true,
13
+ title: 'Find Version By ID'
14
+ },
15
+ description: DEFAULT_DESCRIPTION,
16
+ input: z.object({
17
+ id: z.string().describe('The ID of the version to retrieve'),
18
+ depth: z.number().int().min(0).max(10).describe('How many levels deep to populate relationships in the version document').optional().default(0),
19
+ fallbackLocale: z.string().describe('Optional: fallback locale code to use when requested locale is not available').optional(),
20
+ locale: z.string().describe('Optional: locale code to retrieve data in (e.g., "en", "es"). Use "all" to retrieve all locales for localized fields').optional(),
21
+ populate: z.record(z.string(), z.unknown()).describe('Optional: control which fields to include from populated relationship or upload documents.').optional(),
22
+ select: z.record(z.string(), z.unknown()).describe('Optional: define exactly which fields you\'d like to return in the response, e.g., {"version.title": true}').optional(),
23
+ showHiddenFields: z.boolean().describe('Optional: include hidden fields in the returned version document').optional(),
24
+ trash: z.boolean().describe('Optional: include soft-deleted version documents when trash is enabled').optional()
25
+ })
26
+ }).handler(async ({ authorizedMCP, collectionSlug, input, req })=>{
27
+ const payload = req.payload;
28
+ const logger = getLogger({
29
+ payload
30
+ });
31
+ const { id, depth, fallbackLocale, locale, populate, select, showHiddenFields, trash } = input;
32
+ logger.info(`Finding version in collection: ${collectionSlug} with ID: ${id}`);
33
+ try {
34
+ const result = await payload.findVersionByID({
35
+ id,
36
+ collection: collectionSlug,
37
+ depth,
38
+ overrideAccess: authorizedMCP.overrideAccess,
39
+ req,
40
+ ...fallbackLocale ? {
41
+ fallbackLocale
42
+ } : {},
43
+ ...locale ? {
44
+ locale
45
+ } : {},
46
+ ...populate ? {
47
+ populate: populate
48
+ } : {},
49
+ ...select ? {
50
+ select: select
51
+ } : {},
52
+ ...showHiddenFields !== undefined ? {
53
+ showHiddenFields
54
+ } : {},
55
+ ...trash !== undefined ? {
56
+ trash
57
+ } : {}
58
+ });
59
+ return {
60
+ content: [
61
+ {
62
+ type: 'text',
63
+ text: `Version "${id}" from collection "${collectionSlug}":\n\`\`\`json\n${JSON.stringify(result)}\n\`\`\``
64
+ }
65
+ ],
66
+ doc: result
67
+ };
68
+ } catch (error) {
69
+ const errorMessage = error instanceof Error ? error.message : 'Unknown error';
70
+ logger.error(`Error finding version ${id} in ${collectionSlug}: ${errorMessage}`);
71
+ return {
72
+ content: [
73
+ {
74
+ type: 'text',
75
+ text: `❌ **Error finding version "${id}" in collection "${collectionSlug}":** ${errorMessage}`
76
+ }
77
+ ],
78
+ isError: true
79
+ };
80
+ }
81
+ });
82
+
83
+ //# sourceMappingURL=findVersionByIDTool.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/mcp/builtin/collections/findVersionByIDTool.ts"],"sourcesContent":["import type { PopulateType, SelectType } from 'payload'\n\nimport { z } from 'zod'\n\nimport { defaultAccess } from '../../../defaultAccess.js'\nimport { defineCollectionTool } from '../../../defineTool.js'\nimport { getLogger } from '../../../utils/getLogger.js'\n\nconst DEFAULT_DESCRIPTION =\n 'Find a specific document version in any version-enabled collection by passing the collection slug and version ID.'\n\nexport const findVersionByIDTool = defineCollectionTool({\n access: (args) =>\n defaultAccess(args) &&\n Boolean(args.permissions?.collections?.[args.collectionSlug]?.readVersions),\n annotations: {\n destructiveHint: false,\n idempotentHint: true,\n openWorldHint: false,\n readOnlyHint: true,\n title: 'Find Version By ID',\n },\n description: DEFAULT_DESCRIPTION,\n input: z.object({\n id: z.string().describe('The ID of the version to retrieve'),\n depth: z\n .number()\n .int()\n .min(0)\n .max(10)\n .describe('How many levels deep to populate relationships in the version document')\n .optional()\n .default(0),\n fallbackLocale: z\n .string()\n .describe('Optional: fallback locale code to use when requested locale is not available')\n .optional(),\n locale: z\n .string()\n .describe(\n 'Optional: locale code to retrieve data in (e.g., \"en\", \"es\"). Use \"all\" to retrieve all locales for localized fields',\n )\n .optional(),\n populate: z\n .record(z.string(), z.unknown())\n .describe(\n 'Optional: control which fields to include from populated relationship or upload documents.',\n )\n .optional(),\n select: z\n .record(z.string(), z.unknown())\n .describe(\n 'Optional: define exactly which fields you\\'d like to return in the response, e.g., {\"version.title\": true}',\n )\n .optional(),\n showHiddenFields: z\n .boolean()\n .describe('Optional: include hidden fields in the returned version document')\n .optional(),\n trash: z\n .boolean()\n .describe('Optional: include soft-deleted version documents when trash is enabled')\n .optional(),\n }),\n}).handler(async ({ authorizedMCP, collectionSlug, input, req }) => {\n const payload = req.payload\n const logger = getLogger({ payload })\n const { id, depth, fallbackLocale, locale, populate, select, showHiddenFields, trash } = input\n\n logger.info(`Finding version in collection: ${collectionSlug} with ID: ${id}`)\n\n try {\n const result = await payload.findVersionByID({\n id,\n collection: collectionSlug,\n depth,\n overrideAccess: authorizedMCP.overrideAccess,\n req,\n ...(fallbackLocale ? { fallbackLocale } : {}),\n ...(locale ? { locale } : {}),\n ...(populate ? { populate: populate as PopulateType } : {}),\n ...(select ? { select: select as SelectType } : {}),\n ...(showHiddenFields !== undefined ? { showHiddenFields } : {}),\n ...(trash !== undefined ? { trash } : {}),\n })\n\n return {\n content: [\n {\n type: 'text',\n text: `Version \"${id}\" from collection \"${collectionSlug}\":\\n\\`\\`\\`json\\n${JSON.stringify(result)}\\n\\`\\`\\``,\n },\n ],\n doc: result as unknown as Record<string, unknown>,\n }\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : 'Unknown error'\n logger.error(`Error finding version ${id} in ${collectionSlug}: ${errorMessage}`)\n return {\n content: [\n {\n type: 'text',\n text: `❌ **Error finding version \"${id}\" in collection \"${collectionSlug}\":** ${errorMessage}`,\n },\n ],\n isError: true,\n }\n }\n})\n"],"names":["z","defaultAccess","defineCollectionTool","getLogger","DEFAULT_DESCRIPTION","findVersionByIDTool","access","args","Boolean","permissions","collections","collectionSlug","readVersions","annotations","destructiveHint","idempotentHint","openWorldHint","readOnlyHint","title","description","input","object","id","string","describe","depth","number","int","min","max","optional","default","fallbackLocale","locale","populate","record","unknown","select","showHiddenFields","boolean","trash","handler","authorizedMCP","req","payload","logger","info","result","findVersionByID","collection","overrideAccess","undefined","content","type","text","JSON","stringify","doc","error","errorMessage","Error","message","isError"],"mappings":"AAEA,SAASA,CAAC,QAAQ,MAAK;AAEvB,SAASC,aAAa,QAAQ,4BAA2B;AACzD,SAASC,oBAAoB,QAAQ,yBAAwB;AAC7D,SAASC,SAAS,QAAQ,8BAA6B;AAEvD,MAAMC,sBACJ;AAEF,OAAO,MAAMC,sBAAsBH,qBAAqB;IACtDI,QAAQ,CAACC,OACPN,cAAcM,SACdC,QAAQD,KAAKE,WAAW,EAAEC,aAAa,CAACH,KAAKI,cAAc,CAAC,EAAEC;IAChEC,aAAa;QACXC,iBAAiB;QACjBC,gBAAgB;QAChBC,eAAe;QACfC,cAAc;QACdC,OAAO;IACT;IACAC,aAAaf;IACbgB,OAAOpB,EAAEqB,MAAM,CAAC;QACdC,IAAItB,EAAEuB,MAAM,GAAGC,QAAQ,CAAC;QACxBC,OAAOzB,EACJ0B,MAAM,GACNC,GAAG,GACHC,GAAG,CAAC,GACJC,GAAG,CAAC,IACJL,QAAQ,C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