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

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 (417) hide show
  1. package/LICENSE.md +1 -1
  2. package/bin.js +46 -0
  3. package/dist/defaultAccess.d.ts +3 -0
  4. package/dist/defaultAccess.d.ts.map +1 -0
  5. package/dist/defaultAccess.js +3 -0
  6. package/dist/defaultAccess.js.map +1 -0
  7. package/dist/defineTool.d.ts +26 -0
  8. package/dist/defineTool.d.ts.map +1 -0
  9. package/dist/defineTool.js +37 -0
  10. package/dist/defineTool.js.map +1 -0
  11. package/dist/endpoint/access.d.ts +17 -0
  12. package/dist/endpoint/access.d.ts.map +1 -0
  13. package/dist/endpoint/access.js +93 -0
  14. package/dist/endpoint/access.js.map +1 -0
  15. package/dist/endpoint/index.d.ts +3 -0
  16. package/dist/endpoint/index.d.ts.map +1 -0
  17. package/dist/endpoint/index.js +87 -0
  18. package/dist/endpoint/index.js.map +1 -0
  19. package/dist/exports/client.d.ts +2 -0
  20. package/dist/exports/client.d.ts.map +1 -0
  21. package/dist/exports/client.js +4 -0
  22. package/dist/exports/client.js.map +1 -0
  23. package/dist/exports/internal.d.ts +2 -0
  24. package/dist/exports/internal.d.ts.map +1 -0
  25. package/dist/exports/internal.js +3 -0
  26. package/dist/exports/internal.js.map +1 -0
  27. package/dist/index.d.ts +6 -9
  28. package/dist/index.d.ts.map +1 -1
  29. package/dist/index.js +39 -67
  30. package/dist/index.js.map +1 -1
  31. package/dist/mcp/buildMcpServer.d.ts +19 -0
  32. package/dist/mcp/buildMcpServer.d.ts.map +1 -0
  33. package/dist/mcp/buildMcpServer.js +223 -0
  34. package/dist/mcp/buildMcpServer.js.map +1 -0
  35. package/dist/mcp/builtin/collections/authTools.d.ts +7 -0
  36. package/dist/mcp/builtin/collections/authTools.d.ts.map +1 -0
  37. package/dist/mcp/builtin/collections/authTools.js +288 -0
  38. package/dist/mcp/builtin/collections/authTools.js.map +1 -0
  39. package/dist/mcp/builtin/collections/countTool.d.ts +2 -0
  40. package/dist/mcp/builtin/collections/countTool.d.ts.map +1 -0
  41. package/dist/mcp/builtin/collections/countTool.js +68 -0
  42. package/dist/mcp/builtin/collections/countTool.js.map +1 -0
  43. package/dist/mcp/builtin/collections/countVersionsTool.d.ts +2 -0
  44. package/dist/mcp/builtin/collections/countVersionsTool.d.ts.map +1 -0
  45. package/dist/mcp/builtin/collections/countVersionsTool.js +64 -0
  46. package/dist/mcp/builtin/collections/countVersionsTool.js.map +1 -0
  47. package/dist/mcp/builtin/collections/createTool.d.ts +2 -0
  48. package/dist/mcp/builtin/collections/createTool.d.ts.map +1 -0
  49. package/dist/mcp/builtin/collections/createTool.js +86 -0
  50. package/dist/mcp/builtin/collections/createTool.js.map +1 -0
  51. package/dist/mcp/builtin/collections/deleteTool.d.ts +2 -0
  52. package/dist/mcp/builtin/collections/deleteTool.d.ts.map +1 -0
  53. package/dist/mcp/builtin/collections/deleteTool.js +110 -0
  54. package/dist/mcp/builtin/collections/deleteTool.js.map +1 -0
  55. package/dist/mcp/builtin/collections/duplicateTool.d.ts +2 -0
  56. package/dist/mcp/builtin/collections/duplicateTool.d.ts.map +1 -0
  57. package/dist/mcp/builtin/collections/duplicateTool.js +96 -0
  58. package/dist/mcp/builtin/collections/duplicateTool.js.map +1 -0
  59. package/dist/mcp/builtin/collections/findDistinctTool.d.ts +2 -0
  60. package/dist/mcp/builtin/collections/findDistinctTool.d.ts.map +1 -0
  61. package/dist/mcp/builtin/collections/findDistinctTool.js +92 -0
  62. package/dist/mcp/builtin/collections/findDistinctTool.js.map +1 -0
  63. package/dist/mcp/builtin/collections/findTool.d.ts +2 -0
  64. package/dist/mcp/builtin/collections/findTool.d.ts.map +1 -0
  65. package/dist/mcp/builtin/collections/findTool.js +164 -0
  66. package/dist/mcp/builtin/collections/findTool.js.map +1 -0
  67. package/dist/mcp/builtin/collections/findVersionByIDTool.d.ts +2 -0
  68. package/dist/mcp/builtin/collections/findVersionByIDTool.d.ts.map +1 -0
  69. package/dist/mcp/builtin/collections/findVersionByIDTool.js +83 -0
  70. package/dist/mcp/builtin/collections/findVersionByIDTool.js.map +1 -0
  71. package/dist/mcp/builtin/collections/findVersionsTool.d.ts +2 -0
  72. package/dist/mcp/builtin/collections/findVersionsTool.d.ts.map +1 -0
  73. package/dist/mcp/builtin/collections/findVersionsTool.js +98 -0
  74. package/dist/mcp/builtin/collections/findVersionsTool.js.map +1 -0
  75. package/dist/mcp/builtin/collections/formatCollectionError.d.ts +9 -0
  76. package/dist/mcp/builtin/collections/formatCollectionError.d.ts.map +1 -0
  77. package/dist/mcp/builtin/collections/formatCollectionError.js +60 -0
  78. package/dist/mcp/builtin/collections/formatCollectionError.js.map +1 -0
  79. package/dist/mcp/builtin/collections/getCollectionSchemaTool.d.ts +2 -0
  80. package/dist/mcp/builtin/collections/getCollectionSchemaTool.d.ts.map +1 -0
  81. package/dist/mcp/builtin/collections/getCollectionSchemaTool.js +65 -0
  82. package/dist/mcp/builtin/collections/getCollectionSchemaTool.js.map +1 -0
  83. package/dist/mcp/builtin/collections/restoreVersionTool.d.ts +2 -0
  84. package/dist/mcp/builtin/collections/restoreVersionTool.d.ts.map +1 -0
  85. package/dist/mcp/builtin/collections/restoreVersionTool.js +81 -0
  86. package/dist/mcp/builtin/collections/restoreVersionTool.js.map +1 -0
  87. package/dist/mcp/builtin/collections/updateTool.d.ts +2 -0
  88. package/dist/mcp/builtin/collections/updateTool.d.ts.map +1 -0
  89. package/dist/mcp/builtin/collections/updateTool.js +198 -0
  90. package/dist/mcp/builtin/collections/updateTool.js.map +1 -0
  91. package/dist/mcp/builtin/getConfigInfoTool.d.ts +2 -0
  92. package/dist/mcp/builtin/getConfigInfoTool.d.ts.map +1 -0
  93. package/dist/mcp/builtin/getConfigInfoTool.js +68 -0
  94. package/dist/mcp/builtin/getConfigInfoTool.js.map +1 -0
  95. package/dist/mcp/builtin/globals/countVersionsTool.d.ts +2 -0
  96. package/dist/mcp/builtin/globals/countVersionsTool.d.ts.map +1 -0
  97. package/dist/mcp/builtin/globals/countVersionsTool.js +64 -0
  98. package/dist/mcp/builtin/globals/countVersionsTool.js.map +1 -0
  99. package/dist/mcp/builtin/globals/findTool.d.ts +2 -0
  100. package/dist/mcp/builtin/globals/findTool.d.ts.map +1 -0
  101. package/dist/mcp/builtin/globals/findTool.js +73 -0
  102. package/dist/mcp/builtin/globals/findTool.js.map +1 -0
  103. package/dist/mcp/builtin/globals/findVersionByIDTool.d.ts +2 -0
  104. package/dist/mcp/builtin/globals/findVersionByIDTool.d.ts.map +1 -0
  105. package/dist/mcp/builtin/globals/findVersionByIDTool.js +79 -0
  106. package/dist/mcp/builtin/globals/findVersionByIDTool.js.map +1 -0
  107. package/dist/mcp/builtin/globals/findVersionsTool.d.ts +2 -0
  108. package/dist/mcp/builtin/globals/findVersionsTool.d.ts.map +1 -0
  109. package/dist/mcp/builtin/globals/findVersionsTool.js +94 -0
  110. package/dist/mcp/builtin/globals/findVersionsTool.js.map +1 -0
  111. package/dist/mcp/builtin/globals/getGlobalSchemaTool.d.ts +2 -0
  112. package/dist/mcp/builtin/globals/getGlobalSchemaTool.d.ts.map +1 -0
  113. package/dist/mcp/builtin/globals/getGlobalSchemaTool.js +65 -0
  114. package/dist/mcp/builtin/globals/getGlobalSchemaTool.js.map +1 -0
  115. package/dist/mcp/builtin/globals/restoreVersionTool.d.ts +2 -0
  116. package/dist/mcp/builtin/globals/restoreVersionTool.d.ts.map +1 -0
  117. package/dist/mcp/builtin/globals/restoreVersionTool.js +77 -0
  118. package/dist/mcp/builtin/globals/restoreVersionTool.js.map +1 -0
  119. package/dist/mcp/builtin/globals/updateTool.d.ts +2 -0
  120. package/dist/mcp/builtin/globals/updateTool.d.ts.map +1 -0
  121. package/dist/mcp/builtin/globals/updateTool.js +87 -0
  122. package/dist/mcp/builtin/globals/updateTool.js.map +1 -0
  123. package/dist/mcp/builtin/validateEntityData.d.ts +14 -0
  124. package/dist/mcp/builtin/validateEntityData.d.ts.map +1 -0
  125. package/dist/mcp/builtin/validateEntityData.js +82 -0
  126. package/dist/mcp/builtin/validateEntityData.js.map +1 -0
  127. package/dist/mcp/builtinTools.d.ts +162 -0
  128. package/dist/mcp/builtinTools.d.ts.map +1 -0
  129. package/dist/mcp/builtinTools.js +163 -0
  130. package/dist/mcp/builtinTools.js.map +1 -0
  131. package/dist/mcp/sanitizeMCPConfig.d.ts +16 -0
  132. package/dist/mcp/sanitizeMCPConfig.d.ts.map +1 -0
  133. package/dist/mcp/sanitizeMCPConfig.js +230 -0
  134. package/dist/mcp/sanitizeMCPConfig.js.map +1 -0
  135. package/dist/stdio.d.ts +8 -0
  136. package/dist/stdio.d.ts.map +1 -0
  137. package/dist/stdio.js +126 -0
  138. package/dist/stdio.js.map +1 -0
  139. package/dist/types.d.ts +256 -447
  140. package/dist/types.d.ts.map +1 -1
  141. package/dist/types.js +4 -1
  142. package/dist/types.js.map +1 -1
  143. package/dist/utils/camelCase.d.ts.map +1 -1
  144. package/dist/utils/getLogger.d.ts +10 -0
  145. package/dist/utils/getLogger.d.ts.map +1 -0
  146. package/dist/utils/getLogger.js +22 -0
  147. package/dist/utils/getLogger.js.map +1 -0
  148. package/dist/utils/getPluginConfig.d.ts +12 -0
  149. package/dist/utils/getPluginConfig.d.ts.map +1 -0
  150. package/dist/utils/getPluginConfig.js +15 -0
  151. package/dist/utils/getPluginConfig.js.map +1 -0
  152. package/dist/utils/resolveProjectRoot.d.ts +7 -0
  153. package/dist/utils/resolveProjectRoot.d.ts.map +1 -0
  154. package/dist/utils/resolveProjectRoot.js +15 -0
  155. package/dist/utils/resolveProjectRoot.js.map +1 -0
  156. package/dist/utils/schemaConversion/filterFieldsByAccess.d.ts +28 -0
  157. package/dist/utils/schemaConversion/filterFieldsByAccess.d.ts.map +1 -0
  158. package/dist/utils/schemaConversion/filterFieldsByAccess.js +71 -0
  159. package/dist/utils/schemaConversion/filterFieldsByAccess.js.map +1 -0
  160. package/dist/utils/schemaConversion/getEntityInputSchema.d.ts +13 -0
  161. package/dist/utils/schemaConversion/getEntityInputSchema.d.ts.map +1 -0
  162. package/dist/utils/schemaConversion/getEntityInputSchema.js +66 -0
  163. package/dist/utils/schemaConversion/getEntityInputSchema.js.map +1 -0
  164. package/dist/utils/schemaConversion/sanitizeEntitySchema.d.ts +10 -0
  165. package/dist/utils/schemaConversion/sanitizeEntitySchema.d.ts.map +1 -0
  166. package/dist/utils/schemaConversion/sanitizeEntitySchema.js +384 -0
  167. package/dist/utils/schemaConversion/sanitizeEntitySchema.js.map +1 -0
  168. package/dist/utils/schemaConversion/sanitizeEntitySchema.spec.js +133 -0
  169. package/dist/utils/schemaConversion/sanitizeEntitySchema.spec.js.map +1 -0
  170. package/dist/utils/toStandardSchema.d.ts +5 -0
  171. package/dist/utils/toStandardSchema.d.ts.map +1 -0
  172. package/dist/utils/toStandardSchema.js +4 -0
  173. package/dist/utils/toStandardSchema.js.map +1 -0
  174. package/dist/utils/whereSchema.d.ts +9 -0
  175. package/dist/utils/whereSchema.d.ts.map +1 -0
  176. package/dist/utils/whereSchema.js +13 -0
  177. package/dist/utils/whereSchema.js.map +1 -0
  178. package/package.json +30 -10
  179. package/src/defaultAccess.ts +3 -0
  180. package/src/defineTool.ts +44 -0
  181. package/src/endpoint/access.ts +112 -0
  182. package/src/endpoint/index.ts +77 -0
  183. package/src/exports/client.ts +3 -0
  184. package/src/exports/internal.ts +1 -0
  185. package/src/index.ts +31 -89
  186. package/src/mcp/buildMcpServer.ts +284 -0
  187. package/src/mcp/builtin/collections/authTools.ts +269 -0
  188. package/src/mcp/builtin/collections/countTool.ts +73 -0
  189. package/src/mcp/builtin/collections/countVersionsTool.ts +69 -0
  190. package/src/mcp/builtin/collections/createTool.ts +117 -0
  191. package/src/mcp/builtin/collections/deleteTool.ts +125 -0
  192. package/src/mcp/builtin/collections/duplicateTool.ts +134 -0
  193. package/src/mcp/builtin/collections/findDistinctTool.ts +119 -0
  194. package/src/mcp/builtin/collections/findTool.ts +216 -0
  195. package/src/mcp/builtin/collections/findVersionByIDTool.ts +109 -0
  196. package/src/mcp/builtin/collections/findVersionsTool.ts +154 -0
  197. package/src/mcp/builtin/collections/formatCollectionError.ts +84 -0
  198. package/src/mcp/builtin/collections/getCollectionSchemaTool.ts +63 -0
  199. package/src/mcp/builtin/collections/restoreVersionTool.ts +107 -0
  200. package/src/mcp/builtin/collections/updateTool.ts +225 -0
  201. package/src/mcp/builtin/getConfigInfoTool.ts +67 -0
  202. package/src/mcp/builtin/globals/countVersionsTool.ts +68 -0
  203. package/src/mcp/builtin/globals/findTool.ts +105 -0
  204. package/src/mcp/builtin/globals/findVersionByIDTool.ts +103 -0
  205. package/src/mcp/builtin/globals/findVersionsTool.ts +147 -0
  206. package/src/mcp/builtin/globals/getGlobalSchemaTool.ts +63 -0
  207. package/src/mcp/builtin/globals/restoreVersionTool.ts +99 -0
  208. package/src/mcp/builtin/globals/updateTool.ts +115 -0
  209. package/src/mcp/builtin/validateEntityData.ts +132 -0
  210. package/src/mcp/builtinTools.ts +154 -0
  211. package/src/mcp/sanitizeMCPConfig.ts +278 -0
  212. package/src/stdio.ts +130 -0
  213. package/src/types.ts +304 -486
  214. package/src/utils/getLogger.ts +22 -0
  215. package/src/utils/getPluginConfig.ts +24 -0
  216. package/src/utils/resolveProjectRoot.ts +17 -0
  217. package/src/utils/schemaConversion/filterFieldsByAccess.ts +123 -0
  218. package/src/utils/schemaConversion/getEntityInputSchema.ts +96 -0
  219. package/src/utils/schemaConversion/sanitizeEntitySchema.spec.ts +96 -0
  220. package/src/utils/schemaConversion/sanitizeEntitySchema.ts +432 -0
  221. package/src/utils/toStandardSchema.ts +9 -0
  222. package/src/utils/whereSchema.ts +24 -0
  223. package/dist/collections/createApiKeysCollection.d.ts +0 -7
  224. package/dist/collections/createApiKeysCollection.d.ts.map +0 -1
  225. package/dist/collections/createApiKeysCollection.js +0 -317
  226. package/dist/collections/createApiKeysCollection.js.map +0 -1
  227. package/dist/defaults.d.ts +0 -4
  228. package/dist/defaults.d.ts.map +0 -1
  229. package/dist/defaults.js +0 -5
  230. package/dist/defaults.js.map +0 -1
  231. package/dist/endpoints/mcp.d.ts +0 -4
  232. package/dist/endpoints/mcp.d.ts.map +0 -1
  233. package/dist/endpoints/mcp.js +0 -71
  234. package/dist/endpoints/mcp.js.map +0 -1
  235. package/dist/mcp/createRequest.d.ts +0 -3
  236. package/dist/mcp/createRequest.d.ts.map +0 -1
  237. package/dist/mcp/createRequest.js +0 -14
  238. package/dist/mcp/createRequest.js.map +0 -1
  239. package/dist/mcp/getMcpHandler.d.ts +0 -4
  240. package/dist/mcp/getMcpHandler.d.ts.map +0 -1
  241. package/dist/mcp/getMcpHandler.js +0 -231
  242. package/dist/mcp/getMcpHandler.js.map +0 -1
  243. package/dist/mcp/helpers/config.d.ts +0 -22
  244. package/dist/mcp/helpers/config.d.ts.map +0 -1
  245. package/dist/mcp/helpers/config.js +0 -153
  246. package/dist/mcp/helpers/config.js.map +0 -1
  247. package/dist/mcp/helpers/fields.d.ts +0 -19
  248. package/dist/mcp/helpers/fields.d.ts.map +0 -1
  249. package/dist/mcp/helpers/fields.js +0 -102
  250. package/dist/mcp/helpers/fields.js.map +0 -1
  251. package/dist/mcp/helpers/fileValidation.d.ts +0 -67
  252. package/dist/mcp/helpers/fileValidation.d.ts.map +0 -1
  253. package/dist/mcp/helpers/fileValidation.js +0 -267
  254. package/dist/mcp/helpers/fileValidation.js.map +0 -1
  255. package/dist/mcp/registerTool.d.ts +0 -6
  256. package/dist/mcp/registerTool.d.ts.map +0 -1
  257. package/dist/mcp/registerTool.js +0 -18
  258. package/dist/mcp/registerTool.js.map +0 -1
  259. package/dist/mcp/tools/auth/auth.d.ts +0 -4
  260. package/dist/mcp/tools/auth/auth.d.ts.map +0 -1
  261. package/dist/mcp/tools/auth/auth.js +0 -57
  262. package/dist/mcp/tools/auth/auth.js.map +0 -1
  263. package/dist/mcp/tools/auth/forgotPassword.d.ts +0 -4
  264. package/dist/mcp/tools/auth/forgotPassword.d.ts.map +0 -1
  265. package/dist/mcp/tools/auth/forgotPassword.js +0 -48
  266. package/dist/mcp/tools/auth/forgotPassword.js.map +0 -1
  267. package/dist/mcp/tools/auth/login.d.ts +0 -4
  268. package/dist/mcp/tools/auth/login.d.ts.map +0 -1
  269. package/dist/mcp/tools/auth/login.js +0 -51
  270. package/dist/mcp/tools/auth/login.js.map +0 -1
  271. package/dist/mcp/tools/auth/resetPassword.d.ts +0 -4
  272. package/dist/mcp/tools/auth/resetPassword.d.ts.map +0 -1
  273. package/dist/mcp/tools/auth/resetPassword.js +0 -49
  274. package/dist/mcp/tools/auth/resetPassword.js.map +0 -1
  275. package/dist/mcp/tools/auth/unlock.d.ts +0 -4
  276. package/dist/mcp/tools/auth/unlock.d.ts.map +0 -1
  277. package/dist/mcp/tools/auth/unlock.js +0 -48
  278. package/dist/mcp/tools/auth/unlock.js.map +0 -1
  279. package/dist/mcp/tools/auth/verify.d.ts +0 -4
  280. package/dist/mcp/tools/auth/verify.d.ts.map +0 -1
  281. package/dist/mcp/tools/auth/verify.js +0 -45
  282. package/dist/mcp/tools/auth/verify.js.map +0 -1
  283. package/dist/mcp/tools/collection/create.d.ts +0 -10
  284. package/dist/mcp/tools/collection/create.d.ts.map +0 -1
  285. package/dist/mcp/tools/collection/create.js +0 -139
  286. package/dist/mcp/tools/collection/create.js.map +0 -1
  287. package/dist/mcp/tools/collection/delete.d.ts +0 -10
  288. package/dist/mcp/tools/collection/delete.d.ts.map +0 -1
  289. package/dist/mcp/tools/collection/delete.js +0 -154
  290. package/dist/mcp/tools/collection/delete.js.map +0 -1
  291. package/dist/mcp/tools/collection/find.d.ts +0 -10
  292. package/dist/mcp/tools/collection/find.d.ts.map +0 -1
  293. package/dist/mcp/tools/collection/find.js +0 -165
  294. package/dist/mcp/tools/collection/find.js.map +0 -1
  295. package/dist/mcp/tools/collection/update.d.ts +0 -10
  296. package/dist/mcp/tools/collection/update.d.ts.map +0 -1
  297. package/dist/mcp/tools/collection/update.js +0 -209
  298. package/dist/mcp/tools/collection/update.js.map +0 -1
  299. package/dist/mcp/tools/config/find.d.ts +0 -10
  300. package/dist/mcp/tools/config/find.d.ts.map +0 -1
  301. package/dist/mcp/tools/config/find.js +0 -97
  302. package/dist/mcp/tools/config/find.js.map +0 -1
  303. package/dist/mcp/tools/config/update.d.ts +0 -10
  304. package/dist/mcp/tools/config/update.d.ts.map +0 -1
  305. package/dist/mcp/tools/config/update.js +0 -215
  306. package/dist/mcp/tools/config/update.js.map +0 -1
  307. package/dist/mcp/tools/global/find.d.ts +0 -5
  308. package/dist/mcp/tools/global/find.d.ts.map +0 -1
  309. package/dist/mcp/tools/global/find.js +0 -82
  310. package/dist/mcp/tools/global/find.js.map +0 -1
  311. package/dist/mcp/tools/global/update.d.ts +0 -6
  312. package/dist/mcp/tools/global/update.d.ts.map +0 -1
  313. package/dist/mcp/tools/global/update.js +0 -124
  314. package/dist/mcp/tools/global/update.js.map +0 -1
  315. package/dist/mcp/tools/job/create.d.ts +0 -10
  316. package/dist/mcp/tools/job/create.d.ts.map +0 -1
  317. package/dist/mcp/tools/job/create.js +0 -293
  318. package/dist/mcp/tools/job/create.js.map +0 -1
  319. package/dist/mcp/tools/job/run.d.ts +0 -10
  320. package/dist/mcp/tools/job/run.d.ts.map +0 -1
  321. package/dist/mcp/tools/job/run.js +0 -129
  322. package/dist/mcp/tools/job/run.js.map +0 -1
  323. package/dist/mcp/tools/job/update.d.ts +0 -11
  324. package/dist/mcp/tools/job/update.d.ts.map +0 -1
  325. package/dist/mcp/tools/job/update.js +0 -186
  326. package/dist/mcp/tools/job/update.js.map +0 -1
  327. package/dist/mcp/tools/resource/create.d.ts +0 -6
  328. package/dist/mcp/tools/resource/create.d.ts.map +0 -1
  329. package/dist/mcp/tools/resource/create.js +0 -124
  330. package/dist/mcp/tools/resource/create.js.map +0 -1
  331. package/dist/mcp/tools/resource/delete.d.ts +0 -5
  332. package/dist/mcp/tools/resource/delete.d.ts.map +0 -1
  333. package/dist/mcp/tools/resource/delete.js +0 -151
  334. package/dist/mcp/tools/resource/delete.js.map +0 -1
  335. package/dist/mcp/tools/resource/find.d.ts +0 -5
  336. package/dist/mcp/tools/resource/find.d.ts.map +0 -1
  337. package/dist/mcp/tools/resource/find.js +0 -170
  338. package/dist/mcp/tools/resource/find.js.map +0 -1
  339. package/dist/mcp/tools/resource/update.d.ts +0 -6
  340. package/dist/mcp/tools/resource/update.d.ts.map +0 -1
  341. package/dist/mcp/tools/resource/update.js +0 -256
  342. package/dist/mcp/tools/resource/update.js.map +0 -1
  343. package/dist/mcp/tools/schemas.d.ts +0 -457
  344. package/dist/mcp/tools/schemas.d.ts.map +0 -1
  345. package/dist/mcp/tools/schemas.js +0 -243
  346. package/dist/mcp/tools/schemas.js.map +0 -1
  347. package/dist/utils/adminEntitySettings.d.ts +0 -17
  348. package/dist/utils/adminEntitySettings.d.ts.map +0 -1
  349. package/dist/utils/adminEntitySettings.js +0 -41
  350. package/dist/utils/adminEntitySettings.js.map +0 -1
  351. package/dist/utils/createApiKeyFields.d.ts +0 -15
  352. package/dist/utils/createApiKeyFields.d.ts.map +0 -1
  353. package/dist/utils/createApiKeyFields.js +0 -57
  354. package/dist/utils/createApiKeyFields.js.map +0 -1
  355. package/dist/utils/getEnabledSlugs.d.ts +0 -13
  356. package/dist/utils/getEnabledSlugs.d.ts.map +0 -1
  357. package/dist/utils/getEnabledSlugs.js +0 -32
  358. package/dist/utils/getEnabledSlugs.js.map +0 -1
  359. package/dist/utils/schemaConversion/convertCollectionSchemaToZod.d.ts +0 -3
  360. package/dist/utils/schemaConversion/convertCollectionSchemaToZod.d.ts.map +0 -1
  361. package/dist/utils/schemaConversion/convertCollectionSchemaToZod.js +0 -43
  362. package/dist/utils/schemaConversion/convertCollectionSchemaToZod.js.map +0 -1
  363. package/dist/utils/schemaConversion/removeVirtualFieldsFromSchema.d.ts +0 -7
  364. package/dist/utils/schemaConversion/removeVirtualFieldsFromSchema.d.ts.map +0 -1
  365. package/dist/utils/schemaConversion/removeVirtualFieldsFromSchema.js +0 -20
  366. package/dist/utils/schemaConversion/removeVirtualFieldsFromSchema.js.map +0 -1
  367. package/dist/utils/schemaConversion/sanitizeJsonSchema.d.ts +0 -13
  368. package/dist/utils/schemaConversion/sanitizeJsonSchema.d.ts.map +0 -1
  369. package/dist/utils/schemaConversion/sanitizeJsonSchema.js +0 -56
  370. package/dist/utils/schemaConversion/sanitizeJsonSchema.js.map +0 -1
  371. package/dist/utils/schemaConversion/simplifyRelationshipFields.d.ts +0 -20
  372. package/dist/utils/schemaConversion/simplifyRelationshipFields.d.ts.map +0 -1
  373. package/dist/utils/schemaConversion/simplifyRelationshipFields.js +0 -53
  374. package/dist/utils/schemaConversion/simplifyRelationshipFields.js.map +0 -1
  375. package/dist/utils/schemaConversion/transformPointFields.d.ts +0 -3
  376. package/dist/utils/schemaConversion/transformPointFields.d.ts.map +0 -1
  377. package/dist/utils/schemaConversion/transformPointFields.js +0 -51
  378. package/dist/utils/schemaConversion/transformPointFields.js.map +0 -1
  379. package/src/collections/createApiKeysCollection.ts +0 -373
  380. package/src/defaults.ts +0 -3
  381. package/src/endpoints/mcp.ts +0 -91
  382. package/src/mcp/createRequest.ts +0 -13
  383. package/src/mcp/getMcpHandler.ts +0 -545
  384. package/src/mcp/helpers/config.ts +0 -213
  385. package/src/mcp/helpers/fields.ts +0 -154
  386. package/src/mcp/helpers/fileValidation.ts +0 -362
  387. package/src/mcp/registerTool.ts +0 -22
  388. package/src/mcp/tools/auth/auth.ts +0 -71
  389. package/src/mcp/tools/auth/forgotPassword.ts +0 -70
  390. package/src/mcp/tools/auth/login.ts +0 -72
  391. package/src/mcp/tools/auth/resetPassword.ts +0 -61
  392. package/src/mcp/tools/auth/unlock.ts +0 -64
  393. package/src/mcp/tools/auth/verify.ts +0 -57
  394. package/src/mcp/tools/collection/create.ts +0 -210
  395. package/src/mcp/tools/collection/delete.ts +0 -211
  396. package/src/mcp/tools/collection/find.ts +0 -224
  397. package/src/mcp/tools/collection/update.ts +0 -290
  398. package/src/mcp/tools/config/find.ts +0 -128
  399. package/src/mcp/tools/config/update.ts +0 -280
  400. package/src/mcp/tools/global/find.ts +0 -128
  401. package/src/mcp/tools/global/update.ts +0 -207
  402. package/src/mcp/tools/job/create.ts +0 -416
  403. package/src/mcp/tools/job/run.ts +0 -167
  404. package/src/mcp/tools/job/update.ts +0 -274
  405. package/src/mcp/tools/resource/create.ts +0 -211
  406. package/src/mcp/tools/resource/delete.ts +0 -218
  407. package/src/mcp/tools/resource/find.ts +0 -246
  408. package/src/mcp/tools/resource/update.ts +0 -383
  409. package/src/mcp/tools/schemas.ts +0 -520
  410. package/src/utils/adminEntitySettings.ts +0 -40
  411. package/src/utils/createApiKeyFields.ts +0 -72
  412. package/src/utils/getEnabledSlugs.ts +0 -42
  413. package/src/utils/schemaConversion/convertCollectionSchemaToZod.ts +0 -52
  414. package/src/utils/schemaConversion/removeVirtualFieldsFromSchema.ts +0 -27
  415. package/src/utils/schemaConversion/sanitizeJsonSchema.ts +0 -62
  416. package/src/utils/schemaConversion/simplifyRelationshipFields.ts +0 -65
  417. package/src/utils/schemaConversion/transformPointFields.ts +0 -55
