@payloadcms/plugin-mcp 4.0.0-canary.3 → 4.0.0-internal.17c13d2

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 (418) hide show
  1. package/dist/@types/assets.d.js +2 -0
  2. package/dist/@types/assets.d.js.map +1 -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/endpoint/access.d.ts +17 -5
  8. package/dist/endpoint/access.d.ts.map +1 -1
  9. package/dist/endpoint/access.js +81 -103
  10. package/dist/endpoint/access.js.map +1 -1
  11. package/dist/endpoint/index.d.ts.map +1 -1
  12. package/dist/endpoint/index.js +11 -0
  13. package/dist/endpoint/index.js.map +1 -1
  14. package/dist/exports/client.d.ts +1 -4
  15. package/dist/exports/client.d.ts.map +1 -1
  16. package/dist/exports/client.js +1 -4
  17. package/dist/exports/client.js.map +1 -1
  18. package/dist/exports/internal.d.ts +2 -0
  19. package/dist/exports/internal.d.ts.map +1 -0
  20. package/dist/exports/internal.js +3 -0
  21. package/dist/exports/internal.js.map +1 -0
  22. package/dist/index.d.ts.map +1 -1
  23. package/dist/index.js +1 -54
  24. package/dist/index.js.map +1 -1
  25. package/dist/mcp/buildMcpServer.d.ts.map +1 -1
  26. package/dist/mcp/buildMcpServer.js.map +1 -1
  27. package/dist/mcp/builtin/collections/countTool.d.ts +2 -0
  28. package/dist/mcp/builtin/collections/countTool.d.ts.map +1 -0
  29. package/dist/mcp/builtin/collections/countTool.js +69 -0
  30. package/dist/mcp/builtin/collections/countTool.js.map +1 -0
  31. package/dist/mcp/builtin/collections/countVersionsTool.d.ts +2 -0
  32. package/dist/mcp/builtin/collections/countVersionsTool.d.ts.map +1 -0
  33. package/dist/mcp/builtin/collections/countVersionsTool.js +65 -0
  34. package/dist/mcp/builtin/collections/countVersionsTool.js.map +1 -0
  35. package/dist/mcp/builtin/collections/createTool.d.ts.map +1 -1
  36. package/dist/mcp/builtin/collections/createTool.js +2 -0
  37. package/dist/mcp/builtin/collections/createTool.js.map +1 -1
  38. package/dist/mcp/builtin/collections/deleteTool.d.ts.map +1 -1
  39. package/dist/mcp/builtin/collections/deleteTool.js +2 -0
  40. package/dist/mcp/builtin/collections/deleteTool.js.map +1 -1
  41. package/dist/mcp/builtin/collections/duplicateTool.d.ts +2 -0
  42. package/dist/mcp/builtin/collections/duplicateTool.d.ts.map +1 -0
  43. package/dist/mcp/builtin/collections/duplicateTool.js +97 -0
  44. package/dist/mcp/builtin/collections/duplicateTool.js.map +1 -0
  45. package/dist/mcp/builtin/collections/findDistinctTool.d.ts +2 -0
  46. package/dist/mcp/builtin/collections/findDistinctTool.d.ts.map +1 -0
  47. package/dist/mcp/builtin/collections/findDistinctTool.js +93 -0
  48. package/dist/mcp/builtin/collections/findDistinctTool.js.map +1 -0
  49. package/dist/mcp/builtin/collections/findTool.d.ts.map +1 -1
  50. package/dist/mcp/builtin/collections/findTool.js +2 -0
  51. package/dist/mcp/builtin/collections/findTool.js.map +1 -1
  52. package/dist/mcp/builtin/collections/findVersionByIDTool.d.ts +2 -0
  53. package/dist/mcp/builtin/collections/findVersionByIDTool.d.ts.map +1 -0
  54. package/dist/mcp/builtin/collections/findVersionByIDTool.js +84 -0
  55. package/dist/mcp/builtin/collections/findVersionByIDTool.js.map +1 -0
  56. package/dist/mcp/builtin/collections/findVersionsTool.d.ts +2 -0
  57. package/dist/mcp/builtin/collections/findVersionsTool.d.ts.map +1 -0
  58. package/dist/mcp/builtin/collections/findVersionsTool.js +99 -0
  59. package/dist/mcp/builtin/collections/findVersionsTool.js.map +1 -0
  60. package/dist/mcp/builtin/collections/formatCollectionError.d.ts +1 -1
  61. package/dist/mcp/builtin/collections/formatCollectionError.d.ts.map +1 -1
  62. package/dist/mcp/builtin/collections/formatCollectionError.js.map +1 -1
  63. package/dist/mcp/builtin/collections/getCollectionSchemaTool.d.ts.map +1 -1
  64. package/dist/mcp/builtin/collections/getCollectionSchemaTool.js +5 -0
  65. package/dist/mcp/builtin/collections/getCollectionSchemaTool.js.map +1 -1
  66. package/dist/mcp/builtin/collections/restoreVersionTool.d.ts +2 -0
  67. package/dist/mcp/builtin/collections/restoreVersionTool.d.ts.map +1 -0
  68. package/dist/mcp/builtin/collections/restoreVersionTool.js +82 -0
  69. package/dist/mcp/builtin/collections/restoreVersionTool.js.map +1 -0
  70. package/dist/mcp/builtin/collections/updateTool.d.ts.map +1 -1
  71. package/dist/mcp/builtin/collections/updateTool.js +2 -0
  72. package/dist/mcp/builtin/collections/updateTool.js.map +1 -1
  73. package/dist/mcp/builtin/getConfigInfoTool.d.ts.map +1 -1
  74. package/dist/mcp/builtin/getConfigInfoTool.js +20 -5
  75. package/dist/mcp/builtin/getConfigInfoTool.js.map +1 -1
  76. package/dist/mcp/builtin/globals/countVersionsTool.d.ts +2 -0
  77. package/dist/mcp/builtin/globals/countVersionsTool.d.ts.map +1 -0
  78. package/dist/mcp/builtin/globals/countVersionsTool.js +65 -0
  79. package/dist/mcp/builtin/globals/countVersionsTool.js.map +1 -0
  80. package/dist/mcp/builtin/globals/findTool.d.ts.map +1 -1
  81. package/dist/mcp/builtin/globals/findTool.js +2 -0
  82. package/dist/mcp/builtin/globals/findTool.js.map +1 -1
  83. package/dist/mcp/builtin/globals/findVersionByIDTool.d.ts +2 -0
  84. package/dist/mcp/builtin/globals/findVersionByIDTool.d.ts.map +1 -0
  85. package/dist/mcp/builtin/globals/findVersionByIDTool.js +80 -0
  86. package/dist/mcp/builtin/globals/findVersionByIDTool.js.map +1 -0
  87. package/dist/mcp/builtin/globals/findVersionsTool.d.ts +2 -0
  88. package/dist/mcp/builtin/globals/findVersionsTool.d.ts.map +1 -0
  89. package/dist/mcp/builtin/globals/findVersionsTool.js +95 -0
  90. package/dist/mcp/builtin/globals/findVersionsTool.js.map +1 -0
  91. package/dist/mcp/builtin/globals/getGlobalSchemaTool.d.ts.map +1 -1
  92. package/dist/mcp/builtin/globals/getGlobalSchemaTool.js +5 -0
  93. package/dist/mcp/builtin/globals/getGlobalSchemaTool.js.map +1 -1
  94. package/dist/mcp/builtin/globals/restoreVersionTool.d.ts +2 -0
  95. package/dist/mcp/builtin/globals/restoreVersionTool.d.ts.map +1 -0
  96. package/dist/mcp/builtin/globals/restoreVersionTool.js +78 -0
  97. package/dist/mcp/builtin/globals/restoreVersionTool.js.map +1 -0
  98. package/dist/mcp/builtin/globals/updateTool.d.ts.map +1 -1
  99. package/dist/mcp/builtin/globals/updateTool.js +2 -0
  100. package/dist/mcp/builtin/globals/updateTool.js.map +1 -1
  101. package/dist/mcp/builtinTools.d.ts +67 -2
  102. package/dist/mcp/builtinTools.d.ts.map +1 -1
  103. package/dist/mcp/builtinTools.js +64 -0
  104. package/dist/mcp/builtinTools.js.map +1 -1
  105. package/dist/mcp/sanitizeMCPConfig.d.ts +0 -1
  106. package/dist/mcp/sanitizeMCPConfig.d.ts.map +1 -1
  107. package/dist/mcp/sanitizeMCPConfig.js +44 -17
  108. package/dist/mcp/sanitizeMCPConfig.js.map +1 -1
  109. package/dist/stdio.d.ts +3 -2
  110. package/dist/stdio.d.ts.map +1 -1
  111. package/dist/stdio.js +27 -8
  112. package/dist/stdio.js.map +1 -1
  113. package/dist/types.d.ts +43 -85
  114. package/dist/types.d.ts.map +1 -1
  115. package/dist/types.js +4 -4
  116. package/dist/types.js.map +1 -1
  117. package/dist/utils/getPluginConfig.d.ts +1 -1
  118. package/dist/utils/getPluginConfig.js +1 -1
  119. package/dist/utils/getPluginConfig.js.map +1 -1
  120. package/package.json +9 -13
  121. package/src/@types/assets.d.ts +3 -0
  122. package/src/defaultAccess.ts +3 -0
  123. package/src/endpoint/access.ts +87 -112
  124. package/src/endpoint/index.ts +14 -1
  125. package/src/exports/client.ts +2 -4
  126. package/src/exports/internal.ts +1 -0
  127. package/src/index.ts +1 -58
  128. package/src/mcp/buildMcpServer.ts +6 -1
  129. package/src/mcp/builtin/collections/countTool.ts +74 -0
  130. package/src/mcp/builtin/collections/countVersionsTool.ts +70 -0
  131. package/src/mcp/builtin/collections/createTool.ts +3 -0
  132. package/src/mcp/builtin/collections/deleteTool.ts +3 -0
  133. package/src/mcp/builtin/collections/duplicateTool.ts +135 -0
  134. package/src/mcp/builtin/collections/findDistinctTool.ts +120 -0
  135. package/src/mcp/builtin/collections/findTool.ts +3 -0
  136. package/src/mcp/builtin/collections/findVersionByIDTool.ts +110 -0
  137. package/src/mcp/builtin/collections/findVersionsTool.ts +155 -0
  138. package/src/mcp/builtin/collections/formatCollectionError.ts +1 -1
  139. package/src/mcp/builtin/collections/getCollectionSchemaTool.ts +11 -0
  140. package/src/mcp/builtin/collections/restoreVersionTool.ts +108 -0
  141. package/src/mcp/builtin/collections/updateTool.ts +3 -0
  142. package/src/mcp/builtin/getConfigInfoTool.ts +22 -4
  143. package/src/mcp/builtin/globals/countVersionsTool.ts +69 -0
  144. package/src/mcp/builtin/globals/findTool.ts +3 -0
  145. package/src/mcp/builtin/globals/findVersionByIDTool.ts +104 -0
  146. package/src/mcp/builtin/globals/findVersionsTool.ts +148 -0
  147. package/src/mcp/builtin/globals/getGlobalSchemaTool.ts +6 -0
  148. package/src/mcp/builtin/globals/restoreVersionTool.ts +100 -0
  149. package/src/mcp/builtin/globals/updateTool.ts +3 -0
  150. package/src/mcp/builtinTools.ts +63 -4
  151. package/src/mcp/sanitizeMCPConfig.ts +32 -19
  152. package/src/stdio.ts +23 -8
  153. package/src/types.ts +50 -88
  154. package/src/utils/getPluginConfig.ts +1 -1
  155. package/dist/collection/getAccessField.d.ts +0 -12
  156. package/dist/collection/getAccessField.d.ts.map +0 -1
  157. package/dist/collection/getAccessField.js +0 -72
  158. package/dist/collection/getAccessField.js.map +0 -1
  159. package/dist/collection/index.d.ts +0 -6
  160. package/dist/collection/index.d.ts.map +0 -1
  161. package/dist/collection/index.js +0 -105
  162. package/dist/collection/index.js.map +0 -1
  163. package/dist/components/APIKeyField/index.client.d.ts +0 -9
  164. package/dist/components/APIKeyField/index.client.d.ts.map +0 -1
  165. package/dist/components/APIKeyField/index.client.js +0 -85
  166. package/dist/components/APIKeyField/index.client.js.map +0 -1
  167. package/dist/components/APIKeyField/index.css +0 -105
  168. package/dist/components/APIKeysEmptyState/index.client.d.ts +0 -4
  169. package/dist/components/APIKeysEmptyState/index.client.d.ts.map +0 -1
  170. package/dist/components/APIKeysEmptyState/index.client.js +0 -21
  171. package/dist/components/APIKeysEmptyState/index.client.js.map +0 -1
  172. package/dist/components/AccessField/index.client.d.ts +0 -10
  173. package/dist/components/AccessField/index.client.d.ts.map +0 -1
  174. package/dist/components/AccessField/index.client.js +0 -247
  175. package/dist/components/AccessField/index.client.js.map +0 -1
  176. package/dist/components/AccessField/index.css +0 -99
  177. package/dist/components/SettingsMenu/index.client.d.ts +0 -8
  178. package/dist/components/SettingsMenu/index.client.d.ts.map +0 -1
  179. package/dist/components/SettingsMenu/index.client.js +0 -24
  180. package/dist/components/SettingsMenu/index.client.js.map +0 -1
  181. package/dist/translations/index.d.ts +0 -11
  182. package/dist/translations/index.d.ts.map +0 -1
  183. package/dist/translations/index.js +0 -92
  184. package/dist/translations/index.js.map +0 -1
  185. package/dist/translations/languages/ar.d.ts +0 -31
  186. package/dist/translations/languages/ar.d.ts.map +0 -1
  187. package/dist/translations/languages/ar.js +0 -34
  188. package/dist/translations/languages/ar.js.map +0 -1
  189. package/dist/translations/languages/az.d.ts +0 -31
  190. package/dist/translations/languages/az.d.ts.map +0 -1
  191. package/dist/translations/languages/az.js +0 -34
  192. package/dist/translations/languages/az.js.map +0 -1
  193. package/dist/translations/languages/bg.d.ts +0 -31
  194. package/dist/translations/languages/bg.d.ts.map +0 -1
  195. package/dist/translations/languages/bg.js +0 -34
  196. package/dist/translations/languages/bg.js.map +0 -1
  197. package/dist/translations/languages/bnBd.d.ts +0 -31
  198. package/dist/translations/languages/bnBd.d.ts.map +0 -1
  199. package/dist/translations/languages/bnBd.js +0 -34
  200. package/dist/translations/languages/bnBd.js.map +0 -1
  201. package/dist/translations/languages/bnIn.d.ts +0 -31
  202. package/dist/translations/languages/bnIn.d.ts.map +0 -1
  203. package/dist/translations/languages/bnIn.js +0 -34
  204. package/dist/translations/languages/bnIn.js.map +0 -1
  205. package/dist/translations/languages/ca.d.ts +0 -31
  206. package/dist/translations/languages/ca.d.ts.map +0 -1
  207. package/dist/translations/languages/ca.js +0 -34
  208. package/dist/translations/languages/ca.js.map +0 -1
  209. package/dist/translations/languages/cs.d.ts +0 -31
  210. package/dist/translations/languages/cs.d.ts.map +0 -1
  211. package/dist/translations/languages/cs.js +0 -34
  212. package/dist/translations/languages/cs.js.map +0 -1
  213. package/dist/translations/languages/da.d.ts +0 -31
  214. package/dist/translations/languages/da.d.ts.map +0 -1
  215. package/dist/translations/languages/da.js +0 -34
  216. package/dist/translations/languages/da.js.map +0 -1
  217. package/dist/translations/languages/de.d.ts +0 -31
  218. package/dist/translations/languages/de.d.ts.map +0 -1
  219. package/dist/translations/languages/de.js +0 -34
  220. package/dist/translations/languages/de.js.map +0 -1
  221. package/dist/translations/languages/en.d.ts +0 -31
  222. package/dist/translations/languages/en.d.ts.map +0 -1
  223. package/dist/translations/languages/en.js +0 -34
  224. package/dist/translations/languages/en.js.map +0 -1
  225. package/dist/translations/languages/es.d.ts +0 -31
  226. package/dist/translations/languages/es.d.ts.map +0 -1
  227. package/dist/translations/languages/es.js +0 -34
  228. package/dist/translations/languages/es.js.map +0 -1
  229. package/dist/translations/languages/et.d.ts +0 -31
  230. package/dist/translations/languages/et.d.ts.map +0 -1
  231. package/dist/translations/languages/et.js +0 -34
  232. package/dist/translations/languages/et.js.map +0 -1
  233. package/dist/translations/languages/fa.d.ts +0 -31
  234. package/dist/translations/languages/fa.d.ts.map +0 -1
  235. package/dist/translations/languages/fa.js +0 -34
  236. package/dist/translations/languages/fa.js.map +0 -1
  237. package/dist/translations/languages/fr.d.ts +0 -31
  238. package/dist/translations/languages/fr.d.ts.map +0 -1
  239. package/dist/translations/languages/fr.js +0 -34
  240. package/dist/translations/languages/fr.js.map +0 -1
  241. package/dist/translations/languages/he.d.ts +0 -31
  242. package/dist/translations/languages/he.d.ts.map +0 -1
  243. package/dist/translations/languages/he.js +0 -34
  244. package/dist/translations/languages/he.js.map +0 -1
  245. package/dist/translations/languages/hr.d.ts +0 -31
  246. package/dist/translations/languages/hr.d.ts.map +0 -1
  247. package/dist/translations/languages/hr.js +0 -34
  248. package/dist/translations/languages/hr.js.map +0 -1
  249. package/dist/translations/languages/hu.d.ts +0 -31
  250. package/dist/translations/languages/hu.d.ts.map +0 -1
  251. package/dist/translations/languages/hu.js +0 -34
  252. package/dist/translations/languages/hu.js.map +0 -1
  253. package/dist/translations/languages/hy.d.ts +0 -31
  254. package/dist/translations/languages/hy.d.ts.map +0 -1
  255. package/dist/translations/languages/hy.js +0 -34
  256. package/dist/translations/languages/hy.js.map +0 -1
  257. package/dist/translations/languages/id.d.ts +0 -31
  258. package/dist/translations/languages/id.d.ts.map +0 -1
  259. package/dist/translations/languages/id.js +0 -34
  260. package/dist/translations/languages/id.js.map +0 -1
  261. package/dist/translations/languages/is.d.ts +0 -31
  262. package/dist/translations/languages/is.d.ts.map +0 -1
  263. package/dist/translations/languages/is.js +0 -34
  264. package/dist/translations/languages/is.js.map +0 -1
  265. package/dist/translations/languages/it.d.ts +0 -31
  266. package/dist/translations/languages/it.d.ts.map +0 -1
  267. package/dist/translations/languages/it.js +0 -34
  268. package/dist/translations/languages/it.js.map +0 -1
  269. package/dist/translations/languages/ja.d.ts +0 -31
  270. package/dist/translations/languages/ja.d.ts.map +0 -1
  271. package/dist/translations/languages/ja.js +0 -34
  272. package/dist/translations/languages/ja.js.map +0 -1
  273. package/dist/translations/languages/ko.d.ts +0 -31
  274. package/dist/translations/languages/ko.d.ts.map +0 -1
  275. package/dist/translations/languages/ko.js +0 -34
  276. package/dist/translations/languages/ko.js.map +0 -1
  277. package/dist/translations/languages/lt.d.ts +0 -31
  278. package/dist/translations/languages/lt.d.ts.map +0 -1
  279. package/dist/translations/languages/lt.js +0 -34
  280. package/dist/translations/languages/lt.js.map +0 -1
  281. package/dist/translations/languages/lv.d.ts +0 -31
  282. package/dist/translations/languages/lv.d.ts.map +0 -1
  283. package/dist/translations/languages/lv.js +0 -34
  284. package/dist/translations/languages/lv.js.map +0 -1
  285. package/dist/translations/languages/my.d.ts +0 -31
  286. package/dist/translations/languages/my.d.ts.map +0 -1
  287. package/dist/translations/languages/my.js +0 -34
  288. package/dist/translations/languages/my.js.map +0 -1
  289. package/dist/translations/languages/nb.d.ts +0 -31
  290. package/dist/translations/languages/nb.d.ts.map +0 -1
  291. package/dist/translations/languages/nb.js +0 -34
  292. package/dist/translations/languages/nb.js.map +0 -1
  293. package/dist/translations/languages/nl.d.ts +0 -31
  294. package/dist/translations/languages/nl.d.ts.map +0 -1
  295. package/dist/translations/languages/nl.js +0 -34
  296. package/dist/translations/languages/nl.js.map +0 -1
  297. package/dist/translations/languages/pl.d.ts +0 -31
  298. package/dist/translations/languages/pl.d.ts.map +0 -1
  299. package/dist/translations/languages/pl.js +0 -34
  300. package/dist/translations/languages/pl.js.map +0 -1
  301. package/dist/translations/languages/pt.d.ts +0 -31
  302. package/dist/translations/languages/pt.d.ts.map +0 -1
  303. package/dist/translations/languages/pt.js +0 -34
  304. package/dist/translations/languages/pt.js.map +0 -1
  305. package/dist/translations/languages/ro.d.ts +0 -31
  306. package/dist/translations/languages/ro.d.ts.map +0 -1
  307. package/dist/translations/languages/ro.js +0 -34
  308. package/dist/translations/languages/ro.js.map +0 -1
  309. package/dist/translations/languages/rs.d.ts +0 -31
  310. package/dist/translations/languages/rs.d.ts.map +0 -1
  311. package/dist/translations/languages/rs.js +0 -34
  312. package/dist/translations/languages/rs.js.map +0 -1
  313. package/dist/translations/languages/rsLatin.d.ts +0 -31
  314. package/dist/translations/languages/rsLatin.d.ts.map +0 -1
  315. package/dist/translations/languages/rsLatin.js +0 -34
  316. package/dist/translations/languages/rsLatin.js.map +0 -1
  317. package/dist/translations/languages/ru.d.ts +0 -31
  318. package/dist/translations/languages/ru.d.ts.map +0 -1
  319. package/dist/translations/languages/ru.js +0 -34
  320. package/dist/translations/languages/ru.js.map +0 -1
  321. package/dist/translations/languages/sk.d.ts +0 -31
  322. package/dist/translations/languages/sk.d.ts.map +0 -1
  323. package/dist/translations/languages/sk.js +0 -34
  324. package/dist/translations/languages/sk.js.map +0 -1
  325. package/dist/translations/languages/sl.d.ts +0 -31
  326. package/dist/translations/languages/sl.d.ts.map +0 -1
  327. package/dist/translations/languages/sl.js +0 -34
  328. package/dist/translations/languages/sl.js.map +0 -1
  329. package/dist/translations/languages/sv.d.ts +0 -31
  330. package/dist/translations/languages/sv.d.ts.map +0 -1
  331. package/dist/translations/languages/sv.js +0 -34
  332. package/dist/translations/languages/sv.js.map +0 -1
  333. package/dist/translations/languages/ta.d.ts +0 -31
  334. package/dist/translations/languages/ta.d.ts.map +0 -1
  335. package/dist/translations/languages/ta.js +0 -34
  336. package/dist/translations/languages/ta.js.map +0 -1
  337. package/dist/translations/languages/th.d.ts +0 -31
  338. package/dist/translations/languages/th.d.ts.map +0 -1
  339. package/dist/translations/languages/th.js +0 -34
  340. package/dist/translations/languages/th.js.map +0 -1
  341. package/dist/translations/languages/tr.d.ts +0 -31
  342. package/dist/translations/languages/tr.d.ts.map +0 -1
  343. package/dist/translations/languages/tr.js +0 -34
  344. package/dist/translations/languages/tr.js.map +0 -1
  345. package/dist/translations/languages/uk.d.ts +0 -31
  346. package/dist/translations/languages/uk.d.ts.map +0 -1
  347. package/dist/translations/languages/uk.js +0 -34
  348. package/dist/translations/languages/uk.js.map +0 -1
  349. package/dist/translations/languages/vi.d.ts +0 -31
  350. package/dist/translations/languages/vi.d.ts.map +0 -1
  351. package/dist/translations/languages/vi.js +0 -34
  352. package/dist/translations/languages/vi.js.map +0 -1
  353. package/dist/translations/languages/zh.d.ts +0 -31
  354. package/dist/translations/languages/zh.d.ts.map +0 -1
  355. package/dist/translations/languages/zh.js +0 -34
  356. package/dist/translations/languages/zh.js.map +0 -1
  357. package/dist/translations/languages/zhTw.d.ts +0 -31
  358. package/dist/translations/languages/zhTw.d.ts.map +0 -1
  359. package/dist/translations/languages/zhTw.js +0 -34
  360. package/dist/translations/languages/zhTw.js.map +0 -1
  361. package/dist/translations/types.d.ts +0 -32
  362. package/dist/translations/types.d.ts.map +0 -1
  363. package/dist/translations/types.js +0 -3
  364. package/dist/translations/types.js.map +0 -1
  365. package/src/collection/getAccessField.ts +0 -84
  366. package/src/collection/index.ts +0 -105
  367. package/src/components/APIKeyField/index.client.tsx +0 -68
  368. package/src/components/APIKeyField/index.css +0 -105
  369. package/src/components/APIKeysEmptyState/index.client.tsx +0 -33
  370. package/src/components/AccessField/index.client.tsx +0 -296
  371. package/src/components/AccessField/index.css +0 -99
  372. package/src/components/SettingsMenu/index.client.tsx +0 -30
  373. package/src/translations/index.ts +0 -105
  374. package/src/translations/languages/ar.ts +0 -38
  375. package/src/translations/languages/az.ts +0 -38
  376. package/src/translations/languages/bg.ts +0 -39
  377. package/src/translations/languages/bnBd.ts +0 -39
  378. package/src/translations/languages/bnIn.ts +0 -39
  379. package/src/translations/languages/ca.ts +0 -39
  380. package/src/translations/languages/cs.ts +0 -39
  381. package/src/translations/languages/da.ts +0 -38
  382. package/src/translations/languages/de.ts +0 -39
  383. package/src/translations/languages/en.ts +0 -39
  384. package/src/translations/languages/es.ts +0 -39
  385. package/src/translations/languages/et.ts +0 -38
  386. package/src/translations/languages/fa.ts +0 -39
  387. package/src/translations/languages/fr.ts +0 -39
  388. package/src/translations/languages/he.ts +0 -37
  389. package/src/translations/languages/hr.ts +0 -39
  390. package/src/translations/languages/hu.ts +0 -39
  391. package/src/translations/languages/hy.ts +0 -39
  392. package/src/translations/languages/id.ts +0 -39
  393. package/src/translations/languages/is.ts +0 -39
  394. package/src/translations/languages/it.ts +0 -39
  395. package/src/translations/languages/ja.ts +0 -39
  396. package/src/translations/languages/ko.ts +0 -39
  397. package/src/translations/languages/lt.ts +0 -39
  398. package/src/translations/languages/lv.ts +0 -38
  399. package/src/translations/languages/my.ts +0 -39
  400. package/src/translations/languages/nb.ts +0 -39
  401. package/src/translations/languages/nl.ts +0 -39
  402. package/src/translations/languages/pl.ts +0 -38
  403. package/src/translations/languages/pt.ts +0 -39
  404. package/src/translations/languages/ro.ts +0 -39
  405. package/src/translations/languages/rs.ts +0 -38
  406. package/src/translations/languages/rsLatin.ts +0 -38
  407. package/src/translations/languages/ru.ts +0 -39
  408. package/src/translations/languages/sk.ts +0 -39
  409. package/src/translations/languages/sl.ts +0 -38
  410. package/src/translations/languages/sv.ts +0 -39
  411. package/src/translations/languages/ta.ts +0 -39
  412. package/src/translations/languages/th.ts +0 -38
  413. package/src/translations/languages/tr.ts +0 -38
  414. package/src/translations/languages/uk.ts +0 -39
  415. package/src/translations/languages/vi.ts +0 -39
  416. package/src/translations/languages/zh.ts +0 -36
  417. package/src/translations/languages/zhTw.ts +0 -36
  418. package/src/translations/types.ts +0 -34
