@payloadcms/plugin-mcp 4.0.0-internal.d28e9fb → 4.0.0-internal.d927017

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 (432) hide show
  1. package/LICENSE.md +1 -1
  2. package/bin.js +48 -0
  3. package/dist/bin/index.d.ts +2 -0
  4. package/dist/bin/index.d.ts.map +1 -0
  5. package/dist/bin/index.js +12 -0
  6. package/dist/bin/index.js.map +1 -0
  7. package/dist/bin/initializeViteHMR.d.ts +8 -0
  8. package/dist/bin/initializeViteHMR.d.ts.map +1 -0
  9. package/dist/bin/initializeViteHMR.js +63 -0
  10. package/dist/bin/initializeViteHMR.js.map +1 -0
  11. package/dist/bin/viteConfigBoundary.d.ts +6 -0
  12. package/dist/bin/viteConfigBoundary.d.ts.map +1 -0
  13. package/dist/bin/viteConfigBoundary.js +25 -0
  14. package/dist/bin/viteConfigBoundary.js.map +1 -0
  15. package/dist/defaultAccess.d.ts +3 -0
  16. package/dist/defaultAccess.d.ts.map +1 -0
  17. package/dist/defaultAccess.js +3 -0
  18. package/dist/defaultAccess.js.map +1 -0
  19. package/dist/defineTool.d.ts +26 -0
  20. package/dist/defineTool.d.ts.map +1 -0
  21. package/dist/defineTool.js +37 -0
  22. package/dist/defineTool.js.map +1 -0
  23. package/dist/endpoint/access.d.ts +17 -0
  24. package/dist/endpoint/access.d.ts.map +1 -0
  25. package/dist/endpoint/access.js +93 -0
  26. package/dist/endpoint/access.js.map +1 -0
  27. package/dist/endpoint/index.d.ts +3 -0
  28. package/dist/endpoint/index.d.ts.map +1 -0
  29. package/dist/endpoint/index.js +87 -0
  30. package/dist/endpoint/index.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/index.d.ts +6 -9
  40. package/dist/index.d.ts.map +1 -1
  41. package/dist/index.js +39 -67
  42. package/dist/index.js.map +1 -1
  43. package/dist/mcp/buildMcpServer.d.ts +19 -0
  44. package/dist/mcp/buildMcpServer.d.ts.map +1 -0
  45. package/dist/mcp/buildMcpServer.js +223 -0
  46. package/dist/mcp/buildMcpServer.js.map +1 -0
  47. package/dist/mcp/builtin/collections/authTools.d.ts +7 -0
  48. package/dist/mcp/builtin/collections/authTools.d.ts.map +1 -0
  49. package/dist/mcp/builtin/collections/authTools.js +288 -0
  50. package/dist/mcp/builtin/collections/authTools.js.map +1 -0
  51. package/dist/mcp/builtin/collections/countTool.d.ts +2 -0
  52. package/dist/mcp/builtin/collections/countTool.d.ts.map +1 -0
  53. package/dist/mcp/builtin/collections/countTool.js +68 -0
  54. package/dist/mcp/builtin/collections/countTool.js.map +1 -0
  55. package/dist/mcp/builtin/collections/countVersionsTool.d.ts +2 -0
  56. package/dist/mcp/builtin/collections/countVersionsTool.d.ts.map +1 -0
  57. package/dist/mcp/builtin/collections/countVersionsTool.js +64 -0
  58. package/dist/mcp/builtin/collections/countVersionsTool.js.map +1 -0
  59. package/dist/mcp/builtin/collections/createTool.d.ts +2 -0
  60. package/dist/mcp/builtin/collections/createTool.d.ts.map +1 -0
  61. package/dist/mcp/builtin/collections/createTool.js +86 -0
  62. package/dist/mcp/builtin/collections/createTool.js.map +1 -0
  63. package/dist/mcp/builtin/collections/deleteTool.d.ts +2 -0
  64. package/dist/mcp/builtin/collections/deleteTool.d.ts.map +1 -0
  65. package/dist/mcp/builtin/collections/deleteTool.js +110 -0
  66. package/dist/mcp/builtin/collections/deleteTool.js.map +1 -0
  67. package/dist/mcp/builtin/collections/duplicateTool.d.ts +2 -0
  68. package/dist/mcp/builtin/collections/duplicateTool.d.ts.map +1 -0
  69. package/dist/mcp/builtin/collections/duplicateTool.js +96 -0
  70. package/dist/mcp/builtin/collections/duplicateTool.js.map +1 -0
  71. package/dist/mcp/builtin/collections/findDistinctTool.d.ts +2 -0
  72. package/dist/mcp/builtin/collections/findDistinctTool.d.ts.map +1 -0
  73. package/dist/mcp/builtin/collections/findDistinctTool.js +92 -0
  74. package/dist/mcp/builtin/collections/findDistinctTool.js.map +1 -0
  75. package/dist/mcp/builtin/collections/findTool.d.ts +2 -0
  76. package/dist/mcp/builtin/collections/findTool.d.ts.map +1 -0
  77. package/dist/mcp/builtin/collections/findTool.js +164 -0
  78. package/dist/mcp/builtin/collections/findTool.js.map +1 -0
  79. package/dist/mcp/builtin/collections/findVersionByIDTool.d.ts +2 -0
  80. package/dist/mcp/builtin/collections/findVersionByIDTool.d.ts.map +1 -0
  81. package/dist/mcp/builtin/collections/findVersionByIDTool.js +83 -0
  82. package/dist/mcp/builtin/collections/findVersionByIDTool.js.map +1 -0
  83. package/dist/mcp/builtin/collections/findVersionsTool.d.ts +2 -0
  84. package/dist/mcp/builtin/collections/findVersionsTool.d.ts.map +1 -0
  85. package/dist/mcp/builtin/collections/findVersionsTool.js +98 -0
  86. package/dist/mcp/builtin/collections/findVersionsTool.js.map +1 -0
  87. package/dist/mcp/builtin/collections/formatCollectionError.d.ts +9 -0
  88. package/dist/mcp/builtin/collections/formatCollectionError.d.ts.map +1 -0
  89. package/dist/mcp/builtin/collections/formatCollectionError.js +60 -0
  90. package/dist/mcp/builtin/collections/formatCollectionError.js.map +1 -0
  91. package/dist/mcp/builtin/collections/getCollectionSchemaTool.d.ts +2 -0
  92. package/dist/mcp/builtin/collections/getCollectionSchemaTool.d.ts.map +1 -0
  93. package/dist/mcp/builtin/collections/getCollectionSchemaTool.js +65 -0
  94. package/dist/mcp/builtin/collections/getCollectionSchemaTool.js.map +1 -0
  95. package/dist/mcp/builtin/collections/restoreVersionTool.d.ts +2 -0
  96. package/dist/mcp/builtin/collections/restoreVersionTool.d.ts.map +1 -0
  97. package/dist/mcp/builtin/collections/restoreVersionTool.js +81 -0
  98. package/dist/mcp/builtin/collections/restoreVersionTool.js.map +1 -0
  99. package/dist/mcp/builtin/collections/updateTool.d.ts +2 -0
  100. package/dist/mcp/builtin/collections/updateTool.d.ts.map +1 -0
  101. package/dist/mcp/builtin/collections/updateTool.js +198 -0
  102. package/dist/mcp/builtin/collections/updateTool.js.map +1 -0
  103. package/dist/mcp/builtin/getConfigInfoTool.d.ts +2 -0
  104. package/dist/mcp/builtin/getConfigInfoTool.d.ts.map +1 -0
  105. package/dist/mcp/builtin/getConfigInfoTool.js +68 -0
  106. package/dist/mcp/builtin/getConfigInfoTool.js.map +1 -0
  107. package/dist/mcp/builtin/globals/countVersionsTool.d.ts +2 -0
  108. package/dist/mcp/builtin/globals/countVersionsTool.d.ts.map +1 -0
  109. package/dist/mcp/builtin/globals/countVersionsTool.js +64 -0
  110. package/dist/mcp/builtin/globals/countVersionsTool.js.map +1 -0
  111. package/dist/mcp/builtin/globals/findTool.d.ts +2 -0
  112. package/dist/mcp/builtin/globals/findTool.d.ts.map +1 -0
  113. package/dist/mcp/builtin/globals/findTool.js +73 -0
  114. package/dist/mcp/builtin/globals/findTool.js.map +1 -0
  115. package/dist/mcp/builtin/globals/findVersionByIDTool.d.ts +2 -0
  116. package/dist/mcp/builtin/globals/findVersionByIDTool.d.ts.map +1 -0
  117. package/dist/mcp/builtin/globals/findVersionByIDTool.js +79 -0
  118. package/dist/mcp/builtin/globals/findVersionByIDTool.js.map +1 -0
  119. package/dist/mcp/builtin/globals/findVersionsTool.d.ts +2 -0
  120. package/dist/mcp/builtin/globals/findVersionsTool.d.ts.map +1 -0
  121. package/dist/mcp/builtin/globals/findVersionsTool.js +94 -0
  122. package/dist/mcp/builtin/globals/findVersionsTool.js.map +1 -0
  123. package/dist/mcp/builtin/globals/getGlobalSchemaTool.d.ts +2 -0
  124. package/dist/mcp/builtin/globals/getGlobalSchemaTool.d.ts.map +1 -0
  125. package/dist/mcp/builtin/globals/getGlobalSchemaTool.js +65 -0
  126. package/dist/mcp/builtin/globals/getGlobalSchemaTool.js.map +1 -0
  127. package/dist/mcp/builtin/globals/restoreVersionTool.d.ts +2 -0
  128. package/dist/mcp/builtin/globals/restoreVersionTool.d.ts.map +1 -0
  129. package/dist/mcp/builtin/globals/restoreVersionTool.js +77 -0
  130. package/dist/mcp/builtin/globals/restoreVersionTool.js.map +1 -0
  131. package/dist/mcp/builtin/globals/updateTool.d.ts +2 -0
  132. package/dist/mcp/builtin/globals/updateTool.d.ts.map +1 -0
  133. package/dist/mcp/builtin/globals/updateTool.js +87 -0
  134. package/dist/mcp/builtin/globals/updateTool.js.map +1 -0
  135. package/dist/mcp/builtin/validateEntityData.d.ts +14 -0
  136. package/dist/mcp/builtin/validateEntityData.d.ts.map +1 -0
  137. package/dist/mcp/builtin/validateEntityData.js +82 -0
  138. package/dist/mcp/builtin/validateEntityData.js.map +1 -0
  139. package/dist/mcp/builtinTools.d.ts +162 -0
  140. package/dist/mcp/builtinTools.d.ts.map +1 -0
  141. package/dist/mcp/builtinTools.js +163 -0
  142. package/dist/mcp/builtinTools.js.map +1 -0
  143. package/dist/mcp/sanitizeMCPConfig.d.ts +16 -0
  144. package/dist/mcp/sanitizeMCPConfig.d.ts.map +1 -0
  145. package/dist/mcp/sanitizeMCPConfig.js +230 -0
  146. package/dist/mcp/sanitizeMCPConfig.js.map +1 -0
  147. package/dist/stdio.d.ts +9 -0
  148. package/dist/stdio.d.ts.map +1 -0
  149. package/dist/stdio.js +127 -0
  150. package/dist/stdio.js.map +1 -0
  151. package/dist/types.d.ts +256 -447
  152. package/dist/types.d.ts.map +1 -1
  153. package/dist/types.js +4 -1
  154. package/dist/types.js.map +1 -1
  155. package/dist/utils/camelCase.d.ts.map +1 -1
  156. package/dist/utils/getLogger.d.ts +10 -0
  157. package/dist/utils/getLogger.d.ts.map +1 -0
  158. package/dist/utils/getLogger.js +22 -0
  159. package/dist/utils/getLogger.js.map +1 -0
  160. package/dist/utils/getPluginConfig.d.ts +12 -0
  161. package/dist/utils/getPluginConfig.d.ts.map +1 -0
  162. package/dist/utils/getPluginConfig.js +15 -0
  163. package/dist/utils/getPluginConfig.js.map +1 -0
  164. package/dist/utils/resolveProjectRoot.d.ts +7 -0
  165. package/dist/utils/resolveProjectRoot.d.ts.map +1 -0
  166. package/dist/utils/resolveProjectRoot.js +15 -0
  167. package/dist/utils/resolveProjectRoot.js.map +1 -0
  168. package/dist/utils/schemaConversion/filterFieldsByAccess.d.ts +28 -0
  169. package/dist/utils/schemaConversion/filterFieldsByAccess.d.ts.map +1 -0
  170. package/dist/utils/schemaConversion/filterFieldsByAccess.js +71 -0
  171. package/dist/utils/schemaConversion/filterFieldsByAccess.js.map +1 -0
  172. package/dist/utils/schemaConversion/getEntityInputSchema.d.ts +13 -0
  173. package/dist/utils/schemaConversion/getEntityInputSchema.d.ts.map +1 -0
  174. package/dist/utils/schemaConversion/getEntityInputSchema.js +66 -0
  175. package/dist/utils/schemaConversion/getEntityInputSchema.js.map +1 -0
  176. package/dist/utils/schemaConversion/sanitizeEntitySchema.d.ts +10 -0
  177. package/dist/utils/schemaConversion/sanitizeEntitySchema.d.ts.map +1 -0
  178. package/dist/utils/schemaConversion/sanitizeEntitySchema.js +384 -0
  179. package/dist/utils/schemaConversion/sanitizeEntitySchema.js.map +1 -0
  180. package/dist/utils/schemaConversion/sanitizeEntitySchema.spec.js +133 -0
  181. package/dist/utils/schemaConversion/sanitizeEntitySchema.spec.js.map +1 -0
  182. package/dist/utils/toStandardSchema.d.ts +5 -0
  183. package/dist/utils/toStandardSchema.d.ts.map +1 -0
  184. package/dist/utils/toStandardSchema.js +4 -0
  185. package/dist/utils/toStandardSchema.js.map +1 -0
  186. package/dist/utils/whereSchema.d.ts +9 -0
  187. package/dist/utils/whereSchema.d.ts.map +1 -0
  188. package/dist/utils/whereSchema.js +13 -0
  189. package/dist/utils/whereSchema.js.map +1 -0
  190. package/package.json +43 -10
  191. package/src/bin/index.ts +16 -0
  192. package/src/bin/initializeViteHMR.ts +60 -0
  193. package/src/bin/viteConfigBoundary.ts +39 -0
  194. package/src/defaultAccess.ts +3 -0
  195. package/src/defineTool.ts +44 -0
  196. package/src/endpoint/access.ts +112 -0
  197. package/src/endpoint/index.ts +77 -0
  198. package/src/exports/client.ts +3 -0
  199. package/src/exports/internal.ts +1 -0
  200. package/src/index.ts +31 -89
  201. package/src/mcp/buildMcpServer.ts +284 -0
  202. package/src/mcp/builtin/collections/authTools.ts +269 -0
  203. package/src/mcp/builtin/collections/countTool.ts +73 -0
  204. package/src/mcp/builtin/collections/countVersionsTool.ts +69 -0
  205. package/src/mcp/builtin/collections/createTool.ts +117 -0
  206. package/src/mcp/builtin/collections/deleteTool.ts +125 -0
  207. package/src/mcp/builtin/collections/duplicateTool.ts +134 -0
  208. package/src/mcp/builtin/collections/findDistinctTool.ts +119 -0
  209. package/src/mcp/builtin/collections/findTool.ts +216 -0
  210. package/src/mcp/builtin/collections/findVersionByIDTool.ts +109 -0
  211. package/src/mcp/builtin/collections/findVersionsTool.ts +154 -0
  212. package/src/mcp/builtin/collections/formatCollectionError.ts +84 -0
  213. package/src/mcp/builtin/collections/getCollectionSchemaTool.ts +63 -0
  214. package/src/mcp/builtin/collections/restoreVersionTool.ts +107 -0
  215. package/src/mcp/builtin/collections/updateTool.ts +225 -0
  216. package/src/mcp/builtin/getConfigInfoTool.ts +67 -0
  217. package/src/mcp/builtin/globals/countVersionsTool.ts +68 -0
  218. package/src/mcp/builtin/globals/findTool.ts +105 -0
  219. package/src/mcp/builtin/globals/findVersionByIDTool.ts +103 -0
  220. package/src/mcp/builtin/globals/findVersionsTool.ts +147 -0
  221. package/src/mcp/builtin/globals/getGlobalSchemaTool.ts +63 -0
  222. package/src/mcp/builtin/globals/restoreVersionTool.ts +99 -0
  223. package/src/mcp/builtin/globals/updateTool.ts +115 -0
  224. package/src/mcp/builtin/validateEntityData.ts +132 -0
  225. package/src/mcp/builtinTools.ts +154 -0
  226. package/src/mcp/sanitizeMCPConfig.ts +278 -0
  227. package/src/stdio.ts +131 -0
  228. package/src/types.ts +304 -486
  229. package/src/utils/getLogger.ts +22 -0
  230. package/src/utils/getPluginConfig.ts +24 -0
  231. package/src/utils/resolveProjectRoot.ts +17 -0
  232. package/src/utils/schemaConversion/filterFieldsByAccess.ts +123 -0
  233. package/src/utils/schemaConversion/getEntityInputSchema.ts +96 -0
  234. package/src/utils/schemaConversion/sanitizeEntitySchema.spec.ts +96 -0
  235. package/src/utils/schemaConversion/sanitizeEntitySchema.ts +432 -0
  236. package/src/utils/toStandardSchema.ts +9 -0
  237. package/src/utils/whereSchema.ts +24 -0
  238. package/dist/collections/createApiKeysCollection.d.ts +0 -7
  239. package/dist/collections/createApiKeysCollection.d.ts.map +0 -1
  240. package/dist/collections/createApiKeysCollection.js +0 -317
  241. package/dist/collections/createApiKeysCollection.js.map +0 -1
  242. package/dist/defaults.d.ts +0 -4
  243. package/dist/defaults.d.ts.map +0 -1
  244. package/dist/defaults.js +0 -5
  245. package/dist/defaults.js.map +0 -1
  246. package/dist/endpoints/mcp.d.ts +0 -4
  247. package/dist/endpoints/mcp.d.ts.map +0 -1
  248. package/dist/endpoints/mcp.js +0 -71
  249. package/dist/endpoints/mcp.js.map +0 -1
  250. package/dist/mcp/createRequest.d.ts +0 -3
  251. package/dist/mcp/createRequest.d.ts.map +0 -1
  252. package/dist/mcp/createRequest.js +0 -14
  253. package/dist/mcp/createRequest.js.map +0 -1
  254. package/dist/mcp/getMcpHandler.d.ts +0 -4
  255. package/dist/mcp/getMcpHandler.d.ts.map +0 -1
  256. package/dist/mcp/getMcpHandler.js +0 -231
  257. package/dist/mcp/getMcpHandler.js.map +0 -1
  258. package/dist/mcp/helpers/config.d.ts +0 -22
  259. package/dist/mcp/helpers/config.d.ts.map +0 -1
  260. package/dist/mcp/helpers/config.js +0 -153
  261. package/dist/mcp/helpers/config.js.map +0 -1
  262. package/dist/mcp/helpers/fields.d.ts +0 -19
  263. package/dist/mcp/helpers/fields.d.ts.map +0 -1
  264. package/dist/mcp/helpers/fields.js +0 -102
  265. package/dist/mcp/helpers/fields.js.map +0 -1
  266. package/dist/mcp/helpers/fileValidation.d.ts +0 -67
  267. package/dist/mcp/helpers/fileValidation.d.ts.map +0 -1
  268. package/dist/mcp/helpers/fileValidation.js +0 -267
  269. package/dist/mcp/helpers/fileValidation.js.map +0 -1
  270. package/dist/mcp/registerTool.d.ts +0 -6
  271. package/dist/mcp/registerTool.d.ts.map +0 -1
  272. package/dist/mcp/registerTool.js +0 -18
  273. package/dist/mcp/registerTool.js.map +0 -1
  274. package/dist/mcp/tools/auth/auth.d.ts +0 -4
  275. package/dist/mcp/tools/auth/auth.d.ts.map +0 -1
  276. package/dist/mcp/tools/auth/auth.js +0 -57
  277. package/dist/mcp/tools/auth/auth.js.map +0 -1
  278. package/dist/mcp/tools/auth/forgotPassword.d.ts +0 -4
  279. package/dist/mcp/tools/auth/forgotPassword.d.ts.map +0 -1
  280. package/dist/mcp/tools/auth/forgotPassword.js +0 -48
  281. package/dist/mcp/tools/auth/forgotPassword.js.map +0 -1
  282. package/dist/mcp/tools/auth/login.d.ts +0 -4
  283. package/dist/mcp/tools/auth/login.d.ts.map +0 -1
  284. package/dist/mcp/tools/auth/login.js +0 -51
  285. package/dist/mcp/tools/auth/login.js.map +0 -1
  286. package/dist/mcp/tools/auth/resetPassword.d.ts +0 -4
  287. package/dist/mcp/tools/auth/resetPassword.d.ts.map +0 -1
  288. package/dist/mcp/tools/auth/resetPassword.js +0 -49
  289. package/dist/mcp/tools/auth/resetPassword.js.map +0 -1
  290. package/dist/mcp/tools/auth/unlock.d.ts +0 -4
  291. package/dist/mcp/tools/auth/unlock.d.ts.map +0 -1
  292. package/dist/mcp/tools/auth/unlock.js +0 -48
  293. package/dist/mcp/tools/auth/unlock.js.map +0 -1
  294. package/dist/mcp/tools/auth/verify.d.ts +0 -4
  295. package/dist/mcp/tools/auth/verify.d.ts.map +0 -1
  296. package/dist/mcp/tools/auth/verify.js +0 -45
  297. package/dist/mcp/tools/auth/verify.js.map +0 -1
  298. package/dist/mcp/tools/collection/create.d.ts +0 -10
  299. package/dist/mcp/tools/collection/create.d.ts.map +0 -1
  300. package/dist/mcp/tools/collection/create.js +0 -139
  301. package/dist/mcp/tools/collection/create.js.map +0 -1
  302. package/dist/mcp/tools/collection/delete.d.ts +0 -10
  303. package/dist/mcp/tools/collection/delete.d.ts.map +0 -1
  304. package/dist/mcp/tools/collection/delete.js +0 -154
  305. package/dist/mcp/tools/collection/delete.js.map +0 -1
  306. package/dist/mcp/tools/collection/find.d.ts +0 -10
  307. package/dist/mcp/tools/collection/find.d.ts.map +0 -1
  308. package/dist/mcp/tools/collection/find.js +0 -165
  309. package/dist/mcp/tools/collection/find.js.map +0 -1
  310. package/dist/mcp/tools/collection/update.d.ts +0 -10
  311. package/dist/mcp/tools/collection/update.d.ts.map +0 -1
  312. package/dist/mcp/tools/collection/update.js +0 -209
  313. package/dist/mcp/tools/collection/update.js.map +0 -1
  314. package/dist/mcp/tools/config/find.d.ts +0 -10
  315. package/dist/mcp/tools/config/find.d.ts.map +0 -1
  316. package/dist/mcp/tools/config/find.js +0 -97
  317. package/dist/mcp/tools/config/find.js.map +0 -1
  318. package/dist/mcp/tools/config/update.d.ts +0 -10
  319. package/dist/mcp/tools/config/update.d.ts.map +0 -1
  320. package/dist/mcp/tools/config/update.js +0 -215
  321. package/dist/mcp/tools/config/update.js.map +0 -1
  322. package/dist/mcp/tools/global/find.d.ts +0 -5
  323. package/dist/mcp/tools/global/find.d.ts.map +0 -1
  324. package/dist/mcp/tools/global/find.js +0 -82
  325. package/dist/mcp/tools/global/find.js.map +0 -1
  326. package/dist/mcp/tools/global/update.d.ts +0 -6
  327. package/dist/mcp/tools/global/update.d.ts.map +0 -1
  328. package/dist/mcp/tools/global/update.js +0 -124
  329. package/dist/mcp/tools/global/update.js.map +0 -1
  330. package/dist/mcp/tools/job/create.d.ts +0 -10
  331. package/dist/mcp/tools/job/create.d.ts.map +0 -1
  332. package/dist/mcp/tools/job/create.js +0 -293
  333. package/dist/mcp/tools/job/create.js.map +0 -1
  334. package/dist/mcp/tools/job/run.d.ts +0 -10
  335. package/dist/mcp/tools/job/run.d.ts.map +0 -1
  336. package/dist/mcp/tools/job/run.js +0 -129
  337. package/dist/mcp/tools/job/run.js.map +0 -1
  338. package/dist/mcp/tools/job/update.d.ts +0 -11
  339. package/dist/mcp/tools/job/update.d.ts.map +0 -1
  340. package/dist/mcp/tools/job/update.js +0 -186
  341. package/dist/mcp/tools/job/update.js.map +0 -1
  342. package/dist/mcp/tools/resource/create.d.ts +0 -6
  343. package/dist/mcp/tools/resource/create.d.ts.map +0 -1
  344. package/dist/mcp/tools/resource/create.js +0 -124
  345. package/dist/mcp/tools/resource/create.js.map +0 -1
  346. package/dist/mcp/tools/resource/delete.d.ts +0 -5
  347. package/dist/mcp/tools/resource/delete.d.ts.map +0 -1
  348. package/dist/mcp/tools/resource/delete.js +0 -151
  349. package/dist/mcp/tools/resource/delete.js.map +0 -1
  350. package/dist/mcp/tools/resource/find.d.ts +0 -5
  351. package/dist/mcp/tools/resource/find.d.ts.map +0 -1
  352. package/dist/mcp/tools/resource/find.js +0 -170
  353. package/dist/mcp/tools/resource/find.js.map +0 -1
  354. package/dist/mcp/tools/resource/update.d.ts +0 -6
  355. package/dist/mcp/tools/resource/update.d.ts.map +0 -1
  356. package/dist/mcp/tools/resource/update.js +0 -256
  357. package/dist/mcp/tools/resource/update.js.map +0 -1
  358. package/dist/mcp/tools/schemas.d.ts +0 -457
  359. package/dist/mcp/tools/schemas.d.ts.map +0 -1
  360. package/dist/mcp/tools/schemas.js +0 -243
  361. package/dist/mcp/tools/schemas.js.map +0 -1
  362. package/dist/utils/adminEntitySettings.d.ts +0 -17
  363. package/dist/utils/adminEntitySettings.d.ts.map +0 -1
  364. package/dist/utils/adminEntitySettings.js +0 -41
  365. package/dist/utils/adminEntitySettings.js.map +0 -1
  366. package/dist/utils/createApiKeyFields.d.ts +0 -15
  367. package/dist/utils/createApiKeyFields.d.ts.map +0 -1
  368. package/dist/utils/createApiKeyFields.js +0 -57
  369. package/dist/utils/createApiKeyFields.js.map +0 -1
  370. package/dist/utils/getEnabledSlugs.d.ts +0 -13
  371. package/dist/utils/getEnabledSlugs.d.ts.map +0 -1
  372. package/dist/utils/getEnabledSlugs.js +0 -32
  373. package/dist/utils/getEnabledSlugs.js.map +0 -1
  374. package/dist/utils/schemaConversion/convertCollectionSchemaToZod.d.ts +0 -3
  375. package/dist/utils/schemaConversion/convertCollectionSchemaToZod.d.ts.map +0 -1
  376. package/dist/utils/schemaConversion/convertCollectionSchemaToZod.js +0 -43
  377. package/dist/utils/schemaConversion/convertCollectionSchemaToZod.js.map +0 -1
  378. package/dist/utils/schemaConversion/removeVirtualFieldsFromSchema.d.ts +0 -7
  379. package/dist/utils/schemaConversion/removeVirtualFieldsFromSchema.d.ts.map +0 -1
  380. package/dist/utils/schemaConversion/removeVirtualFieldsFromSchema.js +0 -20
  381. package/dist/utils/schemaConversion/removeVirtualFieldsFromSchema.js.map +0 -1
  382. package/dist/utils/schemaConversion/sanitizeJsonSchema.d.ts +0 -13
  383. package/dist/utils/schemaConversion/sanitizeJsonSchema.d.ts.map +0 -1
  384. package/dist/utils/schemaConversion/sanitizeJsonSchema.js +0 -56
  385. package/dist/utils/schemaConversion/sanitizeJsonSchema.js.map +0 -1
  386. package/dist/utils/schemaConversion/simplifyRelationshipFields.d.ts +0 -20
  387. package/dist/utils/schemaConversion/simplifyRelationshipFields.d.ts.map +0 -1
  388. package/dist/utils/schemaConversion/simplifyRelationshipFields.js +0 -53
  389. package/dist/utils/schemaConversion/simplifyRelationshipFields.js.map +0 -1
  390. package/dist/utils/schemaConversion/transformPointFields.d.ts +0 -3
  391. package/dist/utils/schemaConversion/transformPointFields.d.ts.map +0 -1
  392. package/dist/utils/schemaConversion/transformPointFields.js +0 -51
  393. package/dist/utils/schemaConversion/transformPointFields.js.map +0 -1
  394. package/src/collections/createApiKeysCollection.ts +0 -373
  395. package/src/defaults.ts +0 -3
  396. package/src/endpoints/mcp.ts +0 -91
  397. package/src/mcp/createRequest.ts +0 -13
  398. package/src/mcp/getMcpHandler.ts +0 -545
  399. package/src/mcp/helpers/config.ts +0 -213
  400. package/src/mcp/helpers/fields.ts +0 -154
  401. package/src/mcp/helpers/fileValidation.ts +0 -362
  402. package/src/mcp/registerTool.ts +0 -22
  403. package/src/mcp/tools/auth/auth.ts +0 -71
  404. package/src/mcp/tools/auth/forgotPassword.ts +0 -70
  405. package/src/mcp/tools/auth/login.ts +0 -72
  406. package/src/mcp/tools/auth/resetPassword.ts +0 -61
  407. package/src/mcp/tools/auth/unlock.ts +0 -64
  408. package/src/mcp/tools/auth/verify.ts +0 -57
  409. package/src/mcp/tools/collection/create.ts +0 -210
  410. package/src/mcp/tools/collection/delete.ts +0 -211
  411. package/src/mcp/tools/collection/find.ts +0 -224
  412. package/src/mcp/tools/collection/update.ts +0 -290
  413. package/src/mcp/tools/config/find.ts +0 -128
  414. package/src/mcp/tools/config/update.ts +0 -280
  415. package/src/mcp/tools/global/find.ts +0 -128
  416. package/src/mcp/tools/global/update.ts +0 -207
  417. package/src/mcp/tools/job/create.ts +0 -416
  418. package/src/mcp/tools/job/run.ts +0 -167
  419. package/src/mcp/tools/job/update.ts +0 -274
  420. package/src/mcp/tools/resource/create.ts +0 -211
  421. package/src/mcp/tools/resource/delete.ts +0 -218
  422. package/src/mcp/tools/resource/find.ts +0 -246
  423. package/src/mcp/tools/resource/update.ts +0 -383
  424. package/src/mcp/tools/schemas.ts +0 -520
  425. package/src/utils/adminEntitySettings.ts +0 -40
  426. package/src/utils/createApiKeyFields.ts +0 -72
  427. package/src/utils/getEnabledSlugs.ts +0 -42
  428. package/src/utils/schemaConversion/convertCollectionSchemaToZod.ts +0 -52
  429. package/src/utils/schemaConversion/removeVirtualFieldsFromSchema.ts +0 -27
  430. package/src/utils/schemaConversion/sanitizeJsonSchema.ts +0 -62
  431. package/src/utils/schemaConversion/simplifyRelationshipFields.ts +0 -65
  432. package/src/utils/schemaConversion/transformPointFields.ts +0 -55
