@payloadcms/plugin-mcp 4.0.0-canary.2 → 4.0.0-canary.20

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 (475) hide show
  1. package/LICENSE.md +1 -1
  2. package/bin.js +7 -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 +8 -8
  8. package/dist/defineTool.d.ts.map +1 -1
  9. package/dist/endpoint/access.d.ts +12 -5
  10. package/dist/endpoint/access.d.ts.map +1 -1
  11. package/dist/endpoint/access.js +74 -103
  12. package/dist/endpoint/access.js.map +1 -1
  13. package/dist/endpoint/index.d.ts +1 -1
  14. package/dist/endpoint/index.d.ts.map +1 -1
  15. package/dist/endpoint/index.js +68 -17
  16. package/dist/endpoint/index.js.map +1 -1
  17. package/dist/exports/client.d.ts +1 -4
  18. package/dist/exports/client.d.ts.map +1 -1
  19. package/dist/exports/client.js +1 -4
  20. package/dist/exports/client.js.map +1 -1
  21. package/dist/exports/internal.d.ts +2 -0
  22. package/dist/exports/internal.d.ts.map +1 -0
  23. package/dist/exports/internal.js +3 -0
  24. package/dist/exports/internal.js.map +1 -0
  25. package/dist/index.d.ts +2 -2
  26. package/dist/index.d.ts.map +1 -1
  27. package/dist/index.js +3 -51
  28. package/dist/index.js.map +1 -1
  29. package/dist/mcp/buildMcpServer.d.ts +4 -4
  30. package/dist/mcp/buildMcpServer.d.ts.map +1 -1
  31. package/dist/mcp/buildMcpServer.js +34 -10
  32. package/dist/mcp/buildMcpServer.js.map +1 -1
  33. package/dist/mcp/builtin/collections/authTools.d.ts.map +1 -1
  34. package/dist/mcp/builtin/collections/authTools.js +44 -6
  35. package/dist/mcp/builtin/collections/authTools.js.map +1 -1
  36. package/dist/mcp/builtin/collections/countTool.d.ts +2 -0
  37. package/dist/mcp/builtin/collections/countTool.d.ts.map +1 -0
  38. package/dist/mcp/builtin/collections/countTool.js +68 -0
  39. package/dist/mcp/builtin/collections/countTool.js.map +1 -0
  40. package/dist/mcp/builtin/collections/countVersionsTool.d.ts +2 -0
  41. package/dist/mcp/builtin/collections/countVersionsTool.d.ts.map +1 -0
  42. package/dist/mcp/builtin/collections/countVersionsTool.js +64 -0
  43. package/dist/mcp/builtin/collections/countVersionsTool.js.map +1 -0
  44. package/dist/mcp/builtin/collections/createTool.d.ts +1 -1
  45. package/dist/mcp/builtin/collections/createTool.d.ts.map +1 -1
  46. package/dist/mcp/builtin/collections/createTool.js +98 -54
  47. package/dist/mcp/builtin/collections/createTool.js.map +1 -1
  48. package/dist/mcp/builtin/collections/deleteTool.d.ts.map +1 -1
  49. package/dist/mcp/builtin/collections/deleteTool.js +10 -2
  50. package/dist/mcp/builtin/collections/deleteTool.js.map +1 -1
  51. package/dist/mcp/builtin/collections/duplicateTool.d.ts +2 -0
  52. package/dist/mcp/builtin/collections/duplicateTool.d.ts.map +1 -0
  53. package/dist/mcp/builtin/collections/duplicateTool.js +96 -0
  54. package/dist/mcp/builtin/collections/duplicateTool.js.map +1 -0
  55. package/dist/mcp/builtin/collections/fileInput.d.ts +28 -0
  56. package/dist/mcp/builtin/collections/fileInput.d.ts.map +1 -0
  57. package/dist/mcp/builtin/collections/fileInput.js +124 -0
  58. package/dist/mcp/builtin/collections/fileInput.js.map +1 -0
  59. package/dist/mcp/builtin/collections/fileInput.spec.js +86 -0
  60. package/dist/mcp/builtin/collections/fileInput.spec.js.map +1 -0
  61. package/dist/mcp/builtin/collections/findDistinctTool.d.ts +2 -0
  62. package/dist/mcp/builtin/collections/findDistinctTool.d.ts.map +1 -0
  63. package/dist/mcp/builtin/collections/findDistinctTool.js +92 -0
  64. package/dist/mcp/builtin/collections/findDistinctTool.js.map +1 -0
  65. package/dist/mcp/builtin/collections/findTool.d.ts.map +1 -1
  66. package/dist/mcp/builtin/collections/findTool.js +46 -26
  67. package/dist/mcp/builtin/collections/findTool.js.map +1 -1
  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 +83 -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 +98 -0
  75. package/dist/mcp/builtin/collections/findVersionsTool.js.map +1 -0
  76. package/dist/mcp/builtin/collections/formatCollectionError.d.ts +1 -1
  77. package/dist/mcp/builtin/collections/formatCollectionError.d.ts.map +1 -1
  78. package/dist/mcp/builtin/collections/formatCollectionError.js.map +1 -1
  79. package/dist/mcp/builtin/collections/getCollectionSchemaTool.d.ts.map +1 -1
  80. package/dist/mcp/builtin/collections/getCollectionSchemaTool.js +56 -4
  81. package/dist/mcp/builtin/collections/getCollectionSchemaTool.js.map +1 -1
  82. package/dist/mcp/builtin/collections/restoreVersionTool.d.ts +2 -0
  83. package/dist/mcp/builtin/collections/restoreVersionTool.d.ts.map +1 -0
  84. package/dist/mcp/builtin/collections/restoreVersionTool.js +81 -0
  85. package/dist/mcp/builtin/collections/restoreVersionTool.js.map +1 -0
  86. package/dist/mcp/builtin/collections/updateTool.d.ts.map +1 -1
  87. package/dist/mcp/builtin/collections/updateTool.js +38 -33
  88. package/dist/mcp/builtin/collections/updateTool.js.map +1 -1
  89. package/dist/mcp/builtin/collections/uploadInstructionsTool.d.ts +2 -0
  90. package/dist/mcp/builtin/collections/uploadInstructionsTool.d.ts.map +1 -0
  91. package/dist/mcp/builtin/collections/uploadInstructionsTool.js +55 -0
  92. package/dist/mcp/builtin/collections/uploadInstructionsTool.js.map +1 -0
  93. package/dist/mcp/builtin/getConfigInfoTool.d.ts.map +1 -1
  94. package/dist/mcp/builtin/getConfigInfoTool.js +27 -8
  95. package/dist/mcp/builtin/getConfigInfoTool.js.map +1 -1
  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 +64 -0
  99. package/dist/mcp/builtin/globals/countVersionsTool.js.map +1 -0
  100. package/dist/mcp/builtin/globals/findTool.d.ts.map +1 -1
  101. package/dist/mcp/builtin/globals/findTool.js +19 -22
  102. package/dist/mcp/builtin/globals/findTool.js.map +1 -1
  103. package/dist/mcp/builtin/globals/findVersionByIDTool.d.ts +2 -0
  104. package/dist/mcp/builtin/globals/findVersionByIDTool.d.ts.map +1 -0
  105. package/dist/mcp/builtin/globals/findVersionByIDTool.js +79 -0
  106. package/dist/mcp/builtin/globals/findVersionByIDTool.js.map +1 -0
  107. package/dist/mcp/builtin/globals/findVersionsTool.d.ts +2 -0
  108. package/dist/mcp/builtin/globals/findVersionsTool.d.ts.map +1 -0
  109. package/dist/mcp/builtin/globals/findVersionsTool.js +94 -0
  110. package/dist/mcp/builtin/globals/findVersionsTool.js.map +1 -0
  111. package/dist/mcp/builtin/globals/getGlobalSchemaTool.d.ts.map +1 -1
  112. package/dist/mcp/builtin/globals/getGlobalSchemaTool.js +32 -2
  113. package/dist/mcp/builtin/globals/getGlobalSchemaTool.js.map +1 -1
  114. package/dist/mcp/builtin/globals/restoreVersionTool.d.ts +2 -0
  115. package/dist/mcp/builtin/globals/restoreVersionTool.d.ts.map +1 -0
  116. package/dist/mcp/builtin/globals/restoreVersionTool.js +77 -0
  117. package/dist/mcp/builtin/globals/restoreVersionTool.js.map +1 -0
  118. package/dist/mcp/builtin/globals/updateTool.js +14 -21
  119. package/dist/mcp/builtin/globals/updateTool.js.map +1 -1
  120. package/dist/mcp/builtin/validateEntityData.d.ts.map +1 -1
  121. package/dist/mcp/builtin/validateEntityData.js +1 -1
  122. package/dist/mcp/builtin/validateEntityData.js.map +1 -1
  123. package/dist/mcp/builtinTools.d.ts +75 -12
  124. package/dist/mcp/builtinTools.d.ts.map +1 -1
  125. package/dist/mcp/builtinTools.js +75 -13
  126. package/dist/mcp/builtinTools.js.map +1 -1
  127. package/dist/mcp/sanitizeMCPConfig.d.ts +0 -1
  128. package/dist/mcp/sanitizeMCPConfig.d.ts.map +1 -1
  129. package/dist/mcp/sanitizeMCPConfig.js +72 -27
  130. package/dist/mcp/sanitizeMCPConfig.js.map +1 -1
  131. package/dist/stdio.d.ts +3 -3
  132. package/dist/stdio.d.ts.map +1 -1
  133. package/dist/stdio.js +84 -46
  134. package/dist/stdio.js.map +1 -1
  135. package/dist/types.d.ts +100 -92
  136. package/dist/types.d.ts.map +1 -1
  137. package/dist/types.js +2 -4
  138. package/dist/types.js.map +1 -1
  139. package/dist/utils/camelCase.d.ts.map +1 -1
  140. package/dist/utils/getPluginConfig.d.ts +1 -1
  141. package/dist/utils/getPluginConfig.js +1 -1
  142. package/dist/utils/getPluginConfig.js.map +1 -1
  143. package/dist/utils/resolveProjectRoot.d.ts.map +1 -1
  144. package/dist/utils/schemaConversion/filterFieldsByAccess.d.ts +28 -0
  145. package/dist/utils/schemaConversion/filterFieldsByAccess.d.ts.map +1 -0
  146. package/dist/utils/schemaConversion/filterFieldsByAccess.js +71 -0
  147. package/dist/utils/schemaConversion/filterFieldsByAccess.js.map +1 -0
  148. package/dist/utils/schemaConversion/getEntityInputSchema.d.ts +5 -3
  149. package/dist/utils/schemaConversion/getEntityInputSchema.d.ts.map +1 -1
  150. package/dist/utils/schemaConversion/getEntityInputSchema.js +44 -12
  151. package/dist/utils/schemaConversion/getEntityInputSchema.js.map +1 -1
  152. package/dist/utils/schemaConversion/sanitizeEntitySchema.d.ts +5 -10
  153. package/dist/utils/schemaConversion/sanitizeEntitySchema.d.ts.map +1 -1
  154. package/dist/utils/schemaConversion/sanitizeEntitySchema.js +15 -95
  155. package/dist/utils/schemaConversion/sanitizeEntitySchema.js.map +1 -1
  156. package/dist/utils/schemaConversion/sanitizeEntitySchema.spec.js +15 -40
  157. package/dist/utils/schemaConversion/sanitizeEntitySchema.spec.js.map +1 -1
  158. package/dist/utils/toStandardSchema.d.ts.map +1 -1
  159. package/package.json +10 -16
  160. package/src/defaultAccess.ts +3 -0
  161. package/src/endpoint/access.ts +80 -112
  162. package/src/endpoint/index.ts +58 -16
  163. package/src/exports/client.ts +2 -4
  164. package/src/exports/internal.ts +1 -0
  165. package/src/index.ts +5 -59
  166. package/src/mcp/buildMcpServer.ts +48 -21
  167. package/src/mcp/builtin/collections/authTools.ts +45 -9
  168. package/src/mcp/builtin/collections/countTool.ts +73 -0
  169. package/src/mcp/builtin/collections/countVersionsTool.ts +69 -0
  170. package/src/mcp/builtin/collections/createTool.ts +98 -42
  171. package/src/mcp/builtin/collections/deleteTool.ts +11 -2
  172. package/src/mcp/builtin/collections/duplicateTool.ts +134 -0
  173. package/src/mcp/builtin/collections/fileInput.spec.ts +93 -0
  174. package/src/mcp/builtin/collections/fileInput.ts +164 -0
  175. package/src/mcp/builtin/collections/findDistinctTool.ts +119 -0
  176. package/src/mcp/builtin/collections/findTool.ts +59 -20
  177. package/src/mcp/builtin/collections/findVersionByIDTool.ts +109 -0
  178. package/src/mcp/builtin/collections/findVersionsTool.ts +154 -0
  179. package/src/mcp/builtin/collections/formatCollectionError.ts +1 -1
  180. package/src/mcp/builtin/collections/getCollectionSchemaTool.ts +55 -3
  181. package/src/mcp/builtin/collections/restoreVersionTool.ts +107 -0
  182. package/src/mcp/builtin/collections/updateTool.ts +40 -24
  183. package/src/mcp/builtin/collections/uploadInstructionsTool.ts +64 -0
  184. package/src/mcp/builtin/getConfigInfoTool.ts +27 -4
  185. package/src/mcp/builtin/globals/countVersionsTool.ts +68 -0
  186. package/src/mcp/builtin/globals/findTool.ts +27 -18
  187. package/src/mcp/builtin/globals/findVersionByIDTool.ts +103 -0
  188. package/src/mcp/builtin/globals/findVersionsTool.ts +147 -0
  189. package/src/mcp/builtin/globals/getGlobalSchemaTool.ts +37 -2
  190. package/src/mcp/builtin/globals/restoreVersionTool.ts +99 -0
  191. package/src/mcp/builtin/globals/updateTool.ts +16 -16
  192. package/src/mcp/builtin/validateEntityData.ts +1 -1
  193. package/src/mcp/builtinTools.ts +81 -18
  194. package/src/mcp/sanitizeMCPConfig.ts +51 -30
  195. package/src/stdio.ts +79 -46
  196. package/src/types.ts +108 -95
  197. package/src/utils/getPluginConfig.ts +1 -1
  198. package/src/utils/schemaConversion/filterFieldsByAccess.ts +123 -0
  199. package/src/utils/schemaConversion/getEntityInputSchema.ts +45 -27
  200. package/src/utils/schemaConversion/sanitizeEntitySchema.spec.ts +12 -19
  201. package/src/utils/schemaConversion/sanitizeEntitySchema.ts +17 -114
  202. package/dist/collection/getAccessField.d.ts +0 -12
  203. package/dist/collection/getAccessField.d.ts.map +0 -1
  204. package/dist/collection/getAccessField.js +0 -72
  205. package/dist/collection/getAccessField.js.map +0 -1
  206. package/dist/collection/index.d.ts +0 -6
  207. package/dist/collection/index.d.ts.map +0 -1
  208. package/dist/collection/index.js +0 -105
  209. package/dist/collection/index.js.map +0 -1
  210. package/dist/components/APIKeyField/index.client.d.ts +0 -9
  211. package/dist/components/APIKeyField/index.client.d.ts.map +0 -1
  212. package/dist/components/APIKeyField/index.client.js +0 -85
  213. package/dist/components/APIKeyField/index.client.js.map +0 -1
  214. package/dist/components/APIKeyField/index.css +0 -105
  215. package/dist/components/APIKeysEmptyState/index.client.d.ts +0 -4
  216. package/dist/components/APIKeysEmptyState/index.client.d.ts.map +0 -1
  217. package/dist/components/APIKeysEmptyState/index.client.js +0 -21
  218. package/dist/components/APIKeysEmptyState/index.client.js.map +0 -1
  219. package/dist/components/AccessField/index.client.d.ts +0 -10
  220. package/dist/components/AccessField/index.client.d.ts.map +0 -1
  221. package/dist/components/AccessField/index.client.js +0 -247
  222. package/dist/components/AccessField/index.client.js.map +0 -1
  223. package/dist/components/AccessField/index.css +0 -99
  224. package/dist/components/SettingsMenu/index.client.d.ts +0 -8
  225. package/dist/components/SettingsMenu/index.client.d.ts.map +0 -1
  226. package/dist/components/SettingsMenu/index.client.js +0 -29
  227. package/dist/components/SettingsMenu/index.client.js.map +0 -1
  228. package/dist/translations/index.d.ts +0 -11
  229. package/dist/translations/index.d.ts.map +0 -1
  230. package/dist/translations/index.js +0 -92
  231. package/dist/translations/index.js.map +0 -1
  232. package/dist/translations/languages/ar.d.ts +0 -31
  233. package/dist/translations/languages/ar.d.ts.map +0 -1
  234. package/dist/translations/languages/ar.js +0 -34
  235. package/dist/translations/languages/ar.js.map +0 -1
  236. package/dist/translations/languages/az.d.ts +0 -31
  237. package/dist/translations/languages/az.d.ts.map +0 -1
  238. package/dist/translations/languages/az.js +0 -34
  239. package/dist/translations/languages/az.js.map +0 -1
  240. package/dist/translations/languages/bg.d.ts +0 -31
  241. package/dist/translations/languages/bg.d.ts.map +0 -1
  242. package/dist/translations/languages/bg.js +0 -34
  243. package/dist/translations/languages/bg.js.map +0 -1
  244. package/dist/translations/languages/bnBd.d.ts +0 -31
  245. package/dist/translations/languages/bnBd.d.ts.map +0 -1
  246. package/dist/translations/languages/bnBd.js +0 -34
  247. package/dist/translations/languages/bnBd.js.map +0 -1
  248. package/dist/translations/languages/bnIn.d.ts +0 -31
  249. package/dist/translations/languages/bnIn.d.ts.map +0 -1
  250. package/dist/translations/languages/bnIn.js +0 -34
  251. package/dist/translations/languages/bnIn.js.map +0 -1
  252. package/dist/translations/languages/ca.d.ts +0 -31
  253. package/dist/translations/languages/ca.d.ts.map +0 -1
  254. package/dist/translations/languages/ca.js +0 -34
  255. package/dist/translations/languages/ca.js.map +0 -1
  256. package/dist/translations/languages/cs.d.ts +0 -31
  257. package/dist/translations/languages/cs.d.ts.map +0 -1
  258. package/dist/translations/languages/cs.js +0 -34
  259. package/dist/translations/languages/cs.js.map +0 -1
  260. package/dist/translations/languages/da.d.ts +0 -31
  261. package/dist/translations/languages/da.d.ts.map +0 -1
  262. package/dist/translations/languages/da.js +0 -34
  263. package/dist/translations/languages/da.js.map +0 -1
  264. package/dist/translations/languages/de.d.ts +0 -31
  265. package/dist/translations/languages/de.d.ts.map +0 -1
  266. package/dist/translations/languages/de.js +0 -34
  267. package/dist/translations/languages/de.js.map +0 -1
  268. package/dist/translations/languages/en.d.ts +0 -31
  269. package/dist/translations/languages/en.d.ts.map +0 -1
  270. package/dist/translations/languages/en.js +0 -34
  271. package/dist/translations/languages/en.js.map +0 -1
  272. package/dist/translations/languages/es.d.ts +0 -31
  273. package/dist/translations/languages/es.d.ts.map +0 -1
  274. package/dist/translations/languages/es.js +0 -34
  275. package/dist/translations/languages/es.js.map +0 -1
  276. package/dist/translations/languages/et.d.ts +0 -31
  277. package/dist/translations/languages/et.d.ts.map +0 -1
  278. package/dist/translations/languages/et.js +0 -34
  279. package/dist/translations/languages/et.js.map +0 -1
  280. package/dist/translations/languages/fa.d.ts +0 -31
  281. package/dist/translations/languages/fa.d.ts.map +0 -1
  282. package/dist/translations/languages/fa.js +0 -34
  283. package/dist/translations/languages/fa.js.map +0 -1
  284. package/dist/translations/languages/fr.d.ts +0 -31
  285. package/dist/translations/languages/fr.d.ts.map +0 -1
  286. package/dist/translations/languages/fr.js +0 -34
  287. package/dist/translations/languages/fr.js.map +0 -1
  288. package/dist/translations/languages/he.d.ts +0 -31
  289. package/dist/translations/languages/he.d.ts.map +0 -1
  290. package/dist/translations/languages/he.js +0 -34
  291. package/dist/translations/languages/he.js.map +0 -1
  292. package/dist/translations/languages/hr.d.ts +0 -31
  293. package/dist/translations/languages/hr.d.ts.map +0 -1
  294. package/dist/translations/languages/hr.js +0 -34
  295. package/dist/translations/languages/hr.js.map +0 -1
  296. package/dist/translations/languages/hu.d.ts +0 -31
  297. package/dist/translations/languages/hu.d.ts.map +0 -1
  298. package/dist/translations/languages/hu.js +0 -34
  299. package/dist/translations/languages/hu.js.map +0 -1
  300. package/dist/translations/languages/hy.d.ts +0 -31
  301. package/dist/translations/languages/hy.d.ts.map +0 -1
  302. package/dist/translations/languages/hy.js +0 -34
  303. package/dist/translations/languages/hy.js.map +0 -1
  304. package/dist/translations/languages/id.d.ts +0 -31
  305. package/dist/translations/languages/id.d.ts.map +0 -1
  306. package/dist/translations/languages/id.js +0 -34
  307. package/dist/translations/languages/id.js.map +0 -1
  308. package/dist/translations/languages/is.d.ts +0 -31
  309. package/dist/translations/languages/is.d.ts.map +0 -1
  310. package/dist/translations/languages/is.js +0 -34
  311. package/dist/translations/languages/is.js.map +0 -1
  312. package/dist/translations/languages/it.d.ts +0 -31
  313. package/dist/translations/languages/it.d.ts.map +0 -1
  314. package/dist/translations/languages/it.js +0 -34
  315. package/dist/translations/languages/it.js.map +0 -1
  316. package/dist/translations/languages/ja.d.ts +0 -31
  317. package/dist/translations/languages/ja.d.ts.map +0 -1
  318. package/dist/translations/languages/ja.js +0 -34
  319. package/dist/translations/languages/ja.js.map +0 -1
  320. package/dist/translations/languages/ko.d.ts +0 -31
  321. package/dist/translations/languages/ko.d.ts.map +0 -1
  322. package/dist/translations/languages/ko.js +0 -34
  323. package/dist/translations/languages/ko.js.map +0 -1
  324. package/dist/translations/languages/lt.d.ts +0 -31
  325. package/dist/translations/languages/lt.d.ts.map +0 -1
  326. package/dist/translations/languages/lt.js +0 -34
  327. package/dist/translations/languages/lt.js.map +0 -1
  328. package/dist/translations/languages/lv.d.ts +0 -31
  329. package/dist/translations/languages/lv.d.ts.map +0 -1
  330. package/dist/translations/languages/lv.js +0 -34
  331. package/dist/translations/languages/lv.js.map +0 -1
  332. package/dist/translations/languages/my.d.ts +0 -31
  333. package/dist/translations/languages/my.d.ts.map +0 -1
  334. package/dist/translations/languages/my.js +0 -34
  335. package/dist/translations/languages/my.js.map +0 -1
  336. package/dist/translations/languages/nb.d.ts +0 -31
  337. package/dist/translations/languages/nb.d.ts.map +0 -1
  338. package/dist/translations/languages/nb.js +0 -34
  339. package/dist/translations/languages/nb.js.map +0 -1
  340. package/dist/translations/languages/nl.d.ts +0 -31
  341. package/dist/translations/languages/nl.d.ts.map +0 -1
  342. package/dist/translations/languages/nl.js +0 -34
  343. package/dist/translations/languages/nl.js.map +0 -1
  344. package/dist/translations/languages/pl.d.ts +0 -31
  345. package/dist/translations/languages/pl.d.ts.map +0 -1
  346. package/dist/translations/languages/pl.js +0 -34
  347. package/dist/translations/languages/pl.js.map +0 -1
  348. package/dist/translations/languages/pt.d.ts +0 -31
  349. package/dist/translations/languages/pt.d.ts.map +0 -1
  350. package/dist/translations/languages/pt.js +0 -34
  351. package/dist/translations/languages/pt.js.map +0 -1
  352. package/dist/translations/languages/ro.d.ts +0 -31
  353. package/dist/translations/languages/ro.d.ts.map +0 -1
  354. package/dist/translations/languages/ro.js +0 -34
  355. package/dist/translations/languages/ro.js.map +0 -1
  356. package/dist/translations/languages/rs.d.ts +0 -31
  357. package/dist/translations/languages/rs.d.ts.map +0 -1
  358. package/dist/translations/languages/rs.js +0 -34
  359. package/dist/translations/languages/rs.js.map +0 -1
  360. package/dist/translations/languages/rsLatin.d.ts +0 -31
  361. package/dist/translations/languages/rsLatin.d.ts.map +0 -1
  362. package/dist/translations/languages/rsLatin.js +0 -34
  363. package/dist/translations/languages/rsLatin.js.map +0 -1
  364. package/dist/translations/languages/ru.d.ts +0 -31
  365. package/dist/translations/languages/ru.d.ts.map +0 -1
  366. package/dist/translations/languages/ru.js +0 -34
  367. package/dist/translations/languages/ru.js.map +0 -1
  368. package/dist/translations/languages/sk.d.ts +0 -31
  369. package/dist/translations/languages/sk.d.ts.map +0 -1
  370. package/dist/translations/languages/sk.js +0 -34
  371. package/dist/translations/languages/sk.js.map +0 -1
  372. package/dist/translations/languages/sl.d.ts +0 -31
  373. package/dist/translations/languages/sl.d.ts.map +0 -1
  374. package/dist/translations/languages/sl.js +0 -34
  375. package/dist/translations/languages/sl.js.map +0 -1
  376. package/dist/translations/languages/sv.d.ts +0 -31
  377. package/dist/translations/languages/sv.d.ts.map +0 -1
  378. package/dist/translations/languages/sv.js +0 -34
  379. package/dist/translations/languages/sv.js.map +0 -1
  380. package/dist/translations/languages/ta.d.ts +0 -31
  381. package/dist/translations/languages/ta.d.ts.map +0 -1
  382. package/dist/translations/languages/ta.js +0 -34
  383. package/dist/translations/languages/ta.js.map +0 -1
  384. package/dist/translations/languages/th.d.ts +0 -31
  385. package/dist/translations/languages/th.d.ts.map +0 -1
  386. package/dist/translations/languages/th.js +0 -34
  387. package/dist/translations/languages/th.js.map +0 -1
  388. package/dist/translations/languages/tr.d.ts +0 -31
  389. package/dist/translations/languages/tr.d.ts.map +0 -1
  390. package/dist/translations/languages/tr.js +0 -34
  391. package/dist/translations/languages/tr.js.map +0 -1
  392. package/dist/translations/languages/uk.d.ts +0 -31
  393. package/dist/translations/languages/uk.d.ts.map +0 -1
  394. package/dist/translations/languages/uk.js +0 -34
  395. package/dist/translations/languages/uk.js.map +0 -1
  396. package/dist/translations/languages/vi.d.ts +0 -31
  397. package/dist/translations/languages/vi.d.ts.map +0 -1
  398. package/dist/translations/languages/vi.js +0 -34
  399. package/dist/translations/languages/vi.js.map +0 -1
  400. package/dist/translations/languages/zh.d.ts +0 -31
  401. package/dist/translations/languages/zh.d.ts.map +0 -1
  402. package/dist/translations/languages/zh.js +0 -34
  403. package/dist/translations/languages/zh.js.map +0 -1
  404. package/dist/translations/languages/zhTw.d.ts +0 -31
  405. package/dist/translations/languages/zhTw.d.ts.map +0 -1
  406. package/dist/translations/languages/zhTw.js +0 -34
  407. package/dist/translations/languages/zhTw.js.map +0 -1
  408. package/dist/translations/types.d.ts +0 -32
  409. package/dist/translations/types.d.ts.map +0 -1
  410. package/dist/translations/types.js +0 -3
  411. package/dist/translations/types.js.map +0 -1
  412. package/dist/utils/localAPIDefaults.d.ts +0 -20
  413. package/dist/utils/localAPIDefaults.d.ts.map +0 -1
  414. package/dist/utils/localAPIDefaults.js +0 -19
  415. package/dist/utils/localAPIDefaults.js.map +0 -1
  416. package/dist/utils/schemaConversion/removeVirtualFieldsFromSchema.d.ts +0 -7
  417. package/dist/utils/schemaConversion/removeVirtualFieldsFromSchema.d.ts.map +0 -1
  418. package/dist/utils/schemaConversion/removeVirtualFieldsFromSchema.js +0 -20
  419. package/dist/utils/schemaConversion/removeVirtualFieldsFromSchema.js.map +0 -1
  420. package/src/collection/getAccessField.ts +0 -84
  421. package/src/collection/index.ts +0 -105
  422. package/src/components/APIKeyField/index.client.tsx +0 -73
  423. package/src/components/APIKeyField/index.css +0 -105
  424. package/src/components/APIKeysEmptyState/index.client.tsx +0 -36
  425. package/src/components/AccessField/index.client.tsx +0 -299
  426. package/src/components/AccessField/index.css +0 -99
  427. package/src/components/SettingsMenu/index.client.tsx +0 -34
  428. package/src/translations/index.ts +0 -108
  429. package/src/translations/languages/ar.ts +0 -35
  430. package/src/translations/languages/az.ts +0 -35
  431. package/src/translations/languages/bg.ts +0 -35
  432. package/src/translations/languages/bnBd.ts +0 -35
  433. package/src/translations/languages/bnIn.ts +0 -35
  434. package/src/translations/languages/ca.ts +0 -35
  435. package/src/translations/languages/cs.ts +0 -35
  436. package/src/translations/languages/da.ts +0 -35
  437. package/src/translations/languages/de.ts +0 -35
  438. package/src/translations/languages/en.ts +0 -35
  439. package/src/translations/languages/es.ts +0 -35
  440. package/src/translations/languages/et.ts +0 -35
  441. package/src/translations/languages/fa.ts +0 -35
  442. package/src/translations/languages/fr.ts +0 -35
  443. package/src/translations/languages/he.ts +0 -35
  444. package/src/translations/languages/hr.ts +0 -35
  445. package/src/translations/languages/hu.ts +0 -35
  446. package/src/translations/languages/hy.ts +0 -35
  447. package/src/translations/languages/id.ts +0 -35
  448. package/src/translations/languages/is.ts +0 -35
  449. package/src/translations/languages/it.ts +0 -35
  450. package/src/translations/languages/ja.ts +0 -35
  451. package/src/translations/languages/ko.ts +0 -35
  452. package/src/translations/languages/lt.ts +0 -35
  453. package/src/translations/languages/lv.ts +0 -35
  454. package/src/translations/languages/my.ts +0 -35
  455. package/src/translations/languages/nb.ts +0 -35
  456. package/src/translations/languages/nl.ts +0 -35
  457. package/src/translations/languages/pl.ts +0 -35
  458. package/src/translations/languages/pt.ts +0 -35
  459. package/src/translations/languages/ro.ts +0 -35
  460. package/src/translations/languages/rs.ts +0 -35
  461. package/src/translations/languages/rsLatin.ts +0 -35
  462. package/src/translations/languages/ru.ts +0 -35
  463. package/src/translations/languages/sk.ts +0 -35
  464. package/src/translations/languages/sl.ts +0 -35
  465. package/src/translations/languages/sv.ts +0 -35
  466. package/src/translations/languages/ta.ts +0 -35
  467. package/src/translations/languages/th.ts +0 -35
  468. package/src/translations/languages/tr.ts +0 -35
  469. package/src/translations/languages/uk.ts +0 -35
  470. package/src/translations/languages/vi.ts +0 -35
  471. package/src/translations/languages/zh.ts +0 -35
  472. package/src/translations/languages/zhTw.ts +0 -35
  473. package/src/translations/types.ts +0 -34
  474. package/src/utils/localAPIDefaults.ts +0 -22
  475. package/src/utils/schemaConversion/removeVirtualFieldsFromSchema.ts +0 -27