@@ -1,144 +1,119 @@
1
- import type { DefaultDocumentIDType, PayloadRequest, TypedUser } from 'payload'
1
+ import type { PayloadRequest, SanitizedPermissions } from 'payload'
2
2
 
3
- import crypto from 'crypto'
4
- import { UnauthorizedError } from 'payload'
3
+ import { getAccessResults, UnauthorizedError } from 'payload'
5
4
 
6
- import type { AuthorizedMCP, MCPAPIKeysDoc } from '../types.js'
5
+ import type { AuthorizedMCP, MCPItem } from '../types.js'
7
6
 
8
- import { getLogger } from '../utils/getLogger.js'
9
7
  import { getPluginConfig } from '../utils/getPluginConfig.js'
10
8
 
9
+ export type GetAuthorizedMCPArgs = {
10
+ overrideAccess: boolean
11
+ req: PayloadRequest
12
+ }
13
+
11
14
  /**
12
- * Resolves the API key (or dev-mode session) and returns the items the caller
13
- * may use. Denied items are dropped from the array.
15
+ * Resolves the MCP caller and returns the MCP surface authorized for that request.
16
+ *
17
+ * Authorization has two layers:
18
+ * 1. Payload collection/global permissions determine whether built-in operation tools are shown.
19
+ * 2. MCP `access` callbacks can further hide any configured tool, prompt, or resource.
20
+ *
21
+ * Like Payload core operations, `overrideAccess` skips both layers.
14
22
  */
15
- export const getAuthorizedMCP: (args: { req: PayloadRequest }) => Promise<AuthorizedMCP> = async ({
23
+ export const getAuthorizedMCP: (args: GetAuthorizedMCPArgs) => Promise<AuthorizedMCP> = async ({
24
+ overrideAccess,
16
25
  req,
17
26
  }) => {
18
- const logger = getLogger({ payload: req.payload })
19
27
  const pluginConfig = getPluginConfig({ config: req.payload.config })
20
28
 
21
- const authHeader = req.headers.get('Authorization')
22
- const hasBearerToken = authHeader?.startsWith('Bearer ')
23
-
24
- const buildAuthorized = (apiKeyDoc: MCPAPIKeysDoc): AuthorizedMCP => ({
25
- items: pluginConfig.items.filter((item) => {
26
- switch (item.type) {
27
- case 'collectionTool':
28
- return apiKeyDoc.access.collections?.[item.collectionSlug]?.[item.configKey] !== false
29
- case 'globalTool':
30
- return apiKeyDoc.access.globals?.[item.globalSlug]?.[item.configKey] !== false
31
- case 'prompt':
32
- return apiKeyDoc.access.prompts?.[item.configKey] !== false
33
- case 'resource':
34
- return apiKeyDoc.access.resources?.[item.configKey] !== false
35
- case 'tool':
36
- return apiKeyDoc.access.tools?.[item.configKey] !== false
37
- }
38
- }),
39
- overrideAccess:
40
- typeof apiKeyDoc.overrideAccess === 'boolean' ? apiKeyDoc.overrideAccess : false,
41
- user: apiKeyDoc.user,
42
- })
43
-
44
- if (pluginConfig.overrideAuth) {
45
- return await pluginConfig.overrideAuth({
46
- getAPIKeyDoc: (overrideApiKey) => getAPIKeyDoc({ logger, overrideApiKey, pluginConfig, req }),
47
- getAuthorizedMCP: ({ apiKeyDoc }) => buildAuthorized(apiKeyDoc),
29
+ if (pluginConfig.overrideGetAuthorizedMCP) {
30
+ return await pluginConfig.overrideGetAuthorizedMCP({
31
+ overrideAccess,
48
32
  pluginConfig,
49
33
  req,
50
34
  })
51
35
  }
52
36
 
53
- if (process.env.NODE_ENV === 'development' && !hasBearerToken) {
54
- logger.info('Dev mode: skipping API key check, using session user')
55
- return buildAuthorized({
56
- id: -1,
57
- access: {},
58
- overrideAccess: true,
59
- user: req.user ?? null,
60
- })
37
+ if (req.headers) {
38
+ const headers = new Headers(req.headers)
39
+ const hasAuthorization = headers.has('Authorization')
40
+
41
+ headers.set('DisableAutologin', 'true')
42
+ req.user = (await req.payload.auth({ headers, req })).user
43
+
44
+ if (hasAuthorization && !req.user) {
45
+ throw new UnauthorizedError(req.t)
46
+ }
61
47
  }
62
48
 
63
- return buildAuthorized(await getAPIKeyDoc({ logger, pluginConfig, req }))
49
+ return {
50
+ items: await filterMCPItems({
51
+ items: pluginConfig.items,
52
+ overrideAccess,
53
+ req,
54
+ }),
55
+ overrideAccess,
56
+ user: req.user,
57
+ }
64
58
  }
65
59
 
66
- const getAPIKeyDoc = async ({
67
- logger,
68
- overrideApiKey,
69
- pluginConfig,
60
+ export const filterMCPItems = async ({
61
+ items,
62
+ overrideAccess,
70
63
  req,
71
64
  }: {
72
- logger: ReturnType<typeof getLogger>
73
- overrideApiKey?: string
74
- pluginConfig: ReturnType<typeof getPluginConfig>
65
+ items: MCPItem[]
66
+ overrideAccess: boolean
75
67
  req: PayloadRequest
76
- }): Promise<MCPAPIKeysDoc> => {
77
- const authHeader = req.headers.get('Authorization')
78
- const hasBearerToken = authHeader?.startsWith('Bearer ')
79
-
80
- const apiKey =
81
- overrideApiKey ?? (hasBearerToken ? authHeader?.replace('Bearer ', '').trim() || null : null)
82
-
83
- if (!apiKey) {
84
- throw new UnauthorizedError()
68
+ }): Promise<MCPItem[]> => {
69
+ // Match Payload core: overrideAccess bypasses access evaluation instead of
70
+ // forcing each access function to return true.
71
+ if (overrideAccess) {
72
+ return items
85
73
  }
86
74
 
87
- const sha256APIKeyIndex = crypto
88
- .createHmac('sha256', req.payload.secret)
89
- .update(apiKey)
90
- .digest('hex')
91
-
92
- const doc = await req.payload.db.findOne<MCPAPIKeysDoc>({
93
- collection: 'payload-mcp-api-keys',
94
- req,
95
- where: {
96
- apiKeyIndex: { equals: sha256APIKeyIndex },
97
- },
98
- })
99
-
100
- if (!doc || !doc.user) {
101
- throw new UnauthorizedError()
102
- }
103
-
104
- logger.info('API Key is valid')
75
+ const authorizedItems: MCPItem[] = []
105
76
 
106
- const userRef = doc.user
107
- const userID =
108
- typeof userRef === 'object' && userRef !== null && 'id' in userRef
109
- ? userRef.id
110
- : (userRef as unknown as DefaultDocumentIDType)
77
+ const permissions = await getAccessResults({ req })
111
78
 
112
- const user = (await req.payload.findByID({
113
- id: userID,
114
- collection: pluginConfig.userCollection,
115
- depth: 0,
116
- disableErrors: true,
117
- req,
118
- })) as null | TypedUser
119
-
120
- if (!user) {
121
- throw new UnauthorizedError()
79
+ for (const item of items) {
80
+ if (!(await checkItemAccess({ item, permissions, req }))) {
81
+ continue
82
+ }
83
+ authorizedItems.push(item)
122
84
  }
123
85
 
124
- try {
125
- await req.payload.db.updateOne({
126
- id: doc.id,
127
- collection: 'payload-mcp-api-keys',
128
- data: { lastUsed: new Date().toISOString() },
129
- req,
130
- returning: false,
131
- })
132
- } catch (err) {
133
- logger.warn({ err, msg: 'Failed to update MCP API key last-used timestamp' })
134
- }
86
+ return authorizedItems
87
+ }
135
88
 
136
- return {
137
- ...doc,
138
- user: {
139
- ...user,
140
- _strategy: 'mcp-api-key' as const,
141
- collection: pluginConfig.userCollection,
142
- },
89
+ /**
90
+ * Runs MCP item access callbacks
91
+ */
92
+ const checkItemAccess = async ({
93
+ item,
94
+ permissions,
95
+ req,
96
+ }: {
97
+ item: MCPItem
98
+ permissions?: SanitizedPermissions
99
+ req: PayloadRequest
100
+ }): Promise<boolean> => {
101
+ switch (item.type) {
102
+ case 'collectionTool':
103
+ return (
104
+ !item.tool.access ||
105
+ (await item.tool.access({ collectionSlug: item.collectionSlug, permissions, req }))
106
+ )
107
+ case 'globalTool':
108
+ return (
109
+ !item.tool.access ||
110
+ (await item.tool.access({ globalSlug: item.globalSlug, permissions, req }))
111
+ )
112
+ case 'prompt':
113
+ return !item.prompt.access || (await item.prompt.access({ permissions, req }))
114
+ case 'resource':
115
+ return !item.resource.access || (await item.resource.access({ permissions, req }))
116
+ case 'tool':
117
+ return !item.tool.access || (await item.tool.access({ permissions, req }))
143
118
  }
144
119
  }
@@ -13,7 +13,20 @@ export const mcpEndpoint: PayloadHandler = async (req) => {
13
13
  req.payloadAPI = 'MCP' as const
14
14
 
15
15
  const pluginConfig = getPluginConfig({ config: req.payload.config })
16
- const authorizedMCP = await getAuthorizedMCP({ req })
16
+ const overrideAccessParam = new URL(req.url).searchParams.get('overrideAccess')
17
+
18
+ if (overrideAccessParam !== null && process.env.NODE_ENV !== 'development') {
19
+ throw new APIError('MCP overrideAccess is only available in development.', 400)
20
+ }
21
+
22
+ let overrideAccess = false
23
+ if (overrideAccessParam === 'true') {
24
+ overrideAccess = true
25
+ } else if (overrideAccessParam !== null && overrideAccessParam !== 'false') {
26
+ throw new APIError('MCP overrideAccess must be "true" or "false".', 400)
27
+ }
28
+
29
+ const authorizedMCP = await getAuthorizedMCP({ overrideAccess, req })
17
30
 
18
31
  const server = buildMcpServer({ authorizedMCP, pluginConfig, req })
19
32
 
@@ -1,5 +1,3 @@
1
1
  'use client'
2
- export { AccessField } from '../components/AccessField/index.client.js'
3
- export { APIKeyField } from '../components/APIKeyField/index.client.js'
4
- export { APIKeysEmptyState } from '../components/APIKeysEmptyState/index.client.js'
5
- export { MCPSettingsMenu } from '../components/SettingsMenu/index.client.js'
2
+
3
+ export {}
@@ -0,0 +1 @@
1
+ export { filterMCPItems, getAuthorizedMCP } from '../endpoint/access.js'
package/src/index.ts CHANGED
@@ -1,14 +1,9 @@
1
- import type { AcceptedLanguages } from '@payloadcms/translations'
1
+ import { definePlugin } from 'payload'
2
2
 
3
- import { defaultUserCollection, definePlugin } from 'payload'
4
-
5
- import type { PluginDefaultTranslationsObject } from './translations/types.js'
6
3
  import type { AuthorizedMCP, MCPPluginConfig, SanitizedMCPPluginConfig } from './types.js'
7
4
 
8
- import { getAPIKeysCollection } from './collection/index.js'
9
5
  import { mcpEndpoint } from './endpoint/index.js'
10
6
  import { sanitizeMCPConfig } from './mcp/sanitizeMCPConfig.js'
11
- import { translations } from './translations/index.js'
12
7
 
13
8
  declare module 'payload' {
14
9
  export interface PayloadRequest {
@@ -28,15 +23,6 @@ export const mcpPlugin = definePlugin<MCPPluginConfig>({
28
23
  slug: '@payloadcms/plugin-mcp',
29
24
  order: 10,
30
25
  plugin: ({ config, plugins, ...rawConfig }) => {
31
- // If a project has no auth collection yet, add the default users collection
32
- // so the relationship target and default `userCollection` exist.
33
- if (!config.admin?.user) {
34
- const firstCollectionWithAuth = (config.collections ?? []).find(({ auth }) => Boolean(auth))
35
- if (!firstCollectionWithAuth) {
36
- ;(config.collections ??= []).push(defaultUserCollection)
37
- }
38
- }
39
-
40
26
  const pluginConfig = sanitizeMCPConfig({ config, pluginConfig: rawConfig })
41
27
 
42
28
  // Stash the sanitized config on plugin options so `getPluginConfig()` reads it.
@@ -46,55 +32,12 @@ export const mcpPlugin = definePlugin<MCPPluginConfig>({
46
32
  registered.sanitizedOptions = pluginConfig as unknown as typeof registered.options
47
33
  }
48
34
 
49
- ;(config.collections ??= []).push(getAPIKeysCollection({ pluginConfig }))
50
-
51
- if (!config.i18n) {
52
- config.i18n = {}
53
- }
54
-
55
- if (!config.i18n.translations) {
56
- config.i18n.translations = {}
57
- }
58
-
59
- const supportedLanguageKeys = config.i18n.supportedLanguages
60
- ? Object.keys(config.i18n.supportedLanguages)
61
- : ['en']
62
-
63
- for (const lang of supportedLanguageKeys) {
64
- const pluginEntry = translations[lang as keyof typeof translations]
65
- if (!pluginEntry) {
66
- continue
67
- }
68
-
69
- const typedLocale = lang as AcceptedLanguages
70
- const existing = (config.i18n.translations[typedLocale] ?? {}) as Record<string, unknown>
71
- config.i18n.translations[typedLocale] = {
72
- ...existing,
73
- 'plugin-mcp': pluginEntry.translations['plugin-mcp'],
74
- } as PluginDefaultTranslationsObject
75
- }
76
-
77
- // Keep the API-keys collection registered even when disabled, so DB schema
78
- // and generated types don't drift between enabled/disabled environments.
79
35
  if (pluginConfig.disabled) {
80
36
  return config
81
37
  }
82
38
 
83
39
  return {
84
40
  ...config,
85
- admin: {
86
- ...config.admin,
87
- components: {
88
- ...config.admin?.components,
89
- userMenuSettingsItems: [
90
- ...(config.admin?.components?.userMenuSettingsItems ?? []),
91
- {
92
- group: 'MCP',
93
- items: ['@payloadcms/plugin-mcp/client#MCPSettingsMenu'],
94
- },
95
- ],
96
- },
97
- },
98
41
  endpoints: [
99
42
  ...(config.endpoints ?? []),
100
43
  // Payload prefixes /api, so the full path is /api/mcp.
@@ -109,7 +109,12 @@ export const buildMcpServer = ({
109
109
  }
110
110
  }
111
111
 
112
- const handlerArgs = { authorizedMCP, input: toolInput, req, serverContext }
112
+ const handlerArgs = {
113
+ authorizedMCP,
114
+ input: toolInput,
115
+ req,
116
+ serverContext,
117
+ }
113
118
  const response = await (match.type === 'collectionTool'
114
119
  ? match.tool.handler({ ...handlerArgs, collectionSlug: slug })
115
120
  : match.tool.handler({ ...handlerArgs, globalSlug: slug }))
@@ -0,0 +1,74 @@
1
+ import { z } from 'zod'
2
+
3
+ import { defaultAccess } from '../../../defaultAccess.js'
4
+ import { defineCollectionTool } from '../../../defineTool.js'
5
+ import { getLogger } from '../../../utils/getLogger.js'
6
+ import { localAPIDefaults } from '../../../utils/localAPIDefaults.js'
7
+ import { whereSchema } from '../../../utils/whereSchema.js'
8
+
9
+ const DEFAULT_DESCRIPTION =
10
+ 'Count documents in any collection by passing the collection slug and optional where clause.'
11
+
12
+ export const countDocumentsTool = defineCollectionTool({
13
+ access: (args) =>
14
+ defaultAccess(args) && Boolean(args.permissions?.collections?.[args.collectionSlug]?.read),
15
+ annotations: {
16
+ destructiveHint: false,
17
+ idempotentHint: true,
18
+ openWorldHint: false,
19
+ readOnlyHint: true,
20
+ title: 'Count Documents',
21
+ },
22
+ description: DEFAULT_DESCRIPTION,
23
+ input: z.object({
24
+ locale: z.string().describe('Optional: locale code to count documents in').optional(),
25
+ trash: z
26
+ .boolean()
27
+ .describe('Optional: include soft-deleted documents when trash is enabled on the collection')
28
+ .optional(),
29
+ where: whereSchema
30
+ .describe(
31
+ 'Optional: where clause for filtering. Use field names with Payload operators, and/or arrays for grouping. Example: {"title":{"contains":"test"}}',
32
+ )
33
+ .optional(),
34
+ }),
35
+ }).handler(async ({ authorizedMCP, collectionSlug, input, req }) => {
36
+ const payload = req.payload
37
+ const logger = getLogger({ payload })
38
+ const { locale, trash, where } = input
39
+
40
+ logger.info(`Counting documents in collection: ${collectionSlug}`)
41
+
42
+ try {
43
+ const result = await payload.count({
44
+ collection: collectionSlug,
45
+ req,
46
+ ...localAPIDefaults(authorizedMCP),
47
+ ...(locale ? { locale } : {}),
48
+ ...(trash !== undefined ? { trash } : {}),
49
+ ...(where ? { where } : {}),
50
+ })
51
+
52
+ return {
53
+ content: [
54
+ {
55
+ type: 'text',
56
+ text: `Collection "${collectionSlug}" contains ${result.totalDocs} matching documents.\n\`\`\`json\n${JSON.stringify(result)}\n\`\`\``,
57
+ },
58
+ ],
59
+ doc: result,
60
+ }
61
+ } catch (error) {
62
+ const errorMessage = error instanceof Error ? error.message : 'Unknown error'
63
+ logger.error(`Error counting documents in ${collectionSlug}: ${errorMessage}`)
64
+ return {
65
+ content: [
66
+ {
67
+ type: 'text',
68
+ text: `❌ **Error counting documents in collection "${collectionSlug}":** ${errorMessage}`,
69
+ },
70
+ ],
71
+ isError: true,
72
+ }
73
+ }
74
+ })
@@ -0,0 +1,70 @@
1
+ import { z } from 'zod'
2
+
3
+ import { defaultAccess } from '../../../defaultAccess.js'
4
+ import { defineCollectionTool } from '../../../defineTool.js'
5
+ import { getLogger } from '../../../utils/getLogger.js'
6
+ import { localAPIDefaults } from '../../../utils/localAPIDefaults.js'
7
+ import { whereSchema } from '../../../utils/whereSchema.js'
8
+
9
+ const DEFAULT_DESCRIPTION =
10
+ 'Count document versions in any version-enabled collection by passing the collection slug and optional where clause.'
11
+
12
+ export const countVersionsTool = defineCollectionTool({
13
+ access: (args) =>
14
+ defaultAccess(args) &&
15
+ Boolean(args.permissions?.collections?.[args.collectionSlug]?.readVersions),
16
+ annotations: {
17
+ destructiveHint: false,
18
+ idempotentHint: true,
19
+ openWorldHint: false,
20
+ readOnlyHint: true,
21
+ title: 'Count Versions',
22
+ },
23
+ description: DEFAULT_DESCRIPTION,
24
+ input: z.object({
25
+ locale: z.string().describe('Optional: locale code to count versions in').optional(),
26
+ where: whereSchema
27
+ .describe(
28
+ 'Optional: where clause for filtering versions. Version document fields are usually under "version". Example: {"version.title":{"contains":"test"}}',
29
+ )
30
+ .optional(),
31
+ }),
32
+ }).handler(async ({ authorizedMCP, collectionSlug, input, req }) => {
33
+ const payload = req.payload
34
+ const logger = getLogger({ payload })
35
+ const { locale, where } = input
36
+
37
+ logger.info(`Counting versions in collection: ${collectionSlug}`)
38
+
39
+ try {
40
+ const result = await payload.countVersions({
41
+ collection: collectionSlug,
42
+ req,
43
+ ...localAPIDefaults(authorizedMCP),
44
+ ...(locale ? { locale } : {}),
45
+ ...(where ? { where } : {}),
46
+ })
47
+
48
+ return {
49
+ content: [
50
+ {
51
+ type: 'text',
52
+ text: `Collection "${collectionSlug}" contains ${result.totalDocs} matching versions.\n\`\`\`json\n${JSON.stringify(result)}\n\`\`\``,
53
+ },
54
+ ],
55
+ doc: result,
56
+ }
57
+ } catch (error) {
58
+ const errorMessage = error instanceof Error ? error.message : 'Unknown error'
59
+ logger.error(`Error counting versions in ${collectionSlug}: ${errorMessage}`)
60
+ return {
61
+ content: [
62
+ {
63
+ type: 'text',
64
+ text: `❌ **Error counting versions in collection "${collectionSlug}":** ${errorMessage}`,
65
+ },
66
+ ],
67
+ isError: true,
68
+ }
69
+ }
70
+ })
@@ -2,6 +2,7 @@ import type { SelectType } from 'payload'
2
2
 
3
3
  import { z } from 'zod'
4
4
 
5
+ import { defaultAccess } from '../../../defaultAccess.js'
5
6
  import { defineCollectionTool } from '../../../defineTool.js'
6
7
  import { getLogger } from '../../../utils/getLogger.js'
7
8
  import {
@@ -17,6 +18,8 @@ const DEFAULT_DESCRIPTION =
17
18
  'Create a document in any collection by passing the collection slug and data.'
18
19
 
19
20
  export const createDocumentTool = defineCollectionTool({
21
+ access: (args) =>
22
+ defaultAccess(args) && Boolean(args.permissions?.collections?.[args.collectionSlug]?.create),
20
23
  annotations: {
21
24
  destructiveHint: false,
22
25
  idempotentHint: false,
@@ -1,5 +1,6 @@
1
1
  import { z } from 'zod'
2
2
 
3
+ import { defaultAccess } from '../../../defaultAccess.js'
3
4
  import { defineCollectionTool } from '../../../defineTool.js'
4
5
  import { getLogger } from '../../../utils/getLogger.js'
5
6
  import { localAPIDefaults } from '../../../utils/localAPIDefaults.js'
@@ -9,6 +10,8 @@ const DEFAULT_DESCRIPTION =
9
10
  'Delete documents in any collection by passing the collection slug and ID or where clause.'
10
11
 
11
12
  export const deleteDocumentsTool = defineCollectionTool({
13
+ access: (args) =>
14
+ defaultAccess(args) && Boolean(args.permissions?.collections?.[args.collectionSlug]?.delete),
12
15
  annotations: {
13
16
  destructiveHint: true,
14
17
  idempotentHint: false,
@@ -0,0 +1,135 @@
1
+ import type { PopulateType, SelectType } from 'payload'
2
+
3
+ import { z } from 'zod'
4
+
5
+ import { defaultAccess } from '../../../defaultAccess.js'
6
+ import { defineCollectionTool } from '../../../defineTool.js'
7
+ import { getLogger } from '../../../utils/getLogger.js'
8
+ import {
9
+ getCollectionVirtualFieldNames,
10
+ stripVirtualFields,
11
+ } from '../../../utils/getVirtualFieldNames.js'
12
+ import { localAPIDefaults } from '../../../utils/localAPIDefaults.js'
13
+ import { transformPointDataToPayload } from '../../../utils/transformPointDataToPayload.js'
14
+ import { formatCollectionError } from './formatCollectionError.js'
15
+
16
+ const DEFAULT_DESCRIPTION =
17
+ 'Duplicate a document in any collection by passing the collection slug and source document ID.'
18
+
19
+ export const duplicateDocumentTool = defineCollectionTool({
20
+ access: (args) =>
21
+ defaultAccess(args) && Boolean(args.permissions?.collections?.[args.collectionSlug]?.create),
22
+ annotations: {
23
+ destructiveHint: false,
24
+ idempotentHint: false,
25
+ openWorldHint: false,
26
+ readOnlyHint: false,
27
+ title: 'Duplicate Document',
28
+ },
29
+ description: DEFAULT_DESCRIPTION,
30
+ input: z.object({
31
+ id: z.union([z.string(), z.number()]).describe('The ID of the document to duplicate'),
32
+ data: z
33
+ .record(z.string(), z.unknown())
34
+ .describe('Optional: fields to override on the duplicated document')
35
+ .optional(),
36
+ depth: z
37
+ .number()
38
+ .int()
39
+ .min(0)
40
+ .max(10)
41
+ .describe('How many levels deep to populate relationships in response')
42
+ .optional()
43
+ .default(0),
44
+ draft: z
45
+ .boolean()
46
+ .describe('Whether to create the duplicate as a draft')
47
+ .optional()
48
+ .default(false),
49
+ fallbackLocale: z
50
+ .string()
51
+ .describe('Optional: fallback locale code to use when requested locale is not available')
52
+ .optional(),
53
+ locale: z
54
+ .string()
55
+ .describe(
56
+ 'Optional: locale code to duplicate in (e.g., "en", "es"). Defaults to the default locale',
57
+ )
58
+ .optional(),
59
+ populate: z
60
+ .record(z.string(), z.unknown())
61
+ .describe(
62
+ 'Optional: control which fields to include from populated relationship or upload documents.',
63
+ )
64
+ .optional(),
65
+ select: z
66
+ .record(z.string(), z.unknown())
67
+ .describe(
68
+ 'Optional: define exactly which fields you\'d like to return in the response, e.g., {"title": true}',
69
+ )
70
+ .optional(),
71
+ selectedLocales: z
72
+ .array(z.string())
73
+ .describe('Optional: localized field locales to include in the duplicated document')
74
+ .optional(),
75
+ showHiddenFields: z
76
+ .boolean()
77
+ .describe('Optional: include hidden fields in the duplicated document response')
78
+ .optional(),
79
+ }),
80
+ }).handler(async ({ authorizedMCP, collectionSlug, input, req }) => {
81
+ const payload = req.payload
82
+ const logger = getLogger({ payload })
83
+ const {
84
+ id,
85
+ data,
86
+ depth,
87
+ draft,
88
+ fallbackLocale,
89
+ locale,
90
+ populate,
91
+ select,
92
+ selectedLocales,
93
+ showHiddenFields,
94
+ } = input
95
+
96
+ logger.info(`Duplicating document in collection: ${collectionSlug} with ID: ${id}`)
97
+
98
+ try {
99
+ const virtualFieldNames = getCollectionVirtualFieldNames(payload.config, collectionSlug)
100
+ const inputData = data ? stripVirtualFields(data, virtualFieldNames) : undefined
101
+ const parsedData = inputData ? transformPointDataToPayload(inputData) : undefined
102
+
103
+ const result = await payload.duplicate({
104
+ id,
105
+ collection: collectionSlug,
106
+ depth,
107
+ draft,
108
+ req,
109
+ ...localAPIDefaults(authorizedMCP),
110
+ ...(parsedData ? { data: parsedData } : {}),
111
+ ...(locale ? { locale } : {}),
112
+ ...(fallbackLocale ? { fallbackLocale } : {}),
113
+ ...(populate ? { populate: populate as PopulateType } : {}),
114
+ ...(select ? { select: select as SelectType } : {}),
115
+ ...(selectedLocales ? { selectedLocales } : {}),
116
+ ...(showHiddenFields !== undefined ? { showHiddenFields } : {}),
117
+ })
118
+
119
+ logger.info(`Successfully duplicated document in ${collectionSlug} from ID: ${id}`)
120
+
121
+ return {
122
+ content: [
123
+ {
124
+ type: 'text',
125
+ text: `Document duplicated successfully in collection "${collectionSlug}"!\nDuplicated document:\n\`\`\`json\n${JSON.stringify(result)}\n\`\`\``,
126
+ },
127
+ ],
128
+ doc: result as Record<string, unknown>,
129
+ }
130
+ } catch (error) {
131
+ const errorMessage = error instanceof Error ? error.message : 'Unknown error'
132
+ logger.error(`Error duplicating document in ${collectionSlug}: ${errorMessage}`)
133
+ return formatCollectionError({ action: 'duplicating', collectionSlug, error, req })
134
+ }
135
+ })