@@ -0,0 +1,432 @@
1
+ import type { JsonSchemaType } from '../../types.js'
2
+
3
+ /**
4
+ * Refines Payload's `input`-variant JSON Schema into an MCP create/update tool's input schema. The
5
+ * variant already covers correctness (ID-only relationships, no managed/virtual/join fields); the
6
+ * passes here are MCP-specific - reshaping fields for the model and shrinking the result - and keep
7
+ * every node valid JSON Schema draft 2020-12. Each is tagged **Correctness**, **Size**, or **LLM
8
+ * ergonomics**, with a before/after example on its definition.
9
+ */
10
+ export const sanitizeEntitySchema = (schema: JsonSchemaType): JsonSchemaType => {
11
+ // Work on a copy — the caller reuses the original schema elsewhere (e.g. when listing tools).
12
+ let result = structuredClone(schema)
13
+
14
+ // LLM ergonomics — drop the redundant `'null'` from optional arrays/objects (`['array','null']` → `'array'`).
15
+ result = collapseOptionalContainerTypes(result)
16
+
17
+ // LLM ergonomics — rewrite point fields from a `[number, number]` tuple into a `{ longitude, latitude }` object.
18
+ result = pointFieldsToObjects(result)
19
+
20
+ // Size — strip inert type-gen leftovers that only bloat the schema (`tsType`, block-collision notes).
21
+ result = removeTypeGenArtifacts(result)
22
+
23
+ // Size — where a `const` already pins a value, the sibling `type` is redundant; remove it.
24
+ result = dropRedundantConstType(result)
25
+
26
+ // Size — fold per-collection relationship/upload variants (identical but for `relationTo`) into one `enum`.
27
+ result = mergeConstDiscriminatedUnions(result)
28
+
29
+ // Size — pull any subschema that appears more than once into a single shared `$defs` entry.
30
+ result = deduplicateIntoDefinitions(result)
31
+
32
+ // LLM ergonomics — give `$defs` short, readable names (`Code`, `paragraph`, `node`) so the `$ref`s read nicely.
33
+ result = shortenDefinitionNames(result)
34
+
35
+ return result
36
+ }
37
+
38
+ /**
39
+ * Rebuilds a schema bottom-up, calling `visit` on each node after its children. Shared by the
40
+ * transforms that need to touch every node in the tree.
41
+ */
42
+ const mapNodes = (node: unknown, visit: (node: JsonSchemaType) => JsonSchemaType): unknown => {
43
+ if (Array.isArray(node)) {
44
+ return node.map((child) => mapNodes(child, visit))
45
+ }
46
+ if (!node || typeof node !== 'object') {
47
+ return node
48
+ }
49
+ const out: Record<string, unknown> = {}
50
+ for (const [key, value] of Object.entries(node)) {
51
+ out[key] = mapNodes(value, visit)
52
+ }
53
+ return visit(out)
54
+ }
55
+
56
+ /**
57
+ * **LLM ergonomics.** Collapses optional array/object types (`['array', 'null']` → `'array'`) via
58
+ * {@link collapseNullableType}, recursing through `properties` and array items. The `required` list
59
+ * already conveys optionality, so the `'null'` is redundant noise for the model.
60
+ *
61
+ * @example
62
+ * { properties: { tags: { type: ['array', 'null'], items: {} } }, required: [] }
63
+ * → { properties: { tags: { type: 'array', items: {} } }, required: [] }
64
+ */
65
+ const collapseOptionalContainerTypes = (schema: JsonSchemaType): JsonSchemaType => {
66
+ if (schema.properties && typeof schema.properties === 'object') {
67
+ for (const key of Object.keys(schema.properties)) {
68
+ const prop = schema.properties[key] as JsonSchemaType
69
+ if (!prop || typeof prop !== 'object') {
70
+ continue
71
+ }
72
+ const isRequired = Array.isArray(schema.required) && schema.required.includes(key)
73
+ collapseNullableType(prop, isRequired)
74
+ if (prop.properties) {
75
+ collapseOptionalContainerTypes(prop)
76
+ }
77
+ if (prop.items && typeof prop.items === 'object' && !Array.isArray(prop.items)) {
78
+ collapseOptionalContainerTypes(prop.items)
79
+ }
80
+ }
81
+ }
82
+
83
+ return schema
84
+ }
85
+
86
+ /**
87
+ * Drops the `'null'` from an optional array/object type (`['array', 'null']` → `'array'`, likewise
88
+ * `'object'`). Payload marks a field optional by unioning its type with `'null'`, but a create/update
89
+ * tool already conveys "optional" through the `required` list - the client just omits the field - so the
90
+ * `'null'` is redundant here. Dropping it shows the model a plain `type: 'array'` instead of implying it
91
+ * should send a literal `null`.
92
+ *
93
+ * We never touch the `required` list, so this can't change whether a field is required. And we skip fields
94
+ * that ARE required (`isRequired`): there a `'null'` is a value the field genuinely accepts, not optionality
95
+ * encoding. Nullable scalars (`['string', 'null']`) are also left alone - they read fine as `string | null`.
96
+ *
97
+ * @example
98
+ * optional { type: ['array', 'null'] } → { type: 'array' } (still optional, just no longer null-valued)
99
+ * required { type: ['array', 'null'] } → unchanged
100
+ * { type: ['string', 'null'] } → unchanged
101
+ */
102
+ const collapseNullableType = (schema: JsonSchemaType, isRequired: boolean): void => {
103
+ if (isRequired || !Array.isArray(schema.type)) {
104
+ return
105
+ }
106
+ const nonNullTypes = schema.type.filter((t) => t !== 'null')
107
+ if (nonNullTypes.length === 1 && (nonNullTypes[0] === 'array' || nonNullTypes[0] === 'object')) {
108
+ schema.type = nonNullTypes[0]
109
+ }
110
+ }
111
+
112
+ /**
113
+ * **LLM ergonomics.** Rewrites a point field (stored as a two-number tuple) into a `{ longitude, latitude }` object, which
114
+ * is far easier for the model to fill in than a positional array. This is input-only and lossless: the
115
+ * create/update handler converts the object back to the `[longitude, latitude]` tuple Payload stores,
116
+ * via `transformPointDataToPayload`.
117
+ *
118
+ * @example
119
+ * { type: 'array', items: [{ type: 'number' }, { type: 'number' }] }
120
+ * → { type: 'object', properties: { longitude: { type: 'number' }, latitude: { type: 'number' } }, required: ['longitude', 'latitude'] }
121
+ */
122
+ const pointFieldsToObjects = (schema: JsonSchemaType): JsonSchemaType => {
123
+ if (!schema || typeof schema !== 'object') {
124
+ return schema
125
+ }
126
+
127
+ const transformed = { ...schema }
128
+
129
+ if (transformed.properties && typeof transformed.properties === 'object') {
130
+ transformed.properties = Object.fromEntries(
131
+ Object.entries(transformed.properties).map(([key, value]) => {
132
+ if (!value || typeof value !== 'object') {
133
+ return [key, value]
134
+ }
135
+ const isArrayType =
136
+ value.type === 'array' || (Array.isArray(value.type) && value.type.includes('array'))
137
+ const isPointField =
138
+ isArrayType &&
139
+ Array.isArray(value.items) &&
140
+ value.items.length === 2 &&
141
+ value.items.every((item) => item && typeof item === 'object' && item.type === 'number')
142
+
143
+ if (isPointField) {
144
+ const isNullable = Array.isArray(value.type) && value.type.includes('null')
145
+ return [
146
+ key,
147
+ {
148
+ type: isNullable ? ['object', 'null'] : 'object',
149
+ description: value.description || 'Geographic coordinates (longitude, latitude)',
150
+ properties: {
151
+ latitude: { type: 'number', description: 'Latitude coordinate' },
152
+ longitude: { type: 'number', description: 'Longitude coordinate' },
153
+ },
154
+ required: ['longitude', 'latitude'],
155
+ },
156
+ ]
157
+ }
158
+
159
+ return [key, pointFieldsToObjects(value)]
160
+ }),
161
+ )
162
+ }
163
+
164
+ if (
165
+ transformed.items &&
166
+ typeof transformed.items === 'object' &&
167
+ !Array.isArray(transformed.items)
168
+ ) {
169
+ transformed.items = pointFieldsToObjects(transformed.items)
170
+ }
171
+
172
+ return transformed
173
+ }
174
+
175
+ /**
176
+ * **Size.** Strips type-generation leftovers that bloat the schema without helping the model: the `tsType`
177
+ * hint (a `json-schema-to-typescript` extension; JSON Schema validators just ignore it, they don't reject it)
178
+ * and the block-interface-collision note Payload adds to some block descriptions (the
179
+ * `block-interface-name-collisions` docs link set in `registerBlockInterface`, see configToJSONSchema.ts).
180
+ * Both are inert here - removing them only shrinks the schema (and spares the model irrelevant noise).
181
+ *
182
+ * @example
183
+ * { type: 'object', tsType: 'SerializedBlockNode', description: 'see …#block-interface-name-collisions' }
184
+ * → { type: 'object' }
185
+ */
186
+ const removeTypeGenArtifacts = (schema: JsonSchemaType): JsonSchemaType =>
187
+ mapNodes(schema, (node) => {
188
+ delete (node as { tsType?: unknown }).tsType
189
+ const { description } = node as { description?: string }
190
+ if (
191
+ typeof description === 'string' &&
192
+ description.includes('block-interface-name-collisions')
193
+ ) {
194
+ delete (node as { description?: unknown }).description
195
+ }
196
+ return node
197
+ }) as JsonSchemaType
198
+
199
+ /**
200
+ * **Size.** Removes `type` whenever a `const` sits next to it — the constant already fixes the value.
201
+ *
202
+ * @example
203
+ * { type: 'string', const: 'paragraph' } → { const: 'paragraph' }
204
+ */
205
+ const dropRedundantConstType = (schema: JsonSchemaType): JsonSchemaType =>
206
+ mapNodes(schema, (node) => {
207
+ if ('const' in node && 'type' in node) {
208
+ delete (node as { type?: unknown }).type
209
+ }
210
+ return node
211
+ }) as JsonSchemaType
212
+
213
+ /**
214
+ * **Size.** Merges the members of a `oneOf`/`anyOf` that are identical except for one `const`-valued property
215
+ * into a single member with that property as an `enum`. Since the members differ only by that one
216
+ * constant, the `enum` form accepts exactly the same values - it's just smaller. This folds the
217
+ * per-collection relationship and upload variants, which differ only in their `relationTo` constant.
218
+ *
219
+ * @example
220
+ * { oneOf: [
221
+ * { properties: { relationTo: { const: 'posts' }, value: { type: 'string' } } },
222
+ * { properties: { relationTo: { const: 'pages' }, value: { type: 'string' } } },
223
+ * ] }
224
+ * → { properties: { relationTo: { enum: ['posts', 'pages'] }, value: { type: 'string' } } }
225
+ */
226
+ const mergeConstDiscriminatedUnions = (schema: JsonSchemaType): JsonSchemaType =>
227
+ mapNodes(schema, (node) => {
228
+ for (const keyword of ['oneOf', 'anyOf'] as const) {
229
+ const members = node[keyword]
230
+ if (Array.isArray(members) && members.length > 1) {
231
+ const merged = mergeMembersByConst(members)
232
+ if (merged) {
233
+ delete node[keyword]
234
+ Object.assign(node, merged)
235
+ }
236
+ }
237
+ }
238
+ return node
239
+ }) as JsonSchemaType
240
+
241
+ /** Returns the merged member for {@link mergeConstDiscriminatedUnions}, or `null` if they can't merge. */
242
+ const mergeMembersByConst = (members: Array<boolean | JsonSchemaType>): JsonSchemaType | null => {
243
+ const objects = members.filter(
244
+ (member): member is JsonSchemaType =>
245
+ typeof member === 'object' && member !== null && typeof member.properties === 'object',
246
+ )
247
+ if (objects.length < 2 || objects.length !== members.length) {
248
+ return null
249
+ }
250
+
251
+ for (const discriminator of Object.keys(objects[0]!.properties!)) {
252
+ // Each member must pin this property to a `const`...
253
+ const constValues: unknown[] = []
254
+ const everyMemberPinsConst = objects.every((member) => {
255
+ const prop = member.properties![discriminator]
256
+ if (prop && typeof prop === 'object' && 'const' in prop) {
257
+ constValues.push(prop.const)
258
+ return true
259
+ }
260
+ return false
261
+ })
262
+ if (!everyMemberPinsConst) {
263
+ continue
264
+ }
265
+
266
+ // ...and be otherwise identical (compare each member with the discriminator removed).
267
+ const fingerprintWithoutDiscriminator = (member: JsonSchemaType): string => {
268
+ const { [discriminator]: _discriminator, ...otherProperties } = member.properties!
269
+ return JSON.stringify({ ...member, properties: otherProperties })
270
+ }
271
+ if (new Set(objects.map(fingerprintWithoutDiscriminator)).size !== 1) {
272
+ continue
273
+ }
274
+
275
+ const uniqueConstValues = [...new Set(constValues)]
276
+ if (uniqueConstValues.length < 2) {
277
+ continue
278
+ }
279
+
280
+ // Replace the per-member `const` with a single `enum` of every value.
281
+ const merged = structuredClone(objects[0]!)
282
+ const discriminatorProp = merged.properties![discriminator]
283
+ if (discriminatorProp && typeof discriminatorProp === 'object') {
284
+ delete discriminatorProp.const
285
+ discriminatorProp.enum = uniqueConstValues as NonNullable<typeof discriminatorProp.enum>
286
+ }
287
+ return merged
288
+ }
289
+ return null
290
+ }
291
+
292
+ // A `$ref` costs ~30 characters once names are shortened, so sharing a subschema only pays off when
293
+ // it's larger than that and appears more than once.
294
+ const MIN_SHARED_SIZE = 64
295
+
296
+ /** A subschema worth sharing: a standalone object/union/described schema, not a `$ref` or a primitive. */
297
+ const isShareable = (node: unknown): node is Record<string, unknown> => {
298
+ if (!node || typeof node !== 'object' || Array.isArray(node) || '$ref' in node) {
299
+ return false
300
+ }
301
+ const schema = node as JsonSchemaType
302
+ return (
303
+ Array.isArray(schema.oneOf) ||
304
+ Array.isArray(schema.anyOf) ||
305
+ Boolean(schema.properties) ||
306
+ Boolean(schema.items) ||
307
+ typeof schema.description === 'string'
308
+ )
309
+ }
310
+
311
+ /**
312
+ * **Size.** Replaces any subschema that appears more than once with a single shared `$defs` entry referenced by
313
+ * `$ref`. Lossless — only the serialized size shrinks. A collection with several rich-text fields, for
314
+ * example, inlines the same large lexical node schema once per field; this collapses them into one.
315
+ *
316
+ * @example
317
+ * { properties: { billing: address, shipping: address } }
318
+ * → { properties: { billing: { $ref: '#/$defs/shared_0' }, shipping: { $ref: '#/$defs/shared_0' } }, $defs: { shared_0: address } }
319
+ */
320
+ const deduplicateIntoDefinitions = (schema: JsonSchemaType): JsonSchemaType => {
321
+ // Count how often each shareable subschema appears, keyed by its serialized form.
322
+ const counts = new Map<string, number>()
323
+ const count = (node: unknown): void => {
324
+ if (isShareable(node)) {
325
+ const key = JSON.stringify(node)
326
+ if (key.length >= MIN_SHARED_SIZE) {
327
+ counts.set(key, (counts.get(key) ?? 0) + 1)
328
+ }
329
+ }
330
+ if (Array.isArray(node)) {
331
+ node.forEach(count)
332
+ } else if (node && typeof node === 'object') {
333
+ Object.values(node).forEach(count)
334
+ }
335
+ }
336
+ count(schema)
337
+
338
+ if (![...counts.values()].some((n) => n >= 2)) {
339
+ return schema
340
+ }
341
+
342
+ // Replace each subschema seen 2+ times with a `$ref`. The first time we meet one it becomes a shared
343
+ // entry; we never descend into a stored entry, so shared entries never reference one another.
344
+ const sharedEntries: Record<string, JsonSchemaType> = {}
345
+ const nameByKey = new Map<string, string>()
346
+ const share = (node: unknown): unknown => {
347
+ if (isShareable(node)) {
348
+ const key = JSON.stringify(node)
349
+ if ((counts.get(key) ?? 0) >= 2) {
350
+ let name = nameByKey.get(key)
351
+ if (!name) {
352
+ name = `shared_${nameByKey.size}`
353
+ nameByKey.set(key, name)
354
+ sharedEntries[name] = node
355
+ }
356
+ return { $ref: `#/$defs/${name}` }
357
+ }
358
+ }
359
+ if (Array.isArray(node)) {
360
+ return node.map(share)
361
+ }
362
+ if (node && typeof node === 'object') {
363
+ return Object.fromEntries(
364
+ Object.entries(node).map(([childKey, value]) => [childKey, share(value)]),
365
+ )
366
+ }
367
+ return node
368
+ }
369
+
370
+ const result = share(schema) as JsonSchemaType
371
+ result.$defs = { ...result.$defs, ...sharedEntries }
372
+ return result
373
+ }
374
+
375
+ /**
376
+ * **LLM ergonomics.** Renames `$defs` entries to short, readable names so the `$ref`s stay legible to the model: a block's
377
+ * `blockType` (`Code`), a node's `type` (`paragraph`), `node` for a rich-text node union, otherwise the
378
+ * generated name with its disambiguating hash dropped. A numeric suffix keeps collisions unique.
379
+ *
380
+ * @example
381
+ * { properties: { body: { $ref: '#/$defs/LexicalNodes_9FBEC708' } }, $defs: { LexicalNodes_9FBEC708: {} } }
382
+ * → { properties: { body: { $ref: '#/$defs/node' } }, $defs: { node: {} } }
383
+ */
384
+ const shortenDefinitionNames = (schema: JsonSchemaType): JsonSchemaType => {
385
+ const definitions = schema.$defs
386
+ if (!definitions || Object.keys(definitions).length === 0) {
387
+ return schema
388
+ }
389
+
390
+ const shortNameFor = (name: string, definition: boolean | JsonSchemaType): string => {
391
+ const properties = (typeof definition === 'object' && definition.properties) || {}
392
+ const constString = (key: string): string | undefined => {
393
+ const prop = properties[key]
394
+ return prop && typeof prop === 'object' && typeof prop.const === 'string'
395
+ ? prop.const
396
+ : undefined
397
+ }
398
+ const members =
399
+ typeof definition === 'object' ? (definition.anyOf ?? definition.oneOf) : undefined
400
+ const isNodeUnion =
401
+ Array.isArray(members) &&
402
+ members.some((m) => typeof m === 'object' && Boolean(m.$ref || m.properties?.type))
403
+ return (
404
+ constString('blockType') ??
405
+ constString('type') ??
406
+ (isNodeUnion ? 'node' : undefined) ??
407
+ name.replace(/_[0-9A-F]{6,}$/i, '')
408
+ )
409
+ }
410
+
411
+ const prefix = '#/$defs/'
412
+ const usedNames = new Map<string, number>()
413
+ const rename = new Map<string, string>()
414
+ for (const [name, definition] of Object.entries(definitions)) {
415
+ const shortName = shortNameFor(name, definition)
416
+ const used = usedNames.get(shortName) ?? 0
417
+ usedNames.set(shortName, used + 1)
418
+ rename.set(name, used === 0 ? shortName : `${shortName}${used + 1}`)
419
+ }
420
+
421
+ const result = mapNodes(schema, (node) => {
422
+ if (typeof node.$ref === 'string' && node.$ref.startsWith(prefix)) {
423
+ const name = node.$ref.slice(prefix.length)
424
+ node.$ref = `${prefix}${rename.get(name) ?? name}`
425
+ }
426
+ return node
427
+ }) as JsonSchemaType
428
+ result.$defs = Object.fromEntries(
429
+ Object.entries(result.$defs!).map(([name, body]) => [rename.get(name) ?? name, body]),
430
+ )
431
+ return result
432
+ }
@@ -0,0 +1,9 @@
1
+ import { fromJsonSchema, type StandardSchemaWithJSON } from '@modelcontextprotocol/server'
2
+
3
+ import type { ToolInputSchema } from '../types.js'
4
+
5
+ /** Normalize a tool/prompt input to a Standard Schema. Raw JSON Schema gets wrapped; Standard Schema instances pass through. */
6
+ export const toStandardSchema = (schema: ToolInputSchema): StandardSchemaWithJSON =>
7
+ typeof schema === 'object' && schema !== null && '~standard' in schema
8
+ ? (schema as StandardSchemaWithJSON)
9
+ : fromJsonSchema(schema)
@@ -0,0 +1,24 @@
1
+ import type { Where } from 'payload'
2
+
3
+ import { validOperators } from 'payload/shared'
4
+ import { z } from 'zod'
5
+
6
+ const whereFieldSchema = z
7
+ .partialRecord(z.enum(validOperators), z.unknown())
8
+ .describe('Field query operators')
9
+
10
+ /**
11
+ * - Validates the `where` input of collection tools against Payload's `Where` shape
12
+ * - Field keys map to operator objects restricted to `validOperators`
13
+ * - `and` / `or` nest recursively
14
+ */
15
+ export const whereSchema: z.ZodType<Where> = z
16
+ .lazy(() =>
17
+ z
18
+ .object({
19
+ and: z.array(whereSchema).optional(),
20
+ or: z.array(whereSchema).optional(),
21
+ })
22
+ .catchall(whereFieldSchema),
23
+ )
24
+ .describe('Where clause using field names with Payload query operators, plus and/or groups')
@@ -1,7 +0,0 @@
1
- import type { CollectionConfig } from 'payload';
2
- import type { MCPPluginConfig } from '../types.js';
3
- export declare const createAPIKeysCollection: (collections: MCPPluginConfig["collections"], globals: MCPPluginConfig["globals"], customTools: Array<{
4
- description: string;
5
- name: string;
6
- }> | undefined, experimentalTools: NonNullable<MCPPluginConfig["experimental"]>["tools"] | undefined, pluginOptions: MCPPluginConfig) => CollectionConfig;
7
- //# sourceMappingURL=createApiKeysCollection.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"createApiKeysCollection.d.ts","sourceRoot":"","sources":["../../src/collections/createApiKeysCollection.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAkB,MAAM,SAAS,CAAA;AAE/D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAKlD,eAAO,MAAM,uBAAuB,gBACrB,eAAe,CAAC,aAAa,CAAC,WAClC,eAAe,CAAC,SAAS,CAAC,eACtB,KAAK,CAAC;IAAE,WAAW,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC,iCACtC,WAAW,CAAC,eAAe,CAAC,cAAc,CAAC,CAAC,CAAC,OAAO,CAAC,6BACzD,eAAe,KAC7B,gBAuWF,CAAA"}