@payloadcms/plugin-mcp 4.0.0-internal.5b1e7cd → 4.0.0-internal.5d2e3d1

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 (446) hide show
  1. package/LICENSE.md +1 -1
  2. package/bin.js +39 -0
  3. package/dist/defaultAccess.d.ts +3 -0
  4. package/dist/defaultAccess.d.ts.map +1 -0
  5. package/dist/defaultAccess.js +3 -0
  6. package/dist/defaultAccess.js.map +1 -0
  7. package/dist/defineTool.d.ts +26 -0
  8. package/dist/defineTool.d.ts.map +1 -0
  9. package/dist/defineTool.js +37 -0
  10. package/dist/defineTool.js.map +1 -0
  11. package/dist/endpoint/access.d.ts +22 -0
  12. package/dist/endpoint/access.d.ts.map +1 -0
  13. package/dist/endpoint/access.js +130 -0
  14. package/dist/endpoint/access.js.map +1 -0
  15. package/dist/endpoint/index.d.ts +3 -0
  16. package/dist/endpoint/index.d.ts.map +1 -0
  17. package/dist/endpoint/index.js +141 -0
  18. package/dist/endpoint/index.js.map +1 -0
  19. package/dist/endpoint/oauth.d.ts +37 -0
  20. package/dist/endpoint/oauth.d.ts.map +1 -0
  21. package/dist/endpoint/oauth.js +105 -0
  22. package/dist/endpoint/oauth.js.map +1 -0
  23. package/dist/endpoint/oauthLoginToken.d.ts +23 -0
  24. package/dist/endpoint/oauthLoginToken.d.ts.map +1 -0
  25. package/dist/endpoint/oauthLoginToken.js +80 -0
  26. package/dist/endpoint/oauthLoginToken.js.map +1 -0
  27. package/dist/endpoint/oauthServer.d.ts +28 -0
  28. package/dist/endpoint/oauthServer.d.ts.map +1 -0
  29. package/dist/endpoint/oauthServer.js +423 -0
  30. package/dist/endpoint/oauthServer.js.map +1 -0
  31. package/dist/exports/client.d.ts +2 -0
  32. package/dist/exports/client.d.ts.map +1 -0
  33. package/dist/exports/client.js +4 -0
  34. package/dist/exports/client.js.map +1 -0
  35. package/dist/exports/internal.d.ts +2 -0
  36. package/dist/exports/internal.d.ts.map +1 -0
  37. package/dist/exports/internal.js +3 -0
  38. package/dist/exports/internal.js.map +1 -0
  39. package/dist/exports/rsc.d.ts +2 -0
  40. package/dist/exports/rsc.d.ts.map +1 -0
  41. package/dist/exports/rsc.js +3 -0
  42. package/dist/exports/rsc.js.map +1 -0
  43. package/dist/index.d.ts +14 -9
  44. package/dist/index.d.ts.map +1 -1
  45. package/dist/index.js +63 -67
  46. package/dist/index.js.map +1 -1
  47. package/dist/mcp/buildMcpServer.d.ts +19 -0
  48. package/dist/mcp/buildMcpServer.d.ts.map +1 -0
  49. package/dist/mcp/buildMcpServer.js +235 -0
  50. package/dist/mcp/buildMcpServer.js.map +1 -0
  51. package/dist/mcp/builtin/collections/authTools.d.ts +7 -0
  52. package/dist/mcp/builtin/collections/authTools.d.ts.map +1 -0
  53. package/dist/mcp/builtin/collections/authTools.js +312 -0
  54. package/dist/mcp/builtin/collections/authTools.js.map +1 -0
  55. package/dist/mcp/builtin/collections/countTool.d.ts +2 -0
  56. package/dist/mcp/builtin/collections/countTool.d.ts.map +1 -0
  57. package/dist/mcp/builtin/collections/countTool.js +63 -0
  58. package/dist/mcp/builtin/collections/countTool.js.map +1 -0
  59. package/dist/mcp/builtin/collections/countVersionsTool.d.ts +2 -0
  60. package/dist/mcp/builtin/collections/countVersionsTool.d.ts.map +1 -0
  61. package/dist/mcp/builtin/collections/countVersionsTool.js +60 -0
  62. package/dist/mcp/builtin/collections/countVersionsTool.js.map +1 -0
  63. package/dist/mcp/builtin/collections/createTool.d.ts +2 -0
  64. package/dist/mcp/builtin/collections/createTool.d.ts.map +1 -0
  65. package/dist/mcp/builtin/collections/createTool.js +137 -0
  66. package/dist/mcp/builtin/collections/createTool.js.map +1 -0
  67. package/dist/mcp/builtin/collections/deleteTool.d.ts +2 -0
  68. package/dist/mcp/builtin/collections/deleteTool.d.ts.map +1 -0
  69. package/dist/mcp/builtin/collections/deleteTool.js +113 -0
  70. package/dist/mcp/builtin/collections/deleteTool.js.map +1 -0
  71. package/dist/mcp/builtin/collections/duplicateTool.d.ts +2 -0
  72. package/dist/mcp/builtin/collections/duplicateTool.d.ts.map +1 -0
  73. package/dist/mcp/builtin/collections/duplicateTool.js +90 -0
  74. package/dist/mcp/builtin/collections/duplicateTool.js.map +1 -0
  75. package/dist/mcp/builtin/collections/fileInput.d.ts +28 -0
  76. package/dist/mcp/builtin/collections/fileInput.d.ts.map +1 -0
  77. package/dist/mcp/builtin/collections/fileInput.js +88 -0
  78. package/dist/mcp/builtin/collections/fileInput.js.map +1 -0
  79. package/dist/mcp/builtin/collections/findDistinctTool.d.ts +2 -0
  80. package/dist/mcp/builtin/collections/findDistinctTool.d.ts.map +1 -0
  81. package/dist/mcp/builtin/collections/findDistinctTool.js +77 -0
  82. package/dist/mcp/builtin/collections/findDistinctTool.js.map +1 -0
  83. package/dist/mcp/builtin/collections/findTool.d.ts +2 -0
  84. package/dist/mcp/builtin/collections/findTool.d.ts.map +1 -0
  85. package/dist/mcp/builtin/collections/findTool.js +146 -0
  86. package/dist/mcp/builtin/collections/findTool.js.map +1 -0
  87. package/dist/mcp/builtin/collections/findVersionByIDTool.d.ts +2 -0
  88. package/dist/mcp/builtin/collections/findVersionByIDTool.d.ts.map +1 -0
  89. package/dist/mcp/builtin/collections/findVersionByIDTool.js +74 -0
  90. package/dist/mcp/builtin/collections/findVersionByIDTool.js.map +1 -0
  91. package/dist/mcp/builtin/collections/findVersionsTool.d.ts +2 -0
  92. package/dist/mcp/builtin/collections/findVersionsTool.d.ts.map +1 -0
  93. package/dist/mcp/builtin/collections/findVersionsTool.js +84 -0
  94. package/dist/mcp/builtin/collections/findVersionsTool.js.map +1 -0
  95. package/dist/mcp/builtin/collections/getCollectionSchemaTool.d.ts +2 -0
  96. package/dist/mcp/builtin/collections/getCollectionSchemaTool.d.ts.map +1 -0
  97. package/dist/mcp/builtin/collections/getCollectionSchemaTool.js +103 -0
  98. package/dist/mcp/builtin/collections/getCollectionSchemaTool.js.map +1 -0
  99. package/dist/mcp/builtin/collections/restoreVersionTool.d.ts +2 -0
  100. package/dist/mcp/builtin/collections/restoreVersionTool.d.ts.map +1 -0
  101. package/dist/mcp/builtin/collections/restoreVersionTool.js +69 -0
  102. package/dist/mcp/builtin/collections/restoreVersionTool.js.map +1 -0
  103. package/dist/mcp/builtin/collections/updateTool.d.ts +2 -0
  104. package/dist/mcp/builtin/collections/updateTool.d.ts.map +1 -0
  105. package/dist/mcp/builtin/collections/updateTool.js +172 -0
  106. package/dist/mcp/builtin/collections/updateTool.js.map +1 -0
  107. package/dist/mcp/builtin/collections/uploadInstructionsTool.d.ts +2 -0
  108. package/dist/mcp/builtin/collections/uploadInstructionsTool.d.ts.map +1 -0
  109. package/dist/mcp/builtin/collections/uploadInstructionsTool.js +55 -0
  110. package/dist/mcp/builtin/collections/uploadInstructionsTool.js.map +1 -0
  111. package/dist/mcp/builtin/formatEntityError.d.ts +16 -0
  112. package/dist/mcp/builtin/formatEntityError.d.ts.map +1 -0
  113. package/dist/mcp/builtin/formatEntityError.js +55 -0
  114. package/dist/mcp/builtin/formatEntityError.js.map +1 -0
  115. package/dist/mcp/builtin/getConfigInfoTool.d.ts +2 -0
  116. package/dist/mcp/builtin/getConfigInfoTool.d.ts.map +1 -0
  117. package/dist/mcp/builtin/getConfigInfoTool.js +69 -0
  118. package/dist/mcp/builtin/getConfigInfoTool.js.map +1 -0
  119. package/dist/mcp/builtin/globals/countVersionsTool.d.ts +2 -0
  120. package/dist/mcp/builtin/globals/countVersionsTool.d.ts.map +1 -0
  121. package/dist/mcp/builtin/globals/countVersionsTool.js +60 -0
  122. package/dist/mcp/builtin/globals/countVersionsTool.js.map +1 -0
  123. package/dist/mcp/builtin/globals/findTool.d.ts +2 -0
  124. package/dist/mcp/builtin/globals/findTool.d.ts.map +1 -0
  125. package/dist/mcp/builtin/globals/findTool.js +67 -0
  126. package/dist/mcp/builtin/globals/findTool.js.map +1 -0
  127. package/dist/mcp/builtin/globals/findVersionByIDTool.d.ts +2 -0
  128. package/dist/mcp/builtin/globals/findVersionByIDTool.d.ts.map +1 -0
  129. package/dist/mcp/builtin/globals/findVersionByIDTool.js +68 -0
  130. package/dist/mcp/builtin/globals/findVersionByIDTool.js.map +1 -0
  131. package/dist/mcp/builtin/globals/findVersionsTool.d.ts +2 -0
  132. package/dist/mcp/builtin/globals/findVersionsTool.d.ts.map +1 -0
  133. package/dist/mcp/builtin/globals/findVersionsTool.js +78 -0
  134. package/dist/mcp/builtin/globals/findVersionsTool.js.map +1 -0
  135. package/dist/mcp/builtin/globals/getGlobalSchemaTool.d.ts +2 -0
  136. package/dist/mcp/builtin/globals/getGlobalSchemaTool.d.ts.map +1 -0
  137. package/dist/mcp/builtin/globals/getGlobalSchemaTool.js +81 -0
  138. package/dist/mcp/builtin/globals/getGlobalSchemaTool.js.map +1 -0
  139. package/dist/mcp/builtin/globals/restoreVersionTool.d.ts +2 -0
  140. package/dist/mcp/builtin/globals/restoreVersionTool.d.ts.map +1 -0
  141. package/dist/mcp/builtin/globals/restoreVersionTool.js +70 -0
  142. package/dist/mcp/builtin/globals/restoreVersionTool.js.map +1 -0
  143. package/dist/mcp/builtin/globals/updateTool.d.ts +2 -0
  144. package/dist/mcp/builtin/globals/updateTool.d.ts.map +1 -0
  145. package/dist/mcp/builtin/globals/updateTool.js +78 -0
  146. package/dist/mcp/builtin/globals/updateTool.js.map +1 -0
  147. package/dist/mcp/builtinTools.d.ts +168 -0
  148. package/dist/mcp/builtinTools.d.ts.map +1 -0
  149. package/dist/mcp/builtinTools.js +169 -0
  150. package/dist/mcp/builtinTools.js.map +1 -0
  151. package/dist/mcp/sanitizeMCPConfig.d.ts +16 -0
  152. package/dist/mcp/sanitizeMCPConfig.d.ts.map +1 -0
  153. package/dist/mcp/sanitizeMCPConfig.js +236 -0
  154. package/dist/mcp/sanitizeMCPConfig.js.map +1 -0
  155. package/dist/stdio.d.ts +8 -0
  156. package/dist/stdio.d.ts.map +1 -0
  157. package/dist/stdio.js +128 -0
  158. package/dist/stdio.js.map +1 -0
  159. package/dist/types.d.ts +352 -441
  160. package/dist/types.d.ts.map +1 -1
  161. package/dist/types.js +4 -1
  162. package/dist/types.js.map +1 -1
  163. package/dist/utils/getLogger.d.ts +10 -0
  164. package/dist/utils/getLogger.d.ts.map +1 -0
  165. package/dist/utils/getLogger.js +22 -0
  166. package/dist/utils/getLogger.js.map +1 -0
  167. package/dist/utils/getPluginConfig.d.ts +12 -0
  168. package/dist/utils/getPluginConfig.d.ts.map +1 -0
  169. package/dist/utils/getPluginConfig.js +15 -0
  170. package/dist/utils/getPluginConfig.js.map +1 -0
  171. package/dist/utils/resolveProjectRoot.d.ts +7 -0
  172. package/dist/utils/resolveProjectRoot.d.ts.map +1 -0
  173. package/dist/utils/resolveProjectRoot.js +15 -0
  174. package/dist/utils/resolveProjectRoot.js.map +1 -0
  175. package/dist/utils/seal.d.ts +17 -0
  176. package/dist/utils/seal.d.ts.map +1 -0
  177. package/dist/utils/seal.js +24 -0
  178. package/dist/utils/seal.js.map +1 -0
  179. package/dist/utils/toStandardSchema.d.ts +5 -0
  180. package/dist/utils/toStandardSchema.d.ts.map +1 -0
  181. package/dist/utils/toStandardSchema.js +4 -0
  182. package/dist/utils/toStandardSchema.js.map +1 -0
  183. package/dist/views/Authorize/AllowButtons/index.d.ts +18 -0
  184. package/dist/views/Authorize/AllowButtons/index.d.ts.map +1 -0
  185. package/dist/views/Authorize/AllowButtons/index.js +88 -0
  186. package/dist/views/Authorize/AllowButtons/index.js.map +1 -0
  187. package/dist/views/Authorize/index.css +19 -0
  188. package/dist/views/Authorize/index.d.ts +9 -0
  189. package/dist/views/Authorize/index.d.ts.map +1 -0
  190. package/dist/views/Authorize/index.js +86 -0
  191. package/dist/views/Authorize/index.js.map +1 -0
  192. package/package.json +48 -26
  193. package/src/defaultAccess.ts +3 -0
  194. package/src/defineTool.ts +44 -0
  195. package/src/endpoint/access.ts +153 -0
  196. package/src/endpoint/index.ts +123 -0
  197. package/src/endpoint/oauth.ts +108 -0
  198. package/src/endpoint/oauthLoginToken.ts +94 -0
  199. package/src/endpoint/oauthServer.ts +452 -0
  200. package/src/exports/client.ts +3 -0
  201. package/src/exports/internal.ts +1 -0
  202. package/src/exports/rsc.ts +1 -0
  203. package/src/index.ts +74 -88
  204. package/src/mcp/buildMcpServer.ts +294 -0
  205. package/src/mcp/builtin/collections/authTools.ts +280 -0
  206. package/src/mcp/builtin/collections/countTool.ts +61 -0
  207. package/src/mcp/builtin/collections/countVersionsTool.ts +60 -0
  208. package/src/mcp/builtin/collections/createTool.ts +143 -0
  209. package/src/mcp/builtin/collections/deleteTool.ts +99 -0
  210. package/src/mcp/builtin/collections/duplicateTool.ts +84 -0
  211. package/src/mcp/builtin/collections/fileInput.spec.ts +93 -0
  212. package/src/mcp/builtin/collections/fileInput.ts +127 -0
  213. package/src/mcp/builtin/collections/findDistinctTool.ts +67 -0
  214. package/src/mcp/builtin/collections/findTool.ts +134 -0
  215. package/src/mcp/builtin/collections/findVersionByIDTool.ts +66 -0
  216. package/src/mcp/builtin/collections/findVersionsTool.ts +83 -0
  217. package/src/mcp/builtin/collections/getCollectionSchemaTool.ts +91 -0
  218. package/src/mcp/builtin/collections/restoreVersionTool.ts +65 -0
  219. package/src/mcp/builtin/collections/updateTool.ts +173 -0
  220. package/src/mcp/builtin/collections/uploadInstructionsTool.ts +64 -0
  221. package/src/mcp/builtin/formatEntityError.ts +77 -0
  222. package/src/mcp/builtin/getConfigInfoTool.ts +68 -0
  223. package/src/mcp/builtin/globals/countVersionsTool.ts +60 -0
  224. package/src/mcp/builtin/globals/findTool.ts +66 -0
  225. package/src/mcp/builtin/globals/findVersionByIDTool.ts +64 -0
  226. package/src/mcp/builtin/globals/findVersionsTool.ts +69 -0
  227. package/src/mcp/builtin/globals/getGlobalSchemaTool.ts +73 -0
  228. package/src/mcp/builtin/globals/restoreVersionTool.ts +68 -0
  229. package/src/mcp/builtin/globals/updateTool.ts +92 -0
  230. package/src/mcp/builtinTools.ts +161 -0
  231. package/src/mcp/sanitizeMCPConfig.ts +282 -0
  232. package/src/stdio.ts +131 -0
  233. package/src/types.ts +401 -481
  234. package/src/utils/getLogger.ts +22 -0
  235. package/src/utils/getPluginConfig.ts +24 -0
  236. package/src/utils/resolveProjectRoot.ts +17 -0
  237. package/src/utils/seal.ts +46 -0
  238. package/src/utils/toStandardSchema.ts +9 -0
  239. package/src/views/Authorize/AllowButtons/index.tsx +97 -0
  240. package/src/views/Authorize/index.css +19 -0
  241. package/src/views/Authorize/index.tsx +93 -0
  242. package/dist/collections/createApiKeysCollection.d.ts +0 -7
  243. package/dist/collections/createApiKeysCollection.d.ts.map +0 -1
  244. package/dist/collections/createApiKeysCollection.js +0 -317
  245. package/dist/collections/createApiKeysCollection.js.map +0 -1
  246. package/dist/defaults.d.ts +0 -4
  247. package/dist/defaults.d.ts.map +0 -1
  248. package/dist/defaults.js +0 -5
  249. package/dist/defaults.js.map +0 -1
  250. package/dist/endpoints/mcp.d.ts +0 -4
  251. package/dist/endpoints/mcp.d.ts.map +0 -1
  252. package/dist/endpoints/mcp.js +0 -71
  253. package/dist/endpoints/mcp.js.map +0 -1
  254. package/dist/mcp/createRequest.d.ts +0 -3
  255. package/dist/mcp/createRequest.d.ts.map +0 -1
  256. package/dist/mcp/createRequest.js +0 -14
  257. package/dist/mcp/createRequest.js.map +0 -1
  258. package/dist/mcp/getMcpHandler.d.ts +0 -4
  259. package/dist/mcp/getMcpHandler.d.ts.map +0 -1
  260. package/dist/mcp/getMcpHandler.js +0 -231
  261. package/dist/mcp/getMcpHandler.js.map +0 -1
  262. package/dist/mcp/helpers/config.d.ts +0 -22
  263. package/dist/mcp/helpers/config.d.ts.map +0 -1
  264. package/dist/mcp/helpers/config.js +0 -153
  265. package/dist/mcp/helpers/config.js.map +0 -1
  266. package/dist/mcp/helpers/fields.d.ts +0 -19
  267. package/dist/mcp/helpers/fields.d.ts.map +0 -1
  268. package/dist/mcp/helpers/fields.js +0 -102
  269. package/dist/mcp/helpers/fields.js.map +0 -1
  270. package/dist/mcp/helpers/fileValidation.d.ts +0 -67
  271. package/dist/mcp/helpers/fileValidation.d.ts.map +0 -1
  272. package/dist/mcp/helpers/fileValidation.js +0 -267
  273. package/dist/mcp/helpers/fileValidation.js.map +0 -1
  274. package/dist/mcp/registerTool.d.ts +0 -6
  275. package/dist/mcp/registerTool.d.ts.map +0 -1
  276. package/dist/mcp/registerTool.js +0 -18
  277. package/dist/mcp/registerTool.js.map +0 -1
  278. package/dist/mcp/tools/auth/auth.d.ts +0 -4
  279. package/dist/mcp/tools/auth/auth.d.ts.map +0 -1
  280. package/dist/mcp/tools/auth/auth.js +0 -57
  281. package/dist/mcp/tools/auth/auth.js.map +0 -1
  282. package/dist/mcp/tools/auth/forgotPassword.d.ts +0 -4
  283. package/dist/mcp/tools/auth/forgotPassword.d.ts.map +0 -1
  284. package/dist/mcp/tools/auth/forgotPassword.js +0 -48
  285. package/dist/mcp/tools/auth/forgotPassword.js.map +0 -1
  286. package/dist/mcp/tools/auth/login.d.ts +0 -4
  287. package/dist/mcp/tools/auth/login.d.ts.map +0 -1
  288. package/dist/mcp/tools/auth/login.js +0 -51
  289. package/dist/mcp/tools/auth/login.js.map +0 -1
  290. package/dist/mcp/tools/auth/resetPassword.d.ts +0 -4
  291. package/dist/mcp/tools/auth/resetPassword.d.ts.map +0 -1
  292. package/dist/mcp/tools/auth/resetPassword.js +0 -49
  293. package/dist/mcp/tools/auth/resetPassword.js.map +0 -1
  294. package/dist/mcp/tools/auth/unlock.d.ts +0 -4
  295. package/dist/mcp/tools/auth/unlock.d.ts.map +0 -1
  296. package/dist/mcp/tools/auth/unlock.js +0 -48
  297. package/dist/mcp/tools/auth/unlock.js.map +0 -1
  298. package/dist/mcp/tools/auth/verify.d.ts +0 -4
  299. package/dist/mcp/tools/auth/verify.d.ts.map +0 -1
  300. package/dist/mcp/tools/auth/verify.js +0 -45
  301. package/dist/mcp/tools/auth/verify.js.map +0 -1
  302. package/dist/mcp/tools/collection/create.d.ts +0 -10
  303. package/dist/mcp/tools/collection/create.d.ts.map +0 -1
  304. package/dist/mcp/tools/collection/create.js +0 -139
  305. package/dist/mcp/tools/collection/create.js.map +0 -1
  306. package/dist/mcp/tools/collection/delete.d.ts +0 -10
  307. package/dist/mcp/tools/collection/delete.d.ts.map +0 -1
  308. package/dist/mcp/tools/collection/delete.js +0 -154
  309. package/dist/mcp/tools/collection/delete.js.map +0 -1
  310. package/dist/mcp/tools/collection/find.d.ts +0 -10
  311. package/dist/mcp/tools/collection/find.d.ts.map +0 -1
  312. package/dist/mcp/tools/collection/find.js +0 -165
  313. package/dist/mcp/tools/collection/find.js.map +0 -1
  314. package/dist/mcp/tools/collection/update.d.ts +0 -10
  315. package/dist/mcp/tools/collection/update.d.ts.map +0 -1
  316. package/dist/mcp/tools/collection/update.js +0 -209
  317. package/dist/mcp/tools/collection/update.js.map +0 -1
  318. package/dist/mcp/tools/config/find.d.ts +0 -10
  319. package/dist/mcp/tools/config/find.d.ts.map +0 -1
  320. package/dist/mcp/tools/config/find.js +0 -97
  321. package/dist/mcp/tools/config/find.js.map +0 -1
  322. package/dist/mcp/tools/config/update.d.ts +0 -10
  323. package/dist/mcp/tools/config/update.d.ts.map +0 -1
  324. package/dist/mcp/tools/config/update.js +0 -215
  325. package/dist/mcp/tools/config/update.js.map +0 -1
  326. package/dist/mcp/tools/global/find.d.ts +0 -5
  327. package/dist/mcp/tools/global/find.d.ts.map +0 -1
  328. package/dist/mcp/tools/global/find.js +0 -82
  329. package/dist/mcp/tools/global/find.js.map +0 -1
  330. package/dist/mcp/tools/global/update.d.ts +0 -6
  331. package/dist/mcp/tools/global/update.d.ts.map +0 -1
  332. package/dist/mcp/tools/global/update.js +0 -124
  333. package/dist/mcp/tools/global/update.js.map +0 -1
  334. package/dist/mcp/tools/job/create.d.ts +0 -10
  335. package/dist/mcp/tools/job/create.d.ts.map +0 -1
  336. package/dist/mcp/tools/job/create.js +0 -293
  337. package/dist/mcp/tools/job/create.js.map +0 -1
  338. package/dist/mcp/tools/job/run.d.ts +0 -10
  339. package/dist/mcp/tools/job/run.d.ts.map +0 -1
  340. package/dist/mcp/tools/job/run.js +0 -129
  341. package/dist/mcp/tools/job/run.js.map +0 -1
  342. package/dist/mcp/tools/job/update.d.ts +0 -11
  343. package/dist/mcp/tools/job/update.d.ts.map +0 -1
  344. package/dist/mcp/tools/job/update.js +0 -186
  345. package/dist/mcp/tools/job/update.js.map +0 -1
  346. package/dist/mcp/tools/resource/create.d.ts +0 -6
  347. package/dist/mcp/tools/resource/create.d.ts.map +0 -1
  348. package/dist/mcp/tools/resource/create.js +0 -124
  349. package/dist/mcp/tools/resource/create.js.map +0 -1
  350. package/dist/mcp/tools/resource/delete.d.ts +0 -5
  351. package/dist/mcp/tools/resource/delete.d.ts.map +0 -1
  352. package/dist/mcp/tools/resource/delete.js +0 -151
  353. package/dist/mcp/tools/resource/delete.js.map +0 -1
  354. package/dist/mcp/tools/resource/find.d.ts +0 -5
  355. package/dist/mcp/tools/resource/find.d.ts.map +0 -1
  356. package/dist/mcp/tools/resource/find.js +0 -170
  357. package/dist/mcp/tools/resource/find.js.map +0 -1
  358. package/dist/mcp/tools/resource/update.d.ts +0 -6
  359. package/dist/mcp/tools/resource/update.d.ts.map +0 -1
  360. package/dist/mcp/tools/resource/update.js +0 -256
  361. package/dist/mcp/tools/resource/update.js.map +0 -1
  362. package/dist/mcp/tools/schemas.d.ts +0 -457
  363. package/dist/mcp/tools/schemas.d.ts.map +0 -1
  364. package/dist/mcp/tools/schemas.js +0 -243
  365. package/dist/mcp/tools/schemas.js.map +0 -1
  366. package/dist/utils/adminEntitySettings.d.ts +0 -17
  367. package/dist/utils/adminEntitySettings.d.ts.map +0 -1
  368. package/dist/utils/adminEntitySettings.js +0 -41
  369. package/dist/utils/adminEntitySettings.js.map +0 -1
  370. package/dist/utils/createApiKeyFields.d.ts +0 -15
  371. package/dist/utils/createApiKeyFields.d.ts.map +0 -1
  372. package/dist/utils/createApiKeyFields.js +0 -57
  373. package/dist/utils/createApiKeyFields.js.map +0 -1
  374. package/dist/utils/getEnabledSlugs.d.ts +0 -13
  375. package/dist/utils/getEnabledSlugs.d.ts.map +0 -1
  376. package/dist/utils/getEnabledSlugs.js +0 -32
  377. package/dist/utils/getEnabledSlugs.js.map +0 -1
  378. package/dist/utils/getVirtualFieldNames.d.ts +0 -14
  379. package/dist/utils/getVirtualFieldNames.d.ts.map +0 -1
  380. package/dist/utils/getVirtualFieldNames.js +0 -35
  381. package/dist/utils/getVirtualFieldNames.js.map +0 -1
  382. package/dist/utils/schemaConversion/convertCollectionSchemaToZod.d.ts +0 -3
  383. package/dist/utils/schemaConversion/convertCollectionSchemaToZod.d.ts.map +0 -1
  384. package/dist/utils/schemaConversion/convertCollectionSchemaToZod.js +0 -43
  385. package/dist/utils/schemaConversion/convertCollectionSchemaToZod.js.map +0 -1
  386. package/dist/utils/schemaConversion/removeVirtualFieldsFromSchema.d.ts +0 -7
  387. package/dist/utils/schemaConversion/removeVirtualFieldsFromSchema.d.ts.map +0 -1
  388. package/dist/utils/schemaConversion/removeVirtualFieldsFromSchema.js +0 -20
  389. package/dist/utils/schemaConversion/removeVirtualFieldsFromSchema.js.map +0 -1
  390. package/dist/utils/schemaConversion/sanitizeJsonSchema.d.ts +0 -13
  391. package/dist/utils/schemaConversion/sanitizeJsonSchema.d.ts.map +0 -1
  392. package/dist/utils/schemaConversion/sanitizeJsonSchema.js +0 -56
  393. package/dist/utils/schemaConversion/sanitizeJsonSchema.js.map +0 -1
  394. package/dist/utils/schemaConversion/simplifyRelationshipFields.d.ts +0 -20
  395. package/dist/utils/schemaConversion/simplifyRelationshipFields.d.ts.map +0 -1
  396. package/dist/utils/schemaConversion/simplifyRelationshipFields.js +0 -53
  397. package/dist/utils/schemaConversion/simplifyRelationshipFields.js.map +0 -1
  398. package/dist/utils/schemaConversion/transformPointFields.d.ts +0 -3
  399. package/dist/utils/schemaConversion/transformPointFields.d.ts.map +0 -1
  400. package/dist/utils/schemaConversion/transformPointFields.js +0 -51
  401. package/dist/utils/schemaConversion/transformPointFields.js.map +0 -1
  402. package/dist/utils/transformPointDataToPayload.d.ts +0 -7
  403. package/dist/utils/transformPointDataToPayload.d.ts.map +0 -1
  404. package/dist/utils/transformPointDataToPayload.js +0 -28
  405. package/dist/utils/transformPointDataToPayload.js.map +0 -1
  406. package/src/collections/createApiKeysCollection.ts +0 -373
  407. package/src/defaults.ts +0 -3
  408. package/src/endpoints/mcp.ts +0 -91
  409. package/src/mcp/createRequest.ts +0 -13
  410. package/src/mcp/getMcpHandler.ts +0 -545
  411. package/src/mcp/helpers/config.ts +0 -213
  412. package/src/mcp/helpers/fields.ts +0 -154
  413. package/src/mcp/helpers/fileValidation.ts +0 -362
  414. package/src/mcp/registerTool.ts +0 -22
  415. package/src/mcp/tools/auth/auth.ts +0 -71
  416. package/src/mcp/tools/auth/forgotPassword.ts +0 -70
  417. package/src/mcp/tools/auth/login.ts +0 -72
  418. package/src/mcp/tools/auth/resetPassword.ts +0 -61
  419. package/src/mcp/tools/auth/unlock.ts +0 -64
  420. package/src/mcp/tools/auth/verify.ts +0 -57
  421. package/src/mcp/tools/collection/create.ts +0 -210
  422. package/src/mcp/tools/collection/delete.ts +0 -211
  423. package/src/mcp/tools/collection/find.ts +0 -224
  424. package/src/mcp/tools/collection/update.ts +0 -290
  425. package/src/mcp/tools/config/find.ts +0 -128
  426. package/src/mcp/tools/config/update.ts +0 -280
  427. package/src/mcp/tools/global/find.ts +0 -128
  428. package/src/mcp/tools/global/update.ts +0 -207
  429. package/src/mcp/tools/job/create.ts +0 -416
  430. package/src/mcp/tools/job/run.ts +0 -167
  431. package/src/mcp/tools/job/update.ts +0 -274
  432. package/src/mcp/tools/resource/create.ts +0 -211
  433. package/src/mcp/tools/resource/delete.ts +0 -218
  434. package/src/mcp/tools/resource/find.ts +0 -246
  435. package/src/mcp/tools/resource/update.ts +0 -383
  436. package/src/mcp/tools/schemas.ts +0 -520
  437. package/src/utils/adminEntitySettings.ts +0 -40
  438. package/src/utils/createApiKeyFields.ts +0 -72
  439. package/src/utils/getEnabledSlugs.ts +0 -42
  440. package/src/utils/getVirtualFieldNames.ts +0 -53
  441. package/src/utils/schemaConversion/convertCollectionSchemaToZod.ts +0 -52
  442. package/src/utils/schemaConversion/removeVirtualFieldsFromSchema.ts +0 -27
  443. package/src/utils/schemaConversion/sanitizeJsonSchema.ts +0 -62
  444. package/src/utils/schemaConversion/simplifyRelationshipFields.ts +0 -65
  445. package/src/utils/schemaConversion/transformPointFields.ts +0 -55
  446. package/src/utils/transformPointDataToPayload.ts +0 -40