@@ -0,0 +1,124 @@
1
+ import { APIError } from 'payload';
2
+ import { getExternalFile, getFileFromUploadInstructions, 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
+ const uploadFileSchema = z.object({
7
+ filename: z.string(),
8
+ mimeType: z.string(),
9
+ size: z.number().int().nonnegative(),
10
+ uploadReference: z.record(z.string(), z.unknown())
11
+ });
12
+ export const fileInputSchema = z.discriminatedUnion('source', [
13
+ z.object({
14
+ name: z.string().min(1).describe('The file name, including its extension'),
15
+ data: z.string().describe('The base64-encoded file bytes, without a data URL prefix'),
16
+ mimeType: mimeTypeSchema.describe('The file MIME type, for example image/png'),
17
+ source: z.literal('base64')
18
+ }),
19
+ z.object({
20
+ name: z.string().min(1).describe('Optional file name override').optional(),
21
+ source: z.literal('externalURL'),
22
+ url: z.url().describe('The http or https URL to download')
23
+ }),
24
+ z.object({
25
+ file: uploadFileSchema.describe('getUploadInstructions file field post-upload'),
26
+ source: z.literal('uploadReference')
27
+ })
28
+ ]).describe('A file for an upload collection. Prefer uploadReference after its upload succeeds; use base64 only for small local files or externalURL for an online file.');
29
+ export async function resolveFile({ collectionSlug, input, req }) {
30
+ if (!input) {
31
+ return undefined;
32
+ }
33
+ if (input.source === 'uploadReference') {
34
+ try {
35
+ return await getFileFromUploadInstructions({
36
+ collectionSlug,
37
+ file: input.file,
38
+ req
39
+ });
40
+ } catch (error) {
41
+ if (error instanceof Error && error.message === 'Staged upload was not found.') {
42
+ throw new APIError('Staged upload not found. Complete the upload action first, or use base64 for small local files.', 400);
43
+ }
44
+ throw error;
45
+ }
46
+ }
47
+ const uploadConfig = req.payload.collections[collectionSlug]?.config.upload;
48
+ if (!uploadConfig) {
49
+ throw new APIError(`Collection "${collectionSlug}" does not support file uploads.`, 400);
50
+ }
51
+ const maxFileSize = req.payload.config.upload.limits?.fileSize;
52
+ let file;
53
+ if (input.source === 'base64') {
54
+ const data = decodeBase64({
55
+ maxFileSize,
56
+ value: input.data
57
+ });
58
+ file = {
59
+ name: sanitizeFilename(input.name),
60
+ data,
61
+ mimetype: input.mimeType,
62
+ size: data.length
63
+ };
64
+ } else {
65
+ if (uploadConfig.pasteURL === false) {
66
+ throw new APIError(`Uploading files from URLs is disabled for collection "${collectionSlug}".`, 400);
67
+ }
68
+ const url = new URL(input.url);
69
+ if (![
70
+ 'http:',
71
+ 'https:'
72
+ ].includes(url.protocol)) {
73
+ throw new APIError('File URLs must use http or https.', 400);
74
+ }
75
+ if (typeof uploadConfig.pasteURL === 'object' && !isURLAllowed(input.url, uploadConfig.pasteURL.allowList)) {
76
+ throw new APIError('The provided file URL is not allowed.', 400);
77
+ }
78
+ file = await getExternalFile({
79
+ data: {
80
+ filename: sanitizeFilename(input.name || getURLFilename(url)),
81
+ url: input.url
82
+ },
83
+ req,
84
+ uploadConfig: {
85
+ ...uploadConfig,
86
+ externalFileHeaderFilter: uploadConfig.externalFileHeaderFilter ?? (()=>({}))
87
+ }
88
+ });
89
+ file.mimetype = file.mimetype?.split(';')[0] || 'application/octet-stream';
90
+ file.size = file.data.length;
91
+ }
92
+ if (maxFileSize !== undefined && Number.isFinite(maxFileSize) && file.size > maxFileSize) {
93
+ throw new APIError(`File exceeds the ${maxFileSize} byte upload limit.`, 400);
94
+ }
95
+ return file;
96
+ }
97
+ function decodeBase64({ maxFileSize, value }) {
98
+ const normalized = value.replace(/\s/g, '');
99
+ if (!/^[a-z0-9+/]*={0,2}$/i.test(normalized) || normalized.length % 4 === 1) {
100
+ throw new APIError('File data must be valid base64.', 400);
101
+ }
102
+ if (maxFileSize !== undefined && Number.isFinite(maxFileSize)) {
103
+ const paddingLength = normalized.endsWith('==') ? 2 : normalized.endsWith('=') ? 1 : 0;
104
+ const decodedSize = Math.floor(normalized.length * 3 / 4) - paddingLength;
105
+ if (decodedSize > maxFileSize) {
106
+ throw new APIError(`File exceeds the ${maxFileSize} byte upload limit.`, 400);
107
+ }
108
+ }
109
+ const data = Buffer.from(normalized, 'base64');
110
+ if (data.toString('base64').replace(/=+$/, '') !== normalized.replace(/=+$/, '')) {
111
+ throw new APIError('File data must be valid base64.', 400);
112
+ }
113
+ return data;
114
+ }
115
+ function getURLFilename(url) {
116
+ const pathSegment = url.pathname.split('/').pop() || 'upload';
117
+ try {
118
+ return decodeURIComponent(pathSegment);
119
+ } catch {
120
+ return pathSegment;
121
+ }
122
+ }
123
+
124
+ //# 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, getFileFromUploadInstructions, 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\nconst uploadFileSchema = z.object({\n filename: z.string(),\n mimeType: z.string(),\n size: z.number().int().nonnegative(),\n uploadReference: z.record(z.string(), z.unknown()),\n})\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('externalURL'),\n url: z.url().describe('The http or https URL to download'),\n }),\n z.object({\n file: uploadFileSchema.describe('getUploadInstructions file field post-upload'),\n source: z.literal('uploadReference'),\n }),\n ])\n .describe(\n 'A file for an upload collection. Prefer uploadReference after its upload succeeds; use base64 only for small local files or externalURL for an online file.',\n )\n\ntype FileInput = z.infer<typeof fileInputSchema>\n\nexport async function resolveFile({\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 if (input.source === 'uploadReference') {\n try {\n return await getFileFromUploadInstructions({ collectionSlug, file: input.file, req })\n } catch (error) {\n if (error instanceof Error && error.message === 'Staged upload was not found.') {\n throw new APIError(\n 'Staged upload not found. Complete the upload action first, or use base64 for small local files.',\n 400,\n )\n }\n throw error\n }\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","getFileFromUploadInstructions","isURLAllowed","sanitizeFilename","z","mimeTypeSchema","string","regex","uploadFileSchema","object","filename","mimeType","size","number","int","nonnegative","uploadReference","record","unknown","fileInputSchema","discriminatedUnion","name","min","describe","data","source","literal","optional","url","file","resolveFile","collectionSlug","input","req","undefined","error","Error","message","uploadConfig","payload","collections","config","upload","maxFileSize","limits","fileSize","decodeBase64","value","mimetype","length","pasteURL","URL","includes","protocol","allowList","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,6BAA6B,EAAEC,YAAY,QAAQ,mBAAkB;AAC/F,SAASC,gBAAgB,QAAQ,iBAAgB;AACjD,SAASC,CAAC,QAAQ,MAAK;AAEvB,MAAMC,iBAAiBD,EACpBE,MAAM,GACNC,KAAK,CAAC,8CAA8C;AAEvD,MAAMC,mBAAmBJ,EAAEK,MAAM,CAAC;IAChCC,UAAUN,EAAEE,MAAM;IAClBK,UAAUP,EAAEE,MAAM;IAClBM,MAAMR,EAAES,MAAM,GAAGC,GAAG,GAAGC,WAAW;IAClCC,iBAAiBZ,EAAEa,MAAM,CAACb,EAAEE,MAAM,IAAIF,EAAEc,OAAO;AACjD;AAEA,OAAO,MAAMC,kBAAkBf,EAC5BgB,kBAAkB,CAAC,UAAU;IAC5BhB,EAAEK,MAAM,CAAC;QACPY,MAAMjB,EAAEE,MAAM,GAAGgB,GAAG,CAAC,GAAGC,QAAQ,CAAC;QACjCC,MAAMpB,EAAEE,MAAM,GAAGiB,QAAQ,CAAC;QAC1BZ,UAAUN,eAAekB,QAAQ,CAAC;QAClCE,QAAQrB,EAAEsB,OAAO,CAAC;IACpB;IACAtB,EAAEK,MAAM,CAAC;QACPY,MAAMjB,EAAEE,MAAM,GAAGgB,GAAG,CAAC,GAAGC,QAAQ,CAAC,+BAA+BI,QAAQ;QACxEF,QAAQrB,EAAEsB,OAAO,CAAC;QAClBE,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Q,IAAIJ,WAAWI,QAAQ,CAAC,OAAO,IAAI;QACrF,MAAMC,cAAcC,KAAKC,KAAK,CAAC,AAACP,WAAWX,MAAM,GAAG,IAAK,KAAKc;QAE9D,IAAIE,cAActB,aAAa;YAC7B,MAAM,IAAI5C,SAAS,CAAC,iBAAiB,EAAE4C,YAAY,mBAAmB,CAAC,EAAE;QAC3E;IACF;IAEA,MAAMnB,OAAO4C,OAAOC,IAAI,CAACT,YAAY;IAErC,IAAIpC,KAAK8C,QAAQ,CAAC,UAAUT,OAAO,CAAC,OAAO,QAAQD,WAAWC,OAAO,CAAC,OAAO,KAAK;QAChF,MAAM,IAAI9D,SAAS,mCAAmC;IACxD;IAEA,OAAOyB;AACT;AAEA,SAAS+B,eAAe3B,GAAQ;IAC9B,MAAM2C,cAAc3C,IAAI4C,QAAQ,CAACf,KAAK,CAAC,KAAKgB,GAAG,MAAM;IAErD,IAAI;QACF,OAAOC,mBAAmBH;IAC5B,EAAE,OAAM;QACN,OAAOA;IACT;AACF"}
@@ -0,0 +1,86 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import { fileInputSchema, resolveFile } 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 accept a prepared upload', ()=>{
14
+ const result = fileInputSchema.safeParse({
15
+ file: {
16
+ filename: 'image.png',
17
+ mimeType: 'image/png',
18
+ size: 123,
19
+ uploadReference: {
20
+ uploadId: 'upload-id'
21
+ }
22
+ },
23
+ source: 'uploadReference'
24
+ });
25
+ expect(result.success).toBe(true);
26
+ });
27
+ it('should reject oversized base64 files', async ()=>{
28
+ const req = createRequest({
29
+ maxFileSize: 4
30
+ });
31
+ await expect(resolveFile({
32
+ collectionSlug: 'media',
33
+ input: {
34
+ data: Buffer.from('hello').toString('base64'),
35
+ mimeType: 'text/plain',
36
+ name: 'hello.txt',
37
+ source: 'base64'
38
+ },
39
+ req
40
+ })).rejects.toThrow('File exceeds the 4 byte upload limit.');
41
+ });
42
+ it('should reject URLs outside the collection allowlist', async ()=>{
43
+ const req = createRequest({
44
+ allowList: [
45
+ {
46
+ hostname: 'assets.example.com',
47
+ protocol: 'https'
48
+ }
49
+ ]
50
+ });
51
+ await expect(resolveFile({
52
+ collectionSlug: 'media',
53
+ input: {
54
+ source: 'externalURL',
55
+ url: 'https://example.com/image.png'
56
+ },
57
+ req
58
+ })).rejects.toThrow('The provided file URL is not allowed.');
59
+ });
60
+ });
61
+ function createRequest({ allowList, maxFileSize }) {
62
+ return {
63
+ payload: {
64
+ collections: {
65
+ media: {
66
+ config: {
67
+ upload: allowList ? {
68
+ pasteURL: {
69
+ allowList
70
+ }
71
+ } : {}
72
+ }
73
+ }
74
+ },
75
+ config: {
76
+ upload: {
77
+ limits: {
78
+ fileSize: maxFileSize
79
+ }
80
+ }
81
+ }
82
+ }
83
+ };
84
+ }
85
+
86
+ //# 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, resolveFile } 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 accept a prepared upload', () => {\n const result = fileInputSchema.safeParse({\n file: {\n filename: 'image.png',\n mimeType: 'image/png',\n size: 123,\n uploadReference: { uploadId: 'upload-id' },\n },\n source: 'uploadReference',\n })\n\n expect(result.success).toBe(true)\n })\n\n it('should reject oversized base64 files', async () => {\n const req = createRequest({ maxFileSize: 4 })\n\n await expect(\n resolveFile({\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 resolveFile({\n collectionSlug: 'media',\n input: {\n source: 'externalURL',\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","resolveFile","result","safeParse","data","mimeType","name","source","success","toBe","file","filename","size","uploadReference","uploadId","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,WAAW,QAAQ,iBAAgB;AAE7DJ,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,mCAAmC;QACpC,MAAMG,SAASF,gBAAgBG,SAAS,CAAC;YACvCO,MAAM;gBACJC,UAAU;gBACVN,UAAU;gBACVO,MAAM;gBACNC,iBAAiB;oBAAEC,UAAU;gBAAY;YAC3C;YACAP,QAAQ;QACV;QAEAT,OAAOI,OAAOM,OAAO,EAAEC,IAAI,CAAC;IAC9B;IAEAV,GAAG,wCAAwC;QACzC,MAAMgB,MAAMC,cAAc;YAAEC,aAAa;QAAE;QAE3C,MAAMnB,OACJG,YAAY;YACViB,gBAAgB;YAChBC,OAAO;gBACLf,MAAMgB,OAAOC,IAAI,CAAC,SAASC,QAAQ,CAAC;gBACpCjB,UAAU;gBACVC,MAAM;gBACNC,QAAQ;YACV;YACAQ;QACF,IACAQ,OAAO,CAACC,OAAO,CAAC;IACpB;IAEAzB,GAAG,uDAAuD;QACxD,MAAMgB,MAAMC,cAAc;YACxBS,WAAW;gBAAC;oBAAEC,UAAU;oBAAsBC,UAAU;gBAAQ;aAAE;QACpE;QAEA,MAAM7B,OACJG,YAAY;YACViB,gBAAgB;YAChBC,OAAO;gBACLZ,QAAQ;gBACRqB,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,GAC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YACxCC,YAAYxC;YACZW;YACAQ;YACAsB,gBAAgBR,cAAcQ,cAAc;YAC5CP;YACA,GAAIb,QAAQ;gBAAEA;YAAM,IAAI,CAAC,CAAC;YAC1B,GAAIC,SAAS;gBAAEA;YAAO,IAAI,CAAC,CAAC;YAC5B,GAAIC,OAAO;gBAAEA;YAAK,IAAI,CAAC,CAAC;YACxB,GAAIC,WAAW;gBAAEA,UAAUA;YAAyB,IAAI,CAAC,CAAC;YAC1D,GAAIG,qBAAqBe,YAAY;gBAAEf;YAAiB,IAAI,CAAC,CAAC;YAC9D,GAAIE,OAAO;gBAAEA;YAAK,IAAI,CAAC,CAAC;YACxB,GAAIC,UAAUY,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"}
@@ -1 +1 @@
1
- {"version":3,"file":"findTool.d.ts","sourceRoot":"","sources":["../../../../src/mcp/builtin/collections/findTool.ts"],"names":[],"mappings":"AAYA,eAAO,MAAM,iBAAiB,4CAoK5B,CAAA"}
1
+ {"version":3,"file":"findTool.d.ts","sourceRoot":"","sources":["../../../../src/mcp/builtin/collections/findTool.ts"],"names":[],"mappings":"AAYA,eAAO,MAAM,iBAAiB,4CA2M5B,CAAA"}
@@ -1,10 +1,18 @@
1
1
  import { z } from 'zod';
2
+ import { defaultAccess } from '../../../defaultAccess.js';
2
3
  import { defineCollectionTool } from '../../../defineTool.js';
3
4
  import { getLogger } from '../../../utils/getLogger.js';
4
- import { localAPIDefaults } from '../../../utils/localAPIDefaults.js';
5
5
  import { whereSchema } from '../../../utils/whereSchema.js';
6
6
  const DEFAULT_DESCRIPTION = 'Find documents in any collection by passing the collection slug and optional ID or where clause.';
7
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
+ },
8
16
  description: DEFAULT_DESCRIPTION,
9
17
  input: z.object({
10
18
  id: z.union([
@@ -12,13 +20,20 @@ export const findDocumentsTool = defineCollectionTool({
12
20
  z.number()
13
21
  ]).describe('Optional: specific document ID to retrieve. If not provided, returns all documents').optional(),
14
22
  depth: z.number().int().min(0).max(10).describe('How many levels deep to populate relationships (default: 0)').optional().default(0),
15
- draft: z.boolean().describe('Optional: whether the document should be queried from the versions table/collection or not.').optional(),
23
+ draft: z.boolean().describe('For versioned collections, true returns the latest draft version when available. False reads the main document.').optional(),
16
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(),
17
29
  limit: z.number().int().min(1).max(100).describe('Maximum number of documents to return (default: 10, max: 100)').optional().default(10),
18
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(),
19
31
  page: z.number().int().min(1).describe('Page number for pagination (default: 1)').optional().default(1),
20
- select: z.string().describe("Optional: define exactly which fields you'd like to return in the response (JSON), e.g., '{\"title\": true}'").optional(),
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(),
21
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(),
22
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()
23
38
  })
24
39
  }).handler(async ({ authorizedMCP, collectionSlug, input, req })=>{
@@ -26,35 +41,25 @@ export const findDocumentsTool = defineCollectionTool({
26
41
  const logger = getLogger({
27
42
  payload
28
43
  });
29
- const { id, depth, draft, fallbackLocale, limit, locale, page, select, sort, where } = input;
44
+ const { id, depth, draft, fallbackLocale, joins, limit, locale, page, pagination, populate, select, sort, trash, where } = input;
30
45
  logger.info(`Reading document from collection: ${collectionSlug}${id ? ` with ID: ${id}` : ''}, limit: ${limit}, page: ${page}${locale ? `, locale: ${locale}` : ''}`);
31
46
  try {
32
- let selectClause;
33
- if (select) {
34
- try {
35
- selectClause = JSON.parse(select);
36
- } catch {
37
- logger.warn(`Invalid select clause JSON: ${select}`);
38
- return {
39
- content: [
40
- {
41
- type: 'text',
42
- text: 'Error: Invalid JSON in select clause'
43
- }
44
- ]
45
- };
46
- }
47
- }
48
47
  if (id) {
49
48
  try {
50
49
  const doc = await payload.findByID({
51
50
  id,
52
51
  collection: collectionSlug,
53
52
  depth,
53
+ overrideAccess: authorizedMCP.overrideAccess,
54
54
  req,
55
- ...localAPIDefaults(authorizedMCP),
56
- ...selectClause && {
57
- select: selectClause
55
+ ...select && {
56
+ select: select
57
+ },
58
+ ...populate && {
59
+ populate: populate
60
+ },
61
+ ...joins !== undefined && {
62
+ joins: joins
58
63
  },
59
64
  ...locale && {
60
65
  locale
@@ -64,6 +69,9 @@ export const findDocumentsTool = defineCollectionTool({
64
69
  },
65
70
  ...draft !== undefined && {
66
71
  draft
72
+ },
73
+ ...trash !== undefined && {
74
+ trash
67
75
  }
68
76
  });
69
77
  return {
@@ -91,11 +99,17 @@ export const findDocumentsTool = defineCollectionTool({
91
99
  collection: collectionSlug,
92
100
  depth,
93
101
  limit,
102
+ overrideAccess: authorizedMCP.overrideAccess,
94
103
  page,
95
104
  req,
96
- ...localAPIDefaults(authorizedMCP),
97
- ...selectClause && {
98
- select: selectClause
105
+ ...select && {
106
+ select: select
107
+ },
108
+ ...populate && {
109
+ populate: populate
110
+ },
111
+ ...joins !== undefined && {
112
+ joins: joins
99
113
  },
100
114
  ...locale && {
101
115
  locale
@@ -105,6 +119,12 @@ export const findDocumentsTool = defineCollectionTool({
105
119
  },
106
120
  ...draft !== undefined && {
107
121
  draft
122
+ },
123
+ ...pagination !== undefined && {
124
+ pagination
125
+ },
126
+ ...trash !== undefined && {
127
+ trash
108
128
  }
109
129
  };
110
130
  if (sort) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/mcp/builtin/collections/findTool.ts"],"sourcesContent":["import type { SelectType } from 'payload'\n\nimport { z } from 'zod'\n\nimport { defineCollectionTool } from '../../../defineTool.js'\nimport { getLogger } from '../../../utils/getLogger.js'\nimport { localAPIDefaults } from '../../../utils/localAPIDefaults.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 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 'Optional: whether the document should be queried from the versions table/collection or not.',\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 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 select: z\n .string()\n .describe(\n \"Optional: define exactly which fields you'd like to return in the response (JSON), 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 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 { id, depth, draft, fallbackLocale, limit, locale, page, select, sort, where } = 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 let selectClause: SelectType | undefined\n if (select) {\n try {\n selectClause = JSON.parse(select) as SelectType\n } catch {\n logger.warn(`Invalid select clause JSON: ${select}`)\n return { content: [{ type: 'text', text: 'Error: Invalid JSON in select clause' }] }\n }\n }\n\n if (id) {\n try {\n const doc = await payload.findByID({\n id,\n collection: collectionSlug,\n depth,\n req,\n ...localAPIDefaults(authorizedMCP),\n ...(selectClause && { select: selectClause }),\n ...(locale && { locale }),\n ...(fallbackLocale && { fallbackLocale }),\n ...(draft !== undefined && { draft }),\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 page,\n req,\n ...localAPIDefaults(authorizedMCP),\n ...(selectClause && { select: selectClause }),\n ...(locale && { locale }),\n ...(fallbackLocale && { fallbackLocale }),\n ...(draft !== undefined && { draft }),\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","defineCollectionTool","getLogger","localAPIDefaults","whereSchema","DEFAULT_DESCRIPTION","findDocumentsTool","description","input","object","id","union","string","number","describe","optional","depth","int","min","max","default","draft","boolean","fallbackLocale","limit","locale","page","select","sort","where","handler","authorizedMCP","collectionSlug","req","payload","logger","info","selectClause","JSON","parse","warn","content","type","text","doc","findByID","collection","undefined","stringify","findOptions","result","find","responseText","totalDocs","totalPages","docs","error","errorMessage","Error","message"],"mappings":"AAEA,SAASA,C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6C,EAAEX,eAAe,KAAK,EAAEyB,cAAc;gBAC5F;aACD;QACH;IACF;AACF,GAAE"}
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,SA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AM;YACRoB,YAAYpB,IAAI,GAAGA;QACrB;QACA,IAAIE,OAAO;YACTkB,YAAYlB,KAAK,GAAGA;QACtB;QAEA,MAAMmB,SAAS,MAAMf,QAAQgB,IAAI,CAACF;QAElC,IAAIG,eAAe,CAAC,aAAa,EAAE1D,eAAe,UAAU,EAAEwD,OAAOG,SAAS,CAAC,kBAAkB,EAAEH,OAAOzB,IAAI,CAAC,IAAI,EAAEyB,OAAOI,UAAU,CAAC,EAAE,CAAC;QAC1I,KAAK,MAAMhB,OAAOY,OAAOK,IAAI,CAAE;YAC7BH,gBAAgB,CAAC,cAAc,EAAEN,KAAKC,SAAS,CAACT,KAAK,QAAQ,CAAC;QAChE;QAEA,OAAO;YACLK,SAAS;gBAAC;oBAAEC,MAAM;oBAAQC,MAAMO;gBAAa;aAAE;YAC/Cd,KAAKY;QACP;IACF,EAAE,OAAOM,OAAO;QACd,MAAMC,eAAeD,iBAAiBE,QAAQF,MAAMG,OAAO,GAAG;QAC9DvB,OAAOoB,KAAK,CAAC,CAAC,wCAAwC,EAAE9D,eAAe,EAAE,EAAE+D,cAAc;QACzF,OAAO;YACLd,SAAS;gBACP;oBACEC,MAAM;oBACNC,MAAM,CAAC,6CAA6C,EAAEnD,eAAe,KAAK,EAAE+D,cAAc;gBAC5F;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"}