@@ -0,0 +1 @@
1
+ {"version":3,"file":"buildMcpServer.d.ts","sourceRoot":"","sources":["../../src/mcp/buildMcpServer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAsB,MAAM,8BAA8B,CAAA;AAC5E,OAAO,EAAY,KAAK,cAAc,EAAE,MAAM,SAAS,CAAA;AAGvD,OAAO,KAAK,EACV,aAAa,EAMb,wBAAwB,EAEzB,MAAM,aAAa,CAAA;AAKpB;;;;;;;;;GASG;AACH,eAAO,MAAM,cAAc,GAAI,uCAI5B;IACD,aAAa,EAAE,aAAa,CAAA;IAC5B,YAAY,EAAE,wBAAwB,CAAA;IACtC,GAAG,EAAE,cAAc,CAAA;CACpB,KAAG,SAkNH,CAAA"}
@@ -0,0 +1,223 @@
1
+ import { McpServer } from '@modelcontextprotocol/server';
2
+ import { APIError } from 'payload';
3
+ import { z } from 'zod';
4
+ import { getLogger } from '../utils/getLogger.js';
5
+ import { toStandardSchema } from '../utils/toStandardSchema.js';
6
+ /**
7
+ * Serving-entry-agnostic core: registers every authorized MCP item onto a fresh
8
+ * `McpServer` and returns it. The HTTP and stdio entry point callers provide fresh
9
+ * instances from this builder while they own the transport and protocol-era
10
+ * decision.
11
+ *
12
+ * `req` is the request context handlers see. For HTTP it's the live
13
+ * `PayloadRequest` derived from the incoming HTTP request; for stdio it's a
14
+ * synthesized one built via `createLocalReq`.
15
+ */ export const buildMcpServer = ({ authorizedMCP, pluginConfig, req })=>{
16
+ const serverOptions = pluginConfig.mcp?.serverOptions || {};
17
+ const server = new McpServer({
18
+ name: 'Payload MCP Server',
19
+ version: '1.0.0',
20
+ ...serverOptions.serverInfo
21
+ }, serverOptions.options);
22
+ const logger = getLogger({
23
+ payload: req.payload
24
+ });
25
+ /**
26
+ * Wrap a tool handler's response with the tool's `overrideResponse`, then
27
+ * strip the internal `doc` field so it doesn't leak onto the wire.
28
+ */ const finalizeToolResponse = async ({ input, overrideResponse, response, toolName })=>{
29
+ let overridden = overrideResponse?.(response, response.doc ?? {}, req) ?? response;
30
+ for (const hook of pluginConfig.hooks?.afterToolCall ?? []){
31
+ overridden = await hook({
32
+ input,
33
+ req,
34
+ response: overridden,
35
+ toolName
36
+ });
37
+ }
38
+ const { doc: _doc, ...rest } = overridden;
39
+ return rest;
40
+ };
41
+ /**
42
+ * Runs a collection/global tool call:
43
+ * - reads `collectionSlug` / `globalSlug` from the input
44
+ * - runs access control: errors if `authorizedMCP.items` has no entry for this tool + slug
45
+ * - runs the tool handler and finalizes its response
46
+ */ const callEntityTool = async ({ input, item, serverContext })=>{
47
+ const entity = item.type === 'collectionTool' ? 'collection' : 'global';
48
+ const slugKey = item.type === 'collectionTool' ? 'collectionSlug' : 'globalSlug';
49
+ const toolInput = input ?? {};
50
+ const slug = toolInput[slugKey];
51
+ if (!slug) {
52
+ return {
53
+ content: [
54
+ {
55
+ type: 'text',
56
+ text: `Error: "${item.mcpName}" requires ${slugKey}. Use getConfigInfo to inspect ${entity} slugs.`
57
+ }
58
+ ],
59
+ isError: true
60
+ };
61
+ }
62
+ const match = authorizedMCP.items.find((candidate)=>candidate.type === item.type && candidate.mcpName === item.mcpName && (candidate.type === 'collectionTool' ? candidate.collectionSlug === slug : candidate.type === 'globalTool' && candidate.globalSlug === slug));
63
+ if (!match) {
64
+ return {
65
+ content: [
66
+ {
67
+ type: 'text',
68
+ text: `Error: MCP access to "${item.mcpName}" is not enabled for ${entity} "${slug}"`
69
+ }
70
+ ],
71
+ isError: true
72
+ };
73
+ }
74
+ const handlerArgs = {
75
+ authorizedMCP,
76
+ input: toolInput,
77
+ req,
78
+ serverContext
79
+ };
80
+ const response = await (match.type === 'collectionTool' ? match.tool.handler({
81
+ ...handlerArgs,
82
+ collectionSlug: slug
83
+ }) : match.tool.handler({
84
+ ...handlerArgs,
85
+ globalSlug: slug
86
+ }));
87
+ return finalizeToolResponse({
88
+ input: toolInput,
89
+ overrideResponse: match.tool.overrideResponse,
90
+ response,
91
+ toolName: match.mcpName
92
+ });
93
+ };
94
+ try {
95
+ const registeredEntityTools = new Set();
96
+ for (const item of authorizedMCP.items){
97
+ switch(item.type){
98
+ case 'collectionTool':
99
+ case 'globalTool':
100
+ {
101
+ if (registeredEntityTools.has(item.mcpName)) {
102
+ break;
103
+ }
104
+ registeredEntityTools.add(item.mcpName);
105
+ const inputSchema = withSlugInput({
106
+ name: item.type === 'collectionTool' ? 'collectionSlug' : 'globalSlug',
107
+ input: item.tool.input
108
+ });
109
+ server.registerTool(item.mcpName, {
110
+ annotations: item.tool.annotations,
111
+ description: item.tool.description,
112
+ inputSchema: toStandardSchema(inputSchema)
113
+ }, async (input, ctx)=>callEntityTool({
114
+ input,
115
+ item,
116
+ serverContext: ctx
117
+ }));
118
+ logger.info(`✅ Tool: ${item.mcpName} Registered.`);
119
+ break;
120
+ }
121
+ case 'prompt':
122
+ {
123
+ const prompt = item.prompt;
124
+ server.registerPrompt(item.mcpName, {
125
+ argsSchema: prompt.argsSchema ? toStandardSchema(prompt.argsSchema) : undefined,
126
+ description: prompt.description,
127
+ title: prompt.title
128
+ }, async (input, ctx)=>prompt.handler({
129
+ input: input ?? {},
130
+ req,
131
+ serverContext: ctx
132
+ }));
133
+ logger.info(`✅ Prompt: ${prompt.title} Registered.`);
134
+ break;
135
+ }
136
+ case 'resource':
137
+ {
138
+ const resource = item.resource;
139
+ server.registerResource(item.mcpName, // @ts-expect-error - Overload type ambiguity (string OR ResourceTemplate is valid)
140
+ resource.uri, {
141
+ description: resource.description,
142
+ mimeType: resource.mimeType,
143
+ title: resource.title
144
+ }, // Static URIs call (uri, ctx); ResourceTemplates call (uri, params, ctx).
145
+ // The rest-params shape lets us collect either signature uniformly.
146
+ async (...sdkArgs)=>{
147
+ const ctx = sdkArgs[sdkArgs.length - 1];
148
+ const uri = sdkArgs[0];
149
+ const params = sdkArgs.length > 2 ? sdkArgs[1] : {};
150
+ return resource.handler({
151
+ params,
152
+ req,
153
+ serverContext: ctx,
154
+ uri
155
+ });
156
+ });
157
+ logger.info(`✅ Resource: ${resource.title} Registered.`);
158
+ break;
159
+ }
160
+ case 'tool':
161
+ {
162
+ const tool = item.tool;
163
+ server.registerTool(item.mcpName, {
164
+ annotations: tool.annotations,
165
+ description: tool.description,
166
+ inputSchema: tool.input ? toStandardSchema(tool.input) : undefined
167
+ }, async (input, ctx)=>{
168
+ const toolInput = input ?? {};
169
+ const response = await tool.handler({
170
+ authorizedMCP,
171
+ input: toolInput,
172
+ req,
173
+ serverContext: ctx
174
+ });
175
+ return finalizeToolResponse({
176
+ input: toolInput,
177
+ overrideResponse: tool.overrideResponse,
178
+ response,
179
+ toolName: item.mcpName
180
+ });
181
+ });
182
+ logger.info(`✅ Tool: ${item.mcpName} Registered.`);
183
+ break;
184
+ }
185
+ }
186
+ }
187
+ } catch (error) {
188
+ throw new APIError(`Error initializing MCP handler: ${String(error)}`, 500);
189
+ }
190
+ return server;
191
+ };
192
+ const withSlugInput = ({ name, input })=>{
193
+ const description = name === 'collectionSlug' ? 'The collection slug' : 'The global slug';
194
+ const slugSchema = z.string().describe(description);
195
+ if (!input) {
196
+ return z.object({
197
+ [name]: slugSchema
198
+ });
199
+ }
200
+ if (input instanceof z.ZodObject) {
201
+ return input.extend({
202
+ [name]: slugSchema
203
+ });
204
+ }
205
+ const schema = input;
206
+ return {
207
+ ...schema,
208
+ type: 'object',
209
+ properties: {
210
+ ...schema.properties,
211
+ [name]: {
212
+ type: 'string',
213
+ description
214
+ }
215
+ },
216
+ required: Array.from(new Set([
217
+ name,
218
+ ...schema.required ?? []
219
+ ]))
220
+ };
221
+ };
222
+
223
+ //# sourceMappingURL=buildMcpServer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/mcp/buildMcpServer.ts"],"sourcesContent":["import { McpServer, type ServerContext } from '@modelcontextprotocol/server'\nimport { APIError, type PayloadRequest } from 'payload'\nimport { z } from 'zod'\n\nimport type {\n AuthorizedMCP,\n CollectionMCPItem,\n GlobalMCPItem,\n JsonSchemaType,\n MCPResponseOverride,\n MCPToolResponse,\n SanitizedMCPPluginConfig,\n ToolInputSchema,\n} from '../types.js'\n\nimport { getLogger } from '../utils/getLogger.js'\nimport { toStandardSchema } from '../utils/toStandardSchema.js'\n\n/**\n * Serving-entry-agnostic core: registers every authorized MCP item onto a fresh\n * `McpServer` and returns it. The HTTP and stdio entry point callers provide fresh\n * instances from this builder while they own the transport and protocol-era\n * decision.\n *\n * `req` is the request context handlers see. For HTTP it's the live\n * `PayloadRequest` derived from the incoming HTTP request; for stdio it's a\n * synthesized one built via `createLocalReq`.\n */\nexport const buildMcpServer = ({\n authorizedMCP,\n pluginConfig,\n req,\n}: {\n authorizedMCP: AuthorizedMCP\n pluginConfig: SanitizedMCPPluginConfig\n req: PayloadRequest\n}): McpServer => {\n const serverOptions = pluginConfig.mcp?.serverOptions || {}\n const server = new McpServer(\n { name: 'Payload MCP Server', version: '1.0.0', ...serverOptions.serverInfo },\n serverOptions.options,\n )\n\n const logger = getLogger({ payload: req.payload })\n\n /**\n * Wrap a tool handler's response with the tool's `overrideResponse`, then\n * strip the internal `doc` field so it doesn't leak onto the wire.\n */\n const finalizeToolResponse = async ({\n input,\n overrideResponse,\n response,\n toolName,\n }: {\n input: unknown\n overrideResponse?: MCPResponseOverride\n response: MCPToolResponse\n toolName: string\n }): Promise<MCPToolResponse> => {\n let overridden = overrideResponse?.(response, response.doc ?? {}, req) ?? response\n for (const hook of pluginConfig.hooks?.afterToolCall ?? []) {\n overridden = await hook({ input, req, response: overridden, toolName })\n }\n const { doc: _doc, ...rest } = overridden\n return rest\n }\n\n /**\n * Runs a collection/global tool call:\n * - reads `collectionSlug` / `globalSlug` from the input\n * - runs access control: errors if `authorizedMCP.items` has no entry for this tool + slug\n * - runs the tool handler and finalizes its response\n */\n const callEntityTool = async ({\n input,\n item,\n serverContext,\n }: {\n input: unknown\n item: CollectionMCPItem | GlobalMCPItem\n serverContext: ServerContext\n }): Promise<MCPToolResponse> => {\n const entity = item.type === 'collectionTool' ? 'collection' : 'global'\n const slugKey = item.type === 'collectionTool' ? 'collectionSlug' : 'globalSlug'\n const toolInput = (input ?? {}) as Record<string, unknown>\n const slug = toolInput[slugKey] as string | undefined\n\n if (!slug) {\n return {\n content: [\n {\n type: 'text',\n text: `Error: \"${item.mcpName}\" requires ${slugKey}. Use getConfigInfo to inspect ${entity} slugs.`,\n },\n ],\n isError: true,\n }\n }\n\n const match = authorizedMCP.items.find(\n (candidate): candidate is CollectionMCPItem | GlobalMCPItem =>\n candidate.type === item.type &&\n candidate.mcpName === item.mcpName &&\n (candidate.type === 'collectionTool'\n ? candidate.collectionSlug === slug\n : candidate.type === 'globalTool' && candidate.globalSlug === slug),\n )\n\n if (!match) {\n return {\n content: [\n {\n type: 'text',\n text: `Error: MCP access to \"${item.mcpName}\" is not enabled for ${entity} \"${slug}\"`,\n },\n ],\n isError: true,\n }\n }\n\n const handlerArgs = {\n authorizedMCP,\n input: toolInput,\n req,\n serverContext,\n }\n const response = await (match.type === 'collectionTool'\n ? match.tool.handler({ ...handlerArgs, collectionSlug: slug })\n : match.tool.handler({ ...handlerArgs, globalSlug: slug }))\n\n return finalizeToolResponse({\n input: toolInput,\n overrideResponse: match.tool.overrideResponse,\n response,\n toolName: match.mcpName,\n })\n }\n\n try {\n const registeredEntityTools = new Set<string>()\n\n for (const item of authorizedMCP.items) {\n switch (item.type) {\n case 'collectionTool':\n case 'globalTool': {\n if (registeredEntityTools.has(item.mcpName)) {\n break\n }\n registeredEntityTools.add(item.mcpName)\n\n const inputSchema = withSlugInput({\n name: item.type === 'collectionTool' ? 'collectionSlug' : 'globalSlug',\n input: item.tool.input,\n })\n\n server.registerTool(\n item.mcpName,\n {\n annotations: item.tool.annotations,\n description: item.tool.description,\n inputSchema: toStandardSchema(inputSchema),\n },\n async (input: unknown, ctx: ServerContext) =>\n callEntityTool({ input, item, serverContext: ctx }),\n )\n logger.info(`✅ Tool: ${item.mcpName} Registered.`)\n break\n }\n case 'prompt': {\n const prompt = item.prompt\n server.registerPrompt(\n item.mcpName,\n {\n argsSchema: prompt.argsSchema ? toStandardSchema(prompt.argsSchema) : undefined,\n description: prompt.description,\n title: prompt.title,\n },\n async (input: unknown, ctx: ServerContext) =>\n prompt.handler({\n input: (input ?? {}) as Record<string, unknown>,\n req,\n serverContext: ctx,\n }),\n )\n logger.info(`✅ Prompt: ${prompt.title} Registered.`)\n break\n }\n case 'resource': {\n const resource = item.resource\n server.registerResource(\n item.mcpName,\n // @ts-expect-error - Overload type ambiguity (string OR ResourceTemplate is valid)\n resource.uri,\n {\n description: resource.description,\n mimeType: resource.mimeType,\n title: resource.title,\n },\n // Static URIs call (uri, ctx); ResourceTemplates call (uri, params, ctx).\n // The rest-params shape lets us collect either signature uniformly.\n async (...sdkArgs: unknown[]) => {\n const ctx = sdkArgs[sdkArgs.length - 1] as ServerContext\n const uri = sdkArgs[0] as URL\n const params = (sdkArgs.length > 2 ? sdkArgs[1] : {}) as Record<string, string>\n return resource.handler({ params, req, serverContext: ctx, uri })\n },\n )\n logger.info(`✅ Resource: ${resource.title} Registered.`)\n break\n }\n case 'tool': {\n const tool = item.tool\n server.registerTool(\n item.mcpName,\n {\n annotations: tool.annotations,\n description: tool.description,\n inputSchema: tool.input ? toStandardSchema(tool.input) : undefined,\n },\n async (input: unknown, ctx: ServerContext) => {\n const toolInput = (input ?? {}) as Record<string, unknown>\n const response = await tool.handler({\n authorizedMCP,\n input: toolInput,\n req,\n serverContext: ctx,\n })\n return finalizeToolResponse({\n input: toolInput,\n overrideResponse: tool.overrideResponse,\n response,\n toolName: item.mcpName,\n })\n },\n )\n logger.info(`✅ Tool: ${item.mcpName} Registered.`)\n break\n }\n }\n }\n } catch (error) {\n throw new APIError(`Error initializing MCP handler: ${String(error)}`, 500)\n }\n\n return server\n}\n\nconst withSlugInput = ({\n name,\n input,\n}: {\n input?: ToolInputSchema\n name: 'collectionSlug' | 'globalSlug'\n}): ToolInputSchema => {\n const description = name === 'collectionSlug' ? 'The collection slug' : 'The global slug'\n const slugSchema = z.string().describe(description)\n\n if (!input) {\n return z.object({ [name]: slugSchema })\n }\n\n if (input instanceof z.ZodObject) {\n return input.extend({ [name]: slugSchema })\n }\n\n const schema = input as {\n properties?: Record<string, JsonSchemaType>\n required?: string[]\n } & JsonSchemaType\n\n return {\n ...schema,\n type: 'object',\n properties: {\n ...schema.properties,\n [name]: {\n type: 'string',\n description,\n },\n },\n required: Array.from(new Set([name, ...(schema.required ?? [])])),\n }\n}\n"],"names":["McpServer","APIError","z","getLogger","toStandardSchema","buildMcpServer","authorizedMCP","pluginConfig","req","serverOptions","mcp","server","name","version","serverInfo","options","logger","payload","finalizeToolResponse","input","overrideResponse","response","toolName","overridden","doc","hook","hooks","afterToolCall","_doc","rest","callEntityTool","item","serverContext","entity","type","slugKey","toolInput","slug","content","text","mcpName","isError","match","items","find","candidate","collectionSlug","globalSlug","handlerArgs","tool","handler","registeredEntityTools","Set","has","add","inputSchema","withSlugInput","registerTool","annotations","description","ctx","info","prompt","registerPrompt","argsSchema","undefined","title","resource","registerResource","uri","mimeType","sdkArgs","length","params","error","String","slugSchema","string","describe","object","ZodObject","extend","schema","properties","required","Array","from"],"mappings":"AAAA,SAASA,SAAS,QAA4B,+BAA8B;AAC5E,SAASC,QAAQ,QAA6B,UAAS;AACvD,SAASC,CAAC,QAAQ,MAAK;AAavB,SAASC,SAAS,QAAQ,wBAAuB;AACjD,SAASC,gBAAgB,QAAQ,+BAA8B;AAE/D;;;;;;;;;CASC,GACD,OAAO,MAAMC,iBAAiB,CAAC,EAC7BC,aAAa,EACbC,YAAY,EACZC,GAAG,EAKJ;IACC,MAAMC,gBAAgBF,aAAaG,GAAG,EAAED,iBAAiB,CAAC;IAC1D,MAAME,SAAS,IAAIX,UACjB;QAAEY,MAAM;QAAsBC,SAAS;QAAS,GAAGJ,cAAcK,UAAU;IAAC,GAC5EL,cAAcM,OAAO;IAGvB,MAAMC,SAASb,UAAU;QAAEc,SAAST,IAAIS,OAAO;IAAC;IAEhD;;;GAGC,GACD,MAAMC,uBAAuB,OAAO,EAClCC,KAAK,EACLC,gBAAgB,EAChBC,QAAQ,EACRC,QAAQ,EAMT;QACC,IAAIC,aAAaH,mBAAmBC,UAAUA,SAASG,GAAG,IAAI,CAAC,GAAGhB,QAAQa;QAC1E,KAAK,MAAMI,QAAQlB,aAAamB,KAAK,EAAEC,iBAAiB,EAAE,CAAE;YAC1DJ,aAAa,MAAME,KAAK;gBAAEN;gBAAOX;gBAAKa,UAAUE;gBAAYD;YAAS;QACvE;QACA,MAAM,EAAEE,KAAKI,IAAI,EAAE,GAAGC,MAAM,GAAGN;QAC/B,OAAOM;IACT;IAEA;;;;;GAKC,GACD,MAAMC,iBAAiB,OAAO,EAC5BX,KAAK,EACLY,IAAI,EACJC,aAAa,EAKd;QACC,MAAMC,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AAC,CAAC,QAAQ,EAAE9B,KAAKS,OAAO,CAAC,YAAY,CAAC;wBACjD;oBACF;YACF;QACF;IACF,EAAE,OAAOkC,OAAO;QACd,MAAM,IAAIzE,SAAS,CAAC,gCAAgC,EAAE0E,OAAOD,QAAQ,EAAE;IACzE;IAEA,OAAO/D;AACT,EAAC;AAED,MAAM6C,gBAAgB,CAAC,EACrB5C,IAAI,EACJO,KAAK,EAIN;IACC,MAAMwC,cAAc/C,SAAS,mBAAmB,wBAAwB;IACxE,MAAMgE,aAAa1E,EAAE2E,MAAM,GAAGC,QAAQ,CAACnB;IAEvC,IAAI,CAACxC,OAAO;QACV,OAAOjB,EAAE6E,MAAM,CAAC;YAAE,CAACnE,KAAK,EAAEgE;QAAW;IACvC;IAEA,IAAIzD,iBAAiBjB,EAAE8E,SAAS,EAAE;QAChC,OAAO7D,MAAM8D,MAAM,CAAC;YAAE,CAACrE,KAAK,EAAEgE;QAAW;IAC3C;IAEA,MAAMM,SAAS/D;IAKf,OAAO;QACL,GAAG+D,MAAM;QACThD,MAAM;QACNiD,YAAY;YACV,GAAGD,OAAOC,UAAU;YACpB,CAACvE,KAAK,EAAE;gBACNsB,MAAM;gBACNyB;YACF;QACF;QACAyB,UAAUC,MAAMC,IAAI,CAAC,IAAIlC,IAAI;YAACxC;eAAUsE,OAAOE,QAAQ,IAAI,EAAE;SAAE;IACjE;AACF"}
@@ -0,0 +1,7 @@
1
+ export declare const authCollectionTool: import("../../../types.js").CollectionTool;
2
+ export declare const forgotPasswordCollectionTool: import("../../../types.js").CollectionTool;
3
+ export declare const loginCollectionTool: import("../../../types.js").CollectionTool;
4
+ export declare const resetPasswordCollectionTool: import("../../../types.js").CollectionTool;
5
+ export declare const unlockCollectionTool: import("../../../types.js").CollectionTool;
6
+ export declare const verifyCollectionTool: import("../../../types.js").CollectionTool;
7
+ //# sourceMappingURL=authTools.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authTools.d.ts","sourceRoot":"","sources":["../../../../src/mcp/builtin/collections/authTools.ts"],"names":[],"mappings":"AAiCA,eAAO,MAAM,kBAAkB,4CAqC7B,CAAA;AAEF,eAAO,MAAM,4BAA4B,4CAuCvC,CAAA;AAEF,eAAO,MAAM,mBAAmB,4CAiD9B,CAAA;AAEF,eAAO,MAAM,2BAA2B,4CAmCtC,CAAA;AAEF,eAAO,MAAM,oBAAoB,4CAgC/B,CAAA;AAEF,eAAO,MAAM,oBAAoB,4CAiC/B,CAAA"}
@@ -0,0 +1,288 @@
1
+ import { z } from 'zod';
2
+ import { defineCollectionTool } from '../../../defineTool.js';
3
+ import { getLogger } from '../../../utils/getLogger.js';
4
+ /**
5
+ * Auth tools surfaced under `collections.<auth-collection>.tools`. Opt-in: they
6
+ * default off (an LLM with `login` access can probe passwords; not something
7
+ * to expose by default). Enable in plugin config via `tools: { login: true }`
8
+ * (or `{ description: '...' }`).
9
+ *
10
+ * `auth` (check current token) doesn't actually depend on the collection at
11
+ * runtime — `payload.auth({ headers })` is global — but it's grouped under the
12
+ * users collection so all auth-shaped tools live in one place.
13
+ */ const emailSchema = z.string().email().describe('The user email address');
14
+ const wrapError = (name)=>({ collectionSlug, message })=>{
15
+ return {
16
+ content: [
17
+ {
18
+ type: 'text',
19
+ text: `❌ **Error in ${name}** on ${collectionSlug}: ${message}`
20
+ }
21
+ ]
22
+ };
23
+ };
24
+ export const authCollectionTool = defineCollectionTool({
25
+ annotations: {
26
+ destructiveHint: false,
27
+ idempotentHint: true,
28
+ openWorldHint: false,
29
+ readOnlyHint: true,
30
+ title: 'Check Auth Status'
31
+ },
32
+ description: 'Checks authentication status for the current user.',
33
+ input: z.object({
34
+ headers: z.record(z.string(), z.string()).describe('Optional custom headers to send with the authentication request').optional()
35
+ })
36
+ }).handler(async ({ collectionSlug, input, req })=>{
37
+ const logger = getLogger({
38
+ payload: req.payload
39
+ });
40
+ try {
41
+ let authHeaders = new Headers();
42
+ if (input.headers) {
43
+ authHeaders = new Headers(input.headers);
44
+ }
45
+ const result = await req.payload.auth({
46
+ headers: authHeaders
47
+ });
48
+ return {
49
+ content: [
50
+ {
51
+ type: 'text',
52
+ text: `# Authentication Status\n\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 in auth tool on ${collectionSlug}: ${errorMessage}`);
60
+ return wrapError('auth')({
61
+ collectionSlug,
62
+ message: errorMessage
63
+ });
64
+ }
65
+ });
66
+ export const forgotPasswordCollectionTool = defineCollectionTool({
67
+ annotations: {
68
+ destructiveHint: false,
69
+ idempotentHint: false,
70
+ openWorldHint: true,
71
+ readOnlyHint: false,
72
+ title: 'Forgot Password'
73
+ },
74
+ description: 'Sends a password reset email to a user.',
75
+ input: z.object({
76
+ disableEmail: z.boolean().describe('Whether to disable sending the email (for testing)').optional().default(false),
77
+ email: emailSchema
78
+ })
79
+ }).handler(async ({ collectionSlug, input, req })=>{
80
+ const logger = getLogger({
81
+ payload: req.payload
82
+ });
83
+ try {
84
+ const result = await req.payload.forgotPassword({
85
+ collection: collectionSlug,
86
+ data: {
87
+ email: input.email
88
+ },
89
+ disableEmail: input.disableEmail
90
+ });
91
+ return {
92
+ content: [
93
+ {
94
+ type: 'text',
95
+ text: `# Forgot Password Email Sent\n\n**Collection:** ${collectionSlug}\n**Email:** ${input.email}\n\n\`\`\`json\n${JSON.stringify(result)}\n\`\`\``
96
+ }
97
+ ],
98
+ doc: {
99
+ result
100
+ }
101
+ };
102
+ } catch (error) {
103
+ const errorMessage = error instanceof Error ? error.message : 'Unknown error';
104
+ logger.error(`Error in forgotPassword tool on ${collectionSlug}: ${errorMessage}`);
105
+ return wrapError('forgotPassword')({
106
+ collectionSlug,
107
+ message: errorMessage
108
+ });
109
+ }
110
+ });
111
+ export const loginCollectionTool = defineCollectionTool({
112
+ annotations: {
113
+ destructiveHint: false,
114
+ idempotentHint: false,
115
+ openWorldHint: false,
116
+ readOnlyHint: false,
117
+ title: 'User Login'
118
+ },
119
+ description: 'Authenticates a user with email and password.',
120
+ input: z.object({
121
+ depth: z.number().int().min(0).max(10).describe('Depth of population for relationships').optional().default(0),
122
+ email: emailSchema,
123
+ password: z.string().describe('The user password'),
124
+ showHiddenFields: z.boolean().describe('Whether to show hidden fields in the response').optional().default(false)
125
+ })
126
+ }).handler(async ({ collectionSlug, input, req })=>{
127
+ const logger = getLogger({
128
+ payload: req.payload
129
+ });
130
+ try {
131
+ const result = await req.payload.login({
132
+ collection: collectionSlug,
133
+ data: {
134
+ email: input.email,
135
+ password: input.password
136
+ },
137
+ depth: input.depth,
138
+ showHiddenFields: input.showHiddenFields
139
+ });
140
+ return {
141
+ content: [
142
+ {
143
+ type: 'text',
144
+ text: `# Login Successful\n\n**User:** ${input.email}\n**Collection:** ${collectionSlug}\n\n\`\`\`json\n${JSON.stringify(result)}\n\`\`\``
145
+ }
146
+ ],
147
+ doc: result
148
+ };
149
+ } catch (error) {
150
+ const errorMessage = error instanceof Error ? error.message : 'Unknown error';
151
+ logger.error(`Error in login tool on ${collectionSlug}: ${errorMessage}`);
152
+ return wrapError('login')({
153
+ collectionSlug,
154
+ message: errorMessage
155
+ });
156
+ }
157
+ });
158
+ export const resetPasswordCollectionTool = defineCollectionTool({
159
+ annotations: {
160
+ destructiveHint: false,
161
+ idempotentHint: false,
162
+ openWorldHint: false,
163
+ readOnlyHint: false,
164
+ title: 'Reset Password'
165
+ },
166
+ description: 'Resets a user password with a reset token.',
167
+ input: z.object({
168
+ password: z.string().describe('The new password for the user'),
169
+ token: z.string().describe('The password reset token sent to the user email')
170
+ })
171
+ }).handler(async ({ collectionSlug, input, req })=>{
172
+ const logger = getLogger({
173
+ payload: req.payload
174
+ });
175
+ try {
176
+ const result = await req.payload.resetPassword({
177
+ collection: collectionSlug,
178
+ data: {
179
+ password: input.password,
180
+ token: input.token
181
+ },
182
+ overrideAccess: true
183
+ });
184
+ return {
185
+ content: [
186
+ {
187
+ type: 'text',
188
+ text: `# Password Reset Successful\n\n**Collection:** ${collectionSlug}\n\n\`\`\`json\n${JSON.stringify(result)}\n\`\`\``
189
+ }
190
+ ],
191
+ doc: result
192
+ };
193
+ } catch (error) {
194
+ const errorMessage = error instanceof Error ? error.message : 'Unknown error';
195
+ logger.error(`Error in resetPassword tool on ${collectionSlug}: ${errorMessage}`);
196
+ return wrapError('resetPassword')({
197
+ collectionSlug,
198
+ message: errorMessage
199
+ });
200
+ }
201
+ });
202
+ export const unlockCollectionTool = defineCollectionTool({
203
+ annotations: {
204
+ destructiveHint: false,
205
+ idempotentHint: true,
206
+ openWorldHint: false,
207
+ readOnlyHint: false,
208
+ title: 'Unlock Account'
209
+ },
210
+ description: 'Unlocks a user account that has been locked due to failed login attempts.',
211
+ input: z.object({
212
+ email: emailSchema
213
+ })
214
+ }).handler(async ({ collectionSlug, input, req })=>{
215
+ const logger = getLogger({
216
+ payload: req.payload
217
+ });
218
+ try {
219
+ const result = await req.payload.unlock({
220
+ collection: collectionSlug,
221
+ data: {
222
+ email: input.email
223
+ },
224
+ overrideAccess: true
225
+ });
226
+ return {
227
+ content: [
228
+ {
229
+ type: 'text',
230
+ text: `# Account Unlocked\n\n**Collection:** ${collectionSlug}\n**Email:** ${input.email}\n**Result:** ${result ? 'Success' : 'Failed'}`
231
+ }
232
+ ],
233
+ doc: {
234
+ result
235
+ }
236
+ };
237
+ } catch (error) {
238
+ const errorMessage = error instanceof Error ? error.message : 'Unknown error';
239
+ logger.error(`Error in unlock tool on ${collectionSlug}: ${errorMessage}`);
240
+ return wrapError('unlock')({
241
+ collectionSlug,
242
+ message: errorMessage
243
+ });
244
+ }
245
+ });
246
+ export const verifyCollectionTool = defineCollectionTool({
247
+ annotations: {
248
+ destructiveHint: false,
249
+ idempotentHint: false,
250
+ openWorldHint: false,
251
+ readOnlyHint: false,
252
+ title: 'Email Verification'
253
+ },
254
+ description: 'Verifies a user email with a verification token.',
255
+ input: z.object({
256
+ token: z.string().describe('The verification token sent to the user email')
257
+ })
258
+ }).handler(async ({ collectionSlug, input, req })=>{
259
+ const logger = getLogger({
260
+ payload: req.payload
261
+ });
262
+ try {
263
+ const result = await req.payload.verifyEmail({
264
+ collection: collectionSlug,
265
+ token: input.token
266
+ });
267
+ return {
268
+ content: [
269
+ {
270
+ type: 'text',
271
+ text: `# Email Verification Successful\n\n**Collection:** ${collectionSlug}\n**Result:** ${result ? 'Success' : 'Failed'}`
272
+ }
273
+ ],
274
+ doc: {
275
+ result
276
+ }
277
+ };
278
+ } catch (error) {
279
+ const errorMessage = error instanceof Error ? error.message : 'Unknown error';
280
+ logger.error(`Error in verify tool on ${collectionSlug}: ${errorMessage}`);
281
+ return wrapError('verify')({
282
+ collectionSlug,
283
+ message: errorMessage
284
+ });
285
+ }
286
+ });
287
+
288
+ //# sourceMappingURL=authTools.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/mcp/builtin/collections/authTools.ts"],"sourcesContent":["import { z } from 'zod'\n\nimport type { MCPToolResponse } from '../../../types.js'\n\nimport { defineCollectionTool } from '../../../defineTool.js'\nimport { getLogger } from '../../../utils/getLogger.js'\n\n/**\n * Auth tools surfaced under `collections.<auth-collection>.tools`. Opt-in: they\n * default off (an LLM with `login` access can probe passwords; not something\n * to expose by default). Enable in plugin config via `tools: { login: true }`\n * (or `{ description: '...' }`).\n *\n * `auth` (check current token) doesn't actually depend on the collection at\n * runtime — `payload.auth({ headers })` is global — but it's grouped under the\n * users collection so all auth-shaped tools live in one place.\n */\n\nconst emailSchema = z.string().email().describe('The user email address')\n\nconst wrapError =\n (name: string) =>\n ({ collectionSlug, message }: { collectionSlug: string; message: string }): MCPToolResponse => {\n return {\n content: [\n {\n type: 'text',\n text: `❌ **Error in ${name}** on ${collectionSlug}: ${message}`,\n },\n ],\n }\n }\n\nexport const authCollectionTool = defineCollectionTool({\n annotations: {\n destructiveHint: false,\n idempotentHint: true,\n openWorldHint: false,\n readOnlyHint: true,\n title: 'Check Auth Status',\n },\n description: 'Checks authentication status for the current user.',\n input: z.object({\n headers: z\n .record(z.string(), z.string())\n .describe('Optional custom headers to send with the authentication request')\n .optional(),\n }),\n}).handler(async ({ collectionSlug, input, req }) => {\n const logger = getLogger({ payload: req.payload })\n try {\n let authHeaders = new Headers()\n if (input.headers) {\n authHeaders = new Headers(input.headers)\n }\n const result = await req.payload.auth({ headers: authHeaders })\n return {\n content: [\n {\n type: 'text',\n text: `# Authentication Status\\n\\n\\`\\`\\`json\\n${JSON.stringify(result)}\\n\\`\\`\\``,\n },\n ],\n doc: result as unknown as Record<string, unknown>,\n }\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : 'Unknown error'\n logger.error(`Error in auth tool on ${collectionSlug}: ${errorMessage}`)\n return wrapError('auth')({ collectionSlug, message: errorMessage })\n }\n})\n\nexport const forgotPasswordCollectionTool = defineCollectionTool({\n annotations: {\n destructiveHint: false,\n idempotentHint: false,\n openWorldHint: true,\n readOnlyHint: false,\n title: 'Forgot Password',\n },\n description: 'Sends a password reset email to a user.',\n input: z.object({\n disableEmail: z\n .boolean()\n .describe('Whether to disable sending the email (for testing)')\n .optional()\n .default(false),\n email: emailSchema,\n }),\n}).handler(async ({ collectionSlug, input, req }) => {\n const logger = getLogger({ payload: req.payload })\n try {\n const result = await req.payload.forgotPassword({\n collection: collectionSlug,\n data: { email: input.email },\n disableEmail: input.disableEmail,\n })\n return {\n content: [\n {\n type: 'text',\n text: `# Forgot Password Email Sent\\n\\n**Collection:** ${collectionSlug}\\n**Email:** ${input.email}\\n\\n\\`\\`\\`json\\n${JSON.stringify(result)}\\n\\`\\`\\``,\n },\n ],\n doc: { result } as Record<string, unknown>,\n }\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : 'Unknown error'\n logger.error(`Error in forgotPassword tool on ${collectionSlug}: ${errorMessage}`)\n return wrapError('forgotPassword')({ collectionSlug, message: errorMessage })\n }\n})\n\nexport const loginCollectionTool = defineCollectionTool({\n annotations: {\n destructiveHint: false,\n idempotentHint: false,\n openWorldHint: false,\n readOnlyHint: false,\n title: 'User Login',\n },\n description: 'Authenticates a user with email and password.',\n input: z.object({\n depth: z\n .number()\n .int()\n .min(0)\n .max(10)\n .describe('Depth of population for relationships')\n .optional()\n .default(0),\n email: emailSchema,\n password: z.string().describe('The user password'),\n showHiddenFields: z\n .boolean()\n .describe('Whether to show hidden fields in the response')\n .optional()\n .default(false),\n }),\n}).handler(async ({ collectionSlug, input, req }) => {\n const logger = getLogger({ payload: req.payload })\n try {\n const result = await req.payload.login({\n collection: collectionSlug,\n data: { email: input.email, password: input.password },\n depth: input.depth,\n showHiddenFields: input.showHiddenFields,\n })\n return {\n content: [\n {\n type: 'text',\n text: `# Login Successful\\n\\n**User:** ${input.email}\\n**Collection:** ${collectionSlug}\\n\\n\\`\\`\\`json\\n${JSON.stringify(result)}\\n\\`\\`\\``,\n },\n ],\n doc: result as unknown as Record<string, unknown>,\n }\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : 'Unknown error'\n logger.error(`Error in login tool on ${collectionSlug}: ${errorMessage}`)\n return wrapError('login')({ collectionSlug, message: errorMessage })\n }\n})\n\nexport const resetPasswordCollectionTool = defineCollectionTool({\n annotations: {\n destructiveHint: false,\n idempotentHint: false,\n openWorldHint: false,\n readOnlyHint: false,\n title: 'Reset Password',\n },\n description: 'Resets a user password with a reset token.',\n input: z.object({\n password: z.string().describe('The new password for the user'),\n token: z.string().describe('The password reset token sent to the user email'),\n }),\n}).handler(async ({ collectionSlug, input, req }) => {\n const logger = getLogger({ payload: req.payload })\n try {\n const result = await req.payload.resetPassword({\n collection: collectionSlug,\n data: { password: input.password, token: input.token },\n overrideAccess: true,\n })\n return {\n content: [\n {\n type: 'text',\n text: `# Password Reset Successful\\n\\n**Collection:** ${collectionSlug}\\n\\n\\`\\`\\`json\\n${JSON.stringify(result)}\\n\\`\\`\\``,\n },\n ],\n doc: result as unknown as Record<string, unknown>,\n }\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : 'Unknown error'\n logger.error(`Error in resetPassword tool on ${collectionSlug}: ${errorMessage}`)\n return wrapError('resetPassword')({ collectionSlug, message: errorMessage })\n }\n})\n\nexport const unlockCollectionTool = defineCollectionTool({\n annotations: {\n destructiveHint: false,\n idempotentHint: true,\n openWorldHint: false,\n readOnlyHint: false,\n title: 'Unlock Account',\n },\n description: 'Unlocks a user account that has been locked due to failed login attempts.',\n input: z.object({ email: emailSchema }),\n}).handler(async ({ collectionSlug, input, req }) => {\n const logger = getLogger({ payload: req.payload })\n try {\n const result = await req.payload.unlock({\n collection: collectionSlug,\n data: { email: input.email },\n overrideAccess: true,\n })\n return {\n content: [\n {\n type: 'text',\n text: `# Account Unlocked\\n\\n**Collection:** ${collectionSlug}\\n**Email:** ${input.email}\\n**Result:** ${result ? 'Success' : 'Failed'}`,\n },\n ],\n doc: { result } as Record<string, unknown>,\n }\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : 'Unknown error'\n logger.error(`Error in unlock tool on ${collectionSlug}: ${errorMessage}`)\n return wrapError('unlock')({ collectionSlug, message: errorMessage })\n }\n})\n\nexport const verifyCollectionTool = defineCollectionTool({\n annotations: {\n destructiveHint: false,\n idempotentHint: false,\n openWorldHint: false,\n readOnlyHint: false,\n title: 'Email Verification',\n },\n description: 'Verifies a user email with a verification token.',\n input: z.object({\n token: z.string().describe('The verification token sent to the user email'),\n }),\n}).handler(async ({ collectionSlug, input, req }) => {\n const logger = getLogger({ payload: req.payload })\n try {\n const result = await req.payload.verifyEmail({\n collection: collectionSlug,\n token: input.token,\n })\n return {\n content: [\n {\n type: 'text',\n text: `# Email Verification Successful\\n\\n**Collection:** ${collectionSlug}\\n**Result:** ${result ? 'Success' : 'Failed'}`,\n },\n ],\n doc: { result } as Record<string, unknown>,\n }\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : 'Unknown error'\n logger.error(`Error in verify tool on ${collectionSlug}: ${errorMessage}`)\n return wrapError('verify')({ collectionSlug, message: errorMessage })\n }\n})\n"],"names":["z","defineCollectionTool","getLogger","emailSchema","string","email","describe","wrapError","name","collectionSlug","message","content","type","text","authCollectionTool","annotations","destructiveHint","idempotentHint","openWorldHint","readOnlyHint","title","description","input","object","headers","record","optional","handler","req","logger","payload","authHeaders","Headers","result","auth","JSON","stringify","doc","error","errorMessage","Error","forgotPasswordCollectionTool","disableEmail","boolean","default","forgotPassword","collection","data","loginCollectionTool","depth","number","int","min","max","password","showHiddenFields","login","resetPasswordCollectionTool","token","resetPassword","overrideAccess","unlockCollectionTool","unlock","verifyCollectionTool","verifyEmail"],"mappings":"AAAA,SAASA,CAAC,QAAQ,MAAK;AAIvB,SAASC,oBAAoB,QAAQ,yBAAwB;AAC7D,SAASC,SAAS,QAAQ,8BAA6B;AAEvD;;;;;;;;;CASC,GAED,MAAMC,cAAcH,EAAEI,MAAM,GAAGC,KAAK,GAAGC,QAAQ,CAAC;AAEhD,MAAMC,YACJ,CAACC,OACD,CAAC,EAAEC,cAAc,EAAEC,OAAO,EAA+C;QACvE,OAAO;YACLC,SAAS;gBACP;oBACEC,MAAM;oBACNC,MAAM,CAAC,aAAa,EAAEL,KAAK,MAAM,EAAEC,eAAe,EAAE,EAAEC,SAAS;gBACjE;aACD;QACH;IACF;AAEF,OAAO,MAAMI,qBAAqBb,qBAAqB;IACrDc,aAAa;QACXC,iBAAiB;QACjBC,gBAAgB;QAChBC,eAAe;QACfC,cAAc;QACdC,OAAO;IACT;IACAC,aAAa;IACbC,OAAOtB,EAAEuB,MAAM,CAAC;QACdC,SAASxB,EACNyB,MAAM,CAACzB,EAAEI,MAAM,IAAIJ,EAAEI,MAAM,IAC3BE,QAAQ,CAAC,mEACToB,QAAQ;IACb;AACF,GAAGC,OAAO,CAAC,OAAO,EAAElB,cAAc,EAAEa,KAAK,EAAEM,GAAG,EAAE;IAC9C,MAAMC,SAAS3B,UAAU;QAAE4B,SAASF,IAAIE,OAAO;IAAC;IAChD,IAAI;QACF,IAAIC,cAAc,IAAIC;QACtB,IAAIV,M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ACAC,aAAa;IACbC,OAAOtB,EAAEuB,MAAM,CAAC;QACdmC,OAAO1D,EAAEI,MAAM,GAAGE,QAAQ,CAAC;IAC7B;AACF,GAAGqB,OAAO,CAAC,OAAO,EAAElB,cAAc,EAAEa,KAAK,EAAEM,GAAG,EAAE;IAC9C,MAAMC,SAAS3B,UAAU;QAAE4B,SAASF,IAAIE,OAAO;IAAC;IAChD,IAAI;QACF,MAAMG,SAAS,MAAML,IAAIE,OAAO,CAACkC,WAAW,CAAC;YAC3ClB,YAAYrC;YACZiD,OAAOpC,MAAMoC,KAAK;QACpB;QACA,OAAO;YACL/C,SAAS;gBACP;oBACEC,MAAM;oBACNC,MAAM,CAAC,mDAAmD,EAAEJ,eAAe,cAAc,EAAEwB,SAAS,YAAY,UAAU;gBAC5H;aACD;YACDI,KAAK;gBAAEJ;YAAO;QAChB;IACF,EAAE,OAAOK,OAAO;QACd,MAAMC,eAAeD,iBAAiBE,QAAQF,MAAM5B,OAAO,GAAG;QAC9DmB,OAAOS,KAAK,CAAC,CAAC,wBAAwB,EAAE7B,eAAe,EAAE,EAAE8B,cAAc;QACzE,OAAOhC,UAAU,UAAU;YAAEE;YAAgBC,SAAS6B;QAAa;IACrE;AACF,GAAE"}
@@ -0,0 +1,2 @@
1
+ export declare const countDocumentsTool: import("../../../types.js").CollectionTool;
2
+ //# sourceMappingURL=countTool.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"countTool.d.ts","sourceRoot":"","sources":["../../../../src/mcp/builtin/collections/countTool.ts"],"names":[],"mappings":"AAUA,eAAO,MAAM,kBAAkB,4CA8D7B,CAAA"}