@@ -0,0 +1,280 @@
1
+ import { createPayloadRequest, strictObject, z } from 'payload'
2
+
3
+ import type { MCPToolResponse } from '../../../types.js'
4
+
5
+ import { defaultAccess } from '../../../defaultAccess.js'
6
+ import { defineCollectionTool } from '../../../defineTool.js'
7
+ import { getLogger } from '../../../utils/getLogger.js'
8
+
9
+ /**
10
+ * Auth tools surfaced under `collections.<auth-collection>.tools`. Opt-in: they
11
+ * default off (an LLM with `login` access can probe passwords; not something
12
+ * to expose by default). Enable in plugin config via `tools: { login: true }`
13
+ * (or `{ description: '...' }`).
14
+ *
15
+ * `auth` (check current token) doesn't actually depend on the collection at
16
+ * runtime — `payload.auth({ headers })` is global — but it's grouped under the
17
+ * users collection so all auth-shaped tools live in one place.
18
+ */
19
+
20
+ const emailSchema = z.email().check(z.describe('The user email address.'))
21
+
22
+ const wrapError =
23
+ (name: string) =>
24
+ ({ slug, message }: { message: string; slug: string }): MCPToolResponse => {
25
+ return {
26
+ content: [
27
+ {
28
+ type: 'text',
29
+ text: `❌ **Error in ${name}** on ${slug}: ${message}`,
30
+ },
31
+ ],
32
+ }
33
+ }
34
+
35
+ export const authCollectionTool = defineCollectionTool({
36
+ annotations: {
37
+ destructiveHint: false,
38
+ idempotentHint: true,
39
+ openWorldHint: false,
40
+ readOnlyHint: true,
41
+ title: 'Check Auth Status',
42
+ },
43
+ description: 'Checks authentication status for the current user.',
44
+ input: strictObject({
45
+ headers: z
46
+ .optional(z.record(z.string(), z.string()))
47
+ .check(z.describe('Custom headers to send with the authentication request.')),
48
+ }),
49
+ }).handler(async ({ slug, authorizedMCP, input, req }) => {
50
+ const logger = getLogger({ payload: req.payload })
51
+ try {
52
+ let authHeaders = new Headers()
53
+ if (input.headers) {
54
+ authHeaders = new Headers(input.headers)
55
+ }
56
+ const authReq = await createPayloadRequest({
57
+ payload: req.payload,
58
+ req: { headers: authHeaders },
59
+ })
60
+ const result = await req.payload.auth({ headers: authHeaders, req: authReq })
61
+
62
+ if (result.user) {
63
+ const authenticatedUser = result.user
64
+ // Auth strategies read users with trusted Local API access. Re-read the user with the MCP
65
+ // caller's access level before returning it to the client.
66
+ const user = await req.payload.findByID({
67
+ id: authenticatedUser.id,
68
+ collection: authenticatedUser.collection,
69
+ overrideAccess: authorizedMCP.overrideAccess,
70
+ req: authReq,
71
+ })
72
+ result.user = {
73
+ ...user,
74
+ _sid: authenticatedUser._sid,
75
+ _strategy: authenticatedUser._strategy,
76
+ collection: authenticatedUser.collection,
77
+ }
78
+ }
79
+ return {
80
+ content: [
81
+ {
82
+ type: 'text',
83
+ text: `# Authentication Status\n\n\`\`\`json\n${JSON.stringify(result)}\n\`\`\``,
84
+ },
85
+ ],
86
+ doc: result as unknown as Record<string, unknown>,
87
+ }
88
+ } catch (error) {
89
+ const errorMessage = error instanceof Error ? error.message : 'Unknown error'
90
+ logger.error(`Error in auth tool on ${slug}: ${errorMessage}`)
91
+ return wrapError('auth')({ slug, message: errorMessage })
92
+ }
93
+ })
94
+
95
+ export const forgotPasswordCollectionTool = defineCollectionTool({
96
+ annotations: {
97
+ destructiveHint: false,
98
+ idempotentHint: false,
99
+ openWorldHint: true,
100
+ readOnlyHint: false,
101
+ title: 'Forgot Password',
102
+ },
103
+ description: 'Sends a password reset email to a user.',
104
+ input: strictObject({
105
+ email: emailSchema,
106
+ }),
107
+ }).handler(async ({ slug, input, req }) => {
108
+ const logger = getLogger({ payload: req.payload })
109
+ try {
110
+ await req.payload.forgotPassword({
111
+ collection: slug,
112
+ data: { email: input.email },
113
+ disableEmail: false,
114
+ overrideAccess: false,
115
+ req,
116
+ })
117
+ return {
118
+ content: [
119
+ {
120
+ type: 'text',
121
+ text: 'If an account matches that email, password reset instructions have been sent.',
122
+ },
123
+ ],
124
+ }
125
+ } catch (error) {
126
+ const errorMessage = error instanceof Error ? error.message : 'Unknown error'
127
+ logger.error(`Error in forgotPassword tool on ${slug}: ${errorMessage}`)
128
+ return wrapError('forgotPassword')({ slug, message: errorMessage })
129
+ }
130
+ })
131
+
132
+ export const loginCollectionTool = defineCollectionTool({
133
+ annotations: {
134
+ destructiveHint: false,
135
+ idempotentHint: false,
136
+ openWorldHint: false,
137
+ readOnlyHint: false,
138
+ title: 'User Login',
139
+ },
140
+ description: 'Authenticates a user with email and password.',
141
+ input: strictObject({
142
+ depth: z
143
+ ._default(z.int().check(z.minimum(0), z.maximum(10)), 0)
144
+ .check(z.describe('Depth of population for relationships.')),
145
+ email: emailSchema,
146
+ password: z.string().check(z.describe('The user password.')),
147
+ }),
148
+ }).handler(async ({ slug, authorizedMCP, input, req }) => {
149
+ const logger = getLogger({ payload: req.payload })
150
+ try {
151
+ const result = await req.payload.login({
152
+ collection: slug,
153
+ data: { email: input.email, password: input.password },
154
+ depth: input.depth,
155
+ overrideAccess: authorizedMCP.overrideAccess,
156
+ })
157
+ return {
158
+ content: [
159
+ {
160
+ type: 'text',
161
+ text: `# Login Successful\n\n**User:** ${input.email}\n**Collection:** ${slug}\n\n\`\`\`json\n${JSON.stringify(result)}\n\`\`\``,
162
+ },
163
+ ],
164
+ doc: result as unknown as Record<string, unknown>,
165
+ }
166
+ } catch (error) {
167
+ const errorMessage = error instanceof Error ? error.message : 'Unknown error'
168
+ logger.error(`Error in login tool on ${slug}: ${errorMessage}`)
169
+ return wrapError('login')({ slug, message: errorMessage })
170
+ }
171
+ })
172
+
173
+ export const resetPasswordCollectionTool = defineCollectionTool({
174
+ annotations: {
175
+ destructiveHint: false,
176
+ idempotentHint: false,
177
+ openWorldHint: false,
178
+ readOnlyHint: false,
179
+ title: 'Reset Password',
180
+ },
181
+ description: 'Resets a user password with a reset token.',
182
+ input: strictObject({
183
+ password: z.string().check(z.describe('The new password for the user.')),
184
+ token: z.string().check(z.describe('The password reset token sent to the user email.')),
185
+ }),
186
+ }).handler(async ({ slug, authorizedMCP, input, req }) => {
187
+ const logger = getLogger({ payload: req.payload })
188
+ try {
189
+ const result = await req.payload.resetPassword({
190
+ collection: slug,
191
+ data: { password: input.password, token: input.token },
192
+ overrideAccess: authorizedMCP.overrideAccess,
193
+ })
194
+ return {
195
+ content: [
196
+ {
197
+ type: 'text',
198
+ text: `# Password Reset Successful\n\n**Collection:** ${slug}\n\n\`\`\`json\n${JSON.stringify(result)}\n\`\`\``,
199
+ },
200
+ ],
201
+ doc: result as unknown as Record<string, unknown>,
202
+ }
203
+ } catch (error) {
204
+ const errorMessage = error instanceof Error ? error.message : 'Unknown error'
205
+ logger.error(`Error in resetPassword tool on ${slug}: ${errorMessage}`)
206
+ return wrapError('resetPassword')({ slug, message: errorMessage })
207
+ }
208
+ })
209
+
210
+ export const unlockCollectionTool = defineCollectionTool({
211
+ access: (args) =>
212
+ defaultAccess(args) && Boolean(args.permissions?.collections?.[args.slug]?.unlock),
213
+ annotations: {
214
+ destructiveHint: false,
215
+ idempotentHint: true,
216
+ openWorldHint: false,
217
+ readOnlyHint: false,
218
+ title: 'Unlock Account',
219
+ },
220
+ description: 'Unlocks a user account that has been locked due to failed login attempts.',
221
+ input: strictObject({ email: emailSchema }),
222
+ }).handler(async ({ slug, authorizedMCP, input, req }) => {
223
+ const logger = getLogger({ payload: req.payload })
224
+ try {
225
+ const result = await req.payload.unlock({
226
+ collection: slug,
227
+ data: { email: input.email },
228
+ overrideAccess: authorizedMCP.overrideAccess,
229
+ req,
230
+ })
231
+ return {
232
+ content: [
233
+ {
234
+ type: 'text',
235
+ text: `# Account Unlocked\n\n**Collection:** ${slug}\n**Email:** ${input.email}\n**Result:** ${result ? 'Success' : 'Failed'}`,
236
+ },
237
+ ],
238
+ doc: { result },
239
+ }
240
+ } catch (error) {
241
+ const errorMessage = error instanceof Error ? error.message : 'Unknown error'
242
+ logger.error(`Error in unlock tool on ${slug}: ${errorMessage}`)
243
+ return wrapError('unlock')({ slug, message: errorMessage })
244
+ }
245
+ })
246
+
247
+ export const verifyCollectionTool = defineCollectionTool({
248
+ annotations: {
249
+ destructiveHint: false,
250
+ idempotentHint: false,
251
+ openWorldHint: false,
252
+ readOnlyHint: false,
253
+ title: 'Email Verification',
254
+ },
255
+ description: 'Verifies a user email with a verification token.',
256
+ input: strictObject({
257
+ token: z.string().check(z.describe('The verification token sent to the user email.')),
258
+ }),
259
+ }).handler(async ({ slug, input, req }) => {
260
+ const logger = getLogger({ payload: req.payload })
261
+ try {
262
+ const result = await req.payload.verifyEmail({
263
+ collection: slug,
264
+ token: input.token,
265
+ })
266
+ return {
267
+ content: [
268
+ {
269
+ type: 'text',
270
+ text: `# Email Verification Successful\n\n**Collection:** ${slug}\n**Result:** ${result ? 'Success' : 'Failed'}`,
271
+ },
272
+ ],
273
+ doc: { result },
274
+ }
275
+ } catch (error) {
276
+ const errorMessage = error instanceof Error ? error.message : 'Unknown error'
277
+ logger.error(`Error in verify tool on ${slug}: ${errorMessage}`)
278
+ return wrapError('verify')({ slug, message: errorMessage })
279
+ }
280
+ })
@@ -0,0 +1,61 @@
1
+ import { countDocumentsInputSchema } from 'payload'
2
+
3
+ import { defaultAccess } from '../../../defaultAccess.js'
4
+ import { defineCollectionTool } from '../../../defineTool.js'
5
+ import { getLogger } from '../../../utils/getLogger.js'
6
+
7
+ const DEFAULT_DESCRIPTION =
8
+ 'Count documents in any collection by passing the collection slug and optional where clause.'
9
+
10
+ export const countDocumentsTool = defineCollectionTool({
11
+ access: (args) =>
12
+ defaultAccess(args) && Boolean(args.permissions?.collections?.[args.slug]?.read),
13
+ annotations: {
14
+ destructiveHint: false,
15
+ idempotentHint: true,
16
+ openWorldHint: false,
17
+ readOnlyHint: true,
18
+ title: 'Count Documents',
19
+ },
20
+ description: DEFAULT_DESCRIPTION,
21
+ input: countDocumentsInputSchema,
22
+ }).handler(async ({ slug, authorizedMCP, input, req }) => {
23
+ const payload = req.payload
24
+ const logger = getLogger({ payload })
25
+ const { locale, trash, where } = input
26
+
27
+ logger.info(`Counting documents in collection: ${slug}`)
28
+
29
+ try {
30
+ const result = await payload.count({
31
+ collection: slug,
32
+ overrideAccess: authorizedMCP.overrideAccess,
33
+ req,
34
+ ...(locale ? { locale } : {}),
35
+ ...(trash !== undefined ? { trash } : {}),
36
+ ...(where ? { where } : {}),
37
+ })
38
+
39
+ return {
40
+ content: [
41
+ {
42
+ type: 'text',
43
+ text: `Collection "${slug}" contains ${result.totalDocs} matching documents.\n\`\`\`json\n${JSON.stringify(result)}\n\`\`\``,
44
+ },
45
+ ],
46
+ doc: result,
47
+ }
48
+ } catch (error) {
49
+ const errorMessage = error instanceof Error ? error.message : 'Unknown error'
50
+ logger.error(`Error counting documents in ${slug}: ${errorMessage}`)
51
+ return {
52
+ content: [
53
+ {
54
+ type: 'text',
55
+ text: `❌ **Error counting documents in collection "${slug}":** ${errorMessage}`,
56
+ },
57
+ ],
58
+ isError: true,
59
+ }
60
+ }
61
+ })
@@ -0,0 +1,60 @@
1
+ import { countVersionsInputSchema } from 'payload'
2
+
3
+ import { defaultAccess } from '../../../defaultAccess.js'
4
+ import { defineCollectionTool } from '../../../defineTool.js'
5
+ import { getLogger } from '../../../utils/getLogger.js'
6
+
7
+ const DEFAULT_DESCRIPTION =
8
+ 'Count document versions in any version-enabled collection by passing the collection slug and optional where clause.'
9
+
10
+ export const countVersionsTool = defineCollectionTool({
11
+ access: (args) =>
12
+ defaultAccess(args) && Boolean(args.permissions?.collections?.[args.slug]?.readVersions),
13
+ annotations: {
14
+ destructiveHint: false,
15
+ idempotentHint: true,
16
+ openWorldHint: false,
17
+ readOnlyHint: true,
18
+ title: 'Count Versions',
19
+ },
20
+ description: DEFAULT_DESCRIPTION,
21
+ input: countVersionsInputSchema,
22
+ }).handler(async ({ slug, authorizedMCP, input, req }) => {
23
+ const payload = req.payload
24
+ const logger = getLogger({ payload })
25
+ const { locale, where } = input
26
+
27
+ logger.info(`Counting versions in collection: ${slug}`)
28
+
29
+ try {
30
+ const result = await payload.countVersions({
31
+ collection: slug,
32
+ overrideAccess: authorizedMCP.overrideAccess,
33
+ req,
34
+ ...(locale ? { locale } : {}),
35
+ ...(where ? { where } : {}),
36
+ })
37
+
38
+ return {
39
+ content: [
40
+ {
41
+ type: 'text',
42
+ text: `Collection "${slug}" contains ${result.totalDocs} matching versions.\n\`\`\`json\n${JSON.stringify(result)}\n\`\`\``,
43
+ },
44
+ ],
45
+ doc: result,
46
+ }
47
+ } catch (error) {
48
+ const errorMessage = error instanceof Error ? error.message : 'Unknown error'
49
+ logger.error(`Error counting versions in ${slug}: ${errorMessage}`)
50
+ return {
51
+ content: [
52
+ {
53
+ type: 'text',
54
+ text: `❌ **Error counting versions in collection "${slug}":** ${errorMessage}`,
55
+ },
56
+ ],
57
+ isError: true,
58
+ }
59
+ }
60
+ })
@@ -0,0 +1,143 @@
1
+ import {
2
+ createDocumentsInputSchema,
3
+ getCollectionVirtualFieldNames,
4
+ hasDraftValidationEnabled,
5
+ stripVirtualFields,
6
+ transformPointDataToPayload,
7
+ validateCollectionData,
8
+ } from 'payload'
9
+
10
+ import { defaultAccess } from '../../../defaultAccess.js'
11
+ import { defineCollectionTool } from '../../../defineTool.js'
12
+ import { getLogger } from '../../../utils/getLogger.js'
13
+ import { formatEntityError } from '../formatEntityError.js'
14
+ import { fileInputSchema, resolveFile } from './fileInput.js'
15
+
16
+ const DEFAULT_DESCRIPTION =
17
+ 'Create one or more documents. Each can have different data or a file. Prefer uploadReference after upload, externalURL for URLs, or base64 for small local files.'
18
+
19
+ export const createDocumentsTool = defineCollectionTool({
20
+ access: (args) =>
21
+ defaultAccess(args) && Boolean(args.permissions?.collections?.[args.slug]?.create),
22
+ annotations: {
23
+ destructiveHint: false,
24
+ idempotentHint: false,
25
+ openWorldHint: false,
26
+ readOnlyHint: false,
27
+ title: 'Create Documents',
28
+ },
29
+ description: DEFAULT_DESCRIPTION,
30
+ input: createDocumentsInputSchema({ file: fileInputSchema }),
31
+ }).handler(async ({ slug, authorizedMCP, input, req }) => {
32
+ const payload = req.payload
33
+ const collectionConfig = payload.collections[slug]?.config
34
+ const logger = getLogger({ payload })
35
+ const {
36
+ depth,
37
+ documents,
38
+ draft,
39
+ fallbackLocale,
40
+ locale,
41
+ populate,
42
+ publishAllLocales,
43
+ returning,
44
+ select,
45
+ } = input
46
+ const shouldUsePartialSchema =
47
+ draft === true && collectionConfig !== undefined && !hasDraftValidationEnabled(collectionConfig)
48
+
49
+ logger.info(`Creating ${documents.length} documents in collection: ${slug}`)
50
+
51
+ try {
52
+ const virtualFieldNames = getCollectionVirtualFieldNames(payload.config, slug)
53
+ const docs: Array<
54
+ { doc: Record<string, unknown>; index: number } | { id: number | string; index: number }
55
+ > = []
56
+ const errors: Array<{ index: number; message: string }> = []
57
+ let validationSchema: Record<string, unknown> | undefined
58
+
59
+ for (const [index, document] of documents.entries()) {
60
+ try {
61
+ const inputData = stripVirtualFields(document.data, virtualFieldNames)
62
+ validateCollectionData({
63
+ slug,
64
+ data: inputData,
65
+ partial: shouldUsePartialSchema,
66
+ req,
67
+ })
68
+
69
+ const parsedData = transformPointDataToPayload(inputData)
70
+ const file = await resolveFile({ slug, input: document.file, req })
71
+ const result = await payload.create({
72
+ collection: slug,
73
+ data: parsedData,
74
+ depth,
75
+ draft,
76
+ overrideAccess: authorizedMCP.overrideAccess,
77
+ populate,
78
+ publishAllLocales,
79
+ req,
80
+ ...(file ? { file } : {}),
81
+ ...(locale ? { locale } : {}),
82
+ ...(fallbackLocale !== undefined ? { fallbackLocale } : {}),
83
+ select: returning ? select : { id: true },
84
+ })
85
+
86
+ docs.push(returning ? { doc: result, index } : { id: result.id, index })
87
+ } catch (error) {
88
+ const message = error instanceof Error ? error.message : 'Unknown error'
89
+ const formattedError = formatEntityError({
90
+ slug,
91
+ action: 'creating',
92
+ entity: 'collection',
93
+ error,
94
+ req,
95
+ })
96
+ const structuredContent = formattedError.structuredContent as
97
+ | { schema?: unknown }
98
+ | undefined
99
+ const schema = structuredContent?.schema
100
+ const errorContent = formattedError.content[0]
101
+ const formattedMessage =
102
+ errorContent?.type === 'text'
103
+ ? (errorContent.text.split('\n\nUse this schema')[0] ?? message)
104
+ : message
105
+
106
+ if (!validationSchema && schema && typeof schema === 'object') {
107
+ validationSchema = schema as Record<string, unknown>
108
+ }
109
+
110
+ logger.error(`Error creating document at index ${index} in ${slug}: ${message}`)
111
+ errors.push({ index, message: formattedMessage })
112
+ }
113
+ }
114
+
115
+ const batchResult = { docs, errors }
116
+ const retryMessage = errors.length > 0 ? '\nRetry failed indexes only.' : ''
117
+ const schemaMessage = validationSchema
118
+ ? `\n\nUse this schema for data:\n\`\`\`json\n${JSON.stringify(validationSchema)}\n\`\`\``
119
+ : ''
120
+ const structuredContent = validationSchema
121
+ ? { ...batchResult, schema: validationSchema }
122
+ : batchResult
123
+
124
+ logger.info(`Created ${docs.length} of ${documents.length} documents in ${slug}`)
125
+
126
+ return {
127
+ content: [
128
+ {
129
+ type: 'text',
130
+ text: `Created ${docs.length} of ${documents.length} documents in collection "${slug}".${retryMessage}\nResults:\n\`\`\`json\n${JSON.stringify(batchResult)}\n\`\`\`${schemaMessage}`,
131
+ },
132
+ ],
133
+ doc: structuredContent as unknown as Record<string, unknown>,
134
+ isError: docs.length === 0 && errors.length > 0,
135
+ structuredContent,
136
+ }
137
+ } catch (error) {
138
+ const message = error instanceof Error ? error.message : 'Unknown error'
139
+
140
+ logger.error(`Error creating documents in ${slug}: ${message}`)
141
+ return formatEntityError({ slug, action: 'creating', entity: 'collection', error, req })
142
+ }
143
+ })
@@ -0,0 +1,99 @@
1
+ import { deleteDocumentsInputSchema, parseDocumentID } from 'payload'
2
+
3
+ import { defaultAccess } from '../../../defaultAccess.js'
4
+ import { defineCollectionTool } from '../../../defineTool.js'
5
+ import { getLogger } from '../../../utils/getLogger.js'
6
+
7
+ const DEFAULT_DESCRIPTION =
8
+ 'Delete documents in any collection by passing the collection slug and ID or where clause.'
9
+
10
+ export const deleteDocumentsTool = defineCollectionTool({
11
+ access: (args) =>
12
+ defaultAccess(args) && Boolean(args.permissions?.collections?.[args.slug]?.delete),
13
+ annotations: {
14
+ destructiveHint: true,
15
+ idempotentHint: false,
16
+ openWorldHint: false,
17
+ readOnlyHint: false,
18
+ title: 'Delete Documents',
19
+ },
20
+ description: DEFAULT_DESCRIPTION,
21
+ input: deleteDocumentsInputSchema,
22
+ }).handler(async ({ slug, authorizedMCP, input, req }) => {
23
+ const payload = req.payload
24
+ const logger = getLogger({ payload })
25
+
26
+ const { id, depth, fallbackLocale, locale, trash, where } = input
27
+
28
+ logger.info(
29
+ `Deleting document from collection: ${slug}${id ? ` with ID: ${id}` : ' with where clause'}${locale ? `, locale: ${locale}` : ''}`,
30
+ )
31
+
32
+ try {
33
+ if (id !== undefined) {
34
+ const result = await payload.delete({
35
+ id: parseDocumentID({ id, collectionSlug: slug, payload }),
36
+ collection: slug,
37
+ depth,
38
+ overrideAccess: authorizedMCP.overrideAccess,
39
+ req,
40
+ trash,
41
+ ...(locale && { locale }),
42
+ ...(fallbackLocale !== undefined && { fallbackLocale }),
43
+ })
44
+
45
+ return {
46
+ content: [
47
+ {
48
+ type: 'text',
49
+ text: `Document deleted successfully from collection "${slug}"!\nDeleted document:\n\`\`\`json\n${JSON.stringify(result)}\n\`\`\``,
50
+ },
51
+ ],
52
+ doc: result,
53
+ }
54
+ }
55
+
56
+ if (where === undefined) {
57
+ return {
58
+ content: [{ type: 'text', text: 'Error: Either id or where clause must be provided' }],
59
+ }
60
+ }
61
+
62
+ const result = await payload.delete({
63
+ collection: slug,
64
+ depth,
65
+ overrideAccess: authorizedMCP.overrideAccess,
66
+ req,
67
+ trash,
68
+ where,
69
+ ...(locale && { locale }),
70
+ ...(fallbackLocale !== undefined && { fallbackLocale }),
71
+ })
72
+ const docs = result.docs || []
73
+ const errors = result.errors || []
74
+
75
+ let responseText = `Document deleted successfully from collection "${slug}"!\nDeleted: ${docs.length} documents\nErrors: ${errors.length}\n---`
76
+ if (docs.length > 0) {
77
+ responseText += `\n\nDeleted documents:\n\`\`\`json\n${JSON.stringify(docs)}\n\`\`\``
78
+ }
79
+ if (errors.length > 0) {
80
+ responseText += `\n\nErrors:\n\`\`\`json\n${JSON.stringify(errors)}\n\`\`\``
81
+ }
82
+
83
+ return {
84
+ content: [{ type: 'text', text: responseText }],
85
+ doc: { docs, errors } as unknown as Record<string, unknown>,
86
+ }
87
+ } catch (error) {
88
+ const errorMessage = error instanceof Error ? error.message : 'Unknown error'
89
+ logger.error(`Error deleting document from ${slug}: ${errorMessage}`)
90
+ return {
91
+ content: [
92
+ {
93
+ type: 'text',
94
+ text: `Error deleting document from collection "${slug}": ${errorMessage}`,
95
+ },
96
+ ],
97
+ }
98
+ }
99
+ })