@payloadcms/plugin-mcp 0.0.1-alpha.0

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 (173) hide show
  1. package/LICENSE.md +22 -0
  2. package/README.md +7 -0
  3. package/dist/collections/createApiKeysCollection.d.ts +7 -0
  4. package/dist/collections/createApiKeysCollection.d.ts.map +1 -0
  5. package/dist/collections/createApiKeysCollection.js +315 -0
  6. package/dist/collections/createApiKeysCollection.js.map +1 -0
  7. package/dist/endpoints/mcp.d.ts +4 -0
  8. package/dist/endpoints/mcp.d.ts.map +1 -0
  9. package/dist/endpoints/mcp.js +44 -0
  10. package/dist/endpoints/mcp.js.map +1 -0
  11. package/dist/index.d.ts +10 -0
  12. package/dist/index.d.ts.map +1 -0
  13. package/dist/index.js +67 -0
  14. package/dist/index.js.map +1 -0
  15. package/dist/mcp/createRequest.d.ts +3 -0
  16. package/dist/mcp/createRequest.d.ts.map +1 -0
  17. package/dist/mcp/createRequest.js +14 -0
  18. package/dist/mcp/createRequest.js.map +1 -0
  19. package/dist/mcp/getMcpHandler.d.ts +4 -0
  20. package/dist/mcp/getMcpHandler.d.ts.map +1 -0
  21. package/dist/mcp/getMcpHandler.js +179 -0
  22. package/dist/mcp/getMcpHandler.js.map +1 -0
  23. package/dist/mcp/helpers/config.d.ts +30 -0
  24. package/dist/mcp/helpers/config.d.ts.map +1 -0
  25. package/dist/mcp/helpers/config.js +217 -0
  26. package/dist/mcp/helpers/config.js.map +1 -0
  27. package/dist/mcp/helpers/conversion.d.ts +2 -0
  28. package/dist/mcp/helpers/conversion.d.ts.map +1 -0
  29. package/dist/mcp/helpers/conversion.js +5 -0
  30. package/dist/mcp/helpers/conversion.js.map +1 -0
  31. package/dist/mcp/helpers/fields.d.ts +38 -0
  32. package/dist/mcp/helpers/fields.d.ts.map +1 -0
  33. package/dist/mcp/helpers/fields.js +96 -0
  34. package/dist/mcp/helpers/fields.js.map +1 -0
  35. package/dist/mcp/helpers/fileValidation.d.ts +69 -0
  36. package/dist/mcp/helpers/fileValidation.d.ts.map +1 -0
  37. package/dist/mcp/helpers/fileValidation.js +305 -0
  38. package/dist/mcp/helpers/fileValidation.js.map +1 -0
  39. package/dist/mcp/helpers/validation.d.ts +9 -0
  40. package/dist/mcp/helpers/validation.d.ts.map +1 -0
  41. package/dist/mcp/helpers/validation.js +22 -0
  42. package/dist/mcp/helpers/validation.js.map +1 -0
  43. package/dist/mcp/registerTool.d.ts +6 -0
  44. package/dist/mcp/registerTool.d.ts.map +1 -0
  45. package/dist/mcp/registerTool.js +18 -0
  46. package/dist/mcp/registerTool.js.map +1 -0
  47. package/dist/mcp/tools/auth/auth.d.ts +4 -0
  48. package/dist/mcp/tools/auth/auth.d.ts.map +1 -0
  49. package/dist/mcp/tools/auth/auth.js +54 -0
  50. package/dist/mcp/tools/auth/auth.js.map +1 -0
  51. package/dist/mcp/tools/auth/forgotPassword.d.ts +4 -0
  52. package/dist/mcp/tools/auth/forgotPassword.d.ts.map +1 -0
  53. package/dist/mcp/tools/auth/forgotPassword.js +45 -0
  54. package/dist/mcp/tools/auth/forgotPassword.js.map +1 -0
  55. package/dist/mcp/tools/auth/login.d.ts +4 -0
  56. package/dist/mcp/tools/auth/login.d.ts.map +1 -0
  57. package/dist/mcp/tools/auth/login.js +48 -0
  58. package/dist/mcp/tools/auth/login.js.map +1 -0
  59. package/dist/mcp/tools/auth/resetPassword.d.ts +4 -0
  60. package/dist/mcp/tools/auth/resetPassword.d.ts.map +1 -0
  61. package/dist/mcp/tools/auth/resetPassword.js +46 -0
  62. package/dist/mcp/tools/auth/resetPassword.js.map +1 -0
  63. package/dist/mcp/tools/auth/unlock.d.ts +4 -0
  64. package/dist/mcp/tools/auth/unlock.d.ts.map +1 -0
  65. package/dist/mcp/tools/auth/unlock.js +45 -0
  66. package/dist/mcp/tools/auth/unlock.js.map +1 -0
  67. package/dist/mcp/tools/auth/verify.d.ts +4 -0
  68. package/dist/mcp/tools/auth/verify.d.ts.map +1 -0
  69. package/dist/mcp/tools/auth/verify.js +42 -0
  70. package/dist/mcp/tools/auth/verify.js.map +1 -0
  71. package/dist/mcp/tools/collection/create.d.ts +10 -0
  72. package/dist/mcp/tools/collection/create.d.ts.map +1 -0
  73. package/dist/mcp/tools/collection/create.js +159 -0
  74. package/dist/mcp/tools/collection/create.js.map +1 -0
  75. package/dist/mcp/tools/collection/delete.d.ts +10 -0
  76. package/dist/mcp/tools/collection/delete.d.ts.map +1 -0
  77. package/dist/mcp/tools/collection/delete.js +162 -0
  78. package/dist/mcp/tools/collection/delete.js.map +1 -0
  79. package/dist/mcp/tools/collection/find.d.ts +10 -0
  80. package/dist/mcp/tools/collection/find.d.ts.map +1 -0
  81. package/dist/mcp/tools/collection/find.js +162 -0
  82. package/dist/mcp/tools/collection/find.js.map +1 -0
  83. package/dist/mcp/tools/collection/update.d.ts +10 -0
  84. package/dist/mcp/tools/collection/update.d.ts.map +1 -0
  85. package/dist/mcp/tools/collection/update.js +206 -0
  86. package/dist/mcp/tools/collection/update.js.map +1 -0
  87. package/dist/mcp/tools/config/find.d.ts +10 -0
  88. package/dist/mcp/tools/config/find.d.ts.map +1 -0
  89. package/dist/mcp/tools/config/find.js +94 -0
  90. package/dist/mcp/tools/config/find.js.map +1 -0
  91. package/dist/mcp/tools/config/update.d.ts +10 -0
  92. package/dist/mcp/tools/config/update.d.ts.map +1 -0
  93. package/dist/mcp/tools/config/update.js +212 -0
  94. package/dist/mcp/tools/config/update.js.map +1 -0
  95. package/dist/mcp/tools/job/create.d.ts +10 -0
  96. package/dist/mcp/tools/job/create.d.ts.map +1 -0
  97. package/dist/mcp/tools/job/create.js +293 -0
  98. package/dist/mcp/tools/job/create.js.map +1 -0
  99. package/dist/mcp/tools/job/run.d.ts +10 -0
  100. package/dist/mcp/tools/job/run.d.ts.map +1 -0
  101. package/dist/mcp/tools/job/run.js +147 -0
  102. package/dist/mcp/tools/job/run.js.map +1 -0
  103. package/dist/mcp/tools/job/update.d.ts +11 -0
  104. package/dist/mcp/tools/job/update.d.ts.map +1 -0
  105. package/dist/mcp/tools/job/update.js +211 -0
  106. package/dist/mcp/tools/job/update.js.map +1 -0
  107. package/dist/mcp/tools/resource/create.d.ts +6 -0
  108. package/dist/mcp/tools/resource/create.d.ts.map +1 -0
  109. package/dist/mcp/tools/resource/create.js +75 -0
  110. package/dist/mcp/tools/resource/create.js.map +1 -0
  111. package/dist/mcp/tools/resource/delete.d.ts +5 -0
  112. package/dist/mcp/tools/resource/delete.d.ts.map +1 -0
  113. package/dist/mcp/tools/resource/delete.js +140 -0
  114. package/dist/mcp/tools/resource/delete.js.map +1 -0
  115. package/dist/mcp/tools/resource/find.d.ts +5 -0
  116. package/dist/mcp/tools/resource/find.d.ts.map +1 -0
  117. package/dist/mcp/tools/resource/find.js +119 -0
  118. package/dist/mcp/tools/resource/find.js.map +1 -0
  119. package/dist/mcp/tools/resource/update.d.ts +6 -0
  120. package/dist/mcp/tools/resource/update.d.ts.map +1 -0
  121. package/dist/mcp/tools/resource/update.js +201 -0
  122. package/dist/mcp/tools/resource/update.js.map +1 -0
  123. package/dist/mcp/tools/schemas.d.ts +374 -0
  124. package/dist/mcp/tools/schemas.d.ts.map +1 -0
  125. package/dist/mcp/tools/schemas.js +201 -0
  126. package/dist/mcp/tools/schemas.js.map +1 -0
  127. package/dist/types.d.ts +379 -0
  128. package/dist/types.d.ts.map +1 -0
  129. package/dist/types.js +3 -0
  130. package/dist/types.js.map +1 -0
  131. package/dist/utils/camelCase.d.ts +9 -0
  132. package/dist/utils/camelCase.d.ts.map +1 -0
  133. package/dist/utils/camelCase.js +11 -0
  134. package/dist/utils/camelCase.js.map +1 -0
  135. package/dist/utils/convertCollectionSchemaToZod.d.ts +3 -0
  136. package/dist/utils/convertCollectionSchemaToZod.d.ts.map +1 -0
  137. package/dist/utils/convertCollectionSchemaToZod.js +30 -0
  138. package/dist/utils/convertCollectionSchemaToZod.js.map +1 -0
  139. package/package.json +64 -0
  140. package/src/collections/createApiKeysCollection.ts +393 -0
  141. package/src/endpoints/mcp.ts +60 -0
  142. package/src/index.ts +86 -0
  143. package/src/mcp/createRequest.ts +13 -0
  144. package/src/mcp/getMcpHandler.ts +433 -0
  145. package/src/mcp/helpers/config.ts +326 -0
  146. package/src/mcp/helpers/conversion.ts +3 -0
  147. package/src/mcp/helpers/fields.ts +158 -0
  148. package/src/mcp/helpers/fileValidation.ts +417 -0
  149. package/src/mcp/helpers/validation.ts +32 -0
  150. package/src/mcp/registerTool.ts +22 -0
  151. package/src/mcp/tools/auth/auth.ts +69 -0
  152. package/src/mcp/tools/auth/forgotPassword.ts +68 -0
  153. package/src/mcp/tools/auth/login.ts +70 -0
  154. package/src/mcp/tools/auth/resetPassword.ts +59 -0
  155. package/src/mcp/tools/auth/unlock.ts +62 -0
  156. package/src/mcp/tools/auth/verify.ts +55 -0
  157. package/src/mcp/tools/collection/create.ts +236 -0
  158. package/src/mcp/tools/collection/delete.ts +227 -0
  159. package/src/mcp/tools/collection/find.ts +222 -0
  160. package/src/mcp/tools/collection/update.ts +288 -0
  161. package/src/mcp/tools/config/find.ts +126 -0
  162. package/src/mcp/tools/config/update.ts +282 -0
  163. package/src/mcp/tools/job/create.ts +420 -0
  164. package/src/mcp/tools/job/run.ts +189 -0
  165. package/src/mcp/tools/job/update.ts +319 -0
  166. package/src/mcp/tools/resource/create.ts +121 -0
  167. package/src/mcp/tools/resource/delete.ts +210 -0
  168. package/src/mcp/tools/resource/find.ts +194 -0
  169. package/src/mcp/tools/resource/update.ts +314 -0
  170. package/src/mcp/tools/schemas.ts +373 -0
  171. package/src/types.ts +405 -0
  172. package/src/utils/camelCase.ts +12 -0
  173. package/src/utils/convertCollectionSchemaToZod.ts +35 -0
@@ -0,0 +1,162 @@
1
+ import { readFileSync, unlinkSync, writeFileSync } from 'fs';
2
+ import { join } from 'path';
3
+ import { toolSchemas } from '../schemas.js';
4
+ // Helper function for removing collection from config
5
+ const removeCollectionFromConfig = (configContent, collectionName)=>{
6
+ // Simple implementation - find and remove the collection import and reference
7
+ let updatedContent = configContent;
8
+ // Remove import statement
9
+ const importRegex = new RegExp(`import\\s*{\\s*${collectionName}\\s*}\\s*from\\s*['"]\\./collections/${collectionName}['"];?\\s*\\n?`, 'g');
10
+ updatedContent = updatedContent.replace(importRegex, '');
11
+ // Remove from collections array
12
+ const collectionsRegex = new RegExp(`\\s*${collectionName},?\\s*`, 'g');
13
+ updatedContent = updatedContent.replace(collectionsRegex, '');
14
+ return updatedContent;
15
+ };
16
+ export const deleteCollection = (req, verboseLogs, collectionsDirPath, configFilePath, collectionName, confirmDeletion, updateConfig)=>{
17
+ const payload = req.payload;
18
+ if (verboseLogs) {
19
+ payload.logger.info(`[payload-mcp] Attempting to delete collection: ${collectionName}`);
20
+ }
21
+ if (!confirmDeletion) {
22
+ payload.logger.warn(`[payload-mcp] Deletion cancelled for collection: ${collectionName}`);
23
+ return {
24
+ content: [
25
+ {
26
+ type: 'text',
27
+ text: `❌ **Deletion cancelled**. Set confirmDeletion to true to proceed with deleting collection "${collectionName}".`
28
+ }
29
+ ]
30
+ };
31
+ }
32
+ const capitalizedName = collectionName.charAt(0).toUpperCase() + collectionName.slice(1);
33
+ const collectionFilePath = join(collectionsDirPath, `${capitalizedName}.ts`);
34
+ // Security check: ensure we're working with the collections directory
35
+ if (!collectionFilePath.startsWith(collectionsDirPath)) {
36
+ payload.logger.error(`[payload-mcp] Invalid collection path attempted: ${collectionFilePath}`);
37
+ return {
38
+ content: [
39
+ {
40
+ type: 'text',
41
+ text: '❌ **Error**: Invalid collection path'
42
+ }
43
+ ]
44
+ };
45
+ }
46
+ try {
47
+ // Check if collection file exists
48
+ let fileExists = false;
49
+ try {
50
+ readFileSync(collectionFilePath, 'utf8');
51
+ fileExists = true;
52
+ } catch {
53
+ payload.logger.warn(`[payload-mcp] Collection file does not exist: ${collectionFilePath}`);
54
+ }
55
+ // Read current config if we need to update it
56
+ let configContent = '';
57
+ let configExists = false;
58
+ if (updateConfig) {
59
+ try {
60
+ configContent = readFileSync(configFilePath, 'utf8');
61
+ configExists = true;
62
+ } catch {
63
+ payload.logger.warn(`[payload-mcp] Config file does not exist: ${configFilePath}`);
64
+ }
65
+ }
66
+ let responseText = '';
67
+ let operationsPerformed = 0;
68
+ // Delete the collection file
69
+ if (fileExists) {
70
+ try {
71
+ unlinkSync(collectionFilePath);
72
+ if (verboseLogs) {
73
+ payload.logger.info(`[payload-mcp] Successfully deleted collection file: ${collectionFilePath}`);
74
+ }
75
+ responseText += `✅ Deleted collection file: \`${capitalizedName}.ts\`\n`;
76
+ operationsPerformed++;
77
+ } catch (error) {
78
+ const errorMessage = error.message;
79
+ payload.logger.error(`[payload-mcp] Error deleting collection file: ${errorMessage}`);
80
+ responseText += `❌ Error deleting collection file: ${errorMessage}\n`;
81
+ }
82
+ } else {
83
+ responseText += `⚠️ Collection file not found: \`${capitalizedName}.ts\`\n`;
84
+ }
85
+ // Update the config file if requested and it exists
86
+ if (updateConfig && configExists) {
87
+ try {
88
+ const updatedConfigContent = removeCollectionFromConfig(configContent, capitalizedName);
89
+ writeFileSync(configFilePath, updatedConfigContent, 'utf8');
90
+ if (verboseLogs) {
91
+ payload.logger.info(`[payload-mcp] Successfully updated config file: ${configFilePath}`);
92
+ }
93
+ responseText += `✅ Updated payload.config.ts to remove collection reference\n`;
94
+ operationsPerformed++;
95
+ } catch (error) {
96
+ const errorMessage = error.message;
97
+ payload.logger.error(`[payload-mcp] Error updating config file: ${errorMessage}`);
98
+ responseText += `❌ Error updating config file: ${errorMessage}\n`;
99
+ }
100
+ } else if (updateConfig && !configExists) {
101
+ responseText += `⚠️ Config file not found: payload.config.ts\n`;
102
+ }
103
+ // Summary
104
+ if (operationsPerformed > 0) {
105
+ responseText += `\n✅ **Collection deletion completed!**`;
106
+ } else {
107
+ responseText += `\n⚠️ **No operations performed**
108
+
109
+ The collection file may not have existed or there were errors during deletion.`;
110
+ }
111
+ return {
112
+ content: [
113
+ {
114
+ type: 'text',
115
+ text: responseText
116
+ }
117
+ ]
118
+ };
119
+ } catch (error) {
120
+ const errorMessage = error.message;
121
+ payload.logger.error(`[payload-mcp] Error during collection deletion: ${errorMessage}`);
122
+ return {
123
+ content: [
124
+ {
125
+ type: 'text',
126
+ text: `❌ **Error during collection deletion**: ${errorMessage}`
127
+ }
128
+ ]
129
+ };
130
+ }
131
+ };
132
+ export const deleteCollectionTool = (server, req, verboseLogs, collectionsDirPath, configFilePath)=>{
133
+ const tool = (collectionName, confirmDeletion, updateConfig = false)=>{
134
+ const payload = req.payload;
135
+ if (verboseLogs) {
136
+ payload.logger.info(`[payload-mcp] Deleting collection: ${collectionName}, confirmDeletion: ${confirmDeletion}, updateConfig: ${updateConfig}`);
137
+ }
138
+ try {
139
+ const result = deleteCollection(req, verboseLogs, collectionsDirPath, configFilePath, collectionName, confirmDeletion, updateConfig);
140
+ if (verboseLogs) {
141
+ payload.logger.info(`[payload-mcp] Collection deletion completed for: ${collectionName}`);
142
+ }
143
+ return result;
144
+ } catch (error) {
145
+ const errorMessage = error instanceof Error ? error.message : 'Unknown error';
146
+ payload.logger.error(`[payload-mcp] Error deleting collection ${collectionName}: ${errorMessage}`);
147
+ return {
148
+ content: [
149
+ {
150
+ type: 'text',
151
+ text: `Error deleting collection "${collectionName}": ${errorMessage}`
152
+ }
153
+ ]
154
+ };
155
+ }
156
+ };
157
+ server.tool('deleteCollection', toolSchemas.deleteCollection.description, toolSchemas.deleteCollection.parameters.shape, ({ collectionName, confirmDeletion, updateConfig })=>{
158
+ return tool(collectionName, confirmDeletion, updateConfig);
159
+ });
160
+ };
161
+
162
+ //# sourceMappingURL=delete.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/mcp/tools/collection/delete.ts"],"sourcesContent":["import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'\nimport type { PayloadRequest } from 'payload'\n\nimport { readFileSync, unlinkSync, writeFileSync } from 'fs'\nimport { join } from 'path'\n\nimport { toolSchemas } from '../schemas.js'\n\n// Helper function for removing collection from config\nconst removeCollectionFromConfig = (configContent: string, collectionName: string): string => {\n // Simple implementation - find and remove the collection import and reference\n let updatedContent = configContent\n\n // Remove import statement\n const importRegex = new RegExp(\n `import\\\\s*{\\\\s*${collectionName}\\\\s*}\\\\s*from\\\\s*['\"]\\\\./collections/${collectionName}['\"];?\\\\s*\\\\n?`,\n 'g',\n )\n updatedContent = updatedContent.replace(importRegex, '')\n\n // Remove from collections array\n const collectionsRegex = new RegExp(`\\\\s*${collectionName},?\\\\s*`, 'g')\n updatedContent = updatedContent.replace(collectionsRegex, '')\n\n return updatedContent\n}\n\nexport const deleteCollection = (\n req: PayloadRequest,\n verboseLogs: boolean,\n collectionsDirPath: string,\n configFilePath: string,\n collectionName: string,\n confirmDeletion: boolean,\n updateConfig: boolean,\n) => {\n const payload = req.payload\n\n if (verboseLogs) {\n payload.logger.info(`[payload-mcp] Attempting to delete collection: ${collectionName}`)\n }\n\n if (!confirmDeletion) {\n payload.logger.warn(`[payload-mcp] Deletion cancelled for collection: ${collectionName}`)\n return {\n content: [\n {\n type: 'text' as const,\n text: `❌ **Deletion cancelled**. Set confirmDeletion to true to proceed with deleting collection \"${collectionName}\".`,\n },\n ],\n }\n }\n\n const capitalizedName = collectionName.charAt(0).toUpperCase() + collectionName.slice(1)\n const collectionFilePath = join(collectionsDirPath, `${capitalizedName}.ts`)\n\n // Security check: ensure we're working with the collections directory\n if (!collectionFilePath.startsWith(collectionsDirPath)) {\n payload.logger.error(`[payload-mcp] Invalid collection path attempted: ${collectionFilePath}`)\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 fileExists = false\n try {\n readFileSync(collectionFilePath, 'utf8')\n fileExists = true\n } catch {\n payload.logger.warn(`[payload-mcp] Collection file does not exist: ${collectionFilePath}`)\n }\n\n // Read current config if we need to update it\n let configContent = ''\n let configExists = false\n if (updateConfig) {\n try {\n configContent = readFileSync(configFilePath, 'utf8')\n configExists = true\n } catch {\n payload.logger.warn(`[payload-mcp] Config file does not exist: ${configFilePath}`)\n }\n }\n\n let responseText = ''\n let operationsPerformed = 0\n\n // Delete the collection file\n if (fileExists) {\n try {\n unlinkSync(collectionFilePath)\n if (verboseLogs) {\n payload.logger.info(\n `[payload-mcp] Successfully deleted collection file: ${collectionFilePath}`,\n )\n }\n responseText += `✅ Deleted collection file: \\`${capitalizedName}.ts\\`\\n`\n operationsPerformed++\n } catch (error) {\n const errorMessage = (error as Error).message\n payload.logger.error(`[payload-mcp] Error deleting collection file: ${errorMessage}`)\n responseText += `❌ Error deleting collection file: ${errorMessage}\\n`\n }\n } else {\n responseText += `⚠️ Collection file not found: \\`${capitalizedName}.ts\\`\\n`\n }\n\n // Update the config file if requested and it exists\n if (updateConfig && configExists) {\n try {\n const updatedConfigContent = removeCollectionFromConfig(configContent, capitalizedName)\n writeFileSync(configFilePath, updatedConfigContent, 'utf8')\n if (verboseLogs) {\n payload.logger.info(`[payload-mcp] Successfully updated config file: ${configFilePath}`)\n }\n responseText += `✅ Updated payload.config.ts to remove collection reference\\n`\n operationsPerformed++\n } catch (error) {\n const errorMessage = (error as Error).message\n payload.logger.error(`[payload-mcp] Error updating config file: ${errorMessage}`)\n responseText += `❌ Error updating config file: ${errorMessage}\\n`\n }\n } else if (updateConfig && !configExists) {\n responseText += `⚠️ Config file not found: payload.config.ts\\n`\n }\n\n // Summary\n if (operationsPerformed > 0) {\n responseText += `\\n✅ **Collection deletion completed!**`\n } else {\n responseText += `\\n⚠️ **No operations performed**\n\nThe collection file may not have existed or there were errors during deletion.`\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 during collection deletion: ${errorMessage}`)\n return {\n content: [\n {\n type: 'text' as const,\n text: `❌ **Error during collection deletion**: ${errorMessage}`,\n },\n ],\n }\n }\n}\n\nexport const deleteCollectionTool = (\n server: McpServer,\n req: PayloadRequest,\n verboseLogs: boolean,\n collectionsDirPath: string,\n configFilePath: string,\n) => {\n const tool = (\n collectionName: string,\n confirmDeletion: boolean,\n updateConfig: boolean = false,\n ) => {\n const payload = req.payload\n\n if (verboseLogs) {\n payload.logger.info(\n `[payload-mcp] Deleting collection: ${collectionName}, confirmDeletion: ${confirmDeletion}, updateConfig: ${updateConfig}`,\n )\n }\n\n try {\n const result = deleteCollection(\n req,\n verboseLogs,\n collectionsDirPath,\n configFilePath,\n collectionName,\n confirmDeletion,\n updateConfig,\n )\n\n if (verboseLogs) {\n payload.logger.info(`[payload-mcp] Collection deletion 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 deleting collection ${collectionName}: ${errorMessage}`,\n )\n\n return {\n content: [\n {\n type: 'text' as const,\n text: `Error deleting collection \"${collectionName}\": ${errorMessage}`,\n },\n ],\n }\n }\n }\n\n server.tool(\n 'deleteCollection',\n toolSchemas.deleteCollection.description,\n toolSchemas.deleteCollection.parameters.shape,\n ({ collectionName, confirmDeletion, updateConfig }) => {\n return tool(collectionName, confirmDeletion, updateConfig)\n },\n )\n}\n"],"names":["readFileSync","unlinkSync","writeFileSync","join","toolSchemas","removeCollectionFromConfig","configContent","collectionName","updatedContent","importRegex","RegExp","replace","collectionsRegex","deleteCollection","req","verboseLogs","collectionsDirPath","configFilePath","confirmDeletion","updateConfig","payload","logger","info","warn","content","type","text","capitalizedName","charAt","toUpperCase","slice","collectionFilePath","startsWith","error","fileExists","configExists","responseText","operationsPerformed","errorMessage","message","updatedConfigContent","deleteCollectionTool","server","tool","result","Error","description","parameters","shape"],"mappings":"AAGA,SAASA,YAAY,EAAEC,UAAU,EAAEC,aAAa,QAAQ,KAAI;AAC5D,SAASC,IAAI,QAAQ,OAAM;AAE3B,SAASC,WAAW,QAAQ,gBAAe;AAE3C,sDAAsD;AACtD,MAAMC,6BAA6B,CAACC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QAAQC,MAAM,CAACY,KAAK,CAClB,CAAC,wCAAwC,EAAE1B,eAAe,EAAE,EAAE+B,cAAc;YAG9E,OAAO;gBACLd,SAAS;oBACP;wBACEC,MAAM;wBACNC,MAAM,CAAC,2BAA2B,EAAEnB,eAAe,GAAG,EAAE+B,cAAc;oBACxE;iBACD;YACH;QACF;IACF;IAEAI,OAAOC,IAAI,CACT,oBACAvC,YAAYS,gBAAgB,CAACiC,WAAW,EACxC1C,YAAYS,gBAAgB,CAACkC,UAAU,CAACC,KAAK,EAC7C,CAAC,EAAEzC,cAAc,EAAEW,eAAe,EAAEC,YAAY,EAAE;QAChD,OAAOwB,KAAKpC,gBAAgBW,iBAAiBC;IAC/C;AAEJ,EAAC"}
@@ -0,0 +1,10 @@
1
+ import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
2
+ import type { PayloadRequest } from 'payload';
3
+ export declare const readCollections: (req: PayloadRequest, verboseLogs: boolean, collectionsDirPath: string, collectionName?: string, includeContent?: boolean, includeCount?: boolean) => {
4
+ content: {
5
+ type: "text";
6
+ text: string;
7
+ }[];
8
+ };
9
+ export declare const findCollectionTool: (server: McpServer, req: PayloadRequest, verboseLogs: boolean, collectionsDirPath: string) => void;
10
+ //# sourceMappingURL=find.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"find.d.ts","sourceRoot":"","sources":["../../../../src/mcp/tools/collection/find.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAA;AACxE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAO7C,eAAO,MAAM,eAAe,QACrB,cAAc,eACN,OAAO,sBACA,MAAM,mBACT,MAAM,mBACP,OAAO,iBACT,OAAO;;;;;CAmJtB,CAAA;AAGD,eAAO,MAAM,kBAAkB,WACrB,SAAS,OACZ,cAAc,eACN,OAAO,sBACA,MAAM,SAqD3B,CAAA"}
@@ -0,0 +1,162 @@
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.tool('findCollections', toolSchemas.findCollections.description, toolSchemas.findCollections.parameters.shape, ({ collectionName, includeContent, includeCount })=>{
158
+ return tool(collectionName, includeContent, includeCount);
159
+ });
160
+ };
161
+
162
+ //# sourceMappingURL=find.js.map
@@ -0,0 +1 @@
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.tool(\n 'findCollections',\n toolSchemas.findCollections.description,\n toolSchemas.findCollections.parameters.shape,\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","findCollections","description","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,KAAKR,eAAeS,KAAK,CAAC,GAAG,GAAG,CAAC;YACzF,MAAMC,WAAWhB,KAAKK,oBAAoBO;YAE1C,IAAI,CAACI,SAASC,UAAU,CAACZ,qBAAqB;gBAC5CI,QAAQC,MAAM,CAACQ,KAAK,CAAC,CAAC,iDAAiD,EAAEZ,gBAAgB;gBACzF,OAAO;oBACLa,SAAS;wBAAC;4BAAEC,MAAM;4BAAiBC,MAAM;wBAAiC;qBAAE;gBAC9E;YACF;YAEA,IAAI;gBACF,MAAMF,UAAUtB,aAAamB,UAAU;gBACvC,IAAIZ,aAAa;oBACfK,QAAQC,MAAM,CAACC,IAAI,CA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IAAIM,OAAO;QAE3B,IAAIL,aAAa;YACfK,QAAQC,MAAM,CAACC,IAAI,CACjB,CAAC,iCAAiC,EAAEL,iBAAiB,CAAC,MAAM,EAAEA,gBAAgB,GAAG,GAAG,kBAAkB,EAAEC,eAAe,gBAAgB,EAAEC,cAAc;QAE3J;QAEA,IAAI;YACF,MAAMwC,SAAS9C,gBACbC,KACAC,aACAC,oBACAC,gBACAC,gBACAC;YAGF,IAAIJ,aAAa;gBACfK,QAAQC,MAAM,CAACC,IAAI,CAAC,CAAC,yCAAyC,CAAC;YACjE;YAEA,OAAOqC;QACT,EAAE,OAAO9B,OAAO;YACd,MAAM0B,eAAe1B,iBAAiB+B,QAAQ/B,MAAMwB,OAAO,GAAG;YAC9DjC,QAAQC,MAAM,CAACQ,KAAK,CAAC,CAAC,yCAAyC,EAAE0B,cAAc;YAE/E,OAAO;gBACLzB,SAAS;oBACP;wBACEC,MAAM;wBACNC,MAAM,CAAC,2BAA2B,EAAEuB,cAAc;oBACpD;iBACD;YACH;QACF;IACF;IAEAE,OAAOC,IAAI,CACT,mBACA9C,YAAYiD,eAAe,CAACC,WAAW,EACvClD,YAAYiD,eAAe,CAACE,UAAU,CAACC,KAAK,EAC5C,CAAC,EAAE/C,cAAc,EAAEC,cAAc,EAAEC,YAAY,EAAE;QAC/C,OAAOuC,KAAKzC,gBAAgBC,gBAAgBC;IAC9C;AAEJ,EAAC"}
@@ -0,0 +1,10 @@
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
@@ -0,0 +1 @@
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,SAwEvB,CAAA"}
@@ -0,0 +1,206 @@
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.tool('updateCollection', toolSchemas.updateCollection.description, toolSchemas.updateCollection.parameters.shape, async (args)=>{
202
+ return await tool(args);
203
+ });
204
+ };
205
+
206
+ //# sourceMappingURL=update.js.map
@@ -0,0 +1 @@
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.tool(\n 'updateCollection',\n toolSchemas.updateCollection.description,\n toolSchemas.updateCollection.parameters.shape,\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","description","parameters","shape","args"],"mappings":"AAGA,SAASA,YAAY,EAAEC,aAAa,QAAQ,KAAI;AAChD,SAASC,IAAI,QAAQ,OAAM;AAE3B,SACEC,qBAAqB,EACrBC,wBAAwB,EACxBC,0BAA0B,QACrB,0BAAyB;AAChC,SAASC,sBAAsB,QAAQ,kCAAiC;AACxE,SAASC,WAAW,QAAQ,gBAAe;AAE3C,OAAO,MAAMC,mBAAmB,OAC9BC,KACAC,aACAC,oBACAC,gBACAC,gBACAC,YACAC,WACAC,oBACAC,oBAC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