@payloadcms/plugin-mcp 3.85.0 → 4.0.0-internal.1f9ae9a

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 (329) hide show
  1. package/README.md +2 -2
  2. package/bin.js +39 -0
  3. package/dist/collection/getAccessField.d.ts +12 -0
  4. package/dist/collection/getAccessField.d.ts.map +1 -0
  5. package/dist/collection/getAccessField.js +57 -0
  6. package/dist/collection/getAccessField.js.map +1 -0
  7. package/dist/collection/index.d.ts +6 -0
  8. package/dist/collection/index.d.ts.map +1 -0
  9. package/dist/collection/index.js +59 -0
  10. package/dist/collection/index.js.map +1 -0
  11. package/dist/components/AccessField/index.client.d.ts +10 -0
  12. package/dist/components/AccessField/index.client.d.ts.map +1 -0
  13. package/dist/components/AccessField/index.client.js +305 -0
  14. package/dist/components/AccessField/index.client.js.map +1 -0
  15. package/dist/components/AccessField/index.css +93 -0
  16. package/dist/defineTool.d.ts +26 -0
  17. package/dist/defineTool.d.ts.map +1 -0
  18. package/dist/defineTool.js +37 -0
  19. package/dist/defineTool.js.map +1 -0
  20. package/dist/endpoint/access.d.ts +10 -0
  21. package/dist/endpoint/access.d.ts.map +1 -0
  22. package/dist/endpoint/access.js +106 -0
  23. package/dist/endpoint/access.js.map +1 -0
  24. package/dist/endpoint/index.d.ts +3 -0
  25. package/dist/endpoint/index.d.ts.map +1 -0
  26. package/dist/endpoint/index.js +36 -0
  27. package/dist/endpoint/index.js.map +1 -0
  28. package/dist/exports/client.d.ts +2 -0
  29. package/dist/exports/client.d.ts.map +1 -0
  30. package/dist/exports/client.js +4 -0
  31. package/dist/exports/client.js.map +1 -0
  32. package/dist/index.d.ts +4 -7
  33. package/dist/index.d.ts.map +1 -1
  34. package/dist/index.js +44 -67
  35. package/dist/index.js.map +1 -1
  36. package/dist/mcp/buildMcpServer.d.ts +19 -0
  37. package/dist/mcp/buildMcpServer.d.ts.map +1 -0
  38. package/dist/mcp/buildMcpServer.js +163 -0
  39. package/dist/mcp/buildMcpServer.js.map +1 -0
  40. package/dist/mcp/builtin/collections/authTools.d.ts +7 -0
  41. package/dist/mcp/builtin/collections/authTools.d.ts.map +1 -0
  42. package/dist/mcp/builtin/collections/authTools.js +250 -0
  43. package/dist/mcp/builtin/collections/authTools.js.map +1 -0
  44. package/dist/mcp/builtin/collections/createTool.d.ts +2 -0
  45. package/dist/mcp/builtin/collections/createTool.d.ts.map +1 -0
  46. package/dist/mcp/builtin/collections/createTool.js +87 -0
  47. package/dist/mcp/builtin/collections/createTool.js.map +1 -0
  48. package/dist/mcp/builtin/collections/deleteTool.d.ts +2 -0
  49. package/dist/mcp/builtin/collections/deleteTool.d.ts.map +1 -0
  50. package/dist/mcp/builtin/collections/deleteTool.js +117 -0
  51. package/dist/mcp/builtin/collections/deleteTool.js.map +1 -0
  52. package/dist/mcp/builtin/collections/findTool.d.ts +2 -0
  53. package/dist/mcp/builtin/collections/findTool.d.ts.map +1 -0
  54. package/dist/mcp/builtin/collections/findTool.js +159 -0
  55. package/dist/mcp/builtin/collections/findTool.js.map +1 -0
  56. package/dist/mcp/builtin/collections/updateTool.d.ts +2 -0
  57. package/dist/mcp/builtin/collections/updateTool.d.ts.map +1 -0
  58. package/dist/mcp/builtin/collections/updateTool.js +187 -0
  59. package/dist/mcp/builtin/collections/updateTool.js.map +1 -0
  60. package/dist/mcp/builtin/globals/findTool.d.ts +2 -0
  61. package/dist/mcp/builtin/globals/findTool.d.ts.map +1 -0
  62. package/dist/mcp/builtin/globals/findTool.js +76 -0
  63. package/dist/mcp/builtin/globals/findTool.js.map +1 -0
  64. package/dist/mcp/builtin/globals/updateTool.d.ts +2 -0
  65. package/dist/mcp/builtin/globals/updateTool.d.ts.map +1 -0
  66. package/dist/mcp/builtin/globals/updateTool.js +92 -0
  67. package/dist/mcp/builtin/globals/updateTool.js.map +1 -0
  68. package/dist/mcp/builtinTools.d.ts +37 -0
  69. package/dist/mcp/builtinTools.d.ts.map +1 -0
  70. package/dist/mcp/builtinTools.js +64 -0
  71. package/dist/mcp/builtinTools.js.map +1 -0
  72. package/dist/mcp/sanitizeMCPConfig.d.ts +17 -0
  73. package/dist/mcp/sanitizeMCPConfig.d.ts.map +1 -0
  74. package/dist/mcp/sanitizeMCPConfig.js +167 -0
  75. package/dist/mcp/sanitizeMCPConfig.js.map +1 -0
  76. package/dist/stdio.d.ts +8 -0
  77. package/dist/stdio.d.ts.map +1 -0
  78. package/dist/stdio.js +89 -0
  79. package/dist/stdio.js.map +1 -0
  80. package/dist/types.d.ts +262 -455
  81. package/dist/types.d.ts.map +1 -1
  82. package/dist/types.js +6 -1
  83. package/dist/types.js.map +1 -1
  84. package/dist/utils/camelCase.d.ts.map +1 -1
  85. package/dist/utils/getLogger.d.ts +10 -0
  86. package/dist/utils/getLogger.d.ts.map +1 -0
  87. package/dist/utils/getLogger.js +22 -0
  88. package/dist/utils/getLogger.js.map +1 -0
  89. package/dist/utils/getPluginConfig.d.ts +12 -0
  90. package/dist/utils/getPluginConfig.d.ts.map +1 -0
  91. package/dist/utils/getPluginConfig.js +15 -0
  92. package/dist/utils/getPluginConfig.js.map +1 -0
  93. package/dist/utils/localAPIDefaults.d.ts +20 -0
  94. package/dist/utils/localAPIDefaults.d.ts.map +1 -0
  95. package/dist/utils/localAPIDefaults.js +19 -0
  96. package/dist/utils/localAPIDefaults.js.map +1 -0
  97. package/dist/utils/resolveProjectRoot.d.ts +7 -0
  98. package/dist/utils/resolveProjectRoot.d.ts.map +1 -0
  99. package/dist/utils/resolveProjectRoot.js +15 -0
  100. package/dist/utils/resolveProjectRoot.js.map +1 -0
  101. package/dist/utils/schemaConversion/prepareCollectionSchema.d.ts +7 -0
  102. package/dist/utils/schemaConversion/prepareCollectionSchema.d.ts.map +1 -0
  103. package/dist/utils/schemaConversion/prepareCollectionSchema.js +37 -0
  104. package/dist/utils/schemaConversion/prepareCollectionSchema.js.map +1 -0
  105. package/dist/utils/schemaConversion/removeVirtualFieldsFromSchema.d.ts +2 -2
  106. package/dist/utils/schemaConversion/removeVirtualFieldsFromSchema.d.ts.map +1 -1
  107. package/dist/utils/schemaConversion/removeVirtualFieldsFromSchema.js.map +1 -1
  108. package/dist/utils/schemaConversion/sanitizeJsonSchema.d.ts +2 -2
  109. package/dist/utils/schemaConversion/sanitizeJsonSchema.d.ts.map +1 -1
  110. package/dist/utils/schemaConversion/sanitizeJsonSchema.js.map +1 -1
  111. package/dist/utils/schemaConversion/simplifyRelationshipFields.d.ts +2 -2
  112. package/dist/utils/schemaConversion/simplifyRelationshipFields.d.ts.map +1 -1
  113. package/dist/utils/schemaConversion/simplifyRelationshipFields.js +7 -4
  114. package/dist/utils/schemaConversion/simplifyRelationshipFields.js.map +1 -1
  115. package/dist/utils/schemaConversion/transformPointFields.d.ts +2 -2
  116. package/dist/utils/schemaConversion/transformPointFields.d.ts.map +1 -1
  117. package/dist/utils/schemaConversion/transformPointFields.js +7 -1
  118. package/dist/utils/schemaConversion/transformPointFields.js.map +1 -1
  119. package/dist/utils/toStandardSchema.d.ts +5 -0
  120. package/dist/utils/toStandardSchema.d.ts.map +1 -0
  121. package/dist/utils/toStandardSchema.js +4 -0
  122. package/dist/utils/toStandardSchema.js.map +1 -0
  123. package/package.json +35 -10
  124. package/src/collection/getAccessField.ts +64 -0
  125. package/src/collection/index.ts +63 -0
  126. package/src/components/AccessField/index.client.tsx +344 -0
  127. package/src/components/AccessField/index.css +93 -0
  128. package/src/defineTool.ts +44 -0
  129. package/src/endpoint/access.ts +132 -0
  130. package/src/endpoint/index.ts +35 -0
  131. package/src/exports/client.ts +2 -0
  132. package/src/index.ts +35 -85
  133. package/src/mcp/buildMcpServer.ts +224 -0
  134. package/src/mcp/builtin/collections/authTools.ts +233 -0
  135. package/src/mcp/builtin/collections/createTool.ts +116 -0
  136. package/src/mcp/builtin/collections/deleteTool.ts +123 -0
  137. package/src/mcp/builtin/collections/findTool.ts +187 -0
  138. package/src/mcp/builtin/collections/updateTool.ts +205 -0
  139. package/src/mcp/builtin/globals/findTool.ts +96 -0
  140. package/src/mcp/builtin/globals/updateTool.ts +118 -0
  141. package/src/mcp/builtinTools.ts +84 -0
  142. package/src/mcp/sanitizeMCPConfig.ts +239 -0
  143. package/src/stdio.ts +98 -0
  144. package/src/types.ts +295 -490
  145. package/src/utils/getLogger.ts +22 -0
  146. package/src/utils/getPluginConfig.ts +24 -0
  147. package/src/utils/localAPIDefaults.ts +22 -0
  148. package/src/utils/resolveProjectRoot.ts +17 -0
  149. package/src/utils/schemaConversion/prepareCollectionSchema.ts +39 -0
  150. package/src/utils/schemaConversion/removeVirtualFieldsFromSchema.ts +3 -3
  151. package/src/utils/schemaConversion/sanitizeJsonSchema.ts +4 -4
  152. package/src/utils/schemaConversion/simplifyRelationshipFields.ts +11 -6
  153. package/src/utils/schemaConversion/transformPointFields.ts +6 -5
  154. package/src/utils/toStandardSchema.ts +9 -0
  155. package/dist/collections/createApiKeysCollection.d.ts +0 -7
  156. package/dist/collections/createApiKeysCollection.d.ts.map +0 -1
  157. package/dist/collections/createApiKeysCollection.js +0 -317
  158. package/dist/collections/createApiKeysCollection.js.map +0 -1
  159. package/dist/defaults.d.ts +0 -4
  160. package/dist/defaults.d.ts.map +0 -1
  161. package/dist/defaults.js +0 -5
  162. package/dist/defaults.js.map +0 -1
  163. package/dist/endpoints/mcp.d.ts +0 -4
  164. package/dist/endpoints/mcp.d.ts.map +0 -1
  165. package/dist/endpoints/mcp.js +0 -71
  166. package/dist/endpoints/mcp.js.map +0 -1
  167. package/dist/mcp/createRequest.d.ts +0 -3
  168. package/dist/mcp/createRequest.d.ts.map +0 -1
  169. package/dist/mcp/createRequest.js +0 -14
  170. package/dist/mcp/createRequest.js.map +0 -1
  171. package/dist/mcp/getMcpHandler.d.ts +0 -4
  172. package/dist/mcp/getMcpHandler.d.ts.map +0 -1
  173. package/dist/mcp/getMcpHandler.js +0 -231
  174. package/dist/mcp/getMcpHandler.js.map +0 -1
  175. package/dist/mcp/helpers/config.d.ts +0 -22
  176. package/dist/mcp/helpers/config.d.ts.map +0 -1
  177. package/dist/mcp/helpers/config.js +0 -153
  178. package/dist/mcp/helpers/config.js.map +0 -1
  179. package/dist/mcp/helpers/fields.d.ts +0 -19
  180. package/dist/mcp/helpers/fields.d.ts.map +0 -1
  181. package/dist/mcp/helpers/fields.js +0 -102
  182. package/dist/mcp/helpers/fields.js.map +0 -1
  183. package/dist/mcp/helpers/fileValidation.d.ts +0 -67
  184. package/dist/mcp/helpers/fileValidation.d.ts.map +0 -1
  185. package/dist/mcp/helpers/fileValidation.js +0 -267
  186. package/dist/mcp/helpers/fileValidation.js.map +0 -1
  187. package/dist/mcp/registerTool.d.ts +0 -6
  188. package/dist/mcp/registerTool.d.ts.map +0 -1
  189. package/dist/mcp/registerTool.js +0 -18
  190. package/dist/mcp/registerTool.js.map +0 -1
  191. package/dist/mcp/tools/auth/auth.d.ts +0 -4
  192. package/dist/mcp/tools/auth/auth.d.ts.map +0 -1
  193. package/dist/mcp/tools/auth/auth.js +0 -57
  194. package/dist/mcp/tools/auth/auth.js.map +0 -1
  195. package/dist/mcp/tools/auth/forgotPassword.d.ts +0 -4
  196. package/dist/mcp/tools/auth/forgotPassword.d.ts.map +0 -1
  197. package/dist/mcp/tools/auth/forgotPassword.js +0 -48
  198. package/dist/mcp/tools/auth/forgotPassword.js.map +0 -1
  199. package/dist/mcp/tools/auth/login.d.ts +0 -4
  200. package/dist/mcp/tools/auth/login.d.ts.map +0 -1
  201. package/dist/mcp/tools/auth/login.js +0 -51
  202. package/dist/mcp/tools/auth/login.js.map +0 -1
  203. package/dist/mcp/tools/auth/resetPassword.d.ts +0 -4
  204. package/dist/mcp/tools/auth/resetPassword.d.ts.map +0 -1
  205. package/dist/mcp/tools/auth/resetPassword.js +0 -49
  206. package/dist/mcp/tools/auth/resetPassword.js.map +0 -1
  207. package/dist/mcp/tools/auth/unlock.d.ts +0 -4
  208. package/dist/mcp/tools/auth/unlock.d.ts.map +0 -1
  209. package/dist/mcp/tools/auth/unlock.js +0 -48
  210. package/dist/mcp/tools/auth/unlock.js.map +0 -1
  211. package/dist/mcp/tools/auth/verify.d.ts +0 -4
  212. package/dist/mcp/tools/auth/verify.d.ts.map +0 -1
  213. package/dist/mcp/tools/auth/verify.js +0 -45
  214. package/dist/mcp/tools/auth/verify.js.map +0 -1
  215. package/dist/mcp/tools/collection/create.d.ts +0 -10
  216. package/dist/mcp/tools/collection/create.d.ts.map +0 -1
  217. package/dist/mcp/tools/collection/create.js +0 -139
  218. package/dist/mcp/tools/collection/create.js.map +0 -1
  219. package/dist/mcp/tools/collection/delete.d.ts +0 -10
  220. package/dist/mcp/tools/collection/delete.d.ts.map +0 -1
  221. package/dist/mcp/tools/collection/delete.js +0 -154
  222. package/dist/mcp/tools/collection/delete.js.map +0 -1
  223. package/dist/mcp/tools/collection/find.d.ts +0 -10
  224. package/dist/mcp/tools/collection/find.d.ts.map +0 -1
  225. package/dist/mcp/tools/collection/find.js +0 -165
  226. package/dist/mcp/tools/collection/find.js.map +0 -1
  227. package/dist/mcp/tools/collection/update.d.ts +0 -10
  228. package/dist/mcp/tools/collection/update.d.ts.map +0 -1
  229. package/dist/mcp/tools/collection/update.js +0 -209
  230. package/dist/mcp/tools/collection/update.js.map +0 -1
  231. package/dist/mcp/tools/config/find.d.ts +0 -10
  232. package/dist/mcp/tools/config/find.d.ts.map +0 -1
  233. package/dist/mcp/tools/config/find.js +0 -97
  234. package/dist/mcp/tools/config/find.js.map +0 -1
  235. package/dist/mcp/tools/config/update.d.ts +0 -10
  236. package/dist/mcp/tools/config/update.d.ts.map +0 -1
  237. package/dist/mcp/tools/config/update.js +0 -215
  238. package/dist/mcp/tools/config/update.js.map +0 -1
  239. package/dist/mcp/tools/global/find.d.ts +0 -5
  240. package/dist/mcp/tools/global/find.d.ts.map +0 -1
  241. package/dist/mcp/tools/global/find.js +0 -82
  242. package/dist/mcp/tools/global/find.js.map +0 -1
  243. package/dist/mcp/tools/global/update.d.ts +0 -6
  244. package/dist/mcp/tools/global/update.d.ts.map +0 -1
  245. package/dist/mcp/tools/global/update.js +0 -124
  246. package/dist/mcp/tools/global/update.js.map +0 -1
  247. package/dist/mcp/tools/job/create.d.ts +0 -10
  248. package/dist/mcp/tools/job/create.d.ts.map +0 -1
  249. package/dist/mcp/tools/job/create.js +0 -293
  250. package/dist/mcp/tools/job/create.js.map +0 -1
  251. package/dist/mcp/tools/job/run.d.ts +0 -10
  252. package/dist/mcp/tools/job/run.d.ts.map +0 -1
  253. package/dist/mcp/tools/job/run.js +0 -129
  254. package/dist/mcp/tools/job/run.js.map +0 -1
  255. package/dist/mcp/tools/job/update.d.ts +0 -11
  256. package/dist/mcp/tools/job/update.d.ts.map +0 -1
  257. package/dist/mcp/tools/job/update.js +0 -186
  258. package/dist/mcp/tools/job/update.js.map +0 -1
  259. package/dist/mcp/tools/resource/create.d.ts +0 -6
  260. package/dist/mcp/tools/resource/create.d.ts.map +0 -1
  261. package/dist/mcp/tools/resource/create.js +0 -124
  262. package/dist/mcp/tools/resource/create.js.map +0 -1
  263. package/dist/mcp/tools/resource/delete.d.ts +0 -5
  264. package/dist/mcp/tools/resource/delete.d.ts.map +0 -1
  265. package/dist/mcp/tools/resource/delete.js +0 -151
  266. package/dist/mcp/tools/resource/delete.js.map +0 -1
  267. package/dist/mcp/tools/resource/find.d.ts +0 -5
  268. package/dist/mcp/tools/resource/find.d.ts.map +0 -1
  269. package/dist/mcp/tools/resource/find.js +0 -170
  270. package/dist/mcp/tools/resource/find.js.map +0 -1
  271. package/dist/mcp/tools/resource/update.d.ts +0 -6
  272. package/dist/mcp/tools/resource/update.d.ts.map +0 -1
  273. package/dist/mcp/tools/resource/update.js +0 -256
  274. package/dist/mcp/tools/resource/update.js.map +0 -1
  275. package/dist/mcp/tools/schemas.d.ts +0 -457
  276. package/dist/mcp/tools/schemas.d.ts.map +0 -1
  277. package/dist/mcp/tools/schemas.js +0 -243
  278. package/dist/mcp/tools/schemas.js.map +0 -1
  279. package/dist/utils/adminEntitySettings.d.ts +0 -17
  280. package/dist/utils/adminEntitySettings.d.ts.map +0 -1
  281. package/dist/utils/adminEntitySettings.js +0 -41
  282. package/dist/utils/adminEntitySettings.js.map +0 -1
  283. package/dist/utils/createApiKeyFields.d.ts +0 -15
  284. package/dist/utils/createApiKeyFields.d.ts.map +0 -1
  285. package/dist/utils/createApiKeyFields.js +0 -57
  286. package/dist/utils/createApiKeyFields.js.map +0 -1
  287. package/dist/utils/getEnabledSlugs.d.ts +0 -13
  288. package/dist/utils/getEnabledSlugs.d.ts.map +0 -1
  289. package/dist/utils/getEnabledSlugs.js +0 -32
  290. package/dist/utils/getEnabledSlugs.js.map +0 -1
  291. package/dist/utils/schemaConversion/convertCollectionSchemaToZod.d.ts +0 -3
  292. package/dist/utils/schemaConversion/convertCollectionSchemaToZod.d.ts.map +0 -1
  293. package/dist/utils/schemaConversion/convertCollectionSchemaToZod.js +0 -43
  294. package/dist/utils/schemaConversion/convertCollectionSchemaToZod.js.map +0 -1
  295. package/src/collections/createApiKeysCollection.ts +0 -373
  296. package/src/defaults.ts +0 -3
  297. package/src/endpoints/mcp.ts +0 -91
  298. package/src/mcp/createRequest.ts +0 -13
  299. package/src/mcp/getMcpHandler.ts +0 -545
  300. package/src/mcp/helpers/config.ts +0 -213
  301. package/src/mcp/helpers/fields.ts +0 -154
  302. package/src/mcp/helpers/fileValidation.ts +0 -362
  303. package/src/mcp/registerTool.ts +0 -22
  304. package/src/mcp/tools/auth/auth.ts +0 -71
  305. package/src/mcp/tools/auth/forgotPassword.ts +0 -70
  306. package/src/mcp/tools/auth/login.ts +0 -72
  307. package/src/mcp/tools/auth/resetPassword.ts +0 -61
  308. package/src/mcp/tools/auth/unlock.ts +0 -64
  309. package/src/mcp/tools/auth/verify.ts +0 -57
  310. package/src/mcp/tools/collection/create.ts +0 -210
  311. package/src/mcp/tools/collection/delete.ts +0 -211
  312. package/src/mcp/tools/collection/find.ts +0 -224
  313. package/src/mcp/tools/collection/update.ts +0 -290
  314. package/src/mcp/tools/config/find.ts +0 -128
  315. package/src/mcp/tools/config/update.ts +0 -280
  316. package/src/mcp/tools/global/find.ts +0 -128
  317. package/src/mcp/tools/global/update.ts +0 -207
  318. package/src/mcp/tools/job/create.ts +0 -416
  319. package/src/mcp/tools/job/run.ts +0 -167
  320. package/src/mcp/tools/job/update.ts +0 -274
  321. package/src/mcp/tools/resource/create.ts +0 -211
  322. package/src/mcp/tools/resource/delete.ts +0 -218
  323. package/src/mcp/tools/resource/find.ts +0 -246
  324. package/src/mcp/tools/resource/update.ts +0 -383
  325. package/src/mcp/tools/schemas.ts +0 -520
  326. package/src/utils/adminEntitySettings.ts +0 -40
  327. package/src/utils/createApiKeyFields.ts +0 -72
  328. package/src/utils/getEnabledSlugs.ts +0 -42
  329. package/src/utils/schemaConversion/convertCollectionSchemaToZod.ts +0 -52
@@ -0,0 +1,2 @@
1
+ export declare const updateGlobalTool: import("../../../types.js").GlobalTool;
2
+ //# sourceMappingURL=updateTool.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"updateTool.d.ts","sourceRoot":"","sources":["../../../../src/mcp/builtin/globals/updateTool.ts"],"names":[],"mappings":"AAeA,eAAO,MAAM,gBAAgB,wCAsG3B,CAAA"}
@@ -0,0 +1,92 @@
1
+ import { z } from 'zod';
2
+ import { defineGlobalTool } from '../../../defineTool.js';
3
+ import { getLogger } from '../../../utils/getLogger.js';
4
+ import { getGlobalVirtualFieldNames, stripVirtualFields } from '../../../utils/getVirtualFieldNames.js';
5
+ import { localAPIDefaults } from '../../../utils/localAPIDefaults.js';
6
+ import { prepareCollectionSchema } from '../../../utils/schemaConversion/prepareCollectionSchema.js';
7
+ const DEFAULT_DESCRIPTION = 'Update a Payload global singleton configuration.';
8
+ export const updateGlobalTool = defineGlobalTool({
9
+ description: DEFAULT_DESCRIPTION,
10
+ input: ({ globalSchema })=>{
11
+ const partialSchema = prepareCollectionSchema(globalSchema);
12
+ // Global updates do not require all required fields to be passed => delete .required.
13
+ //
14
+ // Local API equivalent: packages/payload/src/global/operations/local/update.ts#BaseOptions#data:
15
+ // data: DeepPartial<Omit<DataFromGlobalSlug<TSlug>, 'id'>>
16
+ delete partialSchema.required;
17
+ return z.object({
18
+ data: z.fromJSONSchema(partialSchema).describe('The fields to update'),
19
+ depth: z.number().describe('Optional: Depth of relationships to populate').optional().default(0),
20
+ draft: z.boolean().describe('Optional: Whether to save as draft (default: false)').optional().default(false),
21
+ fallbackLocale: z.string().describe('Optional: fallback locale code to use when requested locale is not available').optional(),
22
+ locale: z.string().describe('Optional: locale code to update data in (e.g., "en", "es"). Use "all" to update all locales for localized fields').optional(),
23
+ select: z.string().describe('Optional: define exactly which fields you\'d like to return in the response (JSON), e.g., \'{"siteName": "My Site"}\'').optional()
24
+ });
25
+ }
26
+ }).handler(async ({ authorizedMCP, globalSlug, input, req })=>{
27
+ const payload = req.payload;
28
+ const logger = getLogger({
29
+ payload
30
+ });
31
+ const { data, depth, draft, fallbackLocale, locale, select } = input;
32
+ logger.info(`Updating global: ${globalSlug}, draft: ${draft}${locale ? `, locale: ${locale}` : ''}`);
33
+ try {
34
+ const virtualFieldNames = getGlobalVirtualFieldNames(payload.config, globalSlug);
35
+ const parsedData = stripVirtualFields(data, virtualFieldNames);
36
+ let selectClause;
37
+ if (select) {
38
+ try {
39
+ selectClause = JSON.parse(select);
40
+ } catch {
41
+ logger.warn(`Invalid select clause JSON for global: ${select}`);
42
+ return {
43
+ content: [
44
+ {
45
+ type: 'text',
46
+ text: 'Error: Invalid JSON in select clause'
47
+ }
48
+ ]
49
+ };
50
+ }
51
+ }
52
+ const updateOptions = {
53
+ slug: globalSlug,
54
+ data: parsedData,
55
+ depth,
56
+ draft,
57
+ ...localAPIDefaults(authorizedMCP)
58
+ };
59
+ if (locale) {
60
+ updateOptions.locale = locale;
61
+ }
62
+ if (fallbackLocale) {
63
+ updateOptions.fallbackLocale = fallbackLocale;
64
+ }
65
+ if (selectClause) {
66
+ updateOptions.select = selectClause;
67
+ }
68
+ const result = await payload.updateGlobal(updateOptions);
69
+ return {
70
+ content: [
71
+ {
72
+ type: 'text',
73
+ text: `Global "${globalSlug}" updated successfully!\n\`\`\`json\n${JSON.stringify(result)}\n\`\`\``
74
+ }
75
+ ],
76
+ doc: result
77
+ };
78
+ } catch (error) {
79
+ const errorMessage = error instanceof Error ? error.message : 'Unknown error';
80
+ logger.error(`Error updating global ${globalSlug}: ${errorMessage}`);
81
+ return {
82
+ content: [
83
+ {
84
+ type: 'text',
85
+ text: `Error updating global "${globalSlug}": ${errorMessage}`
86
+ }
87
+ ]
88
+ };
89
+ }
90
+ });
91
+
92
+ //# sourceMappingURL=updateTool.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/mcp/builtin/globals/updateTool.ts"],"sourcesContent":["import type { SelectType } from 'payload'\n\nimport { z } from 'zod'\n\nimport { defineGlobalTool } from '../../../defineTool.js'\nimport { getLogger } from '../../../utils/getLogger.js'\nimport {\n getGlobalVirtualFieldNames,\n stripVirtualFields,\n} from '../../../utils/getVirtualFieldNames.js'\nimport { localAPIDefaults } from '../../../utils/localAPIDefaults.js'\nimport { prepareCollectionSchema } from '../../../utils/schemaConversion/prepareCollectionSchema.js'\n\nconst DEFAULT_DESCRIPTION = 'Update a Payload global singleton configuration.'\n\nexport const updateGlobalTool = defineGlobalTool({\n description: DEFAULT_DESCRIPTION,\n input: ({ globalSchema }) => {\n const partialSchema = prepareCollectionSchema(globalSchema)\n // Global updates do not require all required fields to be passed => delete .required.\n //\n // Local API equivalent: packages/payload/src/global/operations/local/update.ts#BaseOptions#data:\n // data: DeepPartial<Omit<DataFromGlobalSlug<TSlug>, 'id'>>\n delete partialSchema.required\n\n return z.object({\n data: z\n .fromJSONSchema(partialSchema as unknown as z.core.JSONSchema.JSONSchema)\n .describe('The fields to update'),\n depth: z\n .number()\n .describe('Optional: Depth of relationships to populate')\n .optional()\n .default(0),\n draft: z\n .boolean()\n .describe('Optional: Whether to save as draft (default: false)')\n .optional()\n .default(false),\n fallbackLocale: z\n .string()\n .describe('Optional: fallback locale code to use when requested locale is not available')\n .optional(),\n locale: z\n .string()\n .describe(\n 'Optional: locale code to update data in (e.g., \"en\", \"es\"). Use \"all\" to update all locales for localized fields',\n )\n .optional(),\n select: z\n .string()\n .describe(\n 'Optional: define exactly which fields you\\'d like to return in the response (JSON), e.g., \\'{\"siteName\": \"My Site\"}\\'',\n )\n .optional(),\n })\n },\n}).handler(async ({ authorizedMCP, globalSlug, input, req }) => {\n const payload = req.payload\n const logger = getLogger({ payload })\n\n const { data, depth, draft, fallbackLocale, locale, select } = input\n\n logger.info(\n `Updating global: ${globalSlug}, draft: ${draft}${locale ? `, locale: ${locale}` : ''}`,\n )\n\n try {\n const virtualFieldNames = getGlobalVirtualFieldNames(payload.config, globalSlug)\n const parsedData = stripVirtualFields(data as Record<string, unknown>, virtualFieldNames)\n\n let selectClause: SelectType | undefined\n if (select) {\n try {\n selectClause = JSON.parse(select) as SelectType\n } catch {\n logger.warn(`Invalid select clause JSON for global: ${select}`)\n return { content: [{ type: 'text', text: 'Error: Invalid JSON in select clause' }] }\n }\n }\n\n const updateOptions: Parameters<typeof payload.updateGlobal>[0] = {\n slug: globalSlug,\n data: parsedData,\n depth,\n draft,\n ...localAPIDefaults(authorizedMCP),\n }\n\n if (locale) {\n updateOptions.locale = locale\n }\n if (fallbackLocale) {\n updateOptions.fallbackLocale = fallbackLocale\n }\n if (selectClause) {\n updateOptions.select = selectClause\n }\n\n const result = await payload.updateGlobal(updateOptions)\n\n return {\n content: [\n {\n type: 'text',\n text: `Global \"${globalSlug}\" updated successfully!\\n\\`\\`\\`json\\n${JSON.stringify(result)}\\n\\`\\`\\``,\n },\n ],\n doc: result as Record<string, unknown>,\n }\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : 'Unknown error'\n logger.error(`Error updating global ${globalSlug}: ${errorMessage}`)\n return {\n content: [{ type: 'text', text: `Error updating global \"${globalSlug}\": ${errorMessage}` }],\n }\n }\n})\n"],"names":["z","defineGlobalTool","getLogger","getGlobalVirtualFieldNames","stripVirtualFields","localAPIDefaults","prepareCollectionSchema","DEFAULT_DESCRIPTION","updateGlobalTool","description","input","globalSchema","partialSchema","required","object","data","fromJSONSchema","describe","depth","number","optional","default","draft","boolean","fallbackLocale","string","locale","select","handler","authorizedMCP","globalSlug","req","payload","logger","info","virtualFieldNames","config","parsedData","selectClause","JSON","parse","warn","content","type","text","updateOptions","slug","result","updateGlobal","stringify","doc","error","errorMessage","Error","message"],"mappings":"AAEA,SAASA,CAAC,QAAQ,MAAK;AAEvB,SAASC,gBAAgB,QAAQ,yBAAwB;AACzD,SAASC,SAAS,QAAQ,8BAA6B;AACvD,SACEC,0BAA0B,EAC1BC,kBAAkB,QACb,yCAAwC;AAC/C,SAASC,gBAAgB,QAAQ,qCAAoC;AACrE,SAASC,uBAAuB,QAAQ,6DAA4D;AAEpG,MAAMC,sBAAsB;AAE5B,OAAO,MAAMC,mBAAmBP,iBAAiB;IAC/CQ,aAAaF;IACbG,OAAO,CAAC,EAAEC,YAAY,EAAE;QACtB,MAAMC,gBAAgBN,wBAAwBK;QAC9C,sFAAsF;QACtF,EAAE;QACF,iGAAiG;QACjG,2DAA2D;QAC3D,OAAOC,cAAcC,QAAQ;QAE7B,OAAOb,EAAEc,MAAM,CAAC;YACdC,MAAMf,EACHgB,cAAc,CAACJ,eACfK,QAAQ,CAAC;YACZC,OAAOlB,EACJmB,MAAM,GACNF,QAAQ,CAAC,gDACTG,QAAQ,GACRC,OAAO,CAAC;YACXC,OAAOtB,EACJuB,OAAO,GACPN,QAAQ,CAAC,uDACTG,QAAQ,GACRC,OAAO,CAAC;YACXG,gBAAgBxB,EACbyB,MAAM,GACNR,QAAQ,CAAC,gFACTG,QAAQ;YACXM,QAAQ1B,EACLyB,MAAM,GACNR,QAAQ,CACP,oHAEDG,QAAQ;YACXO,QAAQ3B,EACLyB,MAAM,GACNR,QAAQ,CACP,yHAEDG,QAAQ;QACb;IACF;AACF,GAAGQ,OAAO,CAAC,OAAO,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;QACd,MAAMC,eAAeD,iBAAiBE,QAAQF,MAAMG,OAAO,GAAG;QAC9DrB,OAAOkB,KAAK,CAAC,CAAC,sBAAsB,EAAErB,WAAW,EAAE,EAAEsB,cAAc;QACnE,OAAO;YACLV,SAAS;gBAAC;oBAAEC,MAAM;oBAAQC,MAAM,CAAC,uBAAuB,EAAEd,WAAW,GAAG,EAAEsB,cAAc;gBAAC;aAAE;QAC7F;IACF;AACF,GAAE"}
@@ -0,0 +1,37 @@
1
+ import type { CollectionTool, GlobalTool } from '../types.js';
2
+ /**
3
+ * The static built-in collection CRUD tools. Keys here are the source of truth
4
+ * for `MCPCollectionBuiltinName` — adding/removing an entry updates the type
5
+ * automatically.
6
+ */
7
+ export declare const COLLECTION_BUILTINS: Record<MCPCollectionBuiltinName, CollectionTool>;
8
+ /**
9
+ * The static auth tools surfaced under auth-enabled collections. Each entry
10
+ * carries the admin-UI label alongside the tool. Keys are the source of truth
11
+ * for `MCPCollectionAuthToolName`.
12
+ */
13
+ export declare const COLLECTION_AUTH_BUILTINS: Record<MCPCollectionAuthToolName, {
14
+ label: string;
15
+ tool: CollectionTool;
16
+ }>;
17
+ /**
18
+ * The static built-in global tools. Keys are the source of truth for
19
+ * `MCPGlobalBuiltinName`.
20
+ */
21
+ export declare const GLOBAL_BUILTINS: Record<MCPGlobalBuiltinName, GlobalTool>;
22
+ export type MCPCollectionBuiltinName = 'create' | 'delete' | 'find' | 'update';
23
+ export type MCPCollectionAuthToolName = 'auth' | 'forgotPassword' | 'login' | 'resetPassword' | 'unlock' | 'verify';
24
+ export type MCPGlobalBuiltinName = 'find' | 'update';
25
+ /**
26
+ * Pre-typed `Object.entries` for each registry. The cast from `string` to the
27
+ * literal key union lives here once so consumers can iterate without their own
28
+ * cast — TypeScript's `Object.entries` always widens keys to `string`, which
29
+ * defeats the narrow type lookups on `MCPCollectionToolsMap`.
30
+ */
31
+ export declare const COLLECTION_BUILTIN_ENTRIES: Array<[MCPCollectionBuiltinName, CollectionTool]>;
32
+ export declare const COLLECTION_AUTH_BUILTIN_ENTRIES: Array<[MCPCollectionAuthToolName, {
33
+ label: string;
34
+ tool: CollectionTool;
35
+ }]>;
36
+ export declare const GLOBAL_BUILTIN_ENTRIES: Array<[MCPGlobalBuiltinName, GlobalTool]>;
37
+ //# sourceMappingURL=builtinTools.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"builtinTools.d.ts","sourceRoot":"","sources":["../../src/mcp/builtinTools.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAiB7D;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,EAAE,MAAM,CAAC,wBAAwB,EAAE,cAAc,CAKhF,CAAA;AAED;;;;GAIG;AACH,eAAO,MAAM,wBAAwB,EAAE,MAAM,CAC3C,yBAAyB,EACzB;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,cAAc,CAAA;CAAE,CAQxC,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,eAAe,EAAE,MAAM,CAAC,oBAAoB,EAAE,UAAU,CAGpE,CAAA;AAED,MAAM,MAAM,wBAAwB,GAAG,QAAQ,GAAG,QAAQ,GAAG,MAAM,GAAG,QAAQ,CAAA;AAE9E,MAAM,MAAM,yBAAyB,GACjC,MAAM,GACN,gBAAgB,GAChB,OAAO,GACP,eAAe,GACf,QAAQ,GACR,QAAQ,CAAA;AAEZ,MAAM,MAAM,oBAAoB,GAAG,MAAM,GAAG,QAAQ,CAAA;AAEpD;;;;;GAKG;AACH,eAAO,MAAM,0BAA0B,EAA0C,KAAK,CACpF,CAAC,wBAAwB,EAAE,cAAc,CAAC,CAC3C,CAAA;AAED,eAAO,MAAM,+BAA+B,EAA+C,KAAK,CAC9F,CAAC,yBAAyB,EAAE;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,cAAc,CAAA;CAAE,CAAC,CACrE,CAAA;AAED,eAAO,MAAM,sBAAsB,EAAsC,KAAK,CAC5E,CAAC,oBAAoB,EAAE,UAAU,CAAC,CACnC,CAAA"}
@@ -0,0 +1,64 @@
1
+ import { authCollectionTool, forgotPasswordCollectionTool, loginCollectionTool, resetPasswordCollectionTool, unlockCollectionTool, verifyCollectionTool } from './builtin/collections/authTools.js';
2
+ import { createCollectionTool } from './builtin/collections/createTool.js';
3
+ import { deleteCollectionTool } from './builtin/collections/deleteTool.js';
4
+ import { findCollectionTool } from './builtin/collections/findTool.js';
5
+ import { updateCollectionTool } from './builtin/collections/updateTool.js';
6
+ import { findGlobalTool } from './builtin/globals/findTool.js';
7
+ import { updateGlobalTool } from './builtin/globals/updateTool.js';
8
+ /**
9
+ * The static built-in collection CRUD tools. Keys here are the source of truth
10
+ * for `MCPCollectionBuiltinName` — adding/removing an entry updates the type
11
+ * automatically.
12
+ */ export const COLLECTION_BUILTINS = {
13
+ create: createCollectionTool,
14
+ delete: deleteCollectionTool,
15
+ find: findCollectionTool,
16
+ update: updateCollectionTool
17
+ };
18
+ /**
19
+ * The static auth tools surfaced under auth-enabled collections. Each entry
20
+ * carries the admin-UI label alongside the tool. Keys are the source of truth
21
+ * for `MCPCollectionAuthToolName`.
22
+ */ export const COLLECTION_AUTH_BUILTINS = {
23
+ auth: {
24
+ label: 'Check Auth Status',
25
+ tool: authCollectionTool
26
+ },
27
+ forgotPassword: {
28
+ label: 'Forgot Password',
29
+ tool: forgotPasswordCollectionTool
30
+ },
31
+ login: {
32
+ label: 'User Login',
33
+ tool: loginCollectionTool
34
+ },
35
+ resetPassword: {
36
+ label: 'Reset Password',
37
+ tool: resetPasswordCollectionTool
38
+ },
39
+ unlock: {
40
+ label: 'Unlock Account',
41
+ tool: unlockCollectionTool
42
+ },
43
+ verify: {
44
+ label: 'Email Verification',
45
+ tool: verifyCollectionTool
46
+ }
47
+ };
48
+ /**
49
+ * The static built-in global tools. Keys are the source of truth for
50
+ * `MCPGlobalBuiltinName`.
51
+ */ export const GLOBAL_BUILTINS = {
52
+ find: findGlobalTool,
53
+ update: updateGlobalTool
54
+ };
55
+ /**
56
+ * Pre-typed `Object.entries` for each registry. The cast from `string` to the
57
+ * literal key union lives here once so consumers can iterate without their own
58
+ * cast — TypeScript's `Object.entries` always widens keys to `string`, which
59
+ * defeats the narrow type lookups on `MCPCollectionToolsMap`.
60
+ */ export const COLLECTION_BUILTIN_ENTRIES = Object.entries(COLLECTION_BUILTINS);
61
+ export const COLLECTION_AUTH_BUILTIN_ENTRIES = Object.entries(COLLECTION_AUTH_BUILTINS);
62
+ export const GLOBAL_BUILTIN_ENTRIES = Object.entries(GLOBAL_BUILTINS);
63
+
64
+ //# sourceMappingURL=builtinTools.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/mcp/builtinTools.ts"],"sourcesContent":["import type { CollectionTool, GlobalTool } from '../types.js'\n\nimport {\n authCollectionTool,\n forgotPasswordCollectionTool,\n loginCollectionTool,\n resetPasswordCollectionTool,\n unlockCollectionTool,\n verifyCollectionTool,\n} from './builtin/collections/authTools.js'\nimport { createCollectionTool } from './builtin/collections/createTool.js'\nimport { deleteCollectionTool } from './builtin/collections/deleteTool.js'\nimport { findCollectionTool } from './builtin/collections/findTool.js'\nimport { updateCollectionTool } from './builtin/collections/updateTool.js'\nimport { findGlobalTool } from './builtin/globals/findTool.js'\nimport { updateGlobalTool } from './builtin/globals/updateTool.js'\n\n/**\n * The static built-in collection CRUD tools. Keys here are the source of truth\n * for `MCPCollectionBuiltinName` — adding/removing an entry updates the type\n * automatically.\n */\nexport const COLLECTION_BUILTINS: Record<MCPCollectionBuiltinName, CollectionTool> = {\n create: createCollectionTool,\n delete: deleteCollectionTool,\n find: findCollectionTool,\n update: updateCollectionTool,\n}\n\n/**\n * The static auth tools surfaced under auth-enabled collections. Each entry\n * carries the admin-UI label alongside the tool. Keys are the source of truth\n * for `MCPCollectionAuthToolName`.\n */\nexport const COLLECTION_AUTH_BUILTINS: Record<\n MCPCollectionAuthToolName,\n { label: string; tool: CollectionTool }\n> = {\n auth: { label: 'Check Auth Status', tool: authCollectionTool },\n forgotPassword: { label: 'Forgot Password', tool: forgotPasswordCollectionTool },\n login: { label: 'User Login', tool: loginCollectionTool },\n resetPassword: { label: 'Reset Password', tool: resetPasswordCollectionTool },\n unlock: { label: 'Unlock Account', tool: unlockCollectionTool },\n verify: { label: 'Email Verification', tool: verifyCollectionTool },\n}\n\n/**\n * The static built-in global tools. Keys are the source of truth for\n * `MCPGlobalBuiltinName`.\n */\nexport const GLOBAL_BUILTINS: Record<MCPGlobalBuiltinName, GlobalTool> = {\n find: findGlobalTool,\n update: updateGlobalTool,\n}\n\nexport type MCPCollectionBuiltinName = 'create' | 'delete' | 'find' | 'update'\n\nexport type MCPCollectionAuthToolName =\n | 'auth'\n | 'forgotPassword'\n | 'login'\n | 'resetPassword'\n | 'unlock'\n | 'verify'\n\nexport type MCPGlobalBuiltinName = 'find' | 'update'\n\n/**\n * Pre-typed `Object.entries` for each registry. The cast from `string` to the\n * literal key union lives here once so consumers can iterate without their own\n * cast — TypeScript's `Object.entries` always widens keys to `string`, which\n * defeats the narrow type lookups on `MCPCollectionToolsMap`.\n */\nexport const COLLECTION_BUILTIN_ENTRIES = Object.entries(COLLECTION_BUILTINS) as Array<\n [MCPCollectionBuiltinName, CollectionTool]\n>\n\nexport const COLLECTION_AUTH_BUILTIN_ENTRIES = Object.entries(COLLECTION_AUTH_BUILTINS) as Array<\n [MCPCollectionAuthToolName, { label: string; tool: CollectionTool }]\n>\n\nexport const GLOBAL_BUILTIN_ENTRIES = Object.entries(GLOBAL_BUILTINS) as Array<\n [MCPGlobalBuiltinName, GlobalTool]\n>\n"],"names":["authCollectionTool","forgotPasswordCollectionTool","loginCollectionTool","resetPasswordCollectionTool","unlockCollectionTool","verifyCollectionTool","createCollectionTool","deleteCollectionTool","findCollectionTool","updateCollectionTool","findGlobalTool","updateGlobalTool","COLLECTION_BUILTINS","create","delete","find","update","COLLECTION_AUTH_BUILTINS","auth","label","tool","forgot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17 @@
1
+ import type { Config, SanitizedConfig } from 'payload';
2
+ import type { MCPPluginConfig, SanitizedMCPPluginConfig } from '../types.js';
3
+ /**
4
+ * Converts the user-configured `MCPPluginConfig` into a `SanitizedMCPPluginConfig`:
5
+ * - Flattens `tools` / `prompts` / `resources` / per-collection / per-global
6
+ * tool maps into a single `items` array.
7
+ * - Applies built-in tools for collections and globals, respecting opt-out user overrides.
8
+ * - Applies the `userCollection` default
9
+ *
10
+ * Called once during plugin init. After that, `plugins['@payloadcms/plugin-mcp']
11
+ * ?.options` holds the sanitized result
12
+ */
13
+ export declare const sanitizeMCPConfig: ({ config, pluginConfig, }: {
14
+ config: Config | SanitizedConfig;
15
+ pluginConfig: MCPPluginConfig;
16
+ }) => SanitizedMCPPluginConfig;
17
+ //# sourceMappingURL=sanitizeMCPConfig.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sanitizeMCPConfig.d.ts","sourceRoot":"","sources":["../../src/mcp/sanitizeMCPConfig.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,MAAM,EAGN,eAAe,EAEhB,MAAM,SAAS,CAAA;AAEhB,OAAO,KAAK,EAMV,eAAe,EAEf,wBAAwB,EACzB,MAAM,aAAa,CAAA;AAWpB;;;;;;;;;GASG;AACH,eAAO,MAAM,iBAAiB,GAAI,2BAG/B;IACD,MAAM,EAAE,MAAM,GAAG,eAAe,CAAA;IAChC,YAAY,EAAE,eAAe,CAAA;CAC9B,KAAG,wBAkDH,CAAA"}
@@ -0,0 +1,167 @@
1
+ import { COLLECTION_AUTH_BUILTIN_ENTRIES, COLLECTION_AUTH_BUILTINS, COLLECTION_BUILTIN_ENTRIES, COLLECTION_BUILTINS, GLOBAL_BUILTIN_ENTRIES, GLOBAL_BUILTINS } from './builtinTools.js';
2
+ /**
3
+ * Converts the user-configured `MCPPluginConfig` into a `SanitizedMCPPluginConfig`:
4
+ * - Flattens `tools` / `prompts` / `resources` / per-collection / per-global
5
+ * tool maps into a single `items` array.
6
+ * - Applies built-in tools for collections and globals, respecting opt-out user overrides.
7
+ * - Applies the `userCollection` default
8
+ *
9
+ * Called once during plugin init. After that, `plugins['@payloadcms/plugin-mcp']
10
+ * ?.options` holds the sanitized result
11
+ */ export const sanitizeMCPConfig = ({ config, pluginConfig })=>{
12
+ const items = [];
13
+ for (const collection of config.collections ?? []){
14
+ items.push(...sanitizeCollectionConfig({
15
+ collection,
16
+ pluginConfig
17
+ }));
18
+ }
19
+ for (const global of config.globals ?? []){
20
+ items.push(...sanitizeGlobalConfig({
21
+ global,
22
+ pluginConfig
23
+ }));
24
+ }
25
+ for (const [key, tool] of Object.entries(pluginConfig.tools ?? {})){
26
+ items.push({
27
+ type: 'tool',
28
+ key,
29
+ label: key,
30
+ tool
31
+ });
32
+ }
33
+ for (const [key, prompt] of Object.entries(pluginConfig.prompts ?? {})){
34
+ items.push({
35
+ type: 'prompt',
36
+ key,
37
+ label: prompt.title ?? key,
38
+ prompt
39
+ });
40
+ }
41
+ for (const [key, resource] of Object.entries(pluginConfig.resources ?? {})){
42
+ items.push({
43
+ type: 'resource',
44
+ key,
45
+ label: resource.title ?? key,
46
+ resource
47
+ });
48
+ }
49
+ // Mirror Payload's own admin.user detection (sanitize.ts) since plugins run first.
50
+ const firstCollectionWithAuth = config.collections.find(({ auth })=>Boolean(auth));
51
+ return {
52
+ disabled: pluginConfig.disabled,
53
+ items,
54
+ mcp: pluginConfig.mcp,
55
+ overrideApiKeyCollection: pluginConfig.overrideApiKeyCollection,
56
+ overrideAuth: pluginConfig.overrideAuth,
57
+ userCollection: pluginConfig.userCollection ?? config.admin?.user ?? firstCollectionWithAuth?.slug ?? 'users'
58
+ };
59
+ };
60
+ const sanitizeCollectionConfig = ({ collection, pluginConfig })=>{
61
+ if (collection.slug === 'payload-mcp-api-keys') {
62
+ return [];
63
+ }
64
+ const slug = collection.slug;
65
+ const collectionPluginConfig = pluginConfig.collections?.[slug];
66
+ const items = [];
67
+ for (const [toolKey, tool] of COLLECTION_BUILTIN_ENTRIES){
68
+ const matchedConfigEntry = collectionPluginConfig?.tools?.[toolKey];
69
+ if (matchedConfigEntry === false) {
70
+ continue;
71
+ }
72
+ items.push({
73
+ type: 'collectionTool',
74
+ collectionSlug: slug,
75
+ key: toolKey,
76
+ label: capitalize(toolKey),
77
+ tool: overrideBuiltinTool(tool, matchedConfigEntry, collectionPluginConfig)
78
+ });
79
+ }
80
+ if (collection.auth) {
81
+ for (const [authToolKey, { label, tool }] of COLLECTION_AUTH_BUILTIN_ENTRIES){
82
+ const matchedConfigEntry = collectionPluginConfig?.tools?.[authToolKey];
83
+ if (!matchedConfigEntry) {
84
+ continue;
85
+ }
86
+ // `true` means "enable, no override"; only the object form carries fields.
87
+ const override = typeof matchedConfigEntry === 'object' ? matchedConfigEntry : undefined;
88
+ items.push({
89
+ type: 'collectionTool',
90
+ collectionSlug: slug,
91
+ key: authToolKey,
92
+ label,
93
+ tool: overrideBuiltinTool(tool, override, collectionPluginConfig)
94
+ });
95
+ }
96
+ }
97
+ // Cast: builtin keys are filtered out below, so the remaining values are
98
+ // always custom tools (`CollectionTool`) or undefined
99
+ const customEntries = Object.entries(collectionPluginConfig?.tools ?? {});
100
+ for (const [key, customTool] of customEntries){
101
+ if (key in COLLECTION_BUILTINS || key in COLLECTION_AUTH_BUILTINS) {
102
+ continue;
103
+ }
104
+ if (!customTool) {
105
+ continue;
106
+ }
107
+ items.push({
108
+ type: 'collectionTool',
109
+ collectionSlug: slug,
110
+ key,
111
+ label: key,
112
+ tool: customTool
113
+ });
114
+ }
115
+ return items;
116
+ };
117
+ const sanitizeGlobalConfig = ({ global, pluginConfig })=>{
118
+ const slug = global.slug;
119
+ const globalPluginConfig = pluginConfig.globals?.[slug];
120
+ const items = [];
121
+ for (const [toolKey, baseTool] of GLOBAL_BUILTIN_ENTRIES){
122
+ const matchedConfigEntry = globalPluginConfig?.tools?.[toolKey];
123
+ if (matchedConfigEntry === false) {
124
+ continue;
125
+ }
126
+ items.push({
127
+ type: 'globalTool',
128
+ globalSlug: slug,
129
+ key: toolKey,
130
+ label: capitalize(toolKey),
131
+ tool: overrideBuiltinTool(baseTool, matchedConfigEntry, globalPluginConfig)
132
+ });
133
+ }
134
+ const customEntries = Object.entries(globalPluginConfig?.tools ?? {});
135
+ for (const [key, customTool] of customEntries){
136
+ if (key in GLOBAL_BUILTINS) {
137
+ continue;
138
+ }
139
+ if (!customTool) {
140
+ continue;
141
+ }
142
+ items.push({
143
+ type: 'globalTool',
144
+ globalSlug: slug,
145
+ key,
146
+ label: key,
147
+ tool: customTool
148
+ });
149
+ }
150
+ return items;
151
+ };
152
+ const capitalize = (s)=>s.charAt(0).toUpperCase() + s.slice(1);
153
+ /**
154
+ * Spread the static built-in tool and apply consumer-side overrides.
155
+ * Precedence: per-tool override > scope-level (collection/global) override >
156
+ * the static tool's defaults. `toolEntry` is whatever the user put under
157
+ * `tools: { find: ... }` — could be `true`, `false`, or an override object —
158
+ * so it's narrowed internally.
159
+ */ const overrideBuiltinTool = (tool, toolOverride, entityPluginConfig)=>{
160
+ return {
161
+ ...tool,
162
+ description: toolOverride?.description ?? entityPluginConfig?.description ?? tool.description,
163
+ overrideResponse: toolOverride?.overrideResponse ?? entityPluginConfig?.overrideResponse ?? tool.overrideResponse
164
+ };
165
+ };
166
+
167
+ //# sourceMappingURL=sanitizeMCPConfig.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/mcp/sanitizeMCPConfig.ts"],"sourcesContent":["import type {\n CollectionConfig,\n Config,\n GlobalConfig,\n SanitizedCollectionConfig,\n SanitizedConfig,\n SanitizedGlobalConfig,\n} from 'payload'\n\nimport type {\n CollectionTool,\n GlobalTool,\n MCPBuiltInToolOverride,\n MCPItem,\n MCPPluginCollectionConfig,\n MCPPluginConfig,\n MCPPluginGlobalConfig,\n SanitizedMCPPluginConfig,\n} from '../types.js'\n\nimport {\n COLLECTION_AUTH_BUILTIN_ENTRIES,\n COLLECTION_AUTH_BUILTINS,\n COLLECTION_BUILTIN_ENTRIES,\n COLLECTION_BUILTINS,\n GLOBAL_BUILTIN_ENTRIES,\n GLOBAL_BUILTINS,\n} from './builtinTools.js'\n\n/**\n * Converts the user-configured `MCPPluginConfig` into a `SanitizedMCPPluginConfig`:\n * - Flattens `tools` / `prompts` / `resources` / per-collection / per-global\n * tool maps into a single `items` array.\n * - Applies built-in tools for collections and globals, respecting opt-out user overrides.\n * - Applies the `userCollection` default\n *\n * Called once during plugin init. After that, `plugins['@payloadcms/plugin-mcp']\n * ?.options` holds the sanitized result\n */\nexport const sanitizeMCPConfig = ({\n config,\n pluginConfig,\n}: {\n config: Config | SanitizedConfig\n pluginConfig: MCPPluginConfig\n}): SanitizedMCPPluginConfig => {\n const items: MCPItem[] = []\n\n for (const collection of config.collections ?? []) {\n items.push(...sanitizeCollectionConfig({ collection, pluginConfig }))\n }\n\n for (const global of config.globals ?? []) {\n items.push(...sanitizeGlobalConfig({ global, pluginConfig }))\n }\n\n for (const [key, tool] of Object.entries(pluginConfig.tools ?? {})) {\n items.push({\n type: 'tool',\n key,\n label: key,\n tool,\n })\n }\n\n for (const [key, prompt] of Object.entries(pluginConfig.prompts ?? {})) {\n items.push({\n type: 'prompt',\n key,\n label: prompt.title ?? key,\n prompt,\n })\n }\n\n for (const [key, resource] of Object.entries(pluginConfig.resources ?? {})) {\n items.push({\n type: 'resource',\n key,\n label: resource.title ?? key,\n resource,\n })\n }\n\n // Mirror Payload's own admin.user detection (sanitize.ts) since plugins run first.\n const firstCollectionWithAuth = config.collections!.find(({ auth }) => Boolean(auth))\n\n return {\n disabled: pluginConfig.disabled,\n items,\n mcp: pluginConfig.mcp,\n overrideApiKeyCollection: pluginConfig.overrideApiKeyCollection,\n overrideAuth: pluginConfig.overrideAuth,\n userCollection:\n pluginConfig.userCollection ?? config.admin?.user ?? firstCollectionWithAuth?.slug ?? 'users',\n }\n}\n\nconst sanitizeCollectionConfig = ({\n collection,\n pluginConfig,\n}: {\n collection: CollectionConfig | SanitizedCollectionConfig\n pluginConfig: MCPPluginConfig\n}): MCPItem[] => {\n if (collection.slug === 'payload-mcp-api-keys') {\n return []\n }\n const slug = collection.slug\n const collectionPluginConfig = pluginConfig.collections?.[slug]\n const items: MCPItem[] = []\n\n for (const [toolKey, tool] of COLLECTION_BUILTIN_ENTRIES) {\n const matchedConfigEntry = collectionPluginConfig?.tools?.[toolKey]\n if (matchedConfigEntry === false) {\n continue\n }\n items.push({\n type: 'collectionTool',\n collectionSlug: slug,\n key: toolKey,\n label: capitalize(toolKey),\n tool: overrideBuiltinTool(tool, matchedConfigEntry, collectionPluginConfig),\n })\n }\n\n if (collection.auth) {\n for (const [authToolKey, { label, tool }] of COLLECTION_AUTH_BUILTIN_ENTRIES) {\n const matchedConfigEntry = collectionPluginConfig?.tools?.[authToolKey]\n if (!matchedConfigEntry) {\n continue\n }\n // `true` means \"enable, no override\"; only the object form carries fields.\n const override = typeof matchedConfigEntry === 'object' ? matchedConfigEntry : undefined\n items.push({\n type: 'collectionTool',\n collectionSlug: slug,\n key: authToolKey,\n label,\n tool: overrideBuiltinTool(tool, override, collectionPluginConfig),\n })\n }\n }\n\n // Cast: builtin keys are filtered out below, so the remaining values are\n // always custom tools (`CollectionTool`) or undefined\n const customEntries = Object.entries(collectionPluginConfig?.tools ?? {}) as Array<\n [string, CollectionTool | undefined]\n >\n for (const [key, customTool] of customEntries) {\n if (key in COLLECTION_BUILTINS || key in COLLECTION_AUTH_BUILTINS) {\n continue\n }\n if (!customTool) {\n continue\n }\n items.push({\n type: 'collectionTool',\n collectionSlug: slug,\n key,\n label: key,\n tool: customTool,\n })\n }\n\n return items\n}\n\nconst sanitizeGlobalConfig = ({\n global,\n pluginConfig,\n}: {\n global: GlobalConfig | SanitizedGlobalConfig\n pluginConfig: MCPPluginConfig\n}): MCPItem[] => {\n const slug = global.slug\n const globalPluginConfig = pluginConfig.globals?.[slug]\n const items: MCPItem[] = []\n\n for (const [toolKey, baseTool] of GLOBAL_BUILTIN_ENTRIES) {\n const matchedConfigEntry = globalPluginConfig?.tools?.[toolKey]\n if (matchedConfigEntry === false) {\n continue\n }\n items.push({\n type: 'globalTool',\n globalSlug: slug,\n key: toolKey,\n label: capitalize(toolKey),\n tool: overrideBuiltinTool(baseTool, matchedConfigEntry, globalPluginConfig),\n })\n }\n\n const customEntries = Object.entries(globalPluginConfig?.tools ?? {}) as Array<\n [string, GlobalTool | undefined]\n >\n for (const [key, customTool] of customEntries) {\n if (key in GLOBAL_BUILTINS) {\n continue\n }\n if (!customTool) {\n continue\n }\n items.push({\n type: 'globalTool',\n globalSlug: slug,\n key,\n label: key,\n tool: customTool,\n })\n }\n\n return items\n}\n\nconst capitalize = (s: string): string => s.charAt(0).toUpperCase() + s.slice(1)\n\n/**\n * Spread the static built-in tool and apply consumer-side overrides.\n * Precedence: per-tool override > scope-level (collection/global) override >\n * the static tool's defaults. `toolEntry` is whatever the user put under\n * `tools: { find: ... }` — could be `true`, `false`, or an override object —\n * so it's narrowed internally.\n */\nconst overrideBuiltinTool = <TTool extends CollectionTool | GlobalTool>(\n tool: TTool,\n toolOverride?: MCPBuiltInToolOverride,\n entityPluginConfig?: TTool extends CollectionTool\n ? MCPPluginCollectionConfig<any>\n : MCPPluginGlobalConfig,\n): TTool => {\n return {\n ...tool,\n description: toolOverride?.description ?? entityPluginConfig?.description ?? tool.description,\n overrideResponse:\n toolOverride?.overrideResponse ??\n entityPluginConfig?.overrideResponse ??\n tool.overrideResponse,\n }\n}\n"],"names":["COLLECTION_AUTH_BUILTIN_ENTRIES","COLLECTION_AUTH_BUILTINS","COLLECTION_BUILTIN_ENTRIES","COLLECTION_BUILTINS","GLOBAL_BUILTIN_ENTRIES","GLOBAL_BUILTINS","sanitizeMCPConfig","config","pluginConfig","items","collection","collections","push","sanitizeCollectionConfig","global","globals","sanitizeGlobalConfig","key","tool","Object","entries","tools","type","label","prompt","prompts","title","resource","resources","firstCollectionWithAuth","find","auth","Boolean","disabled","mcp","overrideApiKeyCollection","overrideAuth","userCollection","admin","user","slug","collectionPluginConfig","toolKey","matchedConfigEntry","collectionSlug","capitalize","overrideBuiltinTool","authToolKey","override","undefined","customEntries","customTool","globalPluginConfig","baseTool","globalSlug","s","charAt","toUpperCase","slice","toolOverride","entityPluginConfig","description","overrideResponse"],"mappings":"AAoBA,SACEA,+BAA+B,EAC/BC,wBAAwB,EACxBC,0BAA0B,EAC1BC,mBAAmB,EACnBC,sBAAsB,EACtBC,eAAe,QACV,oBAAmB;AAE1B;;;;;;;;;CASC,GACD,OAAO,MAAMC,oBAAoB,CAAC,EAChCC,MAAM,EACNC,YAAY,EAIb;IACC,MAAMC,QAAmB,EAAE;IAE3B,KAAK,MAAMC,cAAcH,OAAOI,WAAW,IAAI,EAAE,CAAE;QACjDF,MAAMG,IAAI,IAAIC,yBAAyB;YAAEH;YAAYF;QAAa;IACpE;IAEA,KAAK,MAAMM,UAAUP,OAAOQ,OAAO,IAAI,EAAE,CAAE;QACzCN,MAAMG,IAAI,IAAII,qBAAqB;YAAEF;YAAQN;QAAa;IAC5D;IAEA,KAAK,MAAM,CAACS,KAAKC,KAAK,IAAIC,OAAOC,OAAO,CAACZ,aAAaa,KAAK,IAAI,CAAC,GAAI;QAClEZ,MAAMG,IAAI,CAAC;YACTU,MAAM;YACNL;YACAM,OAAON;YACPC;QACF;IACF;IAEA,KAAK,MAAM,CAACD,KAAKO,OAAO,IAAIL,OAAOC,OAAO,CAACZ,aAAaiB,OAAO,IAAI,CAAC,GAAI;QACtEhB,MAAMG,IAAI,CAAC;YACTU,MAAM;YACNL;YACAM,OAAOC,OAAOE,KAAK,IAAIT;YACvBO;QACF;IACF;IAEA,KAAK,MAAM,CAACP,KAAKU,SAAS,IAAIR,OAAOC,OAAO,CAACZ,aAAaoB,SAAS,IAAI,CAAC,GAAI;QAC1EnB,MAAMG,IAAI,CAAC;YACTU,MAAM;YACNL;YACAM,OAAOI,SAASD,KAAK,IAAIT;YACzBU;QACF;IACF;IAEA,mFAAmF;IACnF,MAAME,0BAA0BtB,OAAOI,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oC,aAAa,CAACU,IAAsBA,EAAEC,MAAM,CAAC,GAAGC,WAAW,KAAKF,EAAEG,KAAK,CAAC;AAE9E;;;;;;CAMC,GACD,MAAMZ,sBAAsB,CAC1B5B,MACAyC,cACAC;IAIA,OAAO;QACL,GAAG1C,IAAI;QACP2C,aAAaF,cAAcE,eAAeD,oBAAoBC,eAAe3C,KAAK2C,WAAW;QAC7FC,kBACEH,cAAcG,oBACdF,oBAAoBE,oBACpB5C,KAAK4C,gBAAgB;IACzB;AACF"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Stdio adapter for the Payload MCP server.
3
+ *
4
+ * Do not use in production. There's no auth; whoever can spawn the process gets
5
+ * full access to your local data.
6
+ */
7
+ export declare const runMcpStdio: () => Promise<void>;
8
+ //# sourceMappingURL=stdio.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stdio.d.ts","sourceRoot":"","sources":["../src/stdio.ts"],"names":[],"mappings":"AAeA;;;;;GAKG;AACH,eAAO,MAAM,WAAW,QAAa,OAAO,CAAC,IAAI,CA4EhD,CAAA"}
package/dist/stdio.js ADDED
@@ -0,0 +1,89 @@
1
+ /* eslint-disable no-console */ import { StdioServerTransport } from '@modelcontextprotocol/server';
2
+ import { fileURLToPath, pathToFileURL } from 'node:url';
3
+ import { createLocalReq, getPayload } from 'payload';
4
+ import { findConfig } from 'payload/node';
5
+ import { buildMcpServer } from './mcp/buildMcpServer.js';
6
+ import { sanitizeMCPConfig } from './mcp/sanitizeMCPConfig.js';
7
+ import { getPluginConfig } from './utils/getPluginConfig.js';
8
+ import { resolveProjectRoot } from './utils/resolveProjectRoot.js';
9
+ /**
10
+ * Stdio adapter for the Payload MCP server.
11
+ *
12
+ * Do not use in production. There's no auth; whoever can spawn the process gets
13
+ * full access to your local data.
14
+ */ export const runMcpStdio = async ()=>{
15
+ /**
16
+ * If MCP clients spawn stdio servers from an arbitrary working directory,
17
+ * Payload's cwd-anchored `findConfig()` can't locate the project on
18
+ * its own. This module always lives inside the project's `node_modules`, so
19
+ * we derive the project root from its own path and `chdir` into it.
20
+ *
21
+ * An absolute `PAYLOAD_CONFIG_PATH` still overrides everything; unusual
22
+ * layouts (e.g. a monorepo where the package is hoisted above the app) can
23
+ * fall back to it. See the implementation of findConfig for details.
24
+ */ const projectRoot = resolveProjectRoot(fileURLToPath(import.meta.url));
25
+ if (projectRoot) {
26
+ process.chdir(projectRoot);
27
+ }
28
+ const configPath = findConfig();
29
+ const configModule = await import(pathToFileURL(configPath).toString());
30
+ const config = await (configModule.default ?? configModule);
31
+ const payload = await getPayload({
32
+ config
33
+ });
34
+ /**
35
+ * If the user added `mcpPlugin({...})` to their `plugins` array, read the
36
+ * sanitized config they registered. Otherwise fall back to the defaults. That way,
37
+ * the mcp works on any project that has `@payloadcms/plugin-mcp` installed,
38
+ * even if the plugin is not added to the plugins array.
39
+ */ let pluginConfig;
40
+ try {
41
+ pluginConfig = getPluginConfig({
42
+ config: payload.config
43
+ });
44
+ } catch {
45
+ pluginConfig = sanitizeMCPConfig({
46
+ config: payload.config,
47
+ pluginConfig: {}
48
+ });
49
+ const fakePluginFn = (config)=>config;
50
+ fakePluginFn.slug = '@payloadcms/plugin-mcp';
51
+ // @ts-expect-error
52
+ fakePluginFn.sanitizedOptions = pluginConfig;
53
+ (payload.config.plugins ??= []).push(fakePluginFn);
54
+ }
55
+ const authorizedMCP = {
56
+ items: pluginConfig.items,
57
+ overrideAccess: true,
58
+ user: null
59
+ };
60
+ const req = await createLocalReq({}, payload);
61
+ req.payloadAPI = 'MCP';
62
+ const server = buildMcpServer({
63
+ authorizedMCP,
64
+ pluginConfig,
65
+ req
66
+ });
67
+ const transport = new StdioServerTransport();
68
+ await server.connect(transport);
69
+ // Process now lives until stdin closes. Wire graceful shutdown so DB
70
+ // connections (and any other Payload-managed resources) get released.
71
+ const shutdown = async (code = 0)=>{
72
+ try {
73
+ await server.close();
74
+ } catch (err) {
75
+ console.error('[payload-mcp] error closing server:', err);
76
+ }
77
+ try {
78
+ await payload.destroy();
79
+ } catch (err) {
80
+ console.error('[payload-mcp] error destroying payload:', err);
81
+ }
82
+ process.exit(code);
83
+ };
84
+ process.on('SIGINT', ()=>void shutdown(0));
85
+ process.on('SIGTERM', ()=>void shutdown(0));
86
+ process.stdin.on('close', ()=>void shutdown(0));
87
+ };
88
+
89
+ //# sourceMappingURL=stdio.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/stdio.ts"],"sourcesContent":["import type { MaybePromise, Plugin, SanitizedConfig } from 'payload'\n\n/* eslint-disable no-console */\nimport { StdioServerTransport } from '@modelcontextprotocol/server'\nimport { fileURLToPath, pathToFileURL } from 'node:url'\nimport { createLocalReq, getPayload } from 'payload'\nimport { findConfig } from 'payload/node'\n\nimport type { AuthorizedMCP, SanitizedMCPPluginConfig } from './types.js'\n\nimport { buildMcpServer } from './mcp/buildMcpServer.js'\nimport { sanitizeMCPConfig } from './mcp/sanitizeMCPConfig.js'\nimport { getPluginConfig } from './utils/getPluginConfig.js'\nimport { resolveProjectRoot } from './utils/resolveProjectRoot.js'\n\n/**\n * Stdio adapter for the Payload MCP server.\n *\n * Do not use in production. There's no auth; whoever can spawn the process gets\n * full access to your local data.\n */\nexport const runMcpStdio = async (): Promise<void> => {\n /**\n * If MCP clients spawn stdio servers from an arbitrary working directory,\n * Payload's cwd-anchored `findConfig()` can't locate the project on\n * its own. This module always lives inside the project's `node_modules`, so\n * we derive the project root from its own path and `chdir` into it.\n *\n * An absolute `PAYLOAD_CONFIG_PATH` still overrides everything; unusual\n * layouts (e.g. a monorepo where the package is hoisted above the app) can\n * fall back to it. See the implementation of findConfig for details.\n */\n const projectRoot = resolveProjectRoot(fileURLToPath(import.meta.url))\n if (projectRoot) {\n process.chdir(projectRoot)\n }\n\n const configPath = findConfig()\n const configModule = await import(pathToFileURL(configPath).toString())\n const config = (await (configModule.default ?? configModule)) as MaybePromise<SanitizedConfig>\n\n const payload = await getPayload({ config })\n\n /**\n * If the user added `mcpPlugin({...})` to their `plugins` array, read the\n * sanitized config they registered. Otherwise fall back to the defaults. That way,\n * the mcp works on any project that has `@payloadcms/plugin-mcp` installed,\n * even if the plugin is not added to the plugins array.\n */\n let pluginConfig: SanitizedMCPPluginConfig\n try {\n pluginConfig = getPluginConfig({ config: payload.config })\n } catch {\n pluginConfig = sanitizeMCPConfig({ config: payload.config, pluginConfig: {} })\n\n const fakePluginFn: Plugin = (config) => config\n fakePluginFn.slug = '@payloadcms/plugin-mcp'\n // @ts-expect-error\n fakePluginFn.sanitizedOptions = pluginConfig\n\n // Push to payload config, to ensure consecutive calls to `getPluginConfig()` work\n ;(payload.config.plugins ??= []).push(fakePluginFn)\n }\n\n const authorizedMCP: AuthorizedMCP = {\n items: pluginConfig.items,\n overrideAccess: true,\n user: null,\n }\n\n const req = await createLocalReq({}, payload)\n req.payloadAPI = 'MCP' as const\n\n const server = buildMcpServer({ authorizedMCP, pluginConfig, req })\n\n const transport = new StdioServerTransport()\n await server.connect(transport)\n\n // Process now lives until stdin closes. Wire graceful shutdown so DB\n // connections (and any other Payload-managed resources) get released.\n const shutdown = async (code = 0) => {\n try {\n await server.close()\n } catch (err) {\n console.error('[payload-mcp] error closing server:', err)\n }\n try {\n await payload.destroy()\n } catch (err) {\n console.error('[payload-mcp] error destroying payload:', err)\n }\n process.exit(code)\n }\n\n process.on('SIGINT', () => void shutdown(0))\n process.on('SIGTERM', () => void shutdown(0))\n process.stdin.on('close', () => void shutdown(0))\n}\n"],"names":["StdioServerTransport","fileURLToPath","pathToFileURL","createLocalReq","getPayload","findConfig","buildMcpServer","sanitizeMCPConfig","getPluginConfig","resolveProjectRoot","runMcpStdio","projectRoot","url","process","chdir","configPath","configModule","toString","config","default","payload","pluginConfig","fakePluginFn","slug","sanitizedOptions","plugins","push","authorizedMCP","items","overrideAccess","user","req","payloadAPI","server","transport","connect","shutdown","code","close","err","console","error","destroy","exit","on","stdin"],"mappings":"AAEA,6BAA6B,GAC7B,SAASA,oBAAoB,QAAQ,+BAA8B;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