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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (446) hide show
  1. package/LICENSE.md +1 -1
  2. package/bin.js +39 -0
  3. package/dist/defaultAccess.d.ts +3 -0
  4. package/dist/defaultAccess.d.ts.map +1 -0
  5. package/dist/defaultAccess.js +3 -0
  6. package/dist/defaultAccess.js.map +1 -0
  7. package/dist/defineTool.d.ts +26 -0
  8. package/dist/defineTool.d.ts.map +1 -0
  9. package/dist/defineTool.js +37 -0
  10. package/dist/defineTool.js.map +1 -0
  11. package/dist/endpoint/access.d.ts +22 -0
  12. package/dist/endpoint/access.d.ts.map +1 -0
  13. package/dist/endpoint/access.js +130 -0
  14. package/dist/endpoint/access.js.map +1 -0
  15. package/dist/endpoint/index.d.ts +3 -0
  16. package/dist/endpoint/index.d.ts.map +1 -0
  17. package/dist/endpoint/index.js +141 -0
  18. package/dist/endpoint/index.js.map +1 -0
  19. package/dist/endpoint/oauth.d.ts +37 -0
  20. package/dist/endpoint/oauth.d.ts.map +1 -0
  21. package/dist/endpoint/oauth.js +105 -0
  22. package/dist/endpoint/oauth.js.map +1 -0
  23. package/dist/endpoint/oauthLoginToken.d.ts +23 -0
  24. package/dist/endpoint/oauthLoginToken.d.ts.map +1 -0
  25. package/dist/endpoint/oauthLoginToken.js +80 -0
  26. package/dist/endpoint/oauthLoginToken.js.map +1 -0
  27. package/dist/endpoint/oauthServer.d.ts +28 -0
  28. package/dist/endpoint/oauthServer.d.ts.map +1 -0
  29. package/dist/endpoint/oauthServer.js +423 -0
  30. package/dist/endpoint/oauthServer.js.map +1 -0
  31. package/dist/exports/client.d.ts +2 -0
  32. package/dist/exports/client.d.ts.map +1 -0
  33. package/dist/exports/client.js +4 -0
  34. package/dist/exports/client.js.map +1 -0
  35. package/dist/exports/internal.d.ts +2 -0
  36. package/dist/exports/internal.d.ts.map +1 -0
  37. package/dist/exports/internal.js +3 -0
  38. package/dist/exports/internal.js.map +1 -0
  39. package/dist/exports/rsc.d.ts +2 -0
  40. package/dist/exports/rsc.d.ts.map +1 -0
  41. package/dist/exports/rsc.js +3 -0
  42. package/dist/exports/rsc.js.map +1 -0
  43. package/dist/index.d.ts +14 -9
  44. package/dist/index.d.ts.map +1 -1
  45. package/dist/index.js +63 -67
  46. package/dist/index.js.map +1 -1
  47. package/dist/mcp/buildMcpServer.d.ts +19 -0
  48. package/dist/mcp/buildMcpServer.d.ts.map +1 -0
  49. package/dist/mcp/buildMcpServer.js +235 -0
  50. package/dist/mcp/buildMcpServer.js.map +1 -0
  51. package/dist/mcp/builtin/collections/authTools.d.ts +7 -0
  52. package/dist/mcp/builtin/collections/authTools.d.ts.map +1 -0
  53. package/dist/mcp/builtin/collections/authTools.js +312 -0
  54. package/dist/mcp/builtin/collections/authTools.js.map +1 -0
  55. package/dist/mcp/builtin/collections/countTool.d.ts +2 -0
  56. package/dist/mcp/builtin/collections/countTool.d.ts.map +1 -0
  57. package/dist/mcp/builtin/collections/countTool.js +63 -0
  58. package/dist/mcp/builtin/collections/countTool.js.map +1 -0
  59. package/dist/mcp/builtin/collections/countVersionsTool.d.ts +2 -0
  60. package/dist/mcp/builtin/collections/countVersionsTool.d.ts.map +1 -0
  61. package/dist/mcp/builtin/collections/countVersionsTool.js +60 -0
  62. package/dist/mcp/builtin/collections/countVersionsTool.js.map +1 -0
  63. package/dist/mcp/builtin/collections/createTool.d.ts +2 -0
  64. package/dist/mcp/builtin/collections/createTool.d.ts.map +1 -0
  65. package/dist/mcp/builtin/collections/createTool.js +137 -0
  66. package/dist/mcp/builtin/collections/createTool.js.map +1 -0
  67. package/dist/mcp/builtin/collections/deleteTool.d.ts +2 -0
  68. package/dist/mcp/builtin/collections/deleteTool.d.ts.map +1 -0
  69. package/dist/mcp/builtin/collections/deleteTool.js +113 -0
  70. package/dist/mcp/builtin/collections/deleteTool.js.map +1 -0
  71. package/dist/mcp/builtin/collections/duplicateTool.d.ts +2 -0
  72. package/dist/mcp/builtin/collections/duplicateTool.d.ts.map +1 -0
  73. package/dist/mcp/builtin/collections/duplicateTool.js +90 -0
  74. package/dist/mcp/builtin/collections/duplicateTool.js.map +1 -0
  75. package/dist/mcp/builtin/collections/fileInput.d.ts +28 -0
  76. package/dist/mcp/builtin/collections/fileInput.d.ts.map +1 -0
  77. package/dist/mcp/builtin/collections/fileInput.js +88 -0
  78. package/dist/mcp/builtin/collections/fileInput.js.map +1 -0
  79. package/dist/mcp/builtin/collections/findDistinctTool.d.ts +2 -0
  80. package/dist/mcp/builtin/collections/findDistinctTool.d.ts.map +1 -0
  81. package/dist/mcp/builtin/collections/findDistinctTool.js +77 -0
  82. package/dist/mcp/builtin/collections/findDistinctTool.js.map +1 -0
  83. package/dist/mcp/builtin/collections/findTool.d.ts +2 -0
  84. package/dist/mcp/builtin/collections/findTool.d.ts.map +1 -0
  85. package/dist/mcp/builtin/collections/findTool.js +146 -0
  86. package/dist/mcp/builtin/collections/findTool.js.map +1 -0
  87. package/dist/mcp/builtin/collections/findVersionByIDTool.d.ts +2 -0
  88. package/dist/mcp/builtin/collections/findVersionByIDTool.d.ts.map +1 -0
  89. package/dist/mcp/builtin/collections/findVersionByIDTool.js +74 -0
  90. package/dist/mcp/builtin/collections/findVersionByIDTool.js.map +1 -0
  91. package/dist/mcp/builtin/collections/findVersionsTool.d.ts +2 -0
  92. package/dist/mcp/builtin/collections/findVersionsTool.d.ts.map +1 -0
  93. package/dist/mcp/builtin/collections/findVersionsTool.js +84 -0
  94. package/dist/mcp/builtin/collections/findVersionsTool.js.map +1 -0
  95. package/dist/mcp/builtin/collections/getCollectionSchemaTool.d.ts +2 -0
  96. package/dist/mcp/builtin/collections/getCollectionSchemaTool.d.ts.map +1 -0
  97. package/dist/mcp/builtin/collections/getCollectionSchemaTool.js +103 -0
  98. package/dist/mcp/builtin/collections/getCollectionSchemaTool.js.map +1 -0
  99. package/dist/mcp/builtin/collections/restoreVersionTool.d.ts +2 -0
  100. package/dist/mcp/builtin/collections/restoreVersionTool.d.ts.map +1 -0
  101. package/dist/mcp/builtin/collections/restoreVersionTool.js +69 -0
  102. package/dist/mcp/builtin/collections/restoreVersionTool.js.map +1 -0
  103. package/dist/mcp/builtin/collections/updateTool.d.ts +2 -0
  104. package/dist/mcp/builtin/collections/updateTool.d.ts.map +1 -0
  105. package/dist/mcp/builtin/collections/updateTool.js +172 -0
  106. package/dist/mcp/builtin/collections/updateTool.js.map +1 -0
  107. package/dist/mcp/builtin/collections/uploadInstructionsTool.d.ts +2 -0
  108. package/dist/mcp/builtin/collections/uploadInstructionsTool.d.ts.map +1 -0
  109. package/dist/mcp/builtin/collections/uploadInstructionsTool.js +55 -0
  110. package/dist/mcp/builtin/collections/uploadInstructionsTool.js.map +1 -0
  111. package/dist/mcp/builtin/formatEntityError.d.ts +16 -0
  112. package/dist/mcp/builtin/formatEntityError.d.ts.map +1 -0
  113. package/dist/mcp/builtin/formatEntityError.js +55 -0
  114. package/dist/mcp/builtin/formatEntityError.js.map +1 -0
  115. package/dist/mcp/builtin/getConfigInfoTool.d.ts +2 -0
  116. package/dist/mcp/builtin/getConfigInfoTool.d.ts.map +1 -0
  117. package/dist/mcp/builtin/getConfigInfoTool.js +69 -0
  118. package/dist/mcp/builtin/getConfigInfoTool.js.map +1 -0
  119. package/dist/mcp/builtin/globals/countVersionsTool.d.ts +2 -0
  120. package/dist/mcp/builtin/globals/countVersionsTool.d.ts.map +1 -0
  121. package/dist/mcp/builtin/globals/countVersionsTool.js +60 -0
  122. package/dist/mcp/builtin/globals/countVersionsTool.js.map +1 -0
  123. package/dist/mcp/builtin/globals/findTool.d.ts +2 -0
  124. package/dist/mcp/builtin/globals/findTool.d.ts.map +1 -0
  125. package/dist/mcp/builtin/globals/findTool.js +67 -0
  126. package/dist/mcp/builtin/globals/findTool.js.map +1 -0
  127. package/dist/mcp/builtin/globals/findVersionByIDTool.d.ts +2 -0
  128. package/dist/mcp/builtin/globals/findVersionByIDTool.d.ts.map +1 -0
  129. package/dist/mcp/builtin/globals/findVersionByIDTool.js +68 -0
  130. package/dist/mcp/builtin/globals/findVersionByIDTool.js.map +1 -0
  131. package/dist/mcp/builtin/globals/findVersionsTool.d.ts +2 -0
  132. package/dist/mcp/builtin/globals/findVersionsTool.d.ts.map +1 -0
  133. package/dist/mcp/builtin/globals/findVersionsTool.js +78 -0
  134. package/dist/mcp/builtin/globals/findVersionsTool.js.map +1 -0
  135. package/dist/mcp/builtin/globals/getGlobalSchemaTool.d.ts +2 -0
  136. package/dist/mcp/builtin/globals/getGlobalSchemaTool.d.ts.map +1 -0
  137. package/dist/mcp/builtin/globals/getGlobalSchemaTool.js +81 -0
  138. package/dist/mcp/builtin/globals/getGlobalSchemaTool.js.map +1 -0
  139. package/dist/mcp/builtin/globals/restoreVersionTool.d.ts +2 -0
  140. package/dist/mcp/builtin/globals/restoreVersionTool.d.ts.map +1 -0
  141. package/dist/mcp/builtin/globals/restoreVersionTool.js +70 -0
  142. package/dist/mcp/builtin/globals/restoreVersionTool.js.map +1 -0
  143. package/dist/mcp/builtin/globals/updateTool.d.ts +2 -0
  144. package/dist/mcp/builtin/globals/updateTool.d.ts.map +1 -0
  145. package/dist/mcp/builtin/globals/updateTool.js +78 -0
  146. package/dist/mcp/builtin/globals/updateTool.js.map +1 -0
  147. package/dist/mcp/builtinTools.d.ts +168 -0
  148. package/dist/mcp/builtinTools.d.ts.map +1 -0
  149. package/dist/mcp/builtinTools.js +169 -0
  150. package/dist/mcp/builtinTools.js.map +1 -0
  151. package/dist/mcp/sanitizeMCPConfig.d.ts +16 -0
  152. package/dist/mcp/sanitizeMCPConfig.d.ts.map +1 -0
  153. package/dist/mcp/sanitizeMCPConfig.js +236 -0
  154. package/dist/mcp/sanitizeMCPConfig.js.map +1 -0
  155. package/dist/stdio.d.ts +8 -0
  156. package/dist/stdio.d.ts.map +1 -0
  157. package/dist/stdio.js +128 -0
  158. package/dist/stdio.js.map +1 -0
  159. package/dist/types.d.ts +352 -441
  160. package/dist/types.d.ts.map +1 -1
  161. package/dist/types.js +4 -1
  162. package/dist/types.js.map +1 -1
  163. package/dist/utils/getLogger.d.ts +10 -0
  164. package/dist/utils/getLogger.d.ts.map +1 -0
  165. package/dist/utils/getLogger.js +22 -0
  166. package/dist/utils/getLogger.js.map +1 -0
  167. package/dist/utils/getPluginConfig.d.ts +12 -0
  168. package/dist/utils/getPluginConfig.d.ts.map +1 -0
  169. package/dist/utils/getPluginConfig.js +15 -0
  170. package/dist/utils/getPluginConfig.js.map +1 -0
  171. package/dist/utils/resolveProjectRoot.d.ts +7 -0
  172. package/dist/utils/resolveProjectRoot.d.ts.map +1 -0
  173. package/dist/utils/resolveProjectRoot.js +15 -0
  174. package/dist/utils/resolveProjectRoot.js.map +1 -0
  175. package/dist/utils/seal.d.ts +17 -0
  176. package/dist/utils/seal.d.ts.map +1 -0
  177. package/dist/utils/seal.js +24 -0
  178. package/dist/utils/seal.js.map +1 -0
  179. package/dist/utils/toStandardSchema.d.ts +5 -0
  180. package/dist/utils/toStandardSchema.d.ts.map +1 -0
  181. package/dist/utils/toStandardSchema.js +4 -0
  182. package/dist/utils/toStandardSchema.js.map +1 -0
  183. package/dist/views/Authorize/AllowButtons/index.d.ts +18 -0
  184. package/dist/views/Authorize/AllowButtons/index.d.ts.map +1 -0
  185. package/dist/views/Authorize/AllowButtons/index.js +88 -0
  186. package/dist/views/Authorize/AllowButtons/index.js.map +1 -0
  187. package/dist/views/Authorize/index.css +19 -0
  188. package/dist/views/Authorize/index.d.ts +9 -0
  189. package/dist/views/Authorize/index.d.ts.map +1 -0
  190. package/dist/views/Authorize/index.js +86 -0
  191. package/dist/views/Authorize/index.js.map +1 -0
  192. package/package.json +48 -26
  193. package/src/defaultAccess.ts +3 -0
  194. package/src/defineTool.ts +44 -0
  195. package/src/endpoint/access.ts +153 -0
  196. package/src/endpoint/index.ts +123 -0
  197. package/src/endpoint/oauth.ts +108 -0
  198. package/src/endpoint/oauthLoginToken.ts +94 -0
  199. package/src/endpoint/oauthServer.ts +452 -0
  200. package/src/exports/client.ts +3 -0
  201. package/src/exports/internal.ts +1 -0
  202. package/src/exports/rsc.ts +1 -0
  203. package/src/index.ts +74 -88
  204. package/src/mcp/buildMcpServer.ts +294 -0
  205. package/src/mcp/builtin/collections/authTools.ts +280 -0
  206. package/src/mcp/builtin/collections/countTool.ts +61 -0
  207. package/src/mcp/builtin/collections/countVersionsTool.ts +60 -0
  208. package/src/mcp/builtin/collections/createTool.ts +143 -0
  209. package/src/mcp/builtin/collections/deleteTool.ts +99 -0
  210. package/src/mcp/builtin/collections/duplicateTool.ts +84 -0
  211. package/src/mcp/builtin/collections/fileInput.spec.ts +93 -0
  212. package/src/mcp/builtin/collections/fileInput.ts +127 -0
  213. package/src/mcp/builtin/collections/findDistinctTool.ts +67 -0
  214. package/src/mcp/builtin/collections/findTool.ts +134 -0
  215. package/src/mcp/builtin/collections/findVersionByIDTool.ts +66 -0
  216. package/src/mcp/builtin/collections/findVersionsTool.ts +83 -0
  217. package/src/mcp/builtin/collections/getCollectionSchemaTool.ts +91 -0
  218. package/src/mcp/builtin/collections/restoreVersionTool.ts +65 -0
  219. package/src/mcp/builtin/collections/updateTool.ts +173 -0
  220. package/src/mcp/builtin/collections/uploadInstructionsTool.ts +64 -0
  221. package/src/mcp/builtin/formatEntityError.ts +77 -0
  222. package/src/mcp/builtin/getConfigInfoTool.ts +68 -0
  223. package/src/mcp/builtin/globals/countVersionsTool.ts +60 -0
  224. package/src/mcp/builtin/globals/findTool.ts +66 -0
  225. package/src/mcp/builtin/globals/findVersionByIDTool.ts +64 -0
  226. package/src/mcp/builtin/globals/findVersionsTool.ts +69 -0
  227. package/src/mcp/builtin/globals/getGlobalSchemaTool.ts +73 -0
  228. package/src/mcp/builtin/globals/restoreVersionTool.ts +68 -0
  229. package/src/mcp/builtin/globals/updateTool.ts +92 -0
  230. package/src/mcp/builtinTools.ts +161 -0
  231. package/src/mcp/sanitizeMCPConfig.ts +282 -0
  232. package/src/stdio.ts +131 -0
  233. package/src/types.ts +401 -481
  234. package/src/utils/getLogger.ts +22 -0
  235. package/src/utils/getPluginConfig.ts +24 -0
  236. package/src/utils/resolveProjectRoot.ts +17 -0
  237. package/src/utils/seal.ts +46 -0
  238. package/src/utils/toStandardSchema.ts +9 -0
  239. package/src/views/Authorize/AllowButtons/index.tsx +97 -0
  240. package/src/views/Authorize/index.css +19 -0
  241. package/src/views/Authorize/index.tsx +93 -0
  242. package/dist/collections/createApiKeysCollection.d.ts +0 -7
  243. package/dist/collections/createApiKeysCollection.d.ts.map +0 -1
  244. package/dist/collections/createApiKeysCollection.js +0 -317
  245. package/dist/collections/createApiKeysCollection.js.map +0 -1
  246. package/dist/defaults.d.ts +0 -4
  247. package/dist/defaults.d.ts.map +0 -1
  248. package/dist/defaults.js +0 -5
  249. package/dist/defaults.js.map +0 -1
  250. package/dist/endpoints/mcp.d.ts +0 -4
  251. package/dist/endpoints/mcp.d.ts.map +0 -1
  252. package/dist/endpoints/mcp.js +0 -71
  253. package/dist/endpoints/mcp.js.map +0 -1
  254. package/dist/mcp/createRequest.d.ts +0 -3
  255. package/dist/mcp/createRequest.d.ts.map +0 -1
  256. package/dist/mcp/createRequest.js +0 -14
  257. package/dist/mcp/createRequest.js.map +0 -1
  258. package/dist/mcp/getMcpHandler.d.ts +0 -4
  259. package/dist/mcp/getMcpHandler.d.ts.map +0 -1
  260. package/dist/mcp/getMcpHandler.js +0 -231
  261. package/dist/mcp/getMcpHandler.js.map +0 -1
  262. package/dist/mcp/helpers/config.d.ts +0 -22
  263. package/dist/mcp/helpers/config.d.ts.map +0 -1
  264. package/dist/mcp/helpers/config.js +0 -153
  265. package/dist/mcp/helpers/config.js.map +0 -1
  266. package/dist/mcp/helpers/fields.d.ts +0 -19
  267. package/dist/mcp/helpers/fields.d.ts.map +0 -1
  268. package/dist/mcp/helpers/fields.js +0 -102
  269. package/dist/mcp/helpers/fields.js.map +0 -1
  270. package/dist/mcp/helpers/fileValidation.d.ts +0 -67
  271. package/dist/mcp/helpers/fileValidation.d.ts.map +0 -1
  272. package/dist/mcp/helpers/fileValidation.js +0 -267
  273. package/dist/mcp/helpers/fileValidation.js.map +0 -1
  274. package/dist/mcp/registerTool.d.ts +0 -6
  275. package/dist/mcp/registerTool.d.ts.map +0 -1
  276. package/dist/mcp/registerTool.js +0 -18
  277. package/dist/mcp/registerTool.js.map +0 -1
  278. package/dist/mcp/tools/auth/auth.d.ts +0 -4
  279. package/dist/mcp/tools/auth/auth.d.ts.map +0 -1
  280. package/dist/mcp/tools/auth/auth.js +0 -57
  281. package/dist/mcp/tools/auth/auth.js.map +0 -1
  282. package/dist/mcp/tools/auth/forgotPassword.d.ts +0 -4
  283. package/dist/mcp/tools/auth/forgotPassword.d.ts.map +0 -1
  284. package/dist/mcp/tools/auth/forgotPassword.js +0 -48
  285. package/dist/mcp/tools/auth/forgotPassword.js.map +0 -1
  286. package/dist/mcp/tools/auth/login.d.ts +0 -4
  287. package/dist/mcp/tools/auth/login.d.ts.map +0 -1
  288. package/dist/mcp/tools/auth/login.js +0 -51
  289. package/dist/mcp/tools/auth/login.js.map +0 -1
  290. package/dist/mcp/tools/auth/resetPassword.d.ts +0 -4
  291. package/dist/mcp/tools/auth/resetPassword.d.ts.map +0 -1
  292. package/dist/mcp/tools/auth/resetPassword.js +0 -49
  293. package/dist/mcp/tools/auth/resetPassword.js.map +0 -1
  294. package/dist/mcp/tools/auth/unlock.d.ts +0 -4
  295. package/dist/mcp/tools/auth/unlock.d.ts.map +0 -1
  296. package/dist/mcp/tools/auth/unlock.js +0 -48
  297. package/dist/mcp/tools/auth/unlock.js.map +0 -1
  298. package/dist/mcp/tools/auth/verify.d.ts +0 -4
  299. package/dist/mcp/tools/auth/verify.d.ts.map +0 -1
  300. package/dist/mcp/tools/auth/verify.js +0 -45
  301. package/dist/mcp/tools/auth/verify.js.map +0 -1
  302. package/dist/mcp/tools/collection/create.d.ts +0 -10
  303. package/dist/mcp/tools/collection/create.d.ts.map +0 -1
  304. package/dist/mcp/tools/collection/create.js +0 -139
  305. package/dist/mcp/tools/collection/create.js.map +0 -1
  306. package/dist/mcp/tools/collection/delete.d.ts +0 -10
  307. package/dist/mcp/tools/collection/delete.d.ts.map +0 -1
  308. package/dist/mcp/tools/collection/delete.js +0 -154
  309. package/dist/mcp/tools/collection/delete.js.map +0 -1
  310. package/dist/mcp/tools/collection/find.d.ts +0 -10
  311. package/dist/mcp/tools/collection/find.d.ts.map +0 -1
  312. package/dist/mcp/tools/collection/find.js +0 -165
  313. package/dist/mcp/tools/collection/find.js.map +0 -1
  314. package/dist/mcp/tools/collection/update.d.ts +0 -10
  315. package/dist/mcp/tools/collection/update.d.ts.map +0 -1
  316. package/dist/mcp/tools/collection/update.js +0 -209
  317. package/dist/mcp/tools/collection/update.js.map +0 -1
  318. package/dist/mcp/tools/config/find.d.ts +0 -10
  319. package/dist/mcp/tools/config/find.d.ts.map +0 -1
  320. package/dist/mcp/tools/config/find.js +0 -97
  321. package/dist/mcp/tools/config/find.js.map +0 -1
  322. package/dist/mcp/tools/config/update.d.ts +0 -10
  323. package/dist/mcp/tools/config/update.d.ts.map +0 -1
  324. package/dist/mcp/tools/config/update.js +0 -215
  325. package/dist/mcp/tools/config/update.js.map +0 -1
  326. package/dist/mcp/tools/global/find.d.ts +0 -5
  327. package/dist/mcp/tools/global/find.d.ts.map +0 -1
  328. package/dist/mcp/tools/global/find.js +0 -82
  329. package/dist/mcp/tools/global/find.js.map +0 -1
  330. package/dist/mcp/tools/global/update.d.ts +0 -6
  331. package/dist/mcp/tools/global/update.d.ts.map +0 -1
  332. package/dist/mcp/tools/global/update.js +0 -124
  333. package/dist/mcp/tools/global/update.js.map +0 -1
  334. package/dist/mcp/tools/job/create.d.ts +0 -10
  335. package/dist/mcp/tools/job/create.d.ts.map +0 -1
  336. package/dist/mcp/tools/job/create.js +0 -293
  337. package/dist/mcp/tools/job/create.js.map +0 -1
  338. package/dist/mcp/tools/job/run.d.ts +0 -10
  339. package/dist/mcp/tools/job/run.d.ts.map +0 -1
  340. package/dist/mcp/tools/job/run.js +0 -129
  341. package/dist/mcp/tools/job/run.js.map +0 -1
  342. package/dist/mcp/tools/job/update.d.ts +0 -11
  343. package/dist/mcp/tools/job/update.d.ts.map +0 -1
  344. package/dist/mcp/tools/job/update.js +0 -186
  345. package/dist/mcp/tools/job/update.js.map +0 -1
  346. package/dist/mcp/tools/resource/create.d.ts +0 -6
  347. package/dist/mcp/tools/resource/create.d.ts.map +0 -1
  348. package/dist/mcp/tools/resource/create.js +0 -124
  349. package/dist/mcp/tools/resource/create.js.map +0 -1
  350. package/dist/mcp/tools/resource/delete.d.ts +0 -5
  351. package/dist/mcp/tools/resource/delete.d.ts.map +0 -1
  352. package/dist/mcp/tools/resource/delete.js +0 -151
  353. package/dist/mcp/tools/resource/delete.js.map +0 -1
  354. package/dist/mcp/tools/resource/find.d.ts +0 -5
  355. package/dist/mcp/tools/resource/find.d.ts.map +0 -1
  356. package/dist/mcp/tools/resource/find.js +0 -170
  357. package/dist/mcp/tools/resource/find.js.map +0 -1
  358. package/dist/mcp/tools/resource/update.d.ts +0 -6
  359. package/dist/mcp/tools/resource/update.d.ts.map +0 -1
  360. package/dist/mcp/tools/resource/update.js +0 -256
  361. package/dist/mcp/tools/resource/update.js.map +0 -1
  362. package/dist/mcp/tools/schemas.d.ts +0 -457
  363. package/dist/mcp/tools/schemas.d.ts.map +0 -1
  364. package/dist/mcp/tools/schemas.js +0 -243
  365. package/dist/mcp/tools/schemas.js.map +0 -1
  366. package/dist/utils/adminEntitySettings.d.ts +0 -17
  367. package/dist/utils/adminEntitySettings.d.ts.map +0 -1
  368. package/dist/utils/adminEntitySettings.js +0 -41
  369. package/dist/utils/adminEntitySettings.js.map +0 -1
  370. package/dist/utils/createApiKeyFields.d.ts +0 -15
  371. package/dist/utils/createApiKeyFields.d.ts.map +0 -1
  372. package/dist/utils/createApiKeyFields.js +0 -57
  373. package/dist/utils/createApiKeyFields.js.map +0 -1
  374. package/dist/utils/getEnabledSlugs.d.ts +0 -13
  375. package/dist/utils/getEnabledSlugs.d.ts.map +0 -1
  376. package/dist/utils/getEnabledSlugs.js +0 -32
  377. package/dist/utils/getEnabledSlugs.js.map +0 -1
  378. package/dist/utils/getVirtualFieldNames.d.ts +0 -14
  379. package/dist/utils/getVirtualFieldNames.d.ts.map +0 -1
  380. package/dist/utils/getVirtualFieldNames.js +0 -35
  381. package/dist/utils/getVirtualFieldNames.js.map +0 -1
  382. package/dist/utils/schemaConversion/convertCollectionSchemaToZod.d.ts +0 -3
  383. package/dist/utils/schemaConversion/convertCollectionSchemaToZod.d.ts.map +0 -1
  384. package/dist/utils/schemaConversion/convertCollectionSchemaToZod.js +0 -43
  385. package/dist/utils/schemaConversion/convertCollectionSchemaToZod.js.map +0 -1
  386. package/dist/utils/schemaConversion/removeVirtualFieldsFromSchema.d.ts +0 -7
  387. package/dist/utils/schemaConversion/removeVirtualFieldsFromSchema.d.ts.map +0 -1
  388. package/dist/utils/schemaConversion/removeVirtualFieldsFromSchema.js +0 -20
  389. package/dist/utils/schemaConversion/removeVirtualFieldsFromSchema.js.map +0 -1
  390. package/dist/utils/schemaConversion/sanitizeJsonSchema.d.ts +0 -13
  391. package/dist/utils/schemaConversion/sanitizeJsonSchema.d.ts.map +0 -1
  392. package/dist/utils/schemaConversion/sanitizeJsonSchema.js +0 -56
  393. package/dist/utils/schemaConversion/sanitizeJsonSchema.js.map +0 -1
  394. package/dist/utils/schemaConversion/simplifyRelationshipFields.d.ts +0 -20
  395. package/dist/utils/schemaConversion/simplifyRelationshipFields.d.ts.map +0 -1
  396. package/dist/utils/schemaConversion/simplifyRelationshipFields.js +0 -53
  397. package/dist/utils/schemaConversion/simplifyRelationshipFields.js.map +0 -1
  398. package/dist/utils/schemaConversion/transformPointFields.d.ts +0 -3
  399. package/dist/utils/schemaConversion/transformPointFields.d.ts.map +0 -1
  400. package/dist/utils/schemaConversion/transformPointFields.js +0 -51
  401. package/dist/utils/schemaConversion/transformPointFields.js.map +0 -1
  402. package/dist/utils/transformPointDataToPayload.d.ts +0 -7
  403. package/dist/utils/transformPointDataToPayload.d.ts.map +0 -1
  404. package/dist/utils/transformPointDataToPayload.js +0 -28
  405. package/dist/utils/transformPointDataToPayload.js.map +0 -1
  406. package/src/collections/createApiKeysCollection.ts +0 -373
  407. package/src/defaults.ts +0 -3
  408. package/src/endpoints/mcp.ts +0 -91
  409. package/src/mcp/createRequest.ts +0 -13
  410. package/src/mcp/getMcpHandler.ts +0 -545
  411. package/src/mcp/helpers/config.ts +0 -213
  412. package/src/mcp/helpers/fields.ts +0 -154
  413. package/src/mcp/helpers/fileValidation.ts +0 -362
  414. package/src/mcp/registerTool.ts +0 -22
  415. package/src/mcp/tools/auth/auth.ts +0 -71
  416. package/src/mcp/tools/auth/forgotPassword.ts +0 -70
  417. package/src/mcp/tools/auth/login.ts +0 -72
  418. package/src/mcp/tools/auth/resetPassword.ts +0 -61
  419. package/src/mcp/tools/auth/unlock.ts +0 -64
  420. package/src/mcp/tools/auth/verify.ts +0 -57
  421. package/src/mcp/tools/collection/create.ts +0 -210
  422. package/src/mcp/tools/collection/delete.ts +0 -211
  423. package/src/mcp/tools/collection/find.ts +0 -224
  424. package/src/mcp/tools/collection/update.ts +0 -290
  425. package/src/mcp/tools/config/find.ts +0 -128
  426. package/src/mcp/tools/config/update.ts +0 -280
  427. package/src/mcp/tools/global/find.ts +0 -128
  428. package/src/mcp/tools/global/update.ts +0 -207
  429. package/src/mcp/tools/job/create.ts +0 -416
  430. package/src/mcp/tools/job/run.ts +0 -167
  431. package/src/mcp/tools/job/update.ts +0 -274
  432. package/src/mcp/tools/resource/create.ts +0 -211
  433. package/src/mcp/tools/resource/delete.ts +0 -218
  434. package/src/mcp/tools/resource/find.ts +0 -246
  435. package/src/mcp/tools/resource/update.ts +0 -383
  436. package/src/mcp/tools/schemas.ts +0 -520
  437. package/src/utils/adminEntitySettings.ts +0 -40
  438. package/src/utils/createApiKeyFields.ts +0 -72
  439. package/src/utils/getEnabledSlugs.ts +0 -42
  440. package/src/utils/getVirtualFieldNames.ts +0 -53
  441. package/src/utils/schemaConversion/convertCollectionSchemaToZod.ts +0 -52
  442. package/src/utils/schemaConversion/removeVirtualFieldsFromSchema.ts +0 -27
  443. package/src/utils/schemaConversion/sanitizeJsonSchema.ts +0 -62
  444. package/src/utils/schemaConversion/simplifyRelationshipFields.ts +0 -65
  445. package/src/utils/schemaConversion/transformPointFields.ts +0 -55
  446. package/src/utils/transformPointDataToPayload.ts +0 -40
package/src/types.ts CHANGED
@@ -1,542 +1,462 @@
1
1
  import type {
2
- CollectionConfig,
2
+ CallToolResult,
3
+ ContentBlock,
4
+ Implementation,
5
+ JsonSchemaType,
6
+ McpServerOptions,
7
+ ResourceTemplate,
8
+ ServerContext,
9
+ StandardSchemaWithJSON,
10
+ ToolAnnotations,
11
+ } from '@modelcontextprotocol/server'
12
+ import type {
13
+ AuthCollectionSlug,
3
14
  CollectionSlug,
4
15
  GlobalSlug,
16
+ MaybePromise,
5
17
  PayloadRequest,
6
- TypedUser,
18
+ SanitizedPermissions,
7
19
  } from 'payload'
8
- import type { z } from 'zod'
9
20
 
10
- import { type ResourceTemplate } from '@modelcontextprotocol/sdk/server/mcp.js'
21
+ import type { GetAuthorizedMCPArgs } from './endpoint/access.js'
22
+ import type {
23
+ MCPCollectionAuthToolName,
24
+ MCPCollectionBuiltinName,
25
+ MCPGlobalBuiltinName,
26
+ } from './mcp/builtinTools.js'
11
27
 
12
- export type MCPPluginConfig = {
13
- /**
14
- * Set the collections that should be available as resources via MCP.
15
- */
16
- collections?: Partial<
17
- Record<
18
- CollectionSlug,
19
- {
20
- /**
21
- * Set the description of the collection. This is used by MCP clients to determine when to use the collecton as a resource.
22
- */
23
- description?: string
24
- /**
25
- * Set the enabled capabilities of the collection. Admins can then allow or disallow the use of the capability by MCP clients.
26
- */
27
- enabled:
28
- | {
29
- create?: boolean
30
- delete?: boolean
31
- find?: boolean
32
- update?: boolean
33
- }
34
- | boolean
35
-
36
- /**
37
- * Override the response generated by the MCP client. This allows you to modify the response that is sent to the MCP client. This is useful for adding additional data to the response, data normalization, or verifying data.
38
- */
39
- overrideResponse?: (
40
- response: {
41
- content: Array<{
42
- text: string
43
- type: string
44
- }>
45
- },
46
- doc: Record<string, unknown>,
47
- req: PayloadRequest,
48
- ) => {
49
- content: Array<{
50
- text: string
51
- type: string
52
- }>
53
- }
54
- }
55
- >
56
- >
28
+ export type { MCPCollectionAuthToolName, MCPCollectionBuiltinName, MCPGlobalBuiltinName }
29
+
30
+ /** Re-exported from `@modelcontextprotocol/server` — common MCP types used in plugin config. */
31
+ export type { JsonSchemaType, StandardSchemaWithJSON, ToolAnnotations }
32
+
33
+ /**
34
+ * What a tool's `input` (or a prompt's `argsSchema`) can be — either a raw
35
+ * JSON Schema 2020-12 literal, or a Standard Schema instance (Zod, Valibot, …).
36
+ * Raw schemas may omit `$schema`; when present it must declare the 2020-12 dialect.
37
+ */
38
+ export type ToolInputSchema = JsonSchemaType | StandardSchemaWithJSON
39
+
40
+ export type MCPToolResponse = {
41
+ content: ContentBlock[]
57
42
  /**
58
- * Disable the MCP plugin.
43
+ * If available, return the document fetched within the
44
+ * mcp tool. This is threaded as an additional argument to
45
+ * overrideResponse functions and stripped before going on the wire.
59
46
  */
60
- disabled?: boolean
47
+ doc?: Record<string, unknown>
48
+ } & Pick<CallToolResult, '_meta' | 'isError' | 'structuredContent'>
49
+
50
+ export type MCPResponseOverride = (
51
+ response: MCPToolResponse,
52
+ doc: Record<string, unknown>,
53
+ req: PayloadRequest,
54
+ ) => MCPToolResponse
55
+
56
+ export type MCPAfterToolCallHook = (args: {
57
+ input: unknown
58
+ req: PayloadRequest
59
+ response: MCPToolResponse
60
+ toolName: string
61
+ }) => MaybePromise<MCPToolResponse>
62
+
63
+ /**
64
+ * The handler's `input` type. A specific Standard Schema (Zod, Valibot, …) gets
65
+ * its inferred output; anything else falls back to `Record<string, unknown>`.
66
+ */
67
+ export type TypedInput<TSchema> = TSchema extends StandardSchemaWithJSON
68
+ ? StandardSchemaWithJSON extends TSchema
69
+ ? Record<string, unknown>
70
+ : StandardSchemaWithJSON.InferOutput<TSchema>
71
+ : Record<string, unknown>
72
+
73
+ export type MCPAccessArgs = {
74
+ permissions?: SanitizedPermissions
75
+ req: PayloadRequest
76
+ }
77
+
78
+ export type CollectionMCPAccessArgs = {
79
+ slug: CollectionSlug
80
+ } & MCPAccessArgs
81
+
82
+ export type GlobalMCPAccessArgs = {
83
+ slug: GlobalSlug
84
+ } & MCPAccessArgs
85
+
86
+ export type ToolHandlerArgs<TSchema = undefined> = {
87
+ authorizedMCP: AuthorizedMCP
88
+ input: TypedInput<TSchema>
89
+ req: PayloadRequest
90
+ serverContext: ServerContext
91
+ }
92
+
93
+ export type CollectionToolHandlerArgs<TSchema = undefined> = {
94
+ slug: CollectionSlug
95
+ } & ToolHandlerArgs<TSchema>
96
+
97
+ export type GlobalToolHandlerArgs<TSchema = undefined> = {
98
+ slug: GlobalSlug
99
+ } & ToolHandlerArgs<TSchema>
100
+
101
+ export type Tool<TSchema extends ToolInputSchema | undefined = ToolInputSchema | undefined> = {
61
102
  /**
62
- * Experimental features
63
- * **These features are for experimental purposes -- They are Disabled in Production by Default**
103
+ * Runs while authorizing each MCP request, before the tool is advertised or called. Return
104
+ * `false` to make the tool unavailable for that request. This is skipped when `overrideAccess`
105
+ * is enabled.
64
106
  */
65
- experimental?: {
66
- /**
67
- * These are MCP tools that can be used by a client to modify Payload.
68
- */
69
- tools: {
70
- /**
71
- * **Experimental** -- Auth MCP tools allow a client to change authentication priviliages for users. This is for developing ideas that help Admins with authentication tasks.
72
- */
73
- auth?: {
74
- /**
75
- * Enable the auth MCP tools. This allows Admins to enable or disable the auth capabilities.
76
- * @default false
77
- */
78
- enabled: boolean
79
- }
80
- /**
81
- * **Experimental** -- Collection MCP tools allow for the creation, modification, and deletion of Payload collections. This is for developing ideas that help Developers with collection tasks.
82
- */
83
- collections?: {
84
- /**
85
- * Set the directory path to the collections directory. This can be a directory outside of your default directory, or another Payload project.
86
- */
87
- collectionsDirPath: string
88
- /**
89
- * Enable the collection MCP tools. This allows Admins to enable or disable the Collection modification capabilities.
90
- * @default false
91
- */
92
- enabled: boolean
93
- }
94
- /**
95
- * **Experimental** -- Config MCP tools allow for the modification of a Payload Config. This is for developing ideas that help Developers with config tasks.
96
- */
97
- config?: {
98
- /**
99
- * Set the directory path to the config directory. This can be a directory outside of your default directory, or another Payload project.
100
- */
101
- configFilePath: string
102
- /**
103
- * Enable the config MCP tools. This allows Admins to enable or disable the Payload Config modification capabilities.
104
- * @default false
105
- */
106
- enabled: boolean
107
- }
108
- /**
109
- * **Experimental** -- Jobs MCP tools allow for the modification of Payload jobs. This is for developing ideas that help Developers with job tasks.
110
- */
111
- jobs?: {
112
- /**
113
- * Enable the jobs MCP tools. This allows Admins to enable or disable the Job modification capabilities.
114
- * @default false
115
- */
116
- enabled: boolean
117
- /**
118
- * Set the directory path to the jobs directory. This can be a directory outside of your default directory, or another Payload project.
119
- */
120
- jobsDirPath: string
121
- }
122
- }
123
- }
107
+ access?: (args: MCPAccessArgs) => MaybePromise<boolean>
108
+ annotations?: ToolAnnotations
109
+ description: string
110
+ handler: (args: ToolHandlerArgs<TSchema>) => MaybePromise<MCPToolResponse>
111
+ input?: TSchema
124
112
  /**
125
- * Set the globals that should be available as resources via MCP.
126
- * Globals are singleton configuration objects (e.g., site settings, navigation).
127
- * Note: Globals only support find and update operations.
113
+ * Override the return value of the tool handler
128
114
  */
129
- globals?: Partial<
130
- Record<
131
- GlobalSlug,
132
- {
133
- /**
134
- * Set the description of the global. This is used by MCP clients to determine when to use the global as a resource.
135
- */
136
- description?: string
137
- /**
138
- * Set the enabled capabilities of the global. Admins can then allow or disallow the use of the capability by MCP clients.
139
- * Note: Globals only support find and update operations as they are singletons.
140
- */
141
- enabled:
142
- | {
143
- find?: boolean
144
- update?: boolean
145
- }
146
- | boolean
147
-
148
- /**
149
- * Override the response generated by the MCP client. This allows you to modify the response that is sent to the MCP client. This is useful for adding additional data to the response, data normalization, or verifying data.
150
- */
151
- overrideResponse?: (
152
- response: {
153
- content: Array<{
154
- text: string
155
- type: string
156
- }>
157
- },
158
- doc: Record<string, unknown>,
159
- req: PayloadRequest,
160
- ) => {
161
- content: Array<{
162
- text: string
163
- type: string
164
- }>
165
- }
166
- }
167
- >
168
- >
115
+ overrideResponse?: MCPResponseOverride
116
+ }
117
+
118
+ export type CollectionTool<
119
+ TSchema extends ToolInputSchema | undefined = ToolInputSchema | undefined,
120
+ > = {
169
121
  /**
170
- * MCP Server options.
122
+ * Runs while authorizing each MCP request for this collection. Return `false` to reject calls
123
+ * to this tool for the collection. The shared tool is not advertised when no collections allow
124
+ * it, but can remain advertised when it is available for another collection. This is skipped
125
+ * when `overrideAccess` is enabled.
171
126
  */
172
- mcp?: {
173
- handlerOptions?: MCPHandlerOptions
174
- /**
175
- * Add custom MCP Prompts.
176
- */
177
- prompts?: {
178
- /**
179
- * Set the args schema of the prompt. This is the args schema that will be passed to the prompt. This is used by MCP clients to determine the arguments that will be passed to the prompt.
180
- */
181
- argsSchema: z.ZodRawShape
182
- /**
183
- * Set the description of the prompt. This is used by MCP clients to determine when to use the prompt.
184
- */
185
- description: string
186
- /**
187
- * Set the handler of the prompt. This is the function that will be called when the prompt is used.
188
- */
189
- handler: (
190
- args: Record<string, unknown>,
191
- req: PayloadRequest,
192
- _extra: unknown,
193
- ) =>
194
- | {
195
- messages: Array<{
196
- content: {
197
- text: string
198
- type: 'text'
199
- }
200
- role: 'assistant' | 'user'
201
- }>
202
- }
203
- | Promise<{
204
- messages: Array<{
205
- content: {
206
- text: string
207
- type: 'text'
208
- }
209
- role: 'assistant' | 'user'
210
- }>
211
- }>
212
- /**
213
- * Set the function name of the prompt.
214
- */
215
- name: string
216
- /**
217
- * Set the title of the prompt. LLMs will interperate the title to determine when to use the prompt.
218
- */
219
- title: string
220
- }[]
127
+ access?: (args: CollectionMCPAccessArgs) => MaybePromise<boolean>
128
+ handler: (args: CollectionToolHandlerArgs<TSchema>) => MaybePromise<MCPToolResponse>
129
+ input?: TSchema
130
+ } & Pick<Tool, 'annotations' | 'description' | 'overrideResponse'>
221
131
 
132
+ export type GlobalTool<TSchema extends ToolInputSchema | undefined = ToolInputSchema | undefined> =
133
+ {
222
134
  /**
223
- * Add custom MCP Resource.
135
+ * Runs while authorizing each MCP request for this global. Return `false` to reject calls to
136
+ * this tool for the global. The shared tool is not advertised when no globals allow it, but
137
+ * can remain advertised when it is available for another global. This is skipped when
138
+ * `overrideAccess` is enabled.
224
139
  */
225
- resources?: {
226
- /**
227
- * Set the description of the resource. This is used by MCP clients to determine when to use the resource.
228
- * example: 'Data is a resource that contains special data.'
229
- */
230
- description: string
231
- /**
232
- * Set the handler of the resource. This is the function that will be called when the resource is used.
233
- * The handler can have either 3 arguments (when no args are passed) or 4 arguments (when args are passed).
234
- */
235
- handler: (...args: any[]) =>
236
- | {
237
- contents: Array<{
238
- text: string
239
- uri: string
240
- }>
241
- }
242
- | Promise<{
243
- contents: Array<{
244
- text: string
245
- uri: string
246
- }>
247
- }>
248
- /**
249
- * Set the mime type of the resource.
250
- * example: 'text/plain'
251
- */
252
- mimeType: string
253
- /**
254
- * Set the function name of the resource.
255
- * example: 'data'
256
- */
257
- name: string
258
- /**
259
- * Set the title of the resource. LLMs will interperate the title to determine when to use the resource.
260
- * example: 'Data'
261
- */
262
- title: string
263
- /**
264
- * Set the uri of the resource.
265
- * example: 'data://app'
266
- */
267
- uri: ResourceTemplate | string
268
- }[]
269
- serverOptions?: MCPServerOptions
270
- /**
271
- * Add custom MCP Tools.
272
- */
273
- tools?: {
274
- /**
275
- * Set the description of the tool. This is used by MCP clients to determine when to use the tool.
276
- */
277
- description: string
278
- /**
279
- * Set the handler of the tool. This is the function that will be called when the tool is used.
280
- */
281
- handler: (
282
- args: Record<string, unknown>,
283
- req: PayloadRequest,
284
- _extra: unknown,
285
- ) =>
286
- | {
287
- content: Array<{
288
- text: string
289
- type: 'text'
290
- }>
291
- role?: string
292
- }
293
- | Promise<{
294
- content: Array<{
295
- text: string
296
- type: 'text'
297
- }>
298
- role?: string
299
- }>
300
- /**
301
- * Set the name of the tool. This is the name that will be used to identify the tool. LLMs will interperate the name to determine when to use the tool.
302
- */
303
- name: string
304
- /**
305
- * Set the parameters of the tool. This is the parameters that will be passed to the tool.
306
- */
307
- parameters: z.ZodRawShape
308
- }[]
309
- }
310
-
311
- /**
312
- * Override the API key collection.
313
- * This allows you to add fields to the API key collection or modify the collection in any way you want.
314
- * @param collection - The API key collection.
315
- * @returns The modified API key collection.
316
- */
317
- overrideApiKeyCollection?: (collection: CollectionConfig) => CollectionConfig
140
+ access?: (args: GlobalMCPAccessArgs) => MaybePromise<boolean>
141
+ handler: (args: GlobalToolHandlerArgs<TSchema>) => MaybePromise<MCPToolResponse>
142
+ input?: TSchema
143
+ } & Pick<Tool, 'annotations' | 'description' | 'overrideResponse'>
318
144
 
145
+ /**
146
+ * Configures (or disables) a built-in tool without replacing it.
147
+ * `handler?: never` prevents a full `CollectionTool`/`GlobalTool` (which has a
148
+ * required handler) from being silently accepted at a built-in key slot.
149
+ */
150
+ export type MCPBuiltInCollectionToolOverride = {
319
151
  /**
320
- * Override the authentication method.
321
- * This allows you to use a custom authentication method instead of the default API key authentication.
322
- * @param req - The request object.
323
- * @returns The MCP access settings.
152
+ * Replaces the built-in tool's access check. Return `false` to make the tool unavailable for
153
+ * this collection. This is skipped when `overrideAccess` is enabled.
324
154
  */
325
- overrideAuth?: (
326
- req: PayloadRequest,
327
- getDefaultMcpAccessSettings: (overrideApiKey?: null | string) => Promise<MCPAccessSettings>,
328
- ) => MCPAccessSettings | Promise<MCPAccessSettings>
155
+ access?: (args: CollectionMCPAccessArgs) => MaybePromise<boolean>
156
+ annotations?: ToolAnnotations
157
+ description?: string
158
+ handler?: never
159
+ overrideResponse?: MCPResponseOverride
160
+ }
329
161
 
162
+ export type MCPBuiltInGlobalToolOverride = {
330
163
  /**
331
- * Set the users collection that API keys should be associated with.
164
+ * Replaces the built-in tool's access check. Return `false` to make the tool unavailable for
165
+ * this global. This is skipped when `overrideAccess` is enabled.
332
166
  */
333
- userCollection?: CollectionSlug
167
+ access?: (args: GlobalMCPAccessArgs) => MaybePromise<boolean>
168
+ annotations?: ToolAnnotations
169
+ description?: string
170
+ handler?: never
171
+ overrideResponse?: MCPResponseOverride
334
172
  }
335
173
 
336
174
  /**
337
- * MCP Handler options.
175
+ * Value at a custom (non-built-in) tool key. Either the tool itself, or `false`
176
+ * to disable it (useful when one plugin defines a custom tool and another
177
+ * wants to opt out per-collection).
338
178
  */
339
- export type MCPHandlerOptions = {
340
- /**
341
- * Set the base path of the MCP handler. This is the path that will be used to access the MCP handler.
342
- * @default /api
343
- */
344
- basePath?: string
345
- /**
346
- * If true, disables the SSE endpoint. Only Streamable HTTP will be available.
347
- * @default true
348
- */
349
- disableSse?: boolean
179
+ export type MCPTopLevelToolEntry = Tool
180
+
181
+ export type MCPCollectionToolsMap = {
182
+ [customToolName: string]: boolean | CollectionTool | MCPBuiltInCollectionToolOverride | undefined
183
+ } & {
184
+ [K in MCPCollectionBuiltinName]?: false | MCPBuiltInCollectionToolOverride
185
+ }
186
+
187
+ export type MCPAuthCollectionToolsMap = {
188
+ [K in MCPCollectionAuthToolName]?: MCPBuiltInCollectionToolOverride | true
189
+ } & MCPCollectionToolsMap
190
+
191
+ /** Auth-enabled collections get auth-tool name autocomplete; others get CRUD-only. */
192
+ export type MCPToolsMapForCollection<Slug extends CollectionSlug> = Slug extends AuthCollectionSlug
193
+ ? MCPAuthCollectionToolsMap
194
+ : MCPCollectionToolsMap
195
+
196
+ export type MCPGlobalToolsMap = {
197
+ [customToolName: string]: boolean | GlobalTool | MCPBuiltInGlobalToolOverride | undefined
198
+ } & {
199
+ [K in MCPGlobalBuiltinName]?: false | MCPBuiltInGlobalToolOverride
200
+ }
201
+
202
+ export type MCPTopLevelToolsMap = Record<string, Tool>
203
+
204
+ export type PromptHandlerArgs<TSchema = undefined> = {
205
+ input: TypedInput<TSchema>
206
+ req: PayloadRequest
207
+ serverContext: ServerContext
208
+ }
209
+
210
+ export type Prompt<TSchema extends ToolInputSchema = ToolInputSchema> = {
350
211
  /**
351
- * Set the maximum duration of the MCP handler. This is the maximum duration that the MCP handler will run for.
352
- * @default 60
212
+ * Runs while authorizing each MCP request, before the prompt is advertised or used. Return
213
+ * `false` to make the prompt unavailable for that request. This is skipped when
214
+ * `overrideAccess` is enabled.
353
215
  */
354
- maxDuration?: number
216
+ access?: (args: MCPAccessArgs) => MaybePromise<boolean>
217
+ argsSchema: TSchema
218
+ description: string
219
+ handler: (args: PromptHandlerArgs<TSchema>) => MaybePromise<{
220
+ messages: Array<{ content: { text: string; type: 'text' }; role: 'assistant' | 'user' }>
221
+ }>
222
+ title: string
223
+ }
224
+
225
+ export type ResourceHandlerArgs = {
226
+ /** Variables extracted from a `ResourceTemplate` URI. Empty for static-URI resources. */
227
+ params: Record<string, string>
228
+ req: PayloadRequest
229
+ serverContext: ServerContext
230
+ uri: URL
231
+ }
232
+
233
+ export type Resource = {
355
234
  /**
356
- * Callback function that receives MCP events.
357
- * This can be used to track analytics, debug issues, or implement custom behaviors.
235
+ * Runs while authorizing each MCP request, before the resource is advertised or read. Return
236
+ * `false` to make the resource unavailable for that request. This is skipped when
237
+ * `overrideAccess` is enabled.
358
238
  */
359
- onEvent?: (event: unknown) => void
239
+ access?: (args: MCPAccessArgs) => MaybePromise<boolean>
240
+ description: string
241
+ handler: (args: ResourceHandlerArgs) => MaybePromise<{
242
+ contents: Array<{ text: string; uri: string }>
243
+ }>
244
+ mimeType: string
245
+ title: string
246
+ uri: ResourceTemplate | string
247
+ }
248
+
249
+ export type MCPPluginCollectionConfig<TSlug extends CollectionSlug> = {
250
+ description?: string
251
+ /** Fallback for built-in tools that don't set their own `overrideResponse`. */
252
+ overrideResponse?: MCPResponseOverride
253
+ tools?: MCPToolsMapForCollection<TSlug>
254
+ }
255
+
256
+ export type MCPPluginGlobalConfig = {
257
+ description?: string
258
+ overrideResponse?: MCPResponseOverride
259
+ tools?: MCPGlobalToolsMap
260
+ }
261
+
262
+ /**
263
+ * The user-facing config shape passed to `mcpPlugin({ ... })`. Tools, prompts,
264
+ * resources, and per-collection/global tool maps live in their own nested
265
+ * fields. `sanitizeMCPConfig` flattens those into `items` and applies defaults
266
+ * to produce a `SanitizedMCPPluginConfig` — the form every internal consumer
267
+ * actually works with.
268
+ */
269
+ export type MCPPluginConfig = {
270
+ collections?: {
271
+ [Slug in CollectionSlug]?: MCPPluginCollectionConfig<Slug>
272
+ }
273
+ /** Skip MCP endpoint registration. */
274
+ disabled?: boolean
275
+ globals?: {
276
+ [Slug in GlobalSlug]?: MCPPluginGlobalConfig
277
+ }
278
+ hooks?: {
279
+ /** Transform a tool response after its handler returns */
280
+ afterToolCall?: MCPAfterToolCallHook[]
281
+ }
282
+ mcp?: {
283
+ /**
284
+ * Largest HTTP request body, in bytes, that the MCP endpoint accepts. Larger requests
285
+ * are answered with `413`. Base64 file uploads count toward this limit.
286
+ *
287
+ * @default 4194304 (4 MiB, the MCP SDK default)
288
+ */
289
+ maxRequestBodySize?: number
290
+ serverOptions?: MCPServerOptions
291
+ verboseLogs?: boolean
292
+ }
360
293
  /**
361
- * Set the Redis URL for the MCP handler. This is the URL that will be used to access the Redis server.
362
- * @default process.env.REDIS_URL
294
+ * How MCP clients sign in. MCP requests without an authenticated user get a `401` that points
295
+ * to the protected resource metadata (RFC 9728). Set to `false` to only accept API keys and
296
+ * anonymous requests.
297
+ *
298
+ * @default { type: 'builtin' }
363
299
  */
364
- redisUrl?: string
300
+ oauth?: false | MCPOAuthConfig
365
301
  /**
366
- * Set verbose logging.
367
- * @default false
302
+ * Replace the default MCP authorization resolver.
303
+ *
304
+ * This hook replaces the default authentication flow. It must set `req.user` to the
305
+ * authenticated Payload user, or to `null` for an anonymous caller, before returning.
368
306
  */
369
- verboseLogs?: boolean
307
+ overrideGetAuthorizedMCP?: (
308
+ args: {
309
+ pluginConfig: SanitizedMCPPluginConfig
310
+ } & GetAuthorizedMCPArgs,
311
+ ) => MaybePromise<AuthorizedMCP>
312
+ prompts?: Record<string, Prompt>
313
+ resources?: Record<string, Resource>
314
+ /** Cross-cutting tools (not scoped to any collection or global). */
315
+ tools?: MCPTopLevelToolsMap
370
316
  }
371
317
 
318
+ export type MCPOAuthConfig = MCPBuiltinOAuthConfig | MCPExternalOAuthConfig
319
+
372
320
  /**
373
- * MCP Server options.
321
+ * This Payload app is the authorization server. Users sign in to the admin panel and allow the
322
+ * MCP client, which then gets an access token for them.
374
323
  */
375
- export type MCPServerOptions = {
324
+ export type MCPBuiltinOAuthConfig = {
376
325
  /**
377
- * Optional instructions describing how to use the server and its features.
326
+ * Creates the tokens the MCP client gets when the user clicks Allow. `req` is the user's own
327
+ * browser request, so `req.user` is the user who allowed it. Pass `authenticate` too if
328
+ * Payload's auth strategies don't accept the access token.
329
+ *
330
+ * @default a Payload login token for that user that only works for MCP, with a refresh token when
331
+ * the collection uses sessions
378
332
  */
379
- instructions?: string
333
+ issueToken?: (args: { req: PayloadRequest }) => MaybePromise<MCPOAuthTokens>
380
334
  /**
381
- * Set the server info of the MCP server.
335
+ * Trades a refresh token from `issueToken`, or from an earlier refresh, for new tokens. Return
336
+ * `null` when it's no longer valid, and the client sends the user through sign-in again. `req`
337
+ * is the MCP client's request, without a user. Only used together with `issueToken`.
338
+ *
339
+ * OAuth requires noticing copied refresh tokens: return a new refresh token every time, and
340
+ * revoke the tokens when an already used refresh token comes back.
341
+ *
342
+ * It also runs when the client trades its authorization code, on the refresh token from
343
+ * `issueToken`, with `reuseInterval: 0`. OAuth requires a code to work only once, so refuse that
344
+ * refresh token if it was used before, even moments ago.
382
345
  */
383
- serverInfo?: {
384
- /**
385
- * Set the name of the MCP server.
386
- * @default 'Payload MCP Server'
387
- */
388
- name: string
346
+ refreshToken?: (args: {
347
+ refreshToken: string
348
+ req: PayloadRequest
389
349
  /**
390
- * Set the version of the MCP server.
391
- * @default '1.0.0'
350
+ * How long a refresh token that was just used may still be accepted, in milliseconds, e.g. for
351
+ * clients that refresh twice at once. `0` means not at all. When it's missing, use your usual
352
+ * leeway.
392
353
  */
393
- version: string
394
- }
395
- }
354
+ reuseInterval?: number
355
+ }) => MaybePromise<MCPOAuthTokens | null>
356
+ type: 'builtin'
357
+ } & MCPOAuthSharedConfig
396
358
 
397
- export type MCPAccessSettings = {
398
- auth?: {
399
- auth?: boolean
400
- forgotPassword?: boolean
401
- login?: boolean
402
- resetPassword?: boolean
403
- unlock?: boolean
404
- verify?: boolean
405
- }
406
- collections?: {
407
- create?: boolean
408
- delete?: boolean
409
- find?: boolean
410
- update?: boolean
411
- }
412
- config?: {
413
- find?: boolean
414
- update?: boolean
415
- }
416
- custom?: Record<string, boolean>
417
- globals?: {
418
- find?: boolean
419
- update?: boolean
420
- }
421
- jobs?: {
422
- create?: boolean
423
- run?: boolean
424
- update?: boolean
425
- }
426
- 'payload-mcp-prompt'?: Record<string, boolean>
427
- 'payload-mcp-resource'?: Record<string, boolean>
428
- 'payload-mcp-tool'?: Record<string, boolean>
429
- user: TypedUser
430
- } & Record<string, unknown>
431
-
432
- export type EntityConfig = MCPPluginConfig['collections'] | MCPPluginConfig['globals']
433
-
434
- export type FieldDefinition = {
435
- description?: string
436
- name: string
437
- options?: { label: string; value: string }[]
438
- position?: 'main' | 'sidebar'
439
- required?: boolean
440
- type: string
359
+ export type MCPOAuthTokens = {
360
+ accessToken: string
361
+ /** Seconds until the access token expires. */
362
+ expiresIn?: number
363
+ /** Lets the client get new tokens without the user, through `refreshToken`. */
364
+ refreshToken?: string
441
365
  }
442
366
 
443
- export type FieldModification = {
444
- changes: {
445
- description?: string
446
- options?: { label: string; value: string }[]
447
- position?: 'main' | 'sidebar'
448
- required?: boolean
449
- type?: string
450
- }
451
- fieldName: string
452
- }
367
+ /** Another service, e.g. your identity provider, is the authorization server. */
368
+ export type MCPExternalOAuthConfig = {
369
+ /**
370
+ * The authorization servers that issue access tokens for MCP clients. Clients require each one
371
+ * to exactly match the `issuer` in that server's metadata, so pass a function when the exact
372
+ * value is only known at runtime, e.g. from the server's OpenID configuration or per host.
373
+ */
374
+ authorizationServers: ((args: { req: PayloadRequest }) => MaybePromise<string[]>) | string[]
375
+ /**
376
+ * Scopes MCP clients should request, e.g. `['openid', 'email', 'profile']`. Without them,
377
+ * clients request none, which some authorization servers reject or answer with a token that
378
+ * doesn't identify the user.
379
+ */
380
+ scopes?: string[]
381
+ type: 'external'
382
+ } & MCPOAuthSharedConfig
453
383
 
454
- export type CollectionConfigUpdates = {
455
- access?: {
456
- create?: string
457
- delete?: string
458
- read?: string
459
- update?: string
460
- }
461
- description?: string
462
- slug?: string
463
- timestamps?: boolean
464
- versioning?: boolean
384
+ type MCPOAuthSharedConfig = {
385
+ /**
386
+ * Called on MCP requests with a bearer token that Payload's auth strategies didn't accept.
387
+ * Return the Payload user, including its `collection`, or `null` to answer with the OAuth challenge.
388
+ */
389
+ authenticate?: (args: {
390
+ req: PayloadRequest
391
+ token: string
392
+ }) => MaybePromise<PayloadRequest['user']>
393
+ /**
394
+ * The URL clients call to reach the MCP endpoint. The metadata link and the built-in
395
+ * authorization server's issuer are based on it.
396
+ *
397
+ * @default the absolute URL of `/api/mcp`, based on `serverURL` or the request URL
398
+ */
399
+ resource?: ((args: { req: PayloadRequest }) => string) | string
465
400
  }
466
401
 
467
- export type AdminConfig = {
468
- avatar?: string
469
- css?: string
470
- dateFormat?: string
471
- inactivityRoute?: string
472
- livePreview?: {
473
- breakpoints?: Array<{
474
- height: number
475
- label: string
476
- name: string
477
- width: number
478
- }>
479
- }
480
- logoutRoute?: string
481
- meta?: {
482
- favicon?: string
483
- ogImage?: string
484
- titleSuffix?: string
485
- }
486
- user?: string
487
- }
402
+ export type SanitizedMCPPluginConfig = {
403
+ items: MCPItem[]
404
+ /** `undefined` when OAuth is turned off. */
405
+ oauth?: MCPOAuthConfig
406
+ } & Pick<MCPPluginConfig, 'disabled' | 'hooks' | 'mcp' | 'overrideGetAuthorizedMCP'>
488
407
 
489
- export type DatabaseConfig = {
490
- connectOptions?: string
491
- type?: 'mongodb' | 'postgres'
492
- url?: string
408
+ export type MCPServerOptions = {
409
+ options?: McpServerOptions
410
+ serverInfo?: Partial<Implementation>
493
411
  }
494
412
 
495
- export type PluginUpdates = {
496
- add?: string[]
497
- remove?: string[]
413
+ /**
414
+ * One MCP primitive plus the metadata needed for config-driven filtering and
415
+ * registration.
416
+ *
417
+ * - `configKey`: the config identifier, e.g. `find` or `echo`.
418
+ * - `mcpName`: the MCP wire name, e.g. `findDocuments` or `echo`.
419
+ * - `label`: human-readable display text.
420
+ */
421
+ export type MCPItemBase = {
422
+ configKey: string
423
+ label: string
424
+ mcpName: string
498
425
  }
499
426
 
500
- export type GeneralConfig = {
501
- cookiePrefix?: string
502
- cors?: string
503
- csrf?: string
504
- graphQL?: {
505
- disable?: boolean
506
- schemaOutputFile?: string
507
- }
508
- rateLimit?: {
509
- max?: number
510
- skip?: string
511
- window?: number
512
- }
513
- secret?: string
514
- serverURL?: string
515
- typescript?: {
516
- declare?: boolean
517
- outputFile?: string
518
- }
519
- }
427
+ export type CollectionMCPItem = {
428
+ collectionSlug: CollectionSlug
429
+ tool: CollectionTool
430
+ type: 'collectionTool'
431
+ } & MCPItemBase
520
432
 
521
- export interface SchemaField {
522
- description?: string
523
- name: string
524
- options?: string[]
525
- required?: boolean
526
- type: string
527
- }
433
+ export type GlobalMCPItem = {
434
+ globalSlug: GlobalSlug
435
+ tool: GlobalTool
436
+ type: 'globalTool'
437
+ } & MCPItemBase
528
438
 
529
- export interface TaskSequenceItem {
530
- description?: string
531
- retries?: number
532
- taskId: string
533
- taskSlug: string
534
- timeout?: number
535
- }
439
+ export type MCPItem =
440
+ | ({
441
+ prompt: Prompt
442
+ type: 'prompt'
443
+ } & MCPItemBase)
444
+ | ({
445
+ resource: Resource
446
+ type: 'resource'
447
+ } & MCPItemBase)
448
+ | ({
449
+ tool: Tool
450
+ type: 'tool'
451
+ } & MCPItemBase)
452
+ | CollectionMCPItem
453
+ | GlobalMCPItem
536
454
 
537
- export interface JobConfigUpdate {
538
- description?: string
539
- queue?: string
540
- retries?: number
541
- timeout?: number
455
+ /**
456
+ * The MCP items and access mode authorized for this request. The authenticated user is available
457
+ * as `req.user`.
458
+ */
459
+ export type AuthorizedMCP = {
460
+ items: MCPItem[]
461
+ overrideAccess: boolean
542
462
  }