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

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 (328) hide show
  1. package/bin.js +39 -0
  2. package/dist/collection/getAccessField.d.ts +12 -0
  3. package/dist/collection/getAccessField.d.ts.map +1 -0
  4. package/dist/collection/getAccessField.js +57 -0
  5. package/dist/collection/getAccessField.js.map +1 -0
  6. package/dist/collection/index.d.ts +6 -0
  7. package/dist/collection/index.d.ts.map +1 -0
  8. package/dist/collection/index.js +59 -0
  9. package/dist/collection/index.js.map +1 -0
  10. package/dist/components/AccessField/index.client.d.ts +10 -0
  11. package/dist/components/AccessField/index.client.d.ts.map +1 -0
  12. package/dist/components/AccessField/index.client.js +305 -0
  13. package/dist/components/AccessField/index.client.js.map +1 -0
  14. package/dist/components/AccessField/index.css +93 -0
  15. package/dist/defineTool.d.ts +26 -0
  16. package/dist/defineTool.d.ts.map +1 -0
  17. package/dist/defineTool.js +37 -0
  18. package/dist/defineTool.js.map +1 -0
  19. package/dist/endpoint/access.d.ts +10 -0
  20. package/dist/endpoint/access.d.ts.map +1 -0
  21. package/dist/endpoint/access.js +106 -0
  22. package/dist/endpoint/access.js.map +1 -0
  23. package/dist/endpoint/index.d.ts +3 -0
  24. package/dist/endpoint/index.d.ts.map +1 -0
  25. package/dist/endpoint/index.js +36 -0
  26. package/dist/endpoint/index.js.map +1 -0
  27. package/dist/exports/client.d.ts +2 -0
  28. package/dist/exports/client.d.ts.map +1 -0
  29. package/dist/exports/client.js +4 -0
  30. package/dist/exports/client.js.map +1 -0
  31. package/dist/index.d.ts +4 -7
  32. package/dist/index.d.ts.map +1 -1
  33. package/dist/index.js +44 -67
  34. package/dist/index.js.map +1 -1
  35. package/dist/mcp/buildMcpServer.d.ts +19 -0
  36. package/dist/mcp/buildMcpServer.d.ts.map +1 -0
  37. package/dist/mcp/buildMcpServer.js +163 -0
  38. package/dist/mcp/buildMcpServer.js.map +1 -0
  39. package/dist/mcp/builtin/collections/authTools.d.ts +7 -0
  40. package/dist/mcp/builtin/collections/authTools.d.ts.map +1 -0
  41. package/dist/mcp/builtin/collections/authTools.js +250 -0
  42. package/dist/mcp/builtin/collections/authTools.js.map +1 -0
  43. package/dist/mcp/builtin/collections/createTool.d.ts +2 -0
  44. package/dist/mcp/builtin/collections/createTool.d.ts.map +1 -0
  45. package/dist/mcp/builtin/collections/createTool.js +87 -0
  46. package/dist/mcp/builtin/collections/createTool.js.map +1 -0
  47. package/dist/mcp/builtin/collections/deleteTool.d.ts +2 -0
  48. package/dist/mcp/builtin/collections/deleteTool.d.ts.map +1 -0
  49. package/dist/mcp/builtin/collections/deleteTool.js +117 -0
  50. package/dist/mcp/builtin/collections/deleteTool.js.map +1 -0
  51. package/dist/mcp/builtin/collections/findTool.d.ts +2 -0
  52. package/dist/mcp/builtin/collections/findTool.d.ts.map +1 -0
  53. package/dist/mcp/builtin/collections/findTool.js +159 -0
  54. package/dist/mcp/builtin/collections/findTool.js.map +1 -0
  55. package/dist/mcp/builtin/collections/updateTool.d.ts +2 -0
  56. package/dist/mcp/builtin/collections/updateTool.d.ts.map +1 -0
  57. package/dist/mcp/builtin/collections/updateTool.js +187 -0
  58. package/dist/mcp/builtin/collections/updateTool.js.map +1 -0
  59. package/dist/mcp/builtin/globals/findTool.d.ts +2 -0
  60. package/dist/mcp/builtin/globals/findTool.d.ts.map +1 -0
  61. package/dist/mcp/builtin/globals/findTool.js +76 -0
  62. package/dist/mcp/builtin/globals/findTool.js.map +1 -0
  63. package/dist/mcp/builtin/globals/updateTool.d.ts +2 -0
  64. package/dist/mcp/builtin/globals/updateTool.d.ts.map +1 -0
  65. package/dist/mcp/builtin/globals/updateTool.js +92 -0
  66. package/dist/mcp/builtin/globals/updateTool.js.map +1 -0
  67. package/dist/mcp/builtinTools.d.ts +37 -0
  68. package/dist/mcp/builtinTools.d.ts.map +1 -0
  69. package/dist/mcp/builtinTools.js +64 -0
  70. package/dist/mcp/builtinTools.js.map +1 -0
  71. package/dist/mcp/sanitizeMCPConfig.d.ts +17 -0
  72. package/dist/mcp/sanitizeMCPConfig.d.ts.map +1 -0
  73. package/dist/mcp/sanitizeMCPConfig.js +167 -0
  74. package/dist/mcp/sanitizeMCPConfig.js.map +1 -0
  75. package/dist/stdio.d.ts +8 -0
  76. package/dist/stdio.d.ts.map +1 -0
  77. package/dist/stdio.js +89 -0
  78. package/dist/stdio.js.map +1 -0
  79. package/dist/types.d.ts +262 -455
  80. package/dist/types.d.ts.map +1 -1
  81. package/dist/types.js +6 -1
  82. package/dist/types.js.map +1 -1
  83. package/dist/utils/camelCase.d.ts.map +1 -1
  84. package/dist/utils/getLogger.d.ts +10 -0
  85. package/dist/utils/getLogger.d.ts.map +1 -0
  86. package/dist/utils/getLogger.js +22 -0
  87. package/dist/utils/getLogger.js.map +1 -0
  88. package/dist/utils/getPluginConfig.d.ts +12 -0
  89. package/dist/utils/getPluginConfig.d.ts.map +1 -0
  90. package/dist/utils/getPluginConfig.js +15 -0
  91. package/dist/utils/getPluginConfig.js.map +1 -0
  92. package/dist/utils/localAPIDefaults.d.ts +20 -0
  93. package/dist/utils/localAPIDefaults.d.ts.map +1 -0
  94. package/dist/utils/localAPIDefaults.js +19 -0
  95. package/dist/utils/localAPIDefaults.js.map +1 -0
  96. package/dist/utils/resolveProjectRoot.d.ts +7 -0
  97. package/dist/utils/resolveProjectRoot.d.ts.map +1 -0
  98. package/dist/utils/resolveProjectRoot.js +15 -0
  99. package/dist/utils/resolveProjectRoot.js.map +1 -0
  100. package/dist/utils/schemaConversion/prepareCollectionSchema.d.ts +7 -0
  101. package/dist/utils/schemaConversion/prepareCollectionSchema.d.ts.map +1 -0
  102. package/dist/utils/schemaConversion/prepareCollectionSchema.js +37 -0
  103. package/dist/utils/schemaConversion/prepareCollectionSchema.js.map +1 -0
  104. package/dist/utils/schemaConversion/removeVirtualFieldsFromSchema.d.ts +2 -2
  105. package/dist/utils/schemaConversion/removeVirtualFieldsFromSchema.d.ts.map +1 -1
  106. package/dist/utils/schemaConversion/removeVirtualFieldsFromSchema.js.map +1 -1
  107. package/dist/utils/schemaConversion/sanitizeJsonSchema.d.ts +2 -2
  108. package/dist/utils/schemaConversion/sanitizeJsonSchema.d.ts.map +1 -1
  109. package/dist/utils/schemaConversion/sanitizeJsonSchema.js.map +1 -1
  110. package/dist/utils/schemaConversion/simplifyRelationshipFields.d.ts +2 -2
  111. package/dist/utils/schemaConversion/simplifyRelationshipFields.d.ts.map +1 -1
  112. package/dist/utils/schemaConversion/simplifyRelationshipFields.js +7 -4
  113. package/dist/utils/schemaConversion/simplifyRelationshipFields.js.map +1 -1
  114. package/dist/utils/schemaConversion/transformPointFields.d.ts +2 -2
  115. package/dist/utils/schemaConversion/transformPointFields.d.ts.map +1 -1
  116. package/dist/utils/schemaConversion/transformPointFields.js +7 -1
  117. package/dist/utils/schemaConversion/transformPointFields.js.map +1 -1
  118. package/dist/utils/toStandardSchema.d.ts +5 -0
  119. package/dist/utils/toStandardSchema.d.ts.map +1 -0
  120. package/dist/utils/toStandardSchema.js +4 -0
  121. package/dist/utils/toStandardSchema.js.map +1 -0
  122. package/package.json +35 -10
  123. package/src/collection/getAccessField.ts +64 -0
  124. package/src/collection/index.ts +63 -0
  125. package/src/components/AccessField/index.client.tsx +344 -0
  126. package/src/components/AccessField/index.css +93 -0
  127. package/src/defineTool.ts +44 -0
  128. package/src/endpoint/access.ts +132 -0
  129. package/src/endpoint/index.ts +35 -0
  130. package/src/exports/client.ts +2 -0
  131. package/src/index.ts +35 -85
  132. package/src/mcp/buildMcpServer.ts +224 -0
  133. package/src/mcp/builtin/collections/authTools.ts +233 -0
  134. package/src/mcp/builtin/collections/createTool.ts +116 -0
  135. package/src/mcp/builtin/collections/deleteTool.ts +123 -0
  136. package/src/mcp/builtin/collections/findTool.ts +187 -0
  137. package/src/mcp/builtin/collections/updateTool.ts +205 -0
  138. package/src/mcp/builtin/globals/findTool.ts +96 -0
  139. package/src/mcp/builtin/globals/updateTool.ts +118 -0
  140. package/src/mcp/builtinTools.ts +84 -0
  141. package/src/mcp/sanitizeMCPConfig.ts +239 -0
  142. package/src/stdio.ts +98 -0
  143. package/src/types.ts +295 -490
  144. package/src/utils/getLogger.ts +22 -0
  145. package/src/utils/getPluginConfig.ts +24 -0
  146. package/src/utils/localAPIDefaults.ts +22 -0
  147. package/src/utils/resolveProjectRoot.ts +17 -0
  148. package/src/utils/schemaConversion/prepareCollectionSchema.ts +39 -0
  149. package/src/utils/schemaConversion/removeVirtualFieldsFromSchema.ts +3 -3
  150. package/src/utils/schemaConversion/sanitizeJsonSchema.ts +4 -4
  151. package/src/utils/schemaConversion/simplifyRelationshipFields.ts +11 -6
  152. package/src/utils/schemaConversion/transformPointFields.ts +6 -5
  153. package/src/utils/toStandardSchema.ts +9 -0
  154. package/dist/collections/createApiKeysCollection.d.ts +0 -7
  155. package/dist/collections/createApiKeysCollection.d.ts.map +0 -1
  156. package/dist/collections/createApiKeysCollection.js +0 -317
  157. package/dist/collections/createApiKeysCollection.js.map +0 -1
  158. package/dist/defaults.d.ts +0 -4
  159. package/dist/defaults.d.ts.map +0 -1
  160. package/dist/defaults.js +0 -5
  161. package/dist/defaults.js.map +0 -1
  162. package/dist/endpoints/mcp.d.ts +0 -4
  163. package/dist/endpoints/mcp.d.ts.map +0 -1
  164. package/dist/endpoints/mcp.js +0 -71
  165. package/dist/endpoints/mcp.js.map +0 -1
  166. package/dist/mcp/createRequest.d.ts +0 -3
  167. package/dist/mcp/createRequest.d.ts.map +0 -1
  168. package/dist/mcp/createRequest.js +0 -14
  169. package/dist/mcp/createRequest.js.map +0 -1
  170. package/dist/mcp/getMcpHandler.d.ts +0 -4
  171. package/dist/mcp/getMcpHandler.d.ts.map +0 -1
  172. package/dist/mcp/getMcpHandler.js +0 -231
  173. package/dist/mcp/getMcpHandler.js.map +0 -1
  174. package/dist/mcp/helpers/config.d.ts +0 -22
  175. package/dist/mcp/helpers/config.d.ts.map +0 -1
  176. package/dist/mcp/helpers/config.js +0 -153
  177. package/dist/mcp/helpers/config.js.map +0 -1
  178. package/dist/mcp/helpers/fields.d.ts +0 -19
  179. package/dist/mcp/helpers/fields.d.ts.map +0 -1
  180. package/dist/mcp/helpers/fields.js +0 -102
  181. package/dist/mcp/helpers/fields.js.map +0 -1
  182. package/dist/mcp/helpers/fileValidation.d.ts +0 -67
  183. package/dist/mcp/helpers/fileValidation.d.ts.map +0 -1
  184. package/dist/mcp/helpers/fileValidation.js +0 -267
  185. package/dist/mcp/helpers/fileValidation.js.map +0 -1
  186. package/dist/mcp/registerTool.d.ts +0 -6
  187. package/dist/mcp/registerTool.d.ts.map +0 -1
  188. package/dist/mcp/registerTool.js +0 -18
  189. package/dist/mcp/registerTool.js.map +0 -1
  190. package/dist/mcp/tools/auth/auth.d.ts +0 -4
  191. package/dist/mcp/tools/auth/auth.d.ts.map +0 -1
  192. package/dist/mcp/tools/auth/auth.js +0 -57
  193. package/dist/mcp/tools/auth/auth.js.map +0 -1
  194. package/dist/mcp/tools/auth/forgotPassword.d.ts +0 -4
  195. package/dist/mcp/tools/auth/forgotPassword.d.ts.map +0 -1
  196. package/dist/mcp/tools/auth/forgotPassword.js +0 -48
  197. package/dist/mcp/tools/auth/forgotPassword.js.map +0 -1
  198. package/dist/mcp/tools/auth/login.d.ts +0 -4
  199. package/dist/mcp/tools/auth/login.d.ts.map +0 -1
  200. package/dist/mcp/tools/auth/login.js +0 -51
  201. package/dist/mcp/tools/auth/login.js.map +0 -1
  202. package/dist/mcp/tools/auth/resetPassword.d.ts +0 -4
  203. package/dist/mcp/tools/auth/resetPassword.d.ts.map +0 -1
  204. package/dist/mcp/tools/auth/resetPassword.js +0 -49
  205. package/dist/mcp/tools/auth/resetPassword.js.map +0 -1
  206. package/dist/mcp/tools/auth/unlock.d.ts +0 -4
  207. package/dist/mcp/tools/auth/unlock.d.ts.map +0 -1
  208. package/dist/mcp/tools/auth/unlock.js +0 -48
  209. package/dist/mcp/tools/auth/unlock.js.map +0 -1
  210. package/dist/mcp/tools/auth/verify.d.ts +0 -4
  211. package/dist/mcp/tools/auth/verify.d.ts.map +0 -1
  212. package/dist/mcp/tools/auth/verify.js +0 -45
  213. package/dist/mcp/tools/auth/verify.js.map +0 -1
  214. package/dist/mcp/tools/collection/create.d.ts +0 -10
  215. package/dist/mcp/tools/collection/create.d.ts.map +0 -1
  216. package/dist/mcp/tools/collection/create.js +0 -139
  217. package/dist/mcp/tools/collection/create.js.map +0 -1
  218. package/dist/mcp/tools/collection/delete.d.ts +0 -10
  219. package/dist/mcp/tools/collection/delete.d.ts.map +0 -1
  220. package/dist/mcp/tools/collection/delete.js +0 -154
  221. package/dist/mcp/tools/collection/delete.js.map +0 -1
  222. package/dist/mcp/tools/collection/find.d.ts +0 -10
  223. package/dist/mcp/tools/collection/find.d.ts.map +0 -1
  224. package/dist/mcp/tools/collection/find.js +0 -165
  225. package/dist/mcp/tools/collection/find.js.map +0 -1
  226. package/dist/mcp/tools/collection/update.d.ts +0 -10
  227. package/dist/mcp/tools/collection/update.d.ts.map +0 -1
  228. package/dist/mcp/tools/collection/update.js +0 -209
  229. package/dist/mcp/tools/collection/update.js.map +0 -1
  230. package/dist/mcp/tools/config/find.d.ts +0 -10
  231. package/dist/mcp/tools/config/find.d.ts.map +0 -1
  232. package/dist/mcp/tools/config/find.js +0 -97
  233. package/dist/mcp/tools/config/find.js.map +0 -1
  234. package/dist/mcp/tools/config/update.d.ts +0 -10
  235. package/dist/mcp/tools/config/update.d.ts.map +0 -1
  236. package/dist/mcp/tools/config/update.js +0 -215
  237. package/dist/mcp/tools/config/update.js.map +0 -1
  238. package/dist/mcp/tools/global/find.d.ts +0 -5
  239. package/dist/mcp/tools/global/find.d.ts.map +0 -1
  240. package/dist/mcp/tools/global/find.js +0 -82
  241. package/dist/mcp/tools/global/find.js.map +0 -1
  242. package/dist/mcp/tools/global/update.d.ts +0 -6
  243. package/dist/mcp/tools/global/update.d.ts.map +0 -1
  244. package/dist/mcp/tools/global/update.js +0 -124
  245. package/dist/mcp/tools/global/update.js.map +0 -1
  246. package/dist/mcp/tools/job/create.d.ts +0 -10
  247. package/dist/mcp/tools/job/create.d.ts.map +0 -1
  248. package/dist/mcp/tools/job/create.js +0 -293
  249. package/dist/mcp/tools/job/create.js.map +0 -1
  250. package/dist/mcp/tools/job/run.d.ts +0 -10
  251. package/dist/mcp/tools/job/run.d.ts.map +0 -1
  252. package/dist/mcp/tools/job/run.js +0 -129
  253. package/dist/mcp/tools/job/run.js.map +0 -1
  254. package/dist/mcp/tools/job/update.d.ts +0 -11
  255. package/dist/mcp/tools/job/update.d.ts.map +0 -1
  256. package/dist/mcp/tools/job/update.js +0 -186
  257. package/dist/mcp/tools/job/update.js.map +0 -1
  258. package/dist/mcp/tools/resource/create.d.ts +0 -6
  259. package/dist/mcp/tools/resource/create.d.ts.map +0 -1
  260. package/dist/mcp/tools/resource/create.js +0 -124
  261. package/dist/mcp/tools/resource/create.js.map +0 -1
  262. package/dist/mcp/tools/resource/delete.d.ts +0 -5
  263. package/dist/mcp/tools/resource/delete.d.ts.map +0 -1
  264. package/dist/mcp/tools/resource/delete.js +0 -151
  265. package/dist/mcp/tools/resource/delete.js.map +0 -1
  266. package/dist/mcp/tools/resource/find.d.ts +0 -5
  267. package/dist/mcp/tools/resource/find.d.ts.map +0 -1
  268. package/dist/mcp/tools/resource/find.js +0 -170
  269. package/dist/mcp/tools/resource/find.js.map +0 -1
  270. package/dist/mcp/tools/resource/update.d.ts +0 -6
  271. package/dist/mcp/tools/resource/update.d.ts.map +0 -1
  272. package/dist/mcp/tools/resource/update.js +0 -256
  273. package/dist/mcp/tools/resource/update.js.map +0 -1
  274. package/dist/mcp/tools/schemas.d.ts +0 -457
  275. package/dist/mcp/tools/schemas.d.ts.map +0 -1
  276. package/dist/mcp/tools/schemas.js +0 -243
  277. package/dist/mcp/tools/schemas.js.map +0 -1
  278. package/dist/utils/adminEntitySettings.d.ts +0 -17
  279. package/dist/utils/adminEntitySettings.d.ts.map +0 -1
  280. package/dist/utils/adminEntitySettings.js +0 -41
  281. package/dist/utils/adminEntitySettings.js.map +0 -1
  282. package/dist/utils/createApiKeyFields.d.ts +0 -15
  283. package/dist/utils/createApiKeyFields.d.ts.map +0 -1
  284. package/dist/utils/createApiKeyFields.js +0 -57
  285. package/dist/utils/createApiKeyFields.js.map +0 -1
  286. package/dist/utils/getEnabledSlugs.d.ts +0 -13
  287. package/dist/utils/getEnabledSlugs.d.ts.map +0 -1
  288. package/dist/utils/getEnabledSlugs.js +0 -32
  289. package/dist/utils/getEnabledSlugs.js.map +0 -1
  290. package/dist/utils/schemaConversion/convertCollectionSchemaToZod.d.ts +0 -3
  291. package/dist/utils/schemaConversion/convertCollectionSchemaToZod.d.ts.map +0 -1
  292. package/dist/utils/schemaConversion/convertCollectionSchemaToZod.js +0 -43
  293. package/dist/utils/schemaConversion/convertCollectionSchemaToZod.js.map +0 -1
  294. package/src/collections/createApiKeysCollection.ts +0 -373
  295. package/src/defaults.ts +0 -3
  296. package/src/endpoints/mcp.ts +0 -91
  297. package/src/mcp/createRequest.ts +0 -13
  298. package/src/mcp/getMcpHandler.ts +0 -545
  299. package/src/mcp/helpers/config.ts +0 -213
  300. package/src/mcp/helpers/fields.ts +0 -154
  301. package/src/mcp/helpers/fileValidation.ts +0 -362
  302. package/src/mcp/registerTool.ts +0 -22
  303. package/src/mcp/tools/auth/auth.ts +0 -71
  304. package/src/mcp/tools/auth/forgotPassword.ts +0 -70
  305. package/src/mcp/tools/auth/login.ts +0 -72
  306. package/src/mcp/tools/auth/resetPassword.ts +0 -61
  307. package/src/mcp/tools/auth/unlock.ts +0 -64
  308. package/src/mcp/tools/auth/verify.ts +0 -57
  309. package/src/mcp/tools/collection/create.ts +0 -210
  310. package/src/mcp/tools/collection/delete.ts +0 -211
  311. package/src/mcp/tools/collection/find.ts +0 -224
  312. package/src/mcp/tools/collection/update.ts +0 -290
  313. package/src/mcp/tools/config/find.ts +0 -128
  314. package/src/mcp/tools/config/update.ts +0 -280
  315. package/src/mcp/tools/global/find.ts +0 -128
  316. package/src/mcp/tools/global/update.ts +0 -207
  317. package/src/mcp/tools/job/create.ts +0 -416
  318. package/src/mcp/tools/job/run.ts +0 -167
  319. package/src/mcp/tools/job/update.ts +0 -274
  320. package/src/mcp/tools/resource/create.ts +0 -211
  321. package/src/mcp/tools/resource/delete.ts +0 -218
  322. package/src/mcp/tools/resource/find.ts +0 -246
  323. package/src/mcp/tools/resource/update.ts +0 -383
  324. package/src/mcp/tools/schemas.ts +0 -520
  325. package/src/utils/adminEntitySettings.ts +0 -40
  326. package/src/utils/createApiKeyFields.ts +0 -72
  327. package/src/utils/getEnabledSlugs.ts +0 -42
  328. package/src/utils/schemaConversion/convertCollectionSchemaToZod.ts +0 -52
@@ -1,165 +0,0 @@
1
- import { readdirSync, readFileSync, statSync } from 'fs';
2
- import { extname, join } from 'path';
3
- import { toolSchemas } from '../schemas.js';
4
- export const readCollections = (req, verboseLogs, collectionsDirPath, collectionName, includeContent = false, includeCount = false)=>{
5
- const payload = req.payload;
6
- if (verboseLogs) {
7
- payload.logger.info(`[payload-mcp] Reading collections${collectionName ? ` for: ${collectionName}` : ''}, includeContent: ${includeContent}, includeCount: ${includeCount}`);
8
- }
9
- try {
10
- // Read specific Collection (optional)
11
- if (collectionName) {
12
- const fileName = `${collectionName.charAt(0).toUpperCase() + collectionName.slice(1)}.ts`;
13
- const filePath = join(collectionsDirPath, fileName);
14
- if (!filePath.startsWith(collectionsDirPath)) {
15
- payload.logger.error(`[payload-mcp] Invalid collection name attempted: ${collectionName}`);
16
- return {
17
- content: [
18
- {
19
- type: 'text',
20
- text: 'Error: Invalid collection name'
21
- }
22
- ]
23
- };
24
- }
25
- try {
26
- const content = readFileSync(filePath, 'utf8');
27
- if (verboseLogs) {
28
- payload.logger.info(`[payload-mcp] Successfully read collection: ${collectionName}`);
29
- }
30
- return {
31
- content: [
32
- {
33
- type: 'text',
34
- text: `Collection: ${collectionName}
35
- File: ${fileName}
36
- ---
37
- ${content}`
38
- }
39
- ]
40
- };
41
- } catch (_error) {
42
- payload.logger.warn(`[payload-mcp] Collection not found: ${collectionName}`);
43
- return {
44
- content: [
45
- {
46
- type: 'text',
47
- text: `Error: Collection '${collectionName}' not found`
48
- }
49
- ]
50
- };
51
- }
52
- }
53
- // Read all Collections
54
- const files = readdirSync(collectionsDirPath).filter((file)=>extname(file) === '.ts').sort();
55
- if (verboseLogs) {
56
- payload.logger.info(`[payload-mcp] Found ${files.length} collection files in directory`);
57
- }
58
- if (files.length === 0) {
59
- payload.logger.warn('[payload-mcp] No collection files found in src/collections directory');
60
- return {
61
- content: [
62
- {
63
- type: 'text',
64
- text: 'No collection files found in src/collections directory'
65
- }
66
- ]
67
- };
68
- }
69
- const results = [];
70
- // Build complete table as a single markdown string
71
- let tableContent = `Found ${files.length} collection file(s):\n\n`;
72
- // Build table header
73
- let tableHeader = '| Collection | File | Size | Modified';
74
- let tableSeparator = '|------------|------|------|----------';
75
- if (includeCount) {
76
- tableHeader += ' | Documents';
77
- tableSeparator += ' |----------';
78
- }
79
- tableHeader += ' |';
80
- tableSeparator += ' |';
81
- tableContent += tableHeader + '\n';
82
- tableContent += tableSeparator + '\n';
83
- for (const file of files){
84
- const filePath = join(collectionsDirPath, file);
85
- const stats = statSync(filePath);
86
- const fileSize = stats.size;
87
- const lastModified = stats.mtime;
88
- const collectionName = file.replace('.ts', '');
89
- // Build table row
90
- let tableRow = `| **${collectionName}** | ${file} | ${fileSize.toLocaleString()} bytes | ${lastModified.toISOString()}`;
91
- // Add document count if requested
92
- if (includeCount) {
93
- try {
94
- // For now, we'll skip document counting since we don't have access to payload instance
95
- tableRow += ' | -';
96
- } catch (error) {
97
- tableRow += ` | Error: ${error.message}`;
98
- }
99
- }
100
- tableRow += ' |';
101
- tableContent += tableRow + '\n';
102
- if (includeContent) {
103
- try {
104
- const content = readFileSync(filePath, 'utf8');
105
- tableContent += `\n**${collectionName} Content:**\n\`\`\`typescript\n${content}\n\`\`\`\n\n`;
106
- } catch (error) {
107
- tableContent += `\nError reading content: ${error.message}\n\n`;
108
- }
109
- }
110
- }
111
- results.push({
112
- type: 'text',
113
- text: tableContent
114
- });
115
- return {
116
- content: results
117
- };
118
- } catch (error) {
119
- const errorMessage = error.message;
120
- payload.logger.error(`[payload-mcp] Error reading collections: ${errorMessage}`);
121
- return {
122
- content: [
123
- {
124
- type: 'text',
125
- text: `❌ **Error reading collections**: ${errorMessage}`
126
- }
127
- ]
128
- };
129
- }
130
- };
131
- // MCP Server tool registration
132
- export const findCollectionTool = (server, req, verboseLogs, collectionsDirPath)=>{
133
- const tool = (collectionName, includeContent = false, includeCount = false)=>{
134
- const payload = req.payload;
135
- if (verboseLogs) {
136
- payload.logger.info(`[payload-mcp] Finding collections${collectionName ? ` for: ${collectionName}` : ''}, includeContent: ${includeContent}, includeCount: ${includeCount}`);
137
- }
138
- try {
139
- const result = readCollections(req, verboseLogs, collectionsDirPath, collectionName, includeContent, includeCount);
140
- if (verboseLogs) {
141
- payload.logger.info(`[payload-mcp] Collection search completed`);
142
- }
143
- return result;
144
- } catch (error) {
145
- const errorMessage = error instanceof Error ? error.message : 'Unknown error';
146
- payload.logger.error(`[payload-mcp] Error finding collections: ${errorMessage}`);
147
- return {
148
- content: [
149
- {
150
- type: 'text',
151
- text: `Error finding collections: ${errorMessage}`
152
- }
153
- ]
154
- };
155
- }
156
- };
157
- server.registerTool('findCollections', {
158
- description: toolSchemas.findCollections.description,
159
- inputSchema: toolSchemas.findCollections.parameters.shape
160
- }, ({ collectionName, includeContent, includeCount })=>{
161
- return tool(collectionName, includeContent, includeCount);
162
- });
163
- };
164
-
165
- //# sourceMappingURL=find.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../../src/mcp/tools/collection/find.ts"],"sourcesContent":["import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'\nimport type { PayloadRequest } from 'payload'\n\nimport { readdirSync, readFileSync, statSync } from 'fs'\nimport { extname, join } from 'path'\n\nimport { toolSchemas } from '../schemas.js'\n\nexport const readCollections = (\n req: PayloadRequest,\n verboseLogs: boolean,\n collectionsDirPath: string,\n collectionName?: string,\n includeContent: boolean = false,\n includeCount: boolean = false,\n) => {\n const payload = req.payload\n\n if (verboseLogs) {\n payload.logger.info(\n `[payload-mcp] Reading collections${collectionName ? ` for: ${collectionName}` : ''}, includeContent: ${includeContent}, includeCount: ${includeCount}`,\n )\n }\n\n try {\n // Read specific Collection (optional)\n if (collectionName) {\n const fileName = `${collectionName.charAt(0).toUpperCase() + collectionName.slice(1)}.ts`\n const filePath = join(collectionsDirPath, fileName)\n\n if (!filePath.startsWith(collectionsDirPath)) {\n payload.logger.error(`[payload-mcp] Invalid collection name attempted: ${collectionName}`)\n return {\n content: [{ type: 'text' as const, text: 'Error: Invalid collection name' }],\n }\n }\n\n try {\n const content = readFileSync(filePath, 'utf8')\n if (verboseLogs) {\n payload.logger.info(`[payload-mcp] Successfully read collection: ${collectionName}`)\n }\n\n return {\n content: [\n {\n type: 'text' as const,\n text: `Collection: ${collectionName}\nFile: ${fileName}\n---\n${content}`,\n },\n ],\n }\n } catch (_error) {\n payload.logger.warn(`[payload-mcp] Collection not found: ${collectionName}`)\n return {\n content: [\n {\n type: 'text' as const,\n text: `Error: Collection '${collectionName}' not found`,\n },\n ],\n }\n }\n }\n\n // Read all Collections\n const files = readdirSync(collectionsDirPath)\n .filter((file) => extname(file) === '.ts')\n .sort()\n\n if (verboseLogs) {\n payload.logger.info(`[payload-mcp] Found ${files.length} collection files in directory`)\n }\n\n if (files.length === 0) {\n payload.logger.warn('[payload-mcp] No collection files found in src/collections directory')\n return {\n content: [\n {\n type: 'text' as const,\n text: 'No collection files found in src/collections directory',\n },\n ],\n }\n }\n\n const results = []\n\n // Build complete table as a single markdown string\n let tableContent = `Found ${files.length} collection file(s):\\n\\n`\n\n // Build table header\n let tableHeader = '| Collection | File | Size | Modified'\n let tableSeparator = '|------------|------|------|----------'\n\n if (includeCount) {\n tableHeader += ' | Documents'\n tableSeparator += ' |----------'\n }\n tableHeader += ' |'\n tableSeparator += ' |'\n\n tableContent += tableHeader + '\\n'\n tableContent += tableSeparator + '\\n'\n\n for (const file of files) {\n const filePath = join(collectionsDirPath, file)\n const stats = statSync(filePath)\n const fileSize = stats.size\n const lastModified = stats.mtime\n\n const collectionName = file.replace('.ts', '')\n\n // Build table row\n let tableRow = `| **${collectionName}** | ${file} | ${fileSize.toLocaleString()} bytes | ${lastModified.toISOString()}`\n\n // Add document count if requested\n if (includeCount) {\n try {\n // For now, we'll skip document counting since we don't have access to payload instance\n tableRow += ' | -'\n } catch (error) {\n tableRow += ` | Error: ${(error as Error).message}`\n }\n }\n tableRow += ' |'\n\n tableContent += tableRow + '\\n'\n\n if (includeContent) {\n try {\n const content = readFileSync(filePath, 'utf8')\n tableContent += `\\n**${collectionName} Content:**\\n\\`\\`\\`typescript\\n${content}\\n\\`\\`\\`\\n\\n`\n } catch (error) {\n tableContent += `\\nError reading content: ${(error as Error).message}\\n\\n`\n }\n }\n }\n\n results.push({\n type: 'text' as const,\n text: tableContent,\n })\n\n return {\n content: results,\n }\n } catch (error) {\n const errorMessage = (error as Error).message\n payload.logger.error(`[payload-mcp] Error reading collections: ${errorMessage}`)\n return {\n content: [\n {\n type: 'text' as const,\n text: `❌ **Error reading collections**: ${errorMessage}`,\n },\n ],\n }\n }\n}\n\n// MCP Server tool registration\nexport const findCollectionTool = (\n server: McpServer,\n req: PayloadRequest,\n verboseLogs: boolean,\n collectionsDirPath: string,\n) => {\n const tool = (\n collectionName?: string,\n includeContent: boolean = false,\n includeCount: boolean = false,\n ) => {\n const payload = req.payload\n\n if (verboseLogs) {\n payload.logger.info(\n `[payload-mcp] Finding collections${collectionName ? ` for: ${collectionName}` : ''}, includeContent: ${includeContent}, includeCount: ${includeCount}`,\n )\n }\n\n try {\n const result = readCollections(\n req,\n verboseLogs,\n collectionsDirPath,\n collectionName,\n includeContent,\n includeCount,\n )\n\n if (verboseLogs) {\n payload.logger.info(`[payload-mcp] Collection search completed`)\n }\n\n return result\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : 'Unknown error'\n payload.logger.error(`[payload-mcp] Error finding collections: ${errorMessage}`)\n\n return {\n content: [\n {\n type: 'text' as const,\n text: `Error finding collections: ${errorMessage}`,\n },\n ],\n }\n }\n }\n\n server.registerTool(\n 'findCollections',\n {\n description: toolSchemas.findCollections.description,\n inputSchema: toolSchemas.findCollections.parameters.shape,\n },\n ({ collectionName, includeContent, includeCount }) => {\n return tool(collectionName, includeContent, includeCount)\n },\n )\n}\n"],"names":["readdirSync","readFileSync","statSync","extname","join","toolSchemas","readCollections","req","verboseLogs","collectionsDirPath","collectionName","includeContent","includeCount","payload","logger","info","fileName","charAt","toUpperCase","slice","filePath","startsWith","error","content","type","text","_error","warn","files","filter","file","sort","length","results","tableContent","tableHeader","tableSeparator","stats","fileSize","size","lastModified","mtime","replace","tableRow","toLocaleString","toISOString","message","push","errorMessage","findCollectionTool","server","tool","result","Error","registerTool","description","findCollections","inputSchema","parameters","shape"],"mappings":"AAGA,SAASA,WAAW,EAAEC,YAAY,EAAEC,QAAQ,QAAQ,KAAI;AACxD,SAASC,OAAO,EAAEC,IAAI,QAAQ,OAAM;AAEpC,SAASC,WAAW,QAAQ,gBAAe;AAE3C,OAAO,MAAMC,kBAAkB,CAC7BC,KACAC,aACAC,oBACAC,gBACAC,iBAA0B,KAAK,EAC/BC,eAAwB,KAAK;IAE7B,MAAMC,UAAUN,IAAIM,OAAO;IAE3B,IAAIL,aAAa;QACfK,QAAQC,MAAM,CAACC,IAAI,CACjB,CAAC,iCAAiC,EAAEL,iBAAiB,CAAC,MAAM,EAAEA,gBAAgB,GAAG,GAAG,kBAAkB,EAAEC,eAAe,gBAAgB,EAAEC,cAAc;IAE3J;IAEA,IAAI;QACF,sCAAsC;QACtC,IAAIF,gBAAgB;YAClB,MAAMM,WAAW,GAAGN,eAAeO,MAAM,CAAC,GAAGC,WAAW,KAA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C,OAAOuC,KAAKzC,gBAAgBC,gBAAgBC;IAC9C;AAEJ,EAAC"}
@@ -1,10 +0,0 @@
1
- import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
2
- import type { PayloadRequest } from 'payload';
3
- export declare const updateCollection: (req: PayloadRequest, verboseLogs: boolean, collectionsDirPath: string, configFilePath: string, collectionName: string, updateType: string, newFields?: any[], fieldNamesToRemove?: string[], fieldModifications?: any[], configUpdates?: any, newContent?: string) => Promise<{
4
- content: {
5
- type: "text";
6
- text: string;
7
- }[];
8
- }>;
9
- export declare const updateCollectionTool: (server: McpServer, req: PayloadRequest, verboseLogs: boolean, collectionsDirPath: string, configFilePath: string) => void;
10
- //# sourceMappingURL=update.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"update.d.ts","sourceRoot":"","sources":["../../../../src/mcp/tools/collection/update.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAA;AACxE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAa7C,eAAO,MAAM,gBAAgB,QACtB,cAAc,eACN,OAAO,sBACA,MAAM,kBACV,MAAM,kBACN,MAAM,cACV,MAAM,cACN,GAAG,EAAE,uBACI,MAAM,EAAE,uBACR,GAAG,EAAE,kBACV,GAAG,eACN,MAAM;;;;;EAuLpB,CAAA;AAED,eAAO,MAAM,oBAAoB,WACvB,SAAS,OACZ,cAAc,eACN,OAAO,sBACA,MAAM,kBACV,MAAM,SA0EvB,CAAA"}
@@ -1,209 +0,0 @@
1
- import { readFileSync, writeFileSync } from 'fs';
2
- import { join } from 'path';
3
- import { addFieldsToCollection, modifyFieldsInCollection, removeFieldsFromCollection } from '../../helpers/fields.js';
4
- import { validateCollectionFile } from '../../helpers/fileValidation.js';
5
- import { toolSchemas } from '../schemas.js';
6
- export const updateCollection = async (req, verboseLogs, collectionsDirPath, configFilePath, collectionName, updateType, newFields, fieldNamesToRemove, fieldModifications, configUpdates, newContent)=>{
7
- const payload = req.payload;
8
- if (verboseLogs) {
9
- payload.logger.info(`[payload-mcp] Updating collection: ${collectionName}, updateType: ${updateType}`);
10
- }
11
- const capitalizedName = collectionName.charAt(0).toUpperCase() + collectionName.slice(1);
12
- const fileName = `${capitalizedName}.ts`;
13
- const filePath = join(collectionsDirPath, fileName);
14
- // Security check: ensure we're working with the collections directory
15
- if (!filePath.startsWith(collectionsDirPath)) {
16
- payload.logger.error(`[payload-mcp] Invalid collection path attempted: ${filePath}`);
17
- return {
18
- content: [
19
- {
20
- type: 'text',
21
- text: '❌ **Error**: Invalid collection path'
22
- }
23
- ]
24
- };
25
- }
26
- try {
27
- // Check if collection file exists
28
- let currentContent;
29
- try {
30
- currentContent = readFileSync(filePath, 'utf8');
31
- } catch (_ignore) {
32
- return {
33
- content: [
34
- {
35
- type: 'text',
36
- text: `❌ **Error**: Collection file not found: ${fileName}`
37
- }
38
- ]
39
- };
40
- }
41
- let updatedContent;
42
- let updateSummary = [];
43
- switch(updateType){
44
- case 'add_field':
45
- if (!newFields || newFields.length === 0) {
46
- return {
47
- content: [
48
- {
49
- type: 'text',
50
- text: '❌ **Error**: No fields provided for add_field update type'
51
- }
52
- ]
53
- };
54
- }
55
- updatedContent = addFieldsToCollection(currentContent, newFields);
56
- updateSummary = newFields.map((field)=>`Added field: ${field.name} (${field.type})`);
57
- break;
58
- case 'modify_field':
59
- if (!fieldModifications || fieldModifications.length === 0) {
60
- return {
61
- content: [
62
- {
63
- type: 'text',
64
- text: '❌ **Error**: No field modifications provided for modify_field update type'
65
- }
66
- ]
67
- };
68
- }
69
- updatedContent = modifyFieldsInCollection(currentContent, fieldModifications);
70
- updateSummary = fieldModifications.map((mod)=>`Modified field: ${mod.fieldName}`);
71
- break;
72
- case 'remove_field':
73
- if (!fieldNamesToRemove || fieldNamesToRemove.length === 0) {
74
- return {
75
- content: [
76
- {
77
- type: 'text',
78
- text: '❌ **Error**: No field names provided for remove_field update type'
79
- }
80
- ]
81
- };
82
- }
83
- updatedContent = removeFieldsFromCollection(currentContent, fieldNamesToRemove);
84
- updateSummary = fieldNamesToRemove.map((fieldName)=>`Removed field: ${fieldName}`);
85
- break;
86
- case 'replace_content':
87
- if (!newContent) {
88
- return {
89
- content: [
90
- {
91
- type: 'text',
92
- text: '❌ **Error**: No new content provided for replace_content update type'
93
- }
94
- ]
95
- };
96
- }
97
- updatedContent = newContent;
98
- updateSummary = [
99
- 'Replaced entire collection content'
100
- ];
101
- break;
102
- case 'update_config':
103
- if (!configUpdates) {
104
- return {
105
- content: [
106
- {
107
- type: 'text',
108
- text: '❌ **Error**: No config updates provided for update_config update type'
109
- }
110
- ]
111
- };
112
- }
113
- // For now, we'll use a simple approach since the config helper might not have this functionality
114
- updatedContent = currentContent;
115
- updateSummary = Object.keys(configUpdates).map((key)=>`Updated config: ${key}`);
116
- break;
117
- default:
118
- return {
119
- content: [
120
- {
121
- type: 'text',
122
- text: `❌ **Error**: Unknown update type: ${updateType}`
123
- }
124
- ]
125
- };
126
- }
127
- // Write the updated content back to the file
128
- writeFileSync(filePath, updatedContent, 'utf8');
129
- if (verboseLogs) {
130
- payload.logger.info(`[payload-mcp] Successfully updated collection file: ${filePath}`);
131
- }
132
- // Validate the updated file
133
- const validationResult = await validateCollectionFile(fileName);
134
- if (validationResult.error) {
135
- return {
136
- content: [
137
- {
138
- type: 'text',
139
- text: `❌ **Error**: Updated collection has validation issues:\n\n${validationResult.error}`
140
- }
141
- ]
142
- };
143
- }
144
- return {
145
- content: [
146
- {
147
- type: 'text',
148
- text: `✅ **Collection updated successfully!**
149
-
150
- **File**: \`${fileName}\`
151
- **Update Type**: ${updateType}
152
-
153
- **Changes Made**:
154
- ${updateSummary.map((summary)=>`- ${summary}`).join('\n')}
155
-
156
- **Updated Collection Code:**
157
- \`\`\`typescript
158
- ${updatedContent}
159
- \`\`\``
160
- }
161
- ]
162
- };
163
- } catch (error) {
164
- const errorMessage = error.message;
165
- payload.logger.error(`[payload-mcp] Error updating collection: ${errorMessage}`);
166
- return {
167
- content: [
168
- {
169
- type: 'text',
170
- text: `❌ **Error updating collection**: ${errorMessage}`
171
- }
172
- ]
173
- };
174
- }
175
- };
176
- export const updateCollectionTool = (server, req, verboseLogs, collectionsDirPath, configFilePath)=>{
177
- const tool = async ({ collectionName, configUpdates, fieldModifications, fieldNamesToRemove, newContent, newFields, updateType })=>{
178
- const payload = req.payload;
179
- if (verboseLogs) {
180
- payload.logger.info(`[payload-mcp] Updating collection: ${collectionName}, updateType: ${updateType}`);
181
- }
182
- try {
183
- const result = await updateCollection(req, verboseLogs, collectionsDirPath, configFilePath, collectionName, updateType, newFields, fieldNamesToRemove, fieldModifications, configUpdates, newContent);
184
- if (verboseLogs) {
185
- payload.logger.info(`[payload-mcp] Collection update completed for: ${collectionName}`);
186
- }
187
- return result;
188
- } catch (error) {
189
- const errorMessage = error instanceof Error ? error.message : 'Unknown error';
190
- payload.logger.error(`[payload-mcp] Error updating collection ${collectionName}: ${errorMessage}`);
191
- return {
192
- content: [
193
- {
194
- type: 'text',
195
- text: `Error updating collection "${collectionName}": ${errorMessage}`
196
- }
197
- ]
198
- };
199
- }
200
- };
201
- server.registerTool('updateCollection', {
202
- description: toolSchemas.updateCollection.description,
203
- inputSchema: toolSchemas.updateCollection.parameters.shape
204
- }, async (args)=>{
205
- return await tool(args);
206
- });
207
- };
208
-
209
- //# sourceMappingURL=update.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../../src/mcp/tools/collection/update.ts"],"sourcesContent":["import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'\nimport type { PayloadRequest } from 'payload'\n\nimport { readFileSync, writeFileSync } from 'fs'\nimport { join } from 'path'\n\nimport {\n addFieldsToCollection,\n modifyFieldsInCollection,\n removeFieldsFromCollection,\n} from '../../helpers/fields.js'\nimport { validateCollectionFile } from '../../helpers/fileValidation.js'\nimport { toolSchemas } from '../schemas.js'\n\nexport const updateCollection = async (\n req: PayloadRequest,\n verboseLogs: boolean,\n collectionsDirPath: string,\n configFilePath: string,\n collectionName: string,\n updateType: string,\n newFields?: any[],\n fieldNamesToRemove?: string[],\n fieldModifications?: any[],\n configUpdates?: any,\n newContent?: string,\n) => {\n const payload = req.payload\n if (verboseLogs) {\n payload.logger.info(\n `[payload-mcp] Updating collection: ${collectionName}, updateType: ${updateType}`,\n )\n }\n\n const capitalizedName = collectionName.charAt(0).toUpperCase() + collectionName.slice(1)\n const fileName = `${capitalizedName}.ts`\n const filePath = join(collectionsDirPath, fileName)\n\n // Security check: ensure we're working with the collections directory\n if (!filePath.startsWith(collectionsDirPath)) {\n payload.logger.error(`[payload-mcp] Invalid collection path attempted: ${filePath}`)\n return {\n content: [\n {\n type: 'text' as const,\n text: '❌ **Error**: Invalid collection path',\n },\n ],\n }\n }\n\n try {\n // Check if collection file exists\n let currentContent: string\n try {\n currentContent = readFileSync(filePath, 'utf8')\n } catch (_ignore) {\n return {\n content: [\n {\n type: 'text' as const,\n text: `❌ **Error**: Collection file not found: ${fileName}`,\n },\n ],\n }\n }\n\n let updatedContent: string\n let updateSummary: string[] = []\n\n switch (updateType) {\n case 'add_field':\n if (!newFields || newFields.length === 0) {\n return {\n content: [\n {\n type: 'text' as const,\n text: '❌ **Error**: No fields provided for add_field update type',\n },\n ],\n }\n }\n updatedContent = addFieldsToCollection(currentContent, newFields)\n updateSummary = newFields.map((field: any) => `Added field: ${field.name} (${field.type})`)\n break\n\n case 'modify_field':\n if (!fieldModifications || fieldModifications.length === 0) {\n return {\n content: [\n {\n type: 'text' as const,\n text: '❌ **Error**: No field modifications provided for modify_field update type',\n },\n ],\n }\n }\n updatedContent = modifyFieldsInCollection(currentContent, fieldModifications)\n updateSummary = fieldModifications.map((mod: any) => `Modified field: ${mod.fieldName}`)\n break\n\n case 'remove_field':\n if (!fieldNamesToRemove || fieldNamesToRemove.length === 0) {\n return {\n content: [\n {\n type: 'text' as const,\n text: '❌ **Error**: No field names provided for remove_field update type',\n },\n ],\n }\n }\n updatedContent = removeFieldsFromCollection(currentContent, fieldNamesToRemove)\n updateSummary = fieldNamesToRemove.map((fieldName: string) => `Removed field: ${fieldName}`)\n break\n\n case 'replace_content':\n if (!newContent) {\n return {\n content: [\n {\n type: 'text' as const,\n text: '❌ **Error**: No new content provided for replace_content update type',\n },\n ],\n }\n }\n updatedContent = newContent\n updateSummary = ['Replaced entire collection content']\n break\n\n case 'update_config':\n if (!configUpdates) {\n return {\n content: [\n {\n type: 'text' as const,\n text: '❌ **Error**: No config updates provided for update_config update type',\n },\n ],\n }\n }\n // For now, we'll use a simple approach since the config helper might not have this functionality\n updatedContent = currentContent\n updateSummary = Object.keys(configUpdates).map((key) => `Updated config: ${key}`)\n break\n\n default:\n return {\n content: [\n {\n type: 'text' as const,\n text: `❌ **Error**: Unknown update type: ${updateType}`,\n },\n ],\n }\n }\n\n // Write the updated content back to the file\n writeFileSync(filePath, updatedContent, 'utf8')\n if (verboseLogs) {\n payload.logger.info(`[payload-mcp] Successfully updated collection file: ${filePath}`)\n }\n\n // Validate the updated file\n const validationResult = await validateCollectionFile(fileName)\n if (validationResult.error) {\n return {\n content: [\n {\n type: 'text' as const,\n text: `❌ **Error**: Updated collection has validation issues:\\n\\n${validationResult.error}`,\n },\n ],\n }\n }\n\n return {\n content: [\n {\n type: 'text' as const,\n text: `✅ **Collection updated successfully!**\n\n**File**: \\`${fileName}\\`\n**Update Type**: ${updateType}\n\n**Changes Made**:\n${updateSummary.map((summary) => `- ${summary}`).join('\\n')}\n\n**Updated Collection Code:**\n\\`\\`\\`typescript\n${updatedContent}\n\\`\\`\\``,\n },\n ],\n }\n } catch (error) {\n const errorMessage = (error as Error).message\n payload.logger.error(`[payload-mcp] Error updating collection: ${errorMessage}`)\n return {\n content: [\n {\n type: 'text' as const,\n text: `❌ **Error updating collection**: ${errorMessage}`,\n },\n ],\n }\n }\n}\n\nexport const updateCollectionTool = (\n server: McpServer,\n req: PayloadRequest,\n verboseLogs: boolean,\n collectionsDirPath: string,\n configFilePath: string,\n) => {\n const tool = async ({\n collectionName,\n configUpdates,\n fieldModifications,\n fieldNamesToRemove,\n newContent,\n newFields,\n updateType,\n }: {\n collectionName: string\n configUpdates?: any\n fieldModifications?: any[]\n fieldNamesToRemove?: string[]\n newContent?: string\n newFields?: any[]\n updateType: string\n }) => {\n const payload = req.payload\n\n if (verboseLogs) {\n payload.logger.info(\n `[payload-mcp] Updating collection: ${collectionName}, updateType: ${updateType}`,\n )\n }\n\n try {\n const result = await updateCollection(\n req,\n verboseLogs,\n collectionsDirPath,\n configFilePath,\n collectionName,\n updateType,\n newFields,\n fieldNamesToRemove,\n fieldModifications,\n configUpdates,\n newContent,\n )\n\n if (verboseLogs) {\n payload.logger.info(`[payload-mcp] Collection update completed for: ${collectionName}`)\n }\n\n return result\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : 'Unknown error'\n payload.logger.error(\n `[payload-mcp] Error updating collection ${collectionName}: ${errorMessage}`,\n )\n\n return {\n content: [\n {\n type: 'text' as const,\n text: `Error updating collection \"${collectionName}\": ${errorMessage}`,\n },\n ],\n }\n }\n }\n\n server.registerTool(\n 'updateCollection',\n {\n description: toolSchemas.updateCollection.description,\n inputSchema: toolSchemas.updateCollection.parameters.shape,\n },\n async (args) => {\n return await tool(args)\n },\n )\n}\n"],"names":["readFileSync","writeFileSync","join","addFieldsToCollection","modifyFieldsInCollection","removeFieldsFromCollection","validateCollectionFile","toolSchemas","updateCollection","req","verboseLogs","collectionsDirPath","configFilePath","collectionName","updateType","newFields","fieldNamesToRemove","fieldModifications","configUpdates","newContent","payload","logger","info","capitalizedName","charAt","toUpperCase","slice","fileName","filePath","startsWith","error","content","type","text","currentContent","_ignore","updatedContent","updateSummary","length","map","field","name","mod","fieldName","Object","keys","key","validationResult","summary","errorMessage","message","updateCollectionTool","server","tool","result","Error","registerTool","description","inputSchema","parameters","shape","args"],"mappings":"AAGA,SAASA,YAAY,EAAEC,aAAa,QAAQ,KAAI;AAChD,SAASC,IAAI,QAAQ,OAAM;AAE3B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F;QAEA,IAAI;YACF,MAAMwC,SAAS,MAAM9C,iBACnBC,KACAC,aACAC,oBACAC,gBACAC,gBACAC,YACAC,WACAC,oBACAC,oBACAC,eACAC;YAGF,IAAIT,aAAa;gBACfU,QAAQC,MAAM,CAACC,IAAI,CAAC,CAAC,+CAA+C,EAAET,gBAAgB;YACxF;YAEA,OAAOyC;QACT,EAAE,OAAOxB,OAAO;YACd,MAAMmB,eAAenB,iBAAiByB,QAAQzB,MAAMoB,OAAO,GAAG;YAC9D9B,QAAQC,MAAM,CAACS,KAAK,CAClB,CAAC,wCAAwC,EAAEjB,eAAe,EAAE,EAAEoC,cAAc;YAG9E,OAAO;gBACLlB,SAAS;oBACP;wBACEC,MAAM;wBACNC,MAAM,CAAC,2BAA2B,EAAEpB,eAAe,GAAG,EAAEoC,cAAc;oBACxE;iBACD;YACH;QACF;IACF;IAEAG,OAAOI,YAAY,CACjB,oBACA;QACEC,aAAalD,YAAYC,gBAAgB,CAACiD,WAAW;QACrDC,aAAanD,YAAYC,gBAAgB,CAACmD,UAAU,CAACC,KAAK;IAC5D,GACA,OAAOC;QACL,OAAO,MAAMR,KAAKQ;IACpB;AAEJ,EAAC"}
@@ -1,10 +0,0 @@
1
- import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
2
- import type { PayloadRequest } from 'payload';
3
- export declare const readConfigFile: (req: PayloadRequest, verboseLogs: boolean, configFilePath: string, includeMetadata?: boolean) => {
4
- content: {
5
- type: "text";
6
- text: string;
7
- }[];
8
- };
9
- export declare const findConfigTool: (server: McpServer, req: PayloadRequest, verboseLogs: boolean, configFilePath: string) => void;
10
- //# sourceMappingURL=find.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"find.d.ts","sourceRoot":"","sources":["../../../../src/mcp/tools/config/find.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAA;AACxE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAM7C,eAAO,MAAM,cAAc,QACpB,cAAc,eACN,OAAO,kBACJ,MAAM,oBACL,OAAO;;;;;CAmEzB,CAAA;AAGD,eAAO,MAAM,cAAc,WACjB,SAAS,OACZ,cAAc,eACN,OAAO,kBACJ,MAAM,SA0CvB,CAAA"}
@@ -1,97 +0,0 @@
1
- import { readFileSync, statSync } from 'fs';
2
- import { toolSchemas } from '../schemas.js';
3
- export const readConfigFile = (req, verboseLogs, configFilePath, includeMetadata = false)=>{
4
- const payload = req.payload;
5
- if (verboseLogs) {
6
- payload.logger.info(`[payload-mcp] Reading config file, includeMetadata: ${includeMetadata}`);
7
- }
8
- try {
9
- // Security check: ensure we're working with the specified config file
10
- if (!configFilePath.startsWith(process.cwd()) && !configFilePath.startsWith('/')) {
11
- payload.logger.error(`[payload-mcp] Invalid config path attempted: ${configFilePath}`);
12
- return {
13
- content: [
14
- {
15
- type: 'text',
16
- text: '❌ **Error**: Invalid config path'
17
- }
18
- ]
19
- };
20
- }
21
- const content = readFileSync(configFilePath, 'utf8');
22
- const stats = statSync(configFilePath);
23
- if (verboseLogs) {
24
- payload.logger.info(`[payload-mcp] Successfully read config file. Size: ${stats.size} bytes`);
25
- }
26
- let responseText = `# Payload Configuration
27
-
28
- **File**: \`${configFilePath}\``;
29
- if (includeMetadata) {
30
- responseText += `
31
- **Size**: ${stats.size.toLocaleString()} bytes
32
- **Modified**: ${stats.mtime.toISOString()}
33
- **Created**: ${stats.birthtime.toISOString()}`;
34
- }
35
- responseText += `
36
- ---
37
-
38
- **Configuration Content:**
39
- \`\`\`typescript
40
- ${content}
41
- \`\`\``;
42
- return {
43
- content: [
44
- {
45
- type: 'text',
46
- text: responseText
47
- }
48
- ]
49
- };
50
- } catch (error) {
51
- const errorMessage = error.message;
52
- payload.logger.error(`[payload-mcp] Error reading config file: ${errorMessage}`);
53
- return {
54
- content: [
55
- {
56
- type: 'text',
57
- text: `❌ **Error reading config file**: ${errorMessage}`
58
- }
59
- ]
60
- };
61
- }
62
- };
63
- // MCP Server tool registration
64
- export const findConfigTool = (server, req, verboseLogs, configFilePath)=>{
65
- const tool = (includeMetadata = false)=>{
66
- const payload = req.payload;
67
- if (verboseLogs) {
68
- payload.logger.info(`[payload-mcp] Finding config, includeMetadata: ${includeMetadata}`);
69
- }
70
- try {
71
- const result = readConfigFile(req, verboseLogs, configFilePath, includeMetadata);
72
- if (verboseLogs) {
73
- payload.logger.info(`[payload-mcp] Config search completed`);
74
- }
75
- return result;
76
- } catch (error) {
77
- const errorMessage = error instanceof Error ? error.message : 'Unknown error';
78
- payload.logger.error(`[payload-mcp] Error finding config: ${errorMessage}`);
79
- return {
80
- content: [
81
- {
82
- type: 'text',
83
- text: `Error finding config: ${errorMessage}`
84
- }
85
- ]
86
- };
87
- }
88
- };
89
- server.registerTool('findConfig', {
90
- description: toolSchemas.findConfig.description,
91
- inputSchema: toolSchemas.findConfig.parameters.shape
92
- }, ({ includeMetadata })=>{
93
- return tool(includeMetadata);
94
- });
95
- };
96
-
97
- //# sourceMappingURL=find.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../../src/mcp/tools/config/find.ts"],"sourcesContent":["import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'\nimport type { PayloadRequest } from 'payload'\n\nimport { readFileSync, statSync } from 'fs'\n\nimport { toolSchemas } from '../schemas.js'\n\nexport const readConfigFile = (\n req: PayloadRequest,\n verboseLogs: boolean,\n configFilePath: string,\n includeMetadata: boolean = false,\n) => {\n const payload = req.payload\n if (verboseLogs) {\n payload.logger.info(`[payload-mcp] Reading config file, includeMetadata: ${includeMetadata}`)\n }\n\n try {\n // Security check: ensure we're working with the specified config file\n if (!configFilePath.startsWith(process.cwd()) && !configFilePath.startsWith('/')) {\n payload.logger.error(`[payload-mcp] Invalid config path attempted: ${configFilePath}`)\n return {\n content: [\n {\n type: 'text' as const,\n text: '❌ **Error**: Invalid config path',\n },\n ],\n }\n }\n\n const content = readFileSync(configFilePath, 'utf8')\n const stats = statSync(configFilePath)\n\n if (verboseLogs) {\n payload.logger.info(`[payload-mcp] Successfully read config file. Size: ${stats.size} bytes`)\n }\n\n let responseText = `# Payload Configuration\n\n**File**: \\`${configFilePath}\\``\n\n if (includeMetadata) {\n responseText += `\n**Size**: ${stats.size.toLocaleString()} bytes\n**Modified**: ${stats.mtime.toISOString()}\n**Created**: ${stats.birthtime.toISOString()}`\n }\n\n responseText += `\n---\n\n**Configuration Content:**\n\\`\\`\\`typescript\n${content}\n\\`\\`\\``\n\n return {\n content: [\n {\n type: 'text' as const,\n text: responseText,\n },\n ],\n }\n } catch (error) {\n const errorMessage = (error as Error).message\n payload.logger.error(`[payload-mcp] Error reading config file: ${errorMessage}`)\n return {\n content: [\n {\n type: 'text' as const,\n text: `❌ **Error reading config file**: ${errorMessage}`,\n },\n ],\n }\n }\n}\n\n// MCP Server tool registration\nexport const findConfigTool = (\n server: McpServer,\n req: PayloadRequest,\n verboseLogs: boolean,\n configFilePath: string,\n) => {\n const tool = (includeMetadata: boolean = false) => {\n const payload = req.payload\n\n if (verboseLogs) {\n payload.logger.info(`[payload-mcp] Finding config, includeMetadata: ${includeMetadata}`)\n }\n\n try {\n const result = readConfigFile(req, verboseLogs, configFilePath, includeMetadata)\n\n if (verboseLogs) {\n payload.logger.info(`[payload-mcp] Config search completed`)\n }\n\n return result\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : 'Unknown error'\n payload.logger.error(`[payload-mcp] Error finding config: ${errorMessage}`)\n\n return {\n content: [\n {\n type: 'text' as const,\n text: `Error finding config: ${errorMessage}`,\n },\n ],\n }\n }\n }\n\n server.registerTool(\n 'findConfig',\n {\n description: toolSchemas.findConfig.description,\n inputSchema: toolSchemas.findConfig.parameters.shape,\n },\n ({ includeMetadata }) => {\n return tool(includeMetadata)\n },\n )\n}\n"],"names":["readFileSync","statSync","toolSchemas","readConfigFile","req","verboseLogs","configFilePath","includeMetadata","payload","logger","info","startsWith","process","cwd","error","content","type","text","stats","size","responseText","toLocaleString","mtime","toISOString","birthtime","errorMessage","message","findConfigTool","server","tool","result","Error","registerTool","description","findConfig","inputSchema","parameters","shape"],"mappings":"AAGA,SAASA,YAAY,EAAEC,QAAQ,QAAQ,KAAI;AAE3C,SAASC,WAAW,QAAQ,gBAAe;AAE3C,OAAO,MAAMC,iBAAiB,CAC5BC,KACAC,aACAC,gBACAC,kBAA2B,KAAK;IAEhC,MAAMC,UAAUJ,IAAII,OAAO;IAC3B,IAAIH,aAAa;QACfG,QAAQC,MAAM,CAACC,IAAI,CAAC,CAAC,oDAAoD,EAAEH,iBAAiB;IAC9F;IAEA,IAAI;QACF,sEAAsE;QACtE,IAAI,CAACD,eAAeK,UAAU,CAACC,QAAQC,GAAG,OAAO,CAACP,eAAeK,UAAU,CAAC,MAAM;YAChFH,QAAQC,MAAM,CAACK,KAAK,CAAC,CAAC,6CAA6C,EAAER,gBAAgB;YACrF,OAAO;gBACLS,SAAS;oBACP;wBACEC,MAAM;wBACNC,MAAM;oBACR;iBACD;YACH;QACF;QAEA,MAAMF,UAAUf,aAAaM,gBAAgB;QAC7C,MAAMY,QAAQjB,SAASK;QAEvB,IAAID,aAAa;YACfG,QAAQC,MAAM,CAACC,IAAI,CAAC,CAAC,mDAAmD,EAAEQ,MAAMC,IAAI,CAAC,MAAM,CAAC;QAC9F;QAEA,IAAIC,eAAe,CAAC;;YAEZ,EAAEd,eAAe,EAAE,CAAC;QAE5B,IAAIC,iBAAiB;YACnBa,gBAAgB,CAAC;UACb,EAAEF,MAAMC,IAAI,CAACE,cAAc,GAAG;cAC1B,EAAEH,MAAMI,KAAK,CAACC,WAAW,GAAG;aAC7B,EAAEL,MAAMM,SAAS,CAACD,WAAW,IAAI;QAC1C;QAEAH,gBAAgB,CAAC;;;;;AAKrB,EAAEL,QAAQ;MACJ,CAAC;QAEH,OAAO;YACLA,SAAS;gBACP;oBACEC,MAAM;oBACNC,MAAMG;gBACR;aACD;QACH;IACF,EAAE,OAAON,OAAO;QACd,MAAMW,eAAe,AAACX,MAAgBY,OAAO;QAC7ClB,QAAQC,MAAM,CAACK,KAAK,CAAC,CAAC,yCAAyC,EAAEW,cAAc;QAC/E,OAAO;YACLV,SAAS;gBACP;oBACEC,MAAM;oBACNC,MAAM,CAAC,iCAAiC,EAAEQ,cAAc;gBAC1D;aACD;QACH;IACF;AACF,EAAC;AAED,+BAA+B;AAC/B,OAAO,MAAME,iBAAiB,CAC5BC,QACAxB,KACAC,aACAC;IAEA,MAAMuB,OAAO,CAACtB,kBAA2B,KAAK;QAC5C,MAAMC,UAAUJ,IAAII,OAAO;QAE3B,IAAIH,aAAa;YACfG,QAAQC,MAAM,CAACC,IAAI,CAAC,CAAC,+CAA+C,EAAEH,iBAAiB;QACzF;QAEA,IAAI;YACF,MAAMuB,SAAS3B,eAAeC,KAAKC,aAAaC,gBAAgBC;YAEhE,IAAIF,aAAa;gBACfG,QAAQC,MAAM,CAACC,IAAI,CAAC,CAAC,qCAAqC,CAAC;YAC7D;YAEA,OAAOoB;QACT,EAAE,OAAOhB,OAAO;YACd,MAAMW,eAAeX,iBAAiBiB,QAAQjB,MAAMY,OAAO,GAAG;YAC9DlB,QAAQC,MAAM,CAACK,KAAK,CAAC,CAAC,oCAAoC,EAAEW,cAAc;YAE1E,OAAO;gBACLV,SAAS;oBACP;wBACEC,MAAM;wBACNC,MAAM,CAAC,sBAAsB,EAAEQ,cAAc;oBAC/C;iBACD;YACH;QACF;IACF;IAEAG,OAAOI,YAAY,CACjB,cACA;QACEC,aAAa/B,YAAYgC,UAAU,CAACD,WAAW;QAC/CE,aAAajC,YAAYgC,UAAU,CAACE,UAAU,CAACC,KAAK;IACtD,GACA,CAAC,EAAE9B,eAAe,EAAE;QAClB,OAAOsB,KAAKtB;IACd;AAEJ,EAAC"}
@@ -1,10 +0,0 @@
1
- import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
2
- import type { PayloadRequest } from 'payload';
3
- export declare const updateConfig: (req: PayloadRequest, verboseLogs: boolean, configFilePath: string, updateType: string, collectionName?: string, adminConfig?: any, databaseConfig?: any, pluginUpdates?: any, newContent?: string) => {
4
- content: {
5
- type: "text";
6
- text: string;
7
- }[];
8
- };
9
- export declare const updateConfigTool: (server: McpServer, req: PayloadRequest, verboseLogs: boolean, configFilePath: string) => void;
10
- //# sourceMappingURL=update.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"update.d.ts","sourceRoot":"","sources":["../../../../src/mcp/tools/config/update.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAA;AACxE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAa7C,eAAO,MAAM,YAAY,QAClB,cAAc,eACN,OAAO,kBACJ,MAAM,cACV,MAAM,mBACD,MAAM,gBACT,GAAG,mBACA,GAAG,kBACJ,GAAG,eACN,MAAM;;;;;CAwLpB,CAAA;AAED,eAAO,MAAM,gBAAgB,WACnB,SAAS,OACZ,cAAc,eACN,OAAO,kBACJ,MAAM,SAkEvB,CAAA"}