@payloadcms/plugin-mcp 3.78.0-internal-debug.f663370 → 3.78.0-internal.ab11ffa
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.
- package/dist/index.d.ts +0 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -1
- package/dist/index.js.map +1 -1
- package/dist/mcp/getMcpHandler.d.ts.map +1 -1
- package/dist/mcp/getMcpHandler.js +8 -2
- package/dist/mcp/getMcpHandler.js.map +1 -1
- package/dist/mcp/helpers/config.d.ts +1 -9
- package/dist/mcp/helpers/config.d.ts.map +1 -1
- package/dist/mcp/helpers/config.js +0 -62
- package/dist/mcp/helpers/config.js.map +1 -1
- package/dist/mcp/helpers/fields.d.ts +6 -25
- package/dist/mcp/helpers/fields.d.ts.map +1 -1
- package/dist/mcp/helpers/fields.js +35 -29
- package/dist/mcp/helpers/fields.js.map +1 -1
- package/dist/mcp/helpers/fileValidation.d.ts +0 -2
- package/dist/mcp/helpers/fileValidation.d.ts.map +1 -1
- package/dist/mcp/helpers/fileValidation.js +44 -82
- package/dist/mcp/helpers/fileValidation.js.map +1 -1
- package/dist/mcp/tools/collection/create.d.ts.map +1 -1
- package/dist/mcp/tools/collection/create.js +2 -25
- package/dist/mcp/tools/collection/create.js.map +1 -1
- package/dist/mcp/tools/collection/delete.d.ts.map +1 -1
- package/dist/mcp/tools/collection/delete.js +1 -12
- package/dist/mcp/tools/collection/delete.js.map +1 -1
- package/dist/mcp/tools/config/update.d.ts +1 -1
- package/dist/mcp/tools/config/update.d.ts.map +1 -1
- package/dist/mcp/tools/config/update.js +3 -3
- package/dist/mcp/tools/config/update.js.map +1 -1
- package/dist/mcp/tools/global/update.d.ts.map +1 -1
- package/dist/mcp/tools/global/update.js +3 -0
- package/dist/mcp/tools/global/update.js.map +1 -1
- package/dist/mcp/tools/job/create.d.ts.map +1 -1
- package/dist/mcp/tools/job/create.js +3 -6
- package/dist/mcp/tools/job/create.js.map +1 -1
- package/dist/mcp/tools/job/run.d.ts +1 -1
- package/dist/mcp/tools/job/run.d.ts.map +1 -1
- package/dist/mcp/tools/job/run.js +5 -26
- package/dist/mcp/tools/job/run.js.map +1 -1
- package/dist/mcp/tools/job/update.d.ts.map +1 -1
- package/dist/mcp/tools/job/update.js +10 -38
- package/dist/mcp/tools/job/update.js.map +1 -1
- package/dist/mcp/tools/resource/create.d.ts.map +1 -1
- package/dist/mcp/tools/resource/create.js +3 -0
- package/dist/mcp/tools/resource/create.js.map +1 -1
- package/dist/mcp/tools/resource/update.d.ts.map +1 -1
- package/dist/mcp/tools/resource/update.js +3 -0
- package/dist/mcp/tools/resource/update.js.map +1 -1
- package/dist/mcp/tools/schemas.d.ts +2 -5
- package/dist/mcp/tools/schemas.d.ts.map +1 -1
- package/dist/mcp/tools/schemas.js +0 -1
- package/dist/mcp/tools/schemas.js.map +1 -1
- package/dist/utils/getVirtualFieldNames.d.ts +14 -0
- package/dist/utils/getVirtualFieldNames.d.ts.map +1 -0
- package/dist/utils/getVirtualFieldNames.js +35 -0
- package/dist/utils/getVirtualFieldNames.js.map +1 -0
- package/dist/utils/schemaConversion/convertCollectionSchemaToZod.d.ts.map +1 -1
- package/dist/utils/schemaConversion/convertCollectionSchemaToZod.js +1 -2
- package/dist/utils/schemaConversion/convertCollectionSchemaToZod.js.map +1 -1
- package/dist/utils/schemaConversion/removeVirtualFieldsFromSchema.d.ts +7 -0
- package/dist/utils/schemaConversion/removeVirtualFieldsFromSchema.d.ts.map +1 -0
- package/dist/utils/schemaConversion/removeVirtualFieldsFromSchema.js +20 -0
- package/dist/utils/schemaConversion/removeVirtualFieldsFromSchema.js.map +1 -0
- package/dist/utils/schemaConversion/sanitizeJsonSchema.d.ts +5 -0
- package/dist/utils/schemaConversion/sanitizeJsonSchema.d.ts.map +1 -1
- package/dist/utils/schemaConversion/sanitizeJsonSchema.js +38 -0
- package/dist/utils/schemaConversion/sanitizeJsonSchema.js.map +1 -1
- package/package.json +4 -4
- package/src/index.ts +0 -1
- package/src/mcp/getMcpHandler.ts +22 -2
- package/src/mcp/helpers/config.ts +1 -114
- package/src/mcp/helpers/fields.ts +46 -50
- package/src/mcp/helpers/fileValidation.ts +38 -93
- package/src/mcp/tools/collection/create.ts +2 -30
- package/src/mcp/tools/collection/delete.ts +1 -19
- package/src/mcp/tools/config/update.ts +0 -4
- package/src/mcp/tools/global/update.ts +8 -0
- package/src/mcp/tools/job/create.ts +5 -11
- package/src/mcp/tools/job/run.ts +14 -38
- package/src/mcp/tools/job/update.ts +29 -77
- package/src/mcp/tools/resource/create.ts +7 -0
- package/src/mcp/tools/resource/update.ts +7 -0
- package/src/mcp/tools/schemas.ts +0 -1
- package/src/utils/getVirtualFieldNames.ts +53 -0
- package/src/utils/schemaConversion/convertCollectionSchemaToZod.ts +1 -3
- package/src/utils/schemaConversion/removeVirtualFieldsFromSchema.ts +27 -0
- package/src/utils/schemaConversion/sanitizeJsonSchema.ts +41 -0
- package/dist/mcp/helpers/conversion.d.ts +0 -2
- package/dist/mcp/helpers/conversion.d.ts.map +0 -1
- package/dist/mcp/helpers/conversion.js +0 -5
- package/dist/mcp/helpers/conversion.js.map +0 -1
- package/dist/mcp/helpers/validation.d.ts +0 -9
- package/dist/mcp/helpers/validation.d.ts.map +0 -1
- package/dist/mcp/helpers/validation.js +0 -22
- package/dist/mcp/helpers/validation.js.map +0 -1
- package/src/mcp/helpers/conversion.ts +0 -3
- package/src/mcp/helpers/validation.ts +0 -32
|
@@ -64,6 +64,4 @@ export interface WorkflowConfig {
|
|
|
64
64
|
*/
|
|
65
65
|
export declare const validatePayloadFile: <T = CollectionConfig | TaskConfig | WorkflowConfig>(fileName: string, type: ValidationType) => Promise<ValidationResult<T>>;
|
|
66
66
|
export declare const validateCollectionFile: (fileName: string) => Promise<ValidationResult<CollectionConfig>>;
|
|
67
|
-
export declare const validateTaskFile: (fileName: string) => Promise<ValidationResult<TaskConfig>>;
|
|
68
|
-
export declare const validateWorkflowFile: (fileName: string) => Promise<ValidationResult<WorkflowConfig>>;
|
|
69
67
|
//# sourceMappingURL=fileValidation.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fileValidation.d.ts","sourceRoot":"","sources":["../../../src/mcp/helpers/fileValidation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAK/C,MAAM,MAAM,cAAc,GAAG,YAAY,GAAG,MAAM,GAAG,UAAU,CAAA;AAE/D,MAAM,WAAW,gBAAgB,CAAC,CAAC,GAAG,OAAO;IAC3C,MAAM,CAAC,EAAE,CAAC,CAAA;IACV,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,OAAO,EAAE,OAAO,CAAA;CACjB;AAGD,MAAM,WAAW,UAAU;IACzB,OAAO,EAAE,CAAC,IAAI,EAAE;QACd,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;QAC9B,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;QAC5B,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;KAC/B,KAAK,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAC7B,WAAW,CAAC,EAAE,KAAK,CAAC;QAClB,KAAK,CAAC,EAAE,MAAM,CAAA;QACd,IAAI,EAAE,MAAM,CAAA;QACZ,OAAO,CAAC,EAAE,KAAK,CAAC;YAAE,KAAK,EAAE,MAAM,CAAC;YAAC,KAAK,EAAE,MAAM,CAAA;SAAE,CAAC,CAAA;QACjD,QAAQ,CAAC,EAAE,OAAO,CAAA;QAClB,IAAI,EAAE,MAAM,CAAA;KACb,CAAC,CAAA;IACF,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,YAAY,CAAC,EAAE,KAAK,CAAC;QACnB,KAAK,CAAC,EAAE,MAAM,CAAA;QACd,IAAI,EAAE,MAAM,CAAA;QACZ,OAAO,CAAC,EAAE,KAAK,CA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MAAM,WAAW,cAAc;IAC7B,OAAO,EAAE,CAAC,IAAI,EAAE;QACd,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;QAC9B,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;QAC5B,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;KAC/B,KAAK,IAAI,CAAA;IACV,WAAW,CAAC,EAAE,KAAK,CAAC;QAClB,KAAK,CAAC,EAAE,MAAM,CAAA;QACd,IAAI,EAAE,MAAM,CAAA;QACZ,OAAO,CAAC,EAAE,KAAK,CAAC;YAAE,KAAK,EAAE,MAAM,CAAC;YAAC,KAAK,EAAE,MAAM,CAAA;SAAE,CAAC,CAAA;QACjD,QAAQ,CAAC,EAAE,OAAO,CAAA;QAClB,IAAI,EAAE,MAAM,CAAA;KACb,CAAC,CAAA;IACF,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,IAAI,EAAE,MAAM,CAAA;CACb;AAED;;;;;GAKG;AACH,eAAO,MAAM,mBAAmB,GAAU,CAAC,6DAC/B,MAAM,QACV,cAAc,KACnB,OAAO,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAwE7B,CAAA;AAyND,eAAO,MAAM,sBAAsB,aACvB,MAAM,KACf,OAAO,CAAC,gBAAgB,CAAC,gBAAgB,CAAC,CAE5C,CAAA"}
|
|
@@ -128,16 +128,16 @@ import { join } from 'path';
|
|
|
128
128
|
if (config.fields) {
|
|
129
129
|
for(let i = 0; i < config.fields.length; i++){
|
|
130
130
|
const field = config.fields[i];
|
|
131
|
-
if (!field) {
|
|
131
|
+
if (!field || typeof field !== 'object') {
|
|
132
132
|
return {
|
|
133
133
|
error: `Field at index ${i} is not a valid object`,
|
|
134
134
|
success: false
|
|
135
135
|
};
|
|
136
136
|
}
|
|
137
137
|
// Check if field has type property
|
|
138
|
-
if ('type' in field
|
|
138
|
+
if (!('type' in field) || !field.type) {
|
|
139
139
|
return {
|
|
140
|
-
error: `Field at index ${i}
|
|
140
|
+
error: `Field at index ${i} is missing a valid type property`,
|
|
141
141
|
success: false
|
|
142
142
|
};
|
|
143
143
|
}
|
|
@@ -148,6 +148,27 @@ import { join } from 'path';
|
|
|
148
148
|
success: true
|
|
149
149
|
};
|
|
150
150
|
}
|
|
151
|
+
/**
|
|
152
|
+
* Validates an array of schema fields (inputSchema / outputSchema).
|
|
153
|
+
* Returns an error string on the first invalid field, or null if all fields are valid.
|
|
154
|
+
*/ function validateSchemaFields(fields, label) {
|
|
155
|
+
if (!fields || !Array.isArray(fields)) {
|
|
156
|
+
return null;
|
|
157
|
+
}
|
|
158
|
+
for(let i = 0; i < fields.length; i++){
|
|
159
|
+
const field = fields[i];
|
|
160
|
+
if (!field) {
|
|
161
|
+
return `${label} field at index ${i} is not a valid object`;
|
|
162
|
+
}
|
|
163
|
+
if (!field.name) {
|
|
164
|
+
return `${label} field at index ${i} must have a valid name property`;
|
|
165
|
+
}
|
|
166
|
+
if (!field.type) {
|
|
167
|
+
return `${label} field at index ${i} must have a valid type property`;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
return null;
|
|
171
|
+
}
|
|
151
172
|
/**
|
|
152
173
|
* Validate task configuration structure
|
|
153
174
|
*/ function validateTaskConfig(config) {
|
|
@@ -169,59 +190,25 @@ import { join } from 'path';
|
|
|
169
190
|
success: false
|
|
170
191
|
};
|
|
171
192
|
}
|
|
172
|
-
// Validate optional properties
|
|
173
193
|
if (config.retries !== undefined && config.retries < 0) {
|
|
174
194
|
return {
|
|
175
195
|
error: 'Task config retries must be a non-negative number',
|
|
176
196
|
success: false
|
|
177
197
|
};
|
|
178
198
|
}
|
|
179
|
-
|
|
180
|
-
if (
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
error: `Input schema field at index ${i} is not a valid object`,
|
|
186
|
-
success: false
|
|
187
|
-
};
|
|
188
|
-
}
|
|
189
|
-
if (!field.name) {
|
|
190
|
-
return {
|
|
191
|
-
error: `Input schema field at index ${i} must have a valid name property`,
|
|
192
|
-
success: false
|
|
193
|
-
};
|
|
194
|
-
}
|
|
195
|
-
if (!field.type) {
|
|
196
|
-
return {
|
|
197
|
-
error: `Input schema field at index ${i} must have a valid type property`,
|
|
198
|
-
success: false
|
|
199
|
-
};
|
|
200
|
-
}
|
|
201
|
-
}
|
|
199
|
+
const inputError = validateSchemaFields(config.inputSchema, 'Input schema');
|
|
200
|
+
if (inputError) {
|
|
201
|
+
return {
|
|
202
|
+
error: inputError,
|
|
203
|
+
success: false
|
|
204
|
+
};
|
|
202
205
|
}
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
success: false
|
|
210
|
-
};
|
|
211
|
-
}
|
|
212
|
-
if (!field.name) {
|
|
213
|
-
return {
|
|
214
|
-
error: `Output schema field at index ${i} must have a valid name property`,
|
|
215
|
-
success: false
|
|
216
|
-
};
|
|
217
|
-
}
|
|
218
|
-
if (!field.type) {
|
|
219
|
-
return {
|
|
220
|
-
error: `Output schema field at index ${i} must have a valid type property`,
|
|
221
|
-
success: false
|
|
222
|
-
};
|
|
223
|
-
}
|
|
224
|
-
}
|
|
206
|
+
const outputError = validateSchemaFields(config.outputSchema, 'Output schema');
|
|
207
|
+
if (outputError) {
|
|
208
|
+
return {
|
|
209
|
+
error: outputError,
|
|
210
|
+
success: false
|
|
211
|
+
};
|
|
225
212
|
}
|
|
226
213
|
return {
|
|
227
214
|
config,
|
|
@@ -249,10 +236,9 @@ import { join } from 'path';
|
|
|
249
236
|
success: false
|
|
250
237
|
};
|
|
251
238
|
}
|
|
252
|
-
|
|
253
|
-
if (config.queue) {
|
|
239
|
+
if (config.queue !== undefined && typeof config.queue !== 'string') {
|
|
254
240
|
return {
|
|
255
|
-
error: 'Workflow config queue must be a string',
|
|
241
|
+
error: 'Workflow config queue must be a string if provided',
|
|
256
242
|
success: false
|
|
257
243
|
};
|
|
258
244
|
}
|
|
@@ -262,44 +248,20 @@ import { join } from 'path';
|
|
|
262
248
|
success: false
|
|
263
249
|
};
|
|
264
250
|
}
|
|
265
|
-
|
|
266
|
-
if (
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
error: `Input schema field at index ${i} is not a valid object`,
|
|
272
|
-
success: false
|
|
273
|
-
};
|
|
274
|
-
}
|
|
275
|
-
if (!field.name) {
|
|
276
|
-
return {
|
|
277
|
-
error: `Input schema field at index ${i} must have a valid name property`,
|
|
278
|
-
success: false
|
|
279
|
-
};
|
|
280
|
-
}
|
|
281
|
-
if (!field.type) {
|
|
282
|
-
return {
|
|
283
|
-
error: `Input schema field at index ${i} must have a valid type property`,
|
|
284
|
-
success: false
|
|
285
|
-
};
|
|
286
|
-
}
|
|
287
|
-
}
|
|
251
|
+
const inputError = validateSchemaFields(config.inputSchema, 'Input schema');
|
|
252
|
+
if (inputError) {
|
|
253
|
+
return {
|
|
254
|
+
error: inputError,
|
|
255
|
+
success: false
|
|
256
|
+
};
|
|
288
257
|
}
|
|
289
258
|
return {
|
|
290
259
|
config,
|
|
291
260
|
success: true
|
|
292
261
|
};
|
|
293
262
|
}
|
|
294
|
-
// Convenience functions for backward compatibility
|
|
295
263
|
export const validateCollectionFile = async (fileName)=>{
|
|
296
264
|
return validatePayloadFile(fileName, 'collection');
|
|
297
265
|
};
|
|
298
|
-
export const validateTaskFile = async (fileName)=>{
|
|
299
|
-
return validatePayloadFile(fileName, 'task');
|
|
300
|
-
};
|
|
301
|
-
export const validateWorkflowFile = async (fileName)=>{
|
|
302
|
-
return validatePayloadFile(fileName, 'workflow');
|
|
303
|
-
};
|
|
304
266
|
|
|
305
267
|
//# sourceMappingURL=fileValidation.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/mcp/helpers/fileValidation.ts"],"sourcesContent":["import type { CollectionConfig } from 'payload'\n\nimport { existsSync } from 'fs'\nimport { join } from 'path'\n\nexport type ValidationType = 'collection' | 'task' | 'workflow'\n\nexport interface ValidationResult<T = unknown> {\n config?: T\n error?: string\n success: boolean\n}\n\n// Custom task config interface that matches what we're creating\nexport interface TaskConfig {\n handler: (args: {\n input: Record<string, unknown>\n job: Record<string, unknown>\n tasks: Record<string, unknown>\n }) => Record<string, unknown>\n inputSchema?: Array<{\n label?: string\n name: string\n options?: Array<{ label: string; value: string }>\n required?: boolean\n type: string\n }>\n label?: string\n outputSchema?: Array<{\n label?: string\n name: string\n options?: Array<{ label: string; value: string }>\n required?: boolean\n type: string\n }>\n retries?: number\n slug: string\n}\n\n// Custom workflow config interface that matches what we're creating\nexport interface WorkflowConfig {\n handler: (args: {\n input: Record<string, unknown>\n job: Record<string, unknown>\n tasks: Record<string, unknown>\n }) => void\n inputSchema?: Array<{\n label?: string\n name: string\n options?: Array<{ label: string; value: string }>\n required?: boolean\n type: string\n }>\n label?: string\n queue?: string\n retries?: number\n slug: string\n}\n\n/**\n * Generic validation function for Payload configuration files\n * @param fileName - The name of the file (e.g., 'Users.ts', 'my-task.ts')\n * @param type - The type of validation to perform ('collection', 'task', or 'workflow')\n * @returns Object containing success status and any error messages\n */\nexport const validatePayloadFile = async <T = CollectionConfig | TaskConfig | WorkflowConfig>(\n fileName: string,\n type: ValidationType,\n): Promise<ValidationResult<T>> => {\n try {\n const basePath = type === 'collection' ? 'collections' : type === 'task' ? 'tasks' : 'workflows'\n const fullPath = join(process.cwd(), 'src', basePath)\n const filePath = join(fullPath, fileName)\n\n // Check if file exists\n if (!existsSync(filePath)) {\n return {\n error: `${type} file does not exist: ${fileName}`,\n success: false,\n }\n }\n\n // Clear require cache to ensure fresh import\n delete require.cache[filePath]\n\n // Use relative path for webpack compatibility\n const moduleName = fileName.replace('.ts', '')\n const relativePath = `../${basePath}/${moduleName}`\n\n // Dynamic import with relative path\n const importedModule = await import(/* webpackIgnore: true */ relativePath)\n\n // Get the configuration based on type\n let config: T | undefined\n\n if (type === 'collection') {\n config = getCollectionConfig(importedModule, moduleName) as T\n } else if (type === 'task') {\n config = getTaskConfig(importedModule) as T\n } else if (type === 'workflow') {\n config = getWorkflowConfig(importedModule) as T\n }\n\n if (!config) {\n return {\n error: `${type} file does not export a valid ${type} config`,\n success: false,\n }\n }\n\n // Validate the configuration\n let validationResult: ValidationResult<unknown>\n if (type === 'collection') {\n validationResult = validateCollectionConfig(config as unknown as CollectionConfig)\n } else if (type === 'task') {\n validationResult = validateTaskConfig(config as unknown as TaskConfig)\n } else if (type === 'workflow') {\n validationResult = validateWorkflowConfig(config as unknown as WorkflowConfig)\n } else {\n return {\n error: `Unknown validation type: ${type}`,\n success: false,\n }\n }\n\n if (!validationResult.success) {\n return validationResult as ValidationResult<T>\n }\n\n return {\n config,\n success: true,\n }\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : 'Unknown error during validation'\n return {\n error: `Failed to validate ${type} file: ${errorMessage}`,\n success: false,\n }\n }\n}\n\n/**\n * Extract collection configuration from module exports\n */\nfunction getCollectionConfig(\n importedModule: Record<string, unknown>,\n moduleName: string,\n): CollectionConfig | undefined {\n if (importedModule.default) {\n return importedModule.default as CollectionConfig\n }\n\n if (importedModule[moduleName]) {\n return importedModule[moduleName] as CollectionConfig\n }\n\n return undefined\n}\n\n/**\n * Extract task configuration from module exports\n */\nfunction getTaskConfig(importedModule: Record<string, unknown>): TaskConfig | undefined {\n // First check for default export\n if (importedModule.default) {\n return importedModule.default as TaskConfig\n }\n\n // Look for named exports ending with \"Task\"\n const exportNames = Object.keys(importedModule)\n const taskExport = exportNames.find((name) => name.endsWith('Task'))\n\n if (taskExport) {\n return importedModule[taskExport] as TaskConfig\n }\n\n return undefined\n}\n\n/**\n * Extract workflow configuration from module exports\n */\nfunction getWorkflowConfig(importedModule: Record<string, unknown>): undefined | WorkflowConfig {\n // First check for default export\n if (importedModule.default) {\n return importedModule.default as WorkflowConfig\n }\n\n // Look for named exports ending with \"Workflow\"\n const exportNames = Object.keys(importedModule)\n const workflowExport = exportNames.find((name) => name.endsWith('Workflow'))\n\n if (workflowExport) {\n return importedModule[workflowExport] as WorkflowConfig\n }\n\n return undefined\n}\n\n/**\n * Validate collection configuration structure\n */\nfunction validateCollectionConfig(config: CollectionConfig): ValidationResult<CollectionConfig> {\n if (!config) {\n return {\n error: 'Collection config is not a valid object',\n success: false,\n }\n }\n\n if (!config.slug) {\n return {\n error: 'Collection config must have a valid slug property',\n success: false,\n }\n }\n\n // Validate each field has required properties\n if (config.fields) {\n for (let i = 0; i < config.fields.length; i++) {\n const field = config.fields[i] as Record<string, unknown>\n if (!field) {\n return {\n error: `Field at index ${i} is not a valid object`,\n success: false,\n }\n }\n\n // Check if field has type property\n if ('type' in field && field.type) {\n return {\n error: `Field at index ${i} has invalid type property`,\n success: false,\n }\n }\n }\n }\n\n return { config, success: true }\n}\n\n/**\n * Validate task configuration structure\n */\nfunction validateTaskConfig(config: TaskConfig): ValidationResult<TaskConfig> {\n if (!config) {\n return {\n error: 'Task config is not a valid object',\n success: false,\n }\n }\n\n if (!config.slug) {\n return {\n error: 'Task config must have a valid slug property',\n success: false,\n }\n }\n\n if (!config.handler) {\n return {\n error: 'Task config must have a valid handler function',\n success: false,\n }\n }\n\n // Validate optional properties\n if (config.retries !== undefined && config.retries < 0) {\n return {\n error: 'Task config retries must be a non-negative number',\n success: false,\n }\n }\n\n // Validate schemas if present\n if (config.inputSchema && Array.isArray(config.inputSchema)) {\n for (let i = 0; i < config.inputSchema.length; i++) {\n const field = config.inputSchema[i]\n if (!field) {\n return {\n error: `Input schema field at index ${i} is not a valid object`,\n success: false,\n }\n }\n\n if (!field.name) {\n return {\n error: `Input schema field at index ${i} must have a valid name property`,\n success: false,\n }\n }\n\n if (!field.type) {\n return {\n error: `Input schema field at index ${i} must have a valid type property`,\n success: false,\n }\n }\n }\n }\n\n if (config.outputSchema && Array.isArray(config.outputSchema)) {\n for (let i = 0; i < config.outputSchema.length; i++) {\n const field = config.outputSchema[i]\n if (!field) {\n return {\n error: `Output schema field at index ${i} is not a valid object`,\n success: false,\n }\n }\n\n if (!field.name) {\n return {\n error: `Output schema field at index ${i} must have a valid name property`,\n success: false,\n }\n }\n\n if (!field.type) {\n return {\n error: `Output schema field at index ${i} must have a valid type property`,\n success: false,\n }\n }\n }\n }\n\n return { config, success: true }\n}\n\n/**\n * Validate workflow configuration structure\n */\nfunction validateWorkflowConfig(config: WorkflowConfig): ValidationResult<WorkflowConfig> {\n if (!config) {\n return {\n error: 'Workflow config is not a valid object',\n success: false,\n }\n }\n\n if (!config.slug) {\n return {\n error: 'Workflow config must have a valid slug property',\n success: false,\n }\n }\n\n if (!config.handler) {\n return {\n error: 'Workflow config must have a valid handler function',\n success: false,\n }\n }\n\n // Validate optional properties\n if (config.queue) {\n return {\n error: 'Workflow config queue must be a string',\n success: false,\n }\n }\n\n if (config.retries !== undefined && config.retries < 0) {\n return {\n error: 'Workflow config retries must be a non-negative number',\n success: false,\n }\n }\n\n // Validate schema if present\n if (config.inputSchema && Array.isArray(config.inputSchema)) {\n for (let i = 0; i < config.inputSchema.length; i++) {\n const field = config.inputSchema[i]\n if (!field) {\n return {\n error: `Input schema field at index ${i} is not a valid object`,\n success: false,\n }\n }\n\n if (!field.name) {\n return {\n error: `Input schema field at index ${i} must have a valid name property`,\n success: false,\n }\n }\n\n if (!field.type) {\n return {\n error: `Input schema field at index ${i} must have a valid type property`,\n success: false,\n }\n }\n }\n }\n\n return { config, success: true }\n}\n\n// Convenience functions for backward compatibility\nexport const validateCollectionFile = async (\n fileName: string,\n): Promise<ValidationResult<CollectionConfig>> => {\n return validatePayloadFile<CollectionConfig>(fileName, 'collection')\n}\n\nexport const validateTaskFile = async (fileName: string): Promise<ValidationResult<TaskConfig>> => {\n return validatePayloadFile<TaskConfig>(fileName, 'task')\n}\n\nexport const validateWorkflowFile = async (\n fileName: string,\n): Promise<ValidationResult<WorkflowConfig>> => {\n return validatePayloadFile<WorkflowConfig>(fileName, 'workflow')\n}\n"],"names":["existsSync","join","validatePayloadFile","fileName","type","basePath","fullPath","process","cwd","filePath","error","success","require","cache","moduleName","replace","relativePath","importedModule","config","getCollectionConfig","getTaskConfig","getWorkflowConfig","validationResult","validateCollectionConfig","validateTaskConfig","validateWorkflowConfig","errorMessage","Error","message","default","undefined","exportNames","Object","keys","taskExport","find","name","endsWith","workflowExport","slug","fields","i","length","field","handler","retries","inputSchema","Array","isArray","outputSchema","queue","validateCollectionFile","validateTaskFile","validateWorkflowFile"],"mappings":"AAEA,SAASA,UAAU,QAAQ,KAAI;AAC/B,SAASC,IAAI,QAAQ,OAAM;AAwD3B;;;;;CAKC,GACD,OAAO,MAAMC,sBAAsB,OACjCC,UACAC;IAEA,IAAI;QACF,MAAMC,WAAWD,SAAS,eAAe,gBAAgBA,SAAS,SAAS,UAAU;QACrF,MAAME,WAAWL,KAAKM,QAAQC,GAAG,IAAI,OAAOH;QAC5C,MAAMI,WAAWR,KAAKK,UAAUH;QAEhC,uBAAuB;QACvB,IAAI,CAACH,WAAWS,WAAW;YACzB,OAAO;gBACLC,OAAO,GAAGN,KAAK,sBAAsB,EAAED,UAAU;gBACjDQ,SAAS;YACX;QACF;QAEA,6CAA6C;QAC7C,OAAOC,QAAQC,KAAK,CAACJ,SAAS;QAE9B,8CAA8C;QAC9C,MAAMK,aAAaX,SAASY,OAAO,CAAC,OAAO;QAC3C,MAAMC,eAAe,CAAC,GAAG,EAAEX,SAAS,CAAC,EAAES,YAAY;QAEnD,oCAAoC;QACpC,MAAMG,iBAAiB,MAAM,MAAM,CAAC,uBAAuB,GAAGD;QAE9D,sCAAsC;QACtC,IAAIE;QAEJ,IAAId,SAAS,cAAc;YACzBc,SAASC,oBAAoBF,gBAAgBH;QAC/C,OAAO,IAAIV,SAAS,QAAQ;YAC1Bc,SAASE,cAAcH;QACzB,OAAO,IAAIb,SAAS,YAAY;YAC9Bc,SAASG,kBAAkBJ;QAC7B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B,SAAS;gBACX;YACF;YAEA,IAAI,CAACgC,MAAMvC,IAAI,EAAE;gBACf,OAAO;oBACLM,OAAO,CAAC,4BAA4B,EAAE+B,EAAE,gCAAgC,CAAC;oBACzE9B,SAAS;gBACX;YACF;QACF;IACF;IAEA,OAAO;QAAEO;QAAQP,SAAS;IAAK;AACjC;AAEA,mDAAmD;AACnD,OAAO,MAAMwC,yBAAyB,OACpChD;IAEA,OAAOD,oBAAsCC,UAAU;AACzD,EAAC;AAED,OAAO,MAAMiD,mBAAmB,OAAOjD;IACrC,OAAOD,oBAAgCC,UAAU;AACnD,EAAC;AAED,OAAO,MAAMkD,uBAAuB,OAClClD;IAEA,OAAOD,oBAAoCC,UAAU;AACvD,EAAC"}
|
|
1
|
+
{"version":3,"sources":["../../../src/mcp/helpers/fileValidation.ts"],"sourcesContent":["import type { CollectionConfig } from 'payload'\n\nimport { existsSync } from 'fs'\nimport { join } from 'path'\n\nexport type ValidationType = 'collection' | 'task' | 'workflow'\n\nexport interface ValidationResult<T = unknown> {\n config?: T\n error?: string\n success: boolean\n}\n\n// Custom task config interface that matches what we're creating\nexport interface TaskConfig {\n handler: (args: {\n input: Record<string, unknown>\n job: Record<string, unknown>\n tasks: Record<string, unknown>\n }) => Record<string, unknown>\n inputSchema?: Array<{\n label?: string\n name: string\n options?: Array<{ label: string; value: string }>\n required?: boolean\n type: string\n }>\n label?: string\n outputSchema?: Array<{\n label?: string\n name: string\n options?: Array<{ label: string; value: string }>\n required?: boolean\n type: string\n }>\n retries?: number\n slug: string\n}\n\n// Custom workflow config interface that matches what we're creating\nexport interface WorkflowConfig {\n handler: (args: {\n input: Record<string, unknown>\n job: Record<string, unknown>\n tasks: Record<string, unknown>\n }) => void\n inputSchema?: Array<{\n label?: string\n name: string\n options?: Array<{ label: string; value: string }>\n required?: boolean\n type: string\n }>\n label?: string\n queue?: string\n retries?: number\n slug: string\n}\n\n/**\n * Generic validation function for Payload configuration files\n * @param fileName - The name of the file (e.g., 'Users.ts', 'my-task.ts')\n * @param type - The type of validation to perform ('collection', 'task', or 'workflow')\n * @returns Object containing success status and any error messages\n */\nexport const validatePayloadFile = async <T = CollectionConfig | TaskConfig | WorkflowConfig>(\n fileName: string,\n type: ValidationType,\n): Promise<ValidationResult<T>> => {\n try {\n const basePath = type === 'collection' ? 'collections' : type === 'task' ? 'tasks' : 'workflows'\n const fullPath = join(process.cwd(), 'src', basePath)\n const filePath = join(fullPath, fileName)\n\n // Check if file exists\n if (!existsSync(filePath)) {\n return {\n error: `${type} file does not exist: ${fileName}`,\n success: false,\n }\n }\n\n // Clear require cache to ensure fresh import\n delete require.cache[filePath]\n\n // Use relative path for webpack compatibility\n const moduleName = fileName.replace('.ts', '')\n const relativePath = `../${basePath}/${moduleName}`\n\n // Dynamic import with relative path\n const importedModule = await import(/* webpackIgnore: true */ relativePath)\n\n // Get the configuration based on type\n let config: T | undefined\n\n if (type === 'collection') {\n config = getCollectionConfig(importedModule, moduleName) as T\n } else if (type === 'task') {\n config = getTaskConfig(importedModule) as T\n } else if (type === 'workflow') {\n config = getWorkflowConfig(importedModule) as T\n }\n\n if (!config) {\n return {\n error: `${type} file does not export a valid ${type} config`,\n success: false,\n }\n }\n\n // Validate the configuration\n let validationResult: ValidationResult<unknown>\n if (type === 'collection') {\n validationResult = validateCollectionConfig(config as unknown as CollectionConfig)\n } else if (type === 'task') {\n validationResult = validateTaskConfig(config as unknown as TaskConfig)\n } else if (type === 'workflow') {\n validationResult = validateWorkflowConfig(config as unknown as WorkflowConfig)\n } else {\n return {\n error: `Unknown validation type: ${type}`,\n success: false,\n }\n }\n\n if (!validationResult.success) {\n return validationResult as ValidationResult<T>\n }\n\n return {\n config,\n success: true,\n }\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : 'Unknown error during validation'\n return {\n error: `Failed to validate ${type} file: ${errorMessage}`,\n success: false,\n }\n }\n}\n\n/**\n * Extract collection configuration from module exports\n */\nfunction getCollectionConfig(\n importedModule: Record<string, unknown>,\n moduleName: string,\n): CollectionConfig | undefined {\n if (importedModule.default) {\n return importedModule.default as CollectionConfig\n }\n\n if (importedModule[moduleName]) {\n return importedModule[moduleName] as CollectionConfig\n }\n\n return undefined\n}\n\n/**\n * Extract task configuration from module exports\n */\nfunction getTaskConfig(importedModule: Record<string, unknown>): TaskConfig | undefined {\n // First check for default export\n if (importedModule.default) {\n return importedModule.default as TaskConfig\n }\n\n // Look for named exports ending with \"Task\"\n const exportNames = Object.keys(importedModule)\n const taskExport = exportNames.find((name) => name.endsWith('Task'))\n\n if (taskExport) {\n return importedModule[taskExport] as TaskConfig\n }\n\n return undefined\n}\n\n/**\n * Extract workflow configuration from module exports\n */\nfunction getWorkflowConfig(importedModule: Record<string, unknown>): undefined | WorkflowConfig {\n // First check for default export\n if (importedModule.default) {\n return importedModule.default as WorkflowConfig\n }\n\n // Look for named exports ending with \"Workflow\"\n const exportNames = Object.keys(importedModule)\n const workflowExport = exportNames.find((name) => name.endsWith('Workflow'))\n\n if (workflowExport) {\n return importedModule[workflowExport] as WorkflowConfig\n }\n\n return undefined\n}\n\n/**\n * Validate collection configuration structure\n */\nfunction validateCollectionConfig(config: CollectionConfig): ValidationResult<CollectionConfig> {\n if (!config) {\n return {\n error: 'Collection config is not a valid object',\n success: false,\n }\n }\n\n if (!config.slug) {\n return {\n error: 'Collection config must have a valid slug property',\n success: false,\n }\n }\n\n // Validate each field has required properties\n if (config.fields) {\n for (let i = 0; i < config.fields.length; i++) {\n const field = config.fields[i]\n if (!field || typeof field !== 'object') {\n return {\n error: `Field at index ${i} is not a valid object`,\n success: false,\n }\n }\n\n // Check if field has type property\n if (!('type' in field) || !field.type) {\n return {\n error: `Field at index ${i} is missing a valid type property`,\n success: false,\n }\n }\n }\n }\n\n return { config, success: true }\n}\n\n/**\n * Validates an array of schema fields (inputSchema / outputSchema).\n * Returns an error string on the first invalid field, or null if all fields are valid.\n */\nfunction validateSchemaFields(fields: TaskConfig['inputSchema'], label: string): null | string {\n if (!fields || !Array.isArray(fields)) {\n return null\n }\n for (let i = 0; i < fields.length; i++) {\n const field = fields[i]\n if (!field) {\n return `${label} field at index ${i} is not a valid object`\n }\n if (!field.name) {\n return `${label} field at index ${i} must have a valid name property`\n }\n if (!field.type) {\n return `${label} field at index ${i} must have a valid type property`\n }\n }\n return null\n}\n\n/**\n * Validate task configuration structure\n */\nfunction validateTaskConfig(config: TaskConfig): ValidationResult<TaskConfig> {\n if (!config) {\n return {\n error: 'Task config is not a valid object',\n success: false,\n }\n }\n\n if (!config.slug) {\n return {\n error: 'Task config must have a valid slug property',\n success: false,\n }\n }\n\n if (!config.handler) {\n return {\n error: 'Task config must have a valid handler function',\n success: false,\n }\n }\n\n if (config.retries !== undefined && config.retries < 0) {\n return {\n error: 'Task config retries must be a non-negative number',\n success: false,\n }\n }\n\n const inputError = validateSchemaFields(config.inputSchema, 'Input schema')\n if (inputError) {\n return { error: inputError, success: false }\n }\n\n const outputError = validateSchemaFields(config.outputSchema, 'Output schema')\n if (outputError) {\n return { error: outputError, success: false }\n }\n\n return { config, success: true }\n}\n\n/**\n * Validate workflow configuration structure\n */\nfunction validateWorkflowConfig(config: WorkflowConfig): ValidationResult<WorkflowConfig> {\n if (!config) {\n return {\n error: 'Workflow config is not a valid object',\n success: false,\n }\n }\n\n if (!config.slug) {\n return {\n error: 'Workflow config must have a valid slug property',\n success: false,\n }\n }\n\n if (!config.handler) {\n return {\n error: 'Workflow config must have a valid handler function',\n success: false,\n }\n }\n\n if (config.queue !== undefined && typeof config.queue !== 'string') {\n return {\n error: 'Workflow config queue must be a string if provided',\n success: false,\n }\n }\n\n if (config.retries !== undefined && config.retries < 0) {\n return {\n error: 'Workflow config retries must be a non-negative number',\n success: false,\n }\n }\n\n const inputError = validateSchemaFields(config.inputSchema, 'Input schema')\n if (inputError) {\n return { error: inputError, success: false }\n }\n\n return { config, success: true }\n}\n\nexport const validateCollectionFile = async (\n fileName: string,\n): Promise<ValidationResult<CollectionConfig>> => {\n return validatePayloadFile<CollectionConfig>(fileName, 'collection')\n}\n"],"names":["existsSync","join","validatePayloadFile","fileName","type","basePath","fullPath","process","cwd","filePath","error","success","require","cache","moduleName","replace","relativePath","importedModule","config","getCollectionConfig","getTaskConfig","getWorkflowConfig","validationResult","validateCollectionConfig","validateTaskConfig","validateWorkflowConfig","errorMessage","Error","message","default","undefined","exportNames","Object","keys","taskExport","find","name","endsWith","workflowExport","slug","fields","i","length","field","validateSchemaFields","label","Array","isArray","handler","retries","inputError","inputSchema","outputError","outputSchema","queue","validateCollectionFile"],"mappings":"AAEA,SAASA,UAAU,QAAQ,KAAI;AAC/B,SAASC,IAAI,QAAQ,OAAM;AAwD3B;;;;;CAKC,GACD,OAAO,MAAMC,sBAAsB,OACjCC,UACAC;IAEA,IAAI;QACF,MAAMC,WAAWD,SAAS,eAAe,gBAAgBA,SAAS,SAAS,UAAU;QACrF,MAAME,WAAWL,KAAKM,QAAQC,GAAG,IAAI,OAAOH;QAC5C,MAAMI,WAAWR,KAAKK,UAAUH;QAEhC,uBAAuB;QACvB,IAAI,CAACH,WAAWS,WAAW;YACzB,OAAO;gBACLC,OAAO,GAAGN,KAAK,sBAAsB,EAAED,UAAU;gBACjDQ,SAAS;YACX;QACF;QAEA,6CAA6C;QAC7C,OAAOC,QAAQC,KAAK,CAACJ,SAAS;QAE9B,8CAA8C;QAC9C,MAAMK,aAAaX,SAASY,OAAO,CAAC,OAAO;QAC3C,MAAMC,eAAe,CAAC,GAAG,EAAEX,SAAS,CAAC,EAAES,YAAY;QAEnD,oCAAoC;QACpC,MAAMG,iBAAiB,MAAM,MAAM,CAAC,uBAAuB,GAAGD;QAE9D,sCAAsC;QACtC,IAAIE;QAEJ,IAAId,SAAS,cAAc;YACzBc,SAASC,oBAAoBF,gBAAgBH;QAC/C,OAAO,IAAIV,SAAS,QAAQ;YAC1Bc,SAASE,cAAcH;QACzB,OAAO,IAAIb,SAAS,YAAY;YAC9Bc,SAASG,kBAAkBJ;QAC7B;QAEA,IAAI,CAACC,QAAQ;YACX,O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EAAE;QAChB,OAAO;YACL7B,OAAO;YACPC,SAAS;QACX;IACF;IAEA,IAAI,CAACO,OAAO8B,OAAO,EAAE;QACnB,OAAO;YACLtC,OAAO;YACPC,SAAS;QACX;IACF;IAEA,IAAIO,OAAOoC,KAAK,KAAKxB,aAAa,OAAOZ,OAAOoC,KAAK,KAAK,UAAU;QAClE,OAAO;YACL5C,OAAO;YACPC,SAAS;QACX;IACF;IAEA,IAAIO,OAAO+B,OAAO,KAAKnB,aAAaZ,OAAO+B,OAAO,GAAG,GAAG;QACtD,OAAO;YACLvC,OAAO;YACPC,SAAS;QACX;IACF;IAEA,MAAMuC,aAAaN,qBAAqB1B,OAAOiC,WAAW,EAAE;IAC5D,IAAID,YAAY;QACd,OAAO;YAAExC,OAAOwC;YAAYvC,SAAS;QAAM;IAC7C;IAEA,OAAO;QAAEO;QAAQP,SAAS;IAAK;AACjC;AAEA,OAAO,MAAM4C,yBAAyB,OACpCpD;IAEA,OAAOD,oBAAsCC,UAAU;AACzD,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create.d.ts","sourceRoot":"","sources":["../../../../src/mcp/tools/collection/create.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAA;AACxE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"create.d.ts","sourceRoot":"","sources":["../../../../src/mcp/tools/collection/create.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAA;AACxE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAS7C,eAAO,MAAM,gBAAgB,QACtB,cAAc,eACN,OAAO,sBACA,MAAM,kBACV,MAAM,kBACN,MAAM,yBACC,MAAM,GAAG,SAAS,UACjC,GAAG,EAAE,aACF,OAAO,GAAG,SAAS;;;;;EA4H/B,CAAA;AAED,eAAO,MAAM,oBAAoB,WACvB,SAAS,OACZ,cAAc,eACN,OAAO,sBACA,MAAM,kBACV,MAAM,SA4DvB,CAAA"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { writeFileSync } from 'fs';
|
|
2
2
|
import { join } from 'path';
|
|
3
|
+
import { generateFieldDefinitionString } from '../../helpers/fields.js';
|
|
3
4
|
import { validateCollectionFile } from '../../helpers/fileValidation.js';
|
|
4
5
|
import { toolSchemas } from '../schemas.js';
|
|
5
6
|
export const createCollection = async (req, verboseLogs, collectionsDirPath, configFilePath, collectionName, collectionDescription, fields, hasUpload)=>{
|
|
@@ -12,31 +13,7 @@ export const createCollection = async (req, verboseLogs, collectionsDirPath, con
|
|
|
12
13
|
if (verboseLogs) {
|
|
13
14
|
payload.logger.info(`[payload-mcp] Generated slug: ${slug} for collection: ${collectionName}`);
|
|
14
15
|
}
|
|
15
|
-
|
|
16
|
-
const generateFieldDefinition = (field)=>{
|
|
17
|
-
const fieldConfig = [];
|
|
18
|
-
fieldConfig.push(` {`);
|
|
19
|
-
fieldConfig.push(` name: '${field.name}',`);
|
|
20
|
-
fieldConfig.push(` type: '${field.type}',`);
|
|
21
|
-
if (field.required) {
|
|
22
|
-
fieldConfig.push(` required: true,`);
|
|
23
|
-
}
|
|
24
|
-
if (field.description) {
|
|
25
|
-
fieldConfig.push(` admin: {`);
|
|
26
|
-
fieldConfig.push(` description: '${field.description}',`);
|
|
27
|
-
fieldConfig.push(` },`);
|
|
28
|
-
}
|
|
29
|
-
if (field.options && field.type === 'select') {
|
|
30
|
-
fieldConfig.push(` options: [`);
|
|
31
|
-
field.options.forEach((option)=>{
|
|
32
|
-
fieldConfig.push(` { label: '${option.label}', value: '${option.value}' },`);
|
|
33
|
-
});
|
|
34
|
-
fieldConfig.push(` ],`);
|
|
35
|
-
}
|
|
36
|
-
fieldConfig.push(` },`);
|
|
37
|
-
return fieldConfig.join('\n');
|
|
38
|
-
};
|
|
39
|
-
const fieldDefinitions = fields.map(generateFieldDefinition).join('\n');
|
|
16
|
+
const fieldDefinitions = fields.map(generateFieldDefinitionString).join('\n');
|
|
40
17
|
// Generate collection file content
|
|
41
18
|
const collectionContent = `import type { CollectionConfig } from 'payload'
|
|
42
19
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/mcp/tools/collection/create.ts"],"sourcesContent":["import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'\nimport type { PayloadRequest } from 'payload'\n\nimport { writeFileSync } from 'fs'\nimport { join } from 'path'\n\nimport { validateCollectionFile } from '../../helpers/fileValidation.js'\nimport { toolSchemas } from '../schemas.js'\n\nexport const createCollection = async (\n req: PayloadRequest,\n verboseLogs: boolean,\n collectionsDirPath: string,\n configFilePath: string,\n collectionName: string,\n collectionDescription: string | undefined,\n fields: any[],\n hasUpload: boolean | undefined,\n) => {\n const payload = req.payload\n if (verboseLogs) {\n payload.logger.info(\n `[payload-mcp] Creating collection: ${collectionName} with ${fields.length} fields`,\n )\n }\n\n const capitalizedName = collectionName.charAt(0).toUpperCase() + collectionName.slice(1)\n const slug = collectionName\n .replace(/([A-Z])/g, '-$1')\n .toLowerCase()\n .replace(/^-/, '')\n\n if (verboseLogs) {\n payload.logger.info(`[payload-mcp] Generated slug: ${slug} for collection: ${collectionName}`)\n }\n\n // Generate TypeScript field definitions more systematically\n const generateFieldDefinition = (field: any) => {\n const fieldConfig = []\n fieldConfig.push(` {`)\n fieldConfig.push(` name: '${field.name}',`)\n fieldConfig.push(` type: '${field.type}',`)\n\n if (field.required) {\n fieldConfig.push(` required: true,`)\n }\n\n if (field.description) {\n fieldConfig.push(` admin: {`)\n fieldConfig.push(` description: '${field.description}',`)\n fieldConfig.push(` },`)\n }\n\n if (field.options && field.type === 'select') {\n fieldConfig.push(` options: [`)\n field.options.forEach((option: { label: string; value: string }) => {\n fieldConfig.push(` { label: '${option.label}', value: '${option.value}' },`)\n })\n fieldConfig.push(` ],`)\n }\n\n fieldConfig.push(` },`)\n return fieldConfig.join('\\n')\n }\n\n const fieldDefinitions = fields.map(generateFieldDefinition).join('\\n')\n\n // Generate collection file content\n const collectionContent = `import type { CollectionConfig } from 'payload'\n\nexport const ${capitalizedName}: CollectionConfig = {\n slug: '${slug}',${\n collectionDescription\n ? `\n admin: {\n description: '${collectionDescription}',\n },`\n : ''\n }${\n hasUpload\n ? `\n upload: true,`\n : ''\n }\n fields: [\n${fieldDefinitions}\n ],\n}\n`\n\n try {\n // Validate the collection name and path\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 // Check if file already exists\n try {\n const fs = await import('fs')\n if (fs.existsSync(filePath)) {\n return {\n content: [\n {\n type: 'text' as const,\n text: `❌ **Error**: Collection file already exists: ${fileName}`,\n },\n ],\n }\n }\n } catch (_ignore) {\n // File doesn't exist, which is what we want\n }\n\n // Write the collection file\n writeFileSync(filePath, collectionContent, 'utf8')\n if (verboseLogs) {\n payload.logger.info(`[payload-mcp] Successfully created collection file: ${filePath}`)\n }\n\n // Validate the generated file\n const validationResult = await validateCollectionFile(fileName)\n if (validationResult.error) {\n return {\n content: [\n {\n type: 'text' as const,\n text: `❌ **Error**: Generated 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 created successfully!**\n**File**: \\`${fileName}\\`\n**Collection Config:**\n\\`\\`\\`typescript\n${collectionContent}\n\\`\\`\\``,\n },\n ],\n }\n } catch (error) {\n const errorMessage = (error as Error).message\n payload.logger.error(`[payload-mcp] Error creating collection: ${errorMessage}`)\n\n return {\n content: [\n {\n type: 'text' as const,\n text: `❌ **Error creating collection**: ${errorMessage}`,\n },\n ],\n }\n }\n}\n\nexport const createCollectionTool = (\n server: McpServer,\n req: PayloadRequest,\n verboseLogs: boolean,\n collectionsDirPath: string,\n configFilePath: string,\n) => {\n const tool = async (\n collectionName: string,\n collectionDescription?: string,\n fields: any[] = [],\n hasUpload?: boolean,\n ) => {\n const payload = req.payload\n\n if (verboseLogs) {\n payload.logger.info(\n `[payload-mcp] Creating collection: ${collectionName}, fields: ${fields.length}, upload: ${hasUpload}`,\n )\n }\n\n try {\n const result = await createCollection(\n req,\n verboseLogs,\n collectionsDirPath,\n configFilePath,\n collectionName,\n collectionDescription,\n fields,\n hasUpload,\n )\n\n if (verboseLogs) {\n payload.logger.info(`[payload-mcp] Collection creation 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 creating collection ${collectionName}: ${errorMessage}`,\n )\n\n return {\n content: [\n {\n type: 'text' as const,\n text: `Error creating collection \"${collectionName}\": ${errorMessage}`,\n },\n ],\n }\n }\n }\n\n server.registerTool(\n 'createCollection',\n {\n description: toolSchemas.createCollection.description,\n inputSchema: toolSchemas.createCollection.parameters.shape,\n },\n async ({ collectionDescription, collectionName, fields, hasUpload }) => {\n return await tool(collectionName, collectionDescription, fields, hasUpload)\n },\n )\n}\n"],"names":["writeFileSync","join","validateCollectionFile","toolSchemas","createCollection","req","verboseLogs","collectionsDirPath","configFilePath","collectionName","collectionDescription","fields","hasUpload","payload","logger","info","length","capitalizedName","charAt","toUpperCase","slice","slug","replace","toLowerCase","generateFieldDefinition","field","fieldConfig","push","name","type","required","description","options","forEach","option","label","value","fieldDefinitions","map","collectionContent","fileName","filePath","startsWith","error","content","text","fs","existsSync","_ignore","validationResult","errorMessage","message","createCollectionTool","server","tool","result","Error","registerTool","inputSchema","parameters","shape"],"mappings":"AAGA,SAASA,aAAa,QAAQ,KAAI;AAClC,SAASC,IAAI,QAAQ,OAAM;AAE3B,SAASC,sBAAsB,QAAQ,kCAAiC;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T,EAAE,OAAOZ,OAAO;YACd,MAAMO,eAAeP,iBAAiBa,QAAQb,MAAMQ,OAAO,GAAG;YAC9DtC,QAAQC,MAAM,CAAC6B,KAAK,CAClB,CAAC,wCAAwC,EAAElC,eAAe,EAAE,EAAEyC,cAAc;YAG9E,OAAO;gBACLN,SAAS;oBACP;wBACEf,MAAM;wBACNgB,MAAM,CAAC,2BAA2B,EAAEpC,eAAe,GAAG,EAAEyC,cAAc;oBACxE;iBACD;YACH;QACF;IACF;IAEAG,OAAOI,YAAY,CACjB,oBACA;QACE1B,aAAa5B,YAAYC,gBAAgB,CAAC2B,WAAW;QACrD2B,aAAavD,YAAYC,gBAAgB,CAACuD,UAAU,CAACC,KAAK;IAC5D,GACA,OAAO,EAAElD,qBAAqB,EAAED,cAAc,EAAEE,MAAM,EAAEC,SAAS,EAAE;QACjE,OAAO,MAAM0C,KAAK7C,gBAAgBC,uBAAuBC,QAAQC;IACnE;AAEJ,EAAC"}
|
|
1
|
+
{"version":3,"sources":["../../../../src/mcp/tools/collection/create.ts"],"sourcesContent":["import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'\nimport type { PayloadRequest } from 'payload'\n\nimport { writeFileSync } from 'fs'\nimport { join } from 'path'\n\nimport { generateFieldDefinitionString } from '../../helpers/fields.js'\nimport { validateCollectionFile } from '../../helpers/fileValidation.js'\nimport { toolSchemas } from '../schemas.js'\n\nexport const createCollection = async (\n req: PayloadRequest,\n verboseLogs: boolean,\n collectionsDirPath: string,\n configFilePath: string,\n collectionName: string,\n collectionDescription: string | undefined,\n fields: any[],\n hasUpload: boolean | undefined,\n) => {\n const payload = req.payload\n if (verboseLogs) {\n payload.logger.info(\n `[payload-mcp] Creating collection: ${collectionName} with ${fields.length} fields`,\n )\n }\n\n const capitalizedName = collectionName.charAt(0).toUpperCase() + collectionName.slice(1)\n const slug = collectionName\n .replace(/([A-Z])/g, '-$1')\n .toLowerCase()\n .replace(/^-/, '')\n\n if (verboseLogs) {\n payload.logger.info(`[payload-mcp] Generated slug: ${slug} for collection: ${collectionName}`)\n }\n\n const fieldDefinitions = fields.map(generateFieldDefinitionString).join('\\n')\n\n // Generate collection file content\n const collectionContent = `import type { CollectionConfig } from 'payload'\n\nexport const ${capitalizedName}: CollectionConfig = {\n slug: '${slug}',${\n collectionDescription\n ? `\n admin: {\n description: '${collectionDescription}',\n },`\n : ''\n }${\n hasUpload\n ? `\n upload: true,`\n : ''\n }\n fields: [\n${fieldDefinitions}\n ],\n}\n`\n\n try {\n // Validate the collection name and path\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 // Check if file already exists\n try {\n const fs = await import('fs')\n if (fs.existsSync(filePath)) {\n return {\n content: [\n {\n type: 'text' as const,\n text: `❌ **Error**: Collection file already exists: ${fileName}`,\n },\n ],\n }\n }\n } catch (_ignore) {\n // File doesn't exist, which is what we want\n }\n\n // Write the collection file\n writeFileSync(filePath, collectionContent, 'utf8')\n if (verboseLogs) {\n payload.logger.info(`[payload-mcp] Successfully created collection file: ${filePath}`)\n }\n\n // Validate the generated file\n const validationResult = await validateCollectionFile(fileName)\n if (validationResult.error) {\n return {\n content: [\n {\n type: 'text' as const,\n text: `❌ **Error**: Generated 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 created successfully!**\n**File**: \\`${fileName}\\`\n**Collection Config:**\n\\`\\`\\`typescript\n${collectionContent}\n\\`\\`\\``,\n },\n ],\n }\n } catch (error) {\n const errorMessage = (error as Error).message\n payload.logger.error(`[payload-mcp] Error creating collection: ${errorMessage}`)\n\n return {\n content: [\n {\n type: 'text' as const,\n text: `❌ **Error creating collection**: ${errorMessage}`,\n },\n ],\n }\n }\n}\n\nexport const createCollectionTool = (\n server: McpServer,\n req: PayloadRequest,\n verboseLogs: boolean,\n collectionsDirPath: string,\n configFilePath: string,\n) => {\n const tool = async (\n collectionName: string,\n collectionDescription?: string,\n fields: any[] = [],\n hasUpload?: boolean,\n ) => {\n const payload = req.payload\n\n if (verboseLogs) {\n payload.logger.info(\n `[payload-mcp] Creating collection: ${collectionName}, fields: ${fields.length}, upload: ${hasUpload}`,\n )\n }\n\n try {\n const result = await createCollection(\n req,\n verboseLogs,\n collectionsDirPath,\n configFilePath,\n collectionName,\n collectionDescription,\n fields,\n hasUpload,\n )\n\n if (verboseLogs) {\n payload.logger.info(`[payload-mcp] Collection creation 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 creating collection ${collectionName}: ${errorMessage}`,\n )\n\n return {\n content: [\n {\n type: 'text' as const,\n text: `Error creating collection \"${collectionName}\": ${errorMessage}`,\n },\n ],\n }\n }\n }\n\n server.registerTool(\n 'createCollection',\n {\n description: toolSchemas.createCollection.description,\n inputSchema: toolSchemas.createCollection.parameters.shape,\n },\n async ({ collectionDescription, collectionName, fields, hasUpload }) => {\n return await tool(collectionName, collectionDescription, fields, hasUpload)\n },\n )\n}\n"],"names":["writeFileSync","join","generateFieldDefinitionString","validateCollectionFile","toolSchemas","createCollection","req","verboseLogs","collectionsDirPath","configFilePath","collectionName","collectionDescription","fields","hasUpload","payload","logger","info","length","capitalizedName","charAt","toUpperCase","slice","slug","replace","toLowerCase","fieldDefinitions","map","collectionContent","fileName","filePath","startsWith","error","content","type","text","fs","existsSync","_ignore","validationResult","errorMessage","message","createCollectionTool","server","tool","result","Error","registerTool","description","inputSchema","parameters","shape"],"mappings":"AAGA,SAASA,aAAa,QAAQ,KAAI;AAClC,SAASC,IAAI,QAAQ,OAAM;AAE3B,SAASC,6BAA6B,QAAQ,0BAAyB;AACvE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,EAAEE,OAAOK,MAAM,CAAC,UAAU,EAAEJ,WAAW;QAE1G;QAEA,IAAI;YACF,MAAM+B,SAAS,MAAMvC,iBACnBC,KACAC,aACAC,oBACAC,gBACAC,gBACAC,uBACAC,QACAC;YAGF,IAAIN,aAAa;gBACfO,QAAQC,MAAM,CAACC,IAAI,CAAC,CAAC,iDAAiD,EAAEN,gBAAgB;YAC1F;YAEA,OAAOkC;QACT,EAAE,OAAOb,OAAO;YACd,MAAMQ,eAAeR,iBAAiBc,QAAQd,MAAMS,OAAO,GAAG;YAC9D1B,QAAQC,MAAM,CAACgB,KAAK,CAClB,CAAC,wCAAwC,EAAErB,eAAe,EAAE,EAAE6B,cAAc;YAG9E,OAAO;gBACLP,SAAS;oBACP;wBACEC,MAAM;wBACNC,MAAM,CAAC,2BAA2B,EAAExB,eAAe,GAAG,EAAE6B,cAAc;oBACxE;iBACD;YACH;QACF;IACF;IAEAG,OAAOI,YAAY,CACjB,oBACA;QACEC,aAAa3C,YAAYC,gBAAgB,CAAC0C,WAAW;QACrDC,aAAa5C,YAAYC,gBAAgB,CAAC4C,UAAU,CAACC,KAAK;IAC5D,GACA,OAAO,EAAEvC,qBAAqB,EAAED,cAAc,EAAEE,MAAM,EAAEC,SAAS,EAAE;QACjE,OAAO,MAAM8B,KAAKjC,gBAAgBC,uBAAuBC,QAAQC;IACnE;AAEJ,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"delete.d.ts","sourceRoot":"","sources":["../../../../src/mcp/tools/collection/delete.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAA;AACxE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"delete.d.ts","sourceRoot":"","sources":["../../../../src/mcp/tools/collection/delete.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAA;AACxE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAQ7C,eAAO,MAAM,gBAAgB,QACtB,cAAc,eACN,OAAO,sBACA,MAAM,kBACV,MAAM,kBACN,MAAM,mBACL,OAAO,gBACV,OAAO;;;;;CAiItB,CAAA;AAED,eAAO,MAAM,oBAAoB,WACvB,SAAS,OACZ,cAAc,eACN,OAAO,sBACA,MAAM,kBACV,MAAM,SA0DvB,CAAA"}
|
|
@@ -1,18 +1,7 @@
|
|
|
1
1
|
import { readFileSync, unlinkSync, writeFileSync } from 'fs';
|
|
2
2
|
import { join } from 'path';
|
|
3
|
+
import { removeCollectionFromConfig } from '../../helpers/config.js';
|
|
3
4
|
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
5
|
export const deleteCollection = (req, verboseLogs, collectionsDirPath, configFilePath, collectionName, confirmDeletion, updateConfig)=>{
|
|
17
6
|
const payload = req.payload;
|
|
18
7
|
if (verboseLogs) {
|
|
@@ -1 +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.registerTool(\n 'deleteCollection',\n {\n description: toolSchemas.deleteCollection.description,\n inputSchema: toolSchemas.deleteCollection.parameters.shape,\n },\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","registerTool","description","inputSchema","parameters","shape"],"mappings":"AAGA,SAASA,YAAY,EAAEC,UAAU,EAAEC,aAAa,QAAQ,KAAI;AAC5D,SAASC,IAAI,Q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T,EAAE,OAAOX,OAAO;YACd,MAAMK,eAAeL,iBAAiBY,QAAQZ,MAAMM,OAAO,GAAG;YAC9DnB,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,OAAOI,YAAY,CACjB,oBACA;QACEC,aAAa3C,YAAYS,gBAAgB,CAACkC,WAAW;QACrDC,aAAa5C,YAAYS,gBAAgB,CAACoC,UAAU,CAACC,KAAK;IAC5D,GACA,CAAC,EAAE3C,cAAc,EAAEW,eAAe,EAAEC,YAAY,EAAE;QAChD,OAAOwB,KAAKpC,gBAAgBW,iBAAiBC;IAC/C;AAEJ,EAAC"}
|
|
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 { removeCollectionFromConfig } from '../../helpers/config.js'\nimport { toolSchemas } from '../schemas.js'\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.registerTool(\n 'deleteCollection',\n {\n description: toolSchemas.deleteCollection.description,\n inputSchema: toolSchemas.deleteCollection.parameters.shape,\n },\n ({ collectionName, confirmDeletion, updateConfig }) => {\n return tool(collectionName, confirmDeletion, updateConfig)\n },\n )\n}\n"],"names":["readFileSync","unlinkSync","writeFileSync","join","removeCollectionFromConfig","toolSchemas","deleteCollection","req","verboseLogs","collectionsDirPath","configFilePath","collectionName","confirmDeletion","updateConfig","payload","logger","info","warn","content","type","text","capitalizedName","charAt","toUpperCase","slice","collectionFilePath","startsWith","error","fileExists","configContent","configExists","responseText","operationsPerformed","errorMessage","message","updatedConfigContent","deleteCollectionTool","server","tool","result","Error","registerTool","description","inputSchema","parameters","shape"],"mappings":"AAGA,SAASA,YAAY,EAAEC,UAAU,EAAEC,aAAa,QAAQ,KAAI;AAC5D,SAASC,IAAI,QAAQ,OAAM;AAE3B,SAASC,0BAA0B,QAAQ,0BAAyB;AACpE,SAASC,WAAW,QAAQ,gBAAe;AAE3C,OAAO,MAAMC,mBAAmB,CAC9BC,KACAC,aACAC,oBACAC,gBACAC,gBACAC,iBACAC;IAEA,MAAMC,UAAUP,IAAIO,OAAO;IAE3B,IAAIN,aAAa;QACfM,QAAQC,MAAM,CAACC,IAAI,CAAC,CAAC,+CAA+C,EAAEL,gBAAgB;IACxF;IAEA,IAAI,CAACC,iBAAiB;QACpBE,QAAQC,MAAM,CAACE,IAAI,CAAC,CAAC,iDAAiD,EAAEN,gBAAgB;QACxF,OAAO;YACLO,SAAS;gBACP;oBACEC,MAAM;oBACNC,MAAM,CAAC,2FAA2F,EAAET,eAAe,EAAE,CAAC;gBACxH;aACD;QACH;IACF;IAEA,MAAMU,kBAAkBV,eAAeW,MAAM,CAAC,GAAGC,WAAW,KAAKZ,eAAea,KAAK,CAAC;IACtF,MAAMC,qBAAqBtB,KAAKM,oBAAoB,GAAGY,gBAAgB,GAAG,CAAC;IAE3E,sEAAsE;IACtE,IAAI,CAACI,mBAAmBC,UAAU,CAACjB,qBAAqB;QACtDK,QAAQC,MAAM,CAACY,KAAK,CAAC,CAAC,iDAAiD,EAAEF,oBAAoB;QAC7F,OAAO;YACLP,SAAS;gBACP;oBACEC,MAAM;oBACNC,MAAM;gBACR;aACD;QACH;IACF;IAEA,IAAI;QACF,kC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ACd,MAAMM,eAAeN,iBAAiBa,QAAQb,MAAMO,OAAO,GAAG;YAC9DpB,QAAQC,MAAM,CAACY,KAAK,CAClB,CAAC,wCAAwC,EAAEhB,eAAe,EAAE,EAAEsB,cAAc;YAG9E,OAAO;gBACLf,SAAS;oBACP;wBACEC,MAAM;wBACNC,MAAM,CAAC,2BAA2B,EAAET,eAAe,GAAG,EAAEsB,cAAc;oBACxE;iBACD;YACH;QACF;IACF;IAEAI,OAAOI,YAAY,CACjB,oBACA;QACEC,aAAarC,YAAYC,gBAAgB,CAACoC,WAAW;QACrDC,aAAatC,YAAYC,gBAAgB,CAACsC,UAAU,CAACC,KAAK;IAC5D,GACA,CAAC,EAAElC,cAAc,EAAEC,eAAe,EAAEC,YAAY,EAAE;QAChD,OAAOyB,KAAK3B,gBAAgBC,iBAAiBC;IAC/C;AAEJ,EAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
2
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,
|
|
3
|
+
export declare const updateConfig: (req: PayloadRequest, verboseLogs: boolean, configFilePath: string, updateType: string, collectionName?: string, adminConfig?: any, databaseConfig?: any, pluginUpdates?: any, newContent?: string) => {
|
|
4
4
|
content: {
|
|
5
5
|
type: "text";
|
|
6
6
|
text: string;
|
|
@@ -1 +1 @@
|
|
|
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,
|
|
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"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { readFileSync, writeFileSync } from 'fs';
|
|
2
2
|
import { addCollectionToConfig, removeCollectionFromConfig, updateAdminConfig, updateDatabaseConfig, updatePluginsConfig } from '../../helpers/config.js';
|
|
3
3
|
import { toolSchemas } from '../schemas.js';
|
|
4
|
-
export const updateConfig = (req, verboseLogs, configFilePath, updateType, collectionName, adminConfig, databaseConfig, pluginUpdates,
|
|
4
|
+
export const updateConfig = (req, verboseLogs, configFilePath, updateType, collectionName, adminConfig, databaseConfig, pluginUpdates, newContent)=>{
|
|
5
5
|
const payload = req.payload;
|
|
6
6
|
if (verboseLogs) {
|
|
7
7
|
payload.logger.info(`[payload-mcp] Updating config with update type: ${updateType}`);
|
|
@@ -180,13 +180,13 @@ ${updatedContent}
|
|
|
180
180
|
}
|
|
181
181
|
};
|
|
182
182
|
export const updateConfigTool = (server, req, verboseLogs, configFilePath)=>{
|
|
183
|
-
const tool = ({ adminConfig, collectionName, databaseConfig,
|
|
183
|
+
const tool = ({ adminConfig, collectionName, databaseConfig, newContent, pluginUpdates, updateType })=>{
|
|
184
184
|
const payload = req.payload;
|
|
185
185
|
if (verboseLogs) {
|
|
186
186
|
payload.logger.info(`[payload-mcp] Updating config: ${updateType}`);
|
|
187
187
|
}
|
|
188
188
|
try {
|
|
189
|
-
const result = updateConfig(req, verboseLogs, configFilePath, updateType, collectionName, adminConfig, databaseConfig, pluginUpdates,
|
|
189
|
+
const result = updateConfig(req, verboseLogs, configFilePath, updateType, collectionName, adminConfig, databaseConfig, pluginUpdates, newContent);
|
|
190
190
|
if (verboseLogs) {
|
|
191
191
|
payload.logger.info(`[payload-mcp] Config update completed for: ${updateType}`);
|
|
192
192
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/mcp/tools/config/update.ts"],"sourcesContent":["import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'\nimport type { PayloadRequest } from 'payload'\n\nimport { readFileSync, writeFileSync } from 'fs'\n\nimport {\n addCollectionToConfig,\n removeCollectionFromConfig,\n updateAdminConfig,\n updateDatabaseConfig,\n updatePluginsConfig,\n} from '../../helpers/config.js'\nimport { toolSchemas } from '../schemas.js'\n\nexport const updateConfig = (\n req: PayloadRequest,\n verboseLogs: boolean,\n configFilePath: string,\n updateType: string,\n collectionName?: string,\n adminConfig?: any,\n databaseConfig?: any,\n pluginUpdates?: any,\n generalConfig?: any,\n newContent?: string,\n) => {\n const payload = req.payload\n if (verboseLogs) {\n payload.logger.info(`[payload-mcp] Updating config with update type: ${updateType}`)\n }\n\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 try {\n // Read current config\n let currentContent: string\n try {\n currentContent = readFileSync(configFilePath, 'utf8')\n } catch (_ignore) {\n return {\n content: [\n {\n type: 'text' as const,\n text: `❌ **Error**: Config file not found: ${configFilePath}`,\n },\n ],\n }\n }\n\n let updatedContent: string\n let updateSummary: string[] = []\n\n switch (updateType) {\n case 'add_collection':\n if (!collectionName) {\n return {\n content: [\n {\n type: 'text' as const,\n text: '❌ **Error**: No collection name provided for add_collection update type',\n },\n ],\n }\n }\n updatedContent = addCollectionToConfig(currentContent, collectionName)\n updateSummary = [`Added collection: ${collectionName}`]\n break\n\n case 'remove_collection':\n if (!collectionName) {\n return {\n content: [\n {\n type: 'text' as const,\n text: '❌ **Error**: No collection name provided for remove_collection update type',\n },\n ],\n }\n }\n updatedContent = removeCollectionFromConfig(currentContent, collectionName)\n updateSummary = [`Removed collection: ${collectionName}`]\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 config content']\n break\n\n case 'update_admin':\n if (!adminConfig) {\n return {\n content: [\n {\n type: 'text' as const,\n text: '❌ **Error**: No admin config provided for update_admin update type',\n },\n ],\n }\n }\n updatedContent = updateAdminConfig(currentContent, adminConfig)\n updateSummary = Object.keys(adminConfig).map((key) => `Updated admin config: ${key}`)\n break\n\n case 'update_database':\n if (!databaseConfig) {\n return {\n content: [\n {\n type: 'text' as const,\n text: '❌ **Error**: No database config provided for update_database update type',\n },\n ],\n }\n }\n updatedContent = updateDatabaseConfig(currentContent, databaseConfig)\n updateSummary = Object.keys(databaseConfig).map((key) => `Updated database config: ${key}`)\n break\n\n case 'update_plugins':\n if (!pluginUpdates) {\n return {\n content: [\n {\n type: 'text' as const,\n text: '❌ **Error**: No plugin updates provided for update_plugins update type',\n },\n ],\n }\n }\n updatedContent = updatePluginsConfig(currentContent, pluginUpdates)\n updateSummary = []\n if (pluginUpdates.add) {\n updateSummary.push(`Added plugins: ${pluginUpdates.add.join(', ')}`)\n }\n if (pluginUpdates.remove) {\n updateSummary.push(`Removed plugins: ${pluginUpdates.remove.join(', ')}`)\n }\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(configFilePath, updatedContent, 'utf8')\n if (verboseLogs) {\n payload.logger.info(`[payload-mcp] Successfully updated config file: ${configFilePath}`)\n }\n\n return {\n content: [\n {\n type: 'text' as const,\n text: `✅ **Config updated successfully!**\n\n**File**: \\`${configFilePath}\\`\n**Update Type**: ${updateType}\n\n**Changes Made**:\n${updateSummary.map((summary) => `- ${summary}`).join('\\n')}\n\n**Updated Config Content:**\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 config: ${errorMessage}`)\n return {\n content: [\n {\n type: 'text' as const,\n text: `❌ **Error updating config**: ${errorMessage}`,\n },\n ],\n }\n }\n}\n\nexport const updateConfigTool = (\n server: McpServer,\n req: PayloadRequest,\n verboseLogs: boolean,\n configFilePath: string,\n) => {\n const tool = ({\n adminConfig,\n collectionName,\n databaseConfig,\n generalConfig,\n newContent,\n pluginUpdates,\n updateType,\n }: {\n adminConfig?: any\n collectionName?: string\n databaseConfig?: any\n generalConfig?: any\n newContent?: string\n pluginUpdates?: any\n updateType: string\n }) => {\n const payload = req.payload\n\n if (verboseLogs) {\n payload.logger.info(`[payload-mcp] Updating config: ${updateType}`)\n }\n\n try {\n const result = updateConfig(\n req,\n verboseLogs,\n configFilePath,\n updateType,\n collectionName,\n adminConfig,\n databaseConfig,\n pluginUpdates,\n generalConfig,\n newContent,\n )\n\n if (verboseLogs) {\n payload.logger.info(`[payload-mcp] Config update completed for: ${updateType}`)\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 updating config: ${errorMessage}`)\n\n return {\n content: [\n {\n type: 'text' as const,\n text: `Error updating config: ${errorMessage}`,\n },\n ],\n }\n }\n }\n\n server.registerTool(\n 'updateConfig',\n {\n description: toolSchemas.updateConfig.description,\n inputSchema: toolSchemas.updateConfig.parameters.shape,\n },\n (args) => {\n return tool(args)\n },\n )\n}\n"],"names":["readFileSync","writeFileSync","addCollectionToConfig","removeCollectionFromConfig","updateAdminConfig","updateDatabaseConfig","updatePluginsConfig","toolSchemas","updateConfig","req","verboseLogs","configFilePath","updateType","collectionName","adminConfig","databaseConfig","pluginUpdates","generalConfig","newContent","payload","logger","info","startsWith","process","cwd","error","content","type","text","currentContent","_ignore","updatedContent","updateSummary","Object","keys","map","key","add","push","join","remove","summary","errorMessage","message","updateConfigTool","server","tool","result","Error","registerTool","description","inputSchema","parameters","shape","args"],"mappings":"AAGA,SAASA,YAAY,EAAEC,aAAa,QAAQ,KAAI;AAEhD,SACEC,qBAAqB,EACrBC,0BAA0B,EAC1BC,iBAAiB,EACjBC,oBAAoB,EACpBC,mBAAmB,QACd,0BAAyB;AAChC,SAASC,WAAW,QAAQ,gBAAe;AAE3C,OAAO,MAAMC,eAAe,CAC1BC,KACAC,aACAC,gBACAC,YACAC,gBACAC,aACAC,gBACAC,eACAC,eACAC;IAEA,MAAMC,UAAUV,IAAIU,OAAO;IAC3B,IAAIT,aAAa;QACfS,QAAQC,MAAM,CAACC,IAAI,CAAC,CAAC,gDAAgD,EAAET,YAAY;IACrF;IAEA,sEAAsE;IACtE,IAAI,CAACD,eAAeW,UAAU,CAACC,QAAQC,GAAG,OAAO,CAACb,eAAeW,UAAU,CAAC,MAAM;QAChFH,QAAQC,MAAM,CAACK,KAAK,CAAC,CAAC,6CAA6C,EAAEd,gBAAgB;QACrF,OAAO;YACLe,SAAS;gBACP;oBACEC,MAAM;oBACNC,MAAM;gBACR;aACD;QACH;IACF;IAEA,IAAI;QACF,sBAAsB;QACtB,IAAIC;QACJ,IAAI;YACFA,iBAAiB7B,aAAaW,gBAAgB;QAChD,EAAE,OAAOmB,SAAS;YAChB,OAAO;gBACLJ,SAAS;oBACP;wBACEC,MAAM;wBACNC,MAAM,CAAC,oCAAoC,EAAEjB,gBAAgB;oBAC/D;iB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,EAAC;AAED,OAAO,MAAME,mBAAmB,CAC9BC,QACApC,KACAC,aACAC;IAEA,MAAMmC,OAAO,CAAC,EACZhC,WAAW,EACXD,cAAc,EACdE,cAAc,EACdE,aAAa,EACbC,UAAU,EACVF,aAAa,EACbJ,UAAU,EASX;QACC,MAAMO,UAAUV,IAAIU,OAAO;QAE3B,IAAIT,aAAa;YACfS,QAAQC,MAAM,CAACC,IAAI,CAAC,CAAC,+BAA+B,EAAET,YAAY;QACpE;QAEA,IAAI;YACF,MAAMmC,SAASvC,aACbC,KACAC,aACAC,gBACAC,YACAC,gBACAC,aACAC,gBACAC,eACAC,eACAC;YAGF,IAAIR,aAAa;gBACfS,QAAQC,MAAM,CAACC,IAAI,CAAC,CAAC,2CAA2C,EAAET,YAAY;YAChF;YAEA,OAAOmC;QACT,EAAE,OAAOtB,OAAO;YACd,MAAMiB,eAAejB,iBAAiBuB,QAAQvB,MAAMkB,OAAO,GAAG;YAC9DxB,QAAQC,MAAM,CAACK,KAAK,CAAC,CAAC,qCAAqC,EAAEiB,cAAc;YAE3E,OAAO;gBACLhB,SAAS;oBACP;wBACEC,MAAM;wBACNC,MAAM,CAAC,uBAAuB,EAAEc,cAAc;oBAChD;iBACD;YACH;QACF;IACF;IAEAG,OAAOI,YAAY,CACjB,gBACA;QACEC,aAAa3C,YAAYC,YAAY,CAAC0C,WAAW;QACjDC,aAAa5C,YAAYC,YAAY,CAAC4C,UAAU,CAACC,KAAK;IACxD,GACA,CAACC;QACC,OAAOR,KAAKQ;IACd;AAEJ,EAAC"}
|
|
1
|
+
{"version":3,"sources":["../../../../src/mcp/tools/config/update.ts"],"sourcesContent":["import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'\nimport type { PayloadRequest } from 'payload'\n\nimport { readFileSync, writeFileSync } from 'fs'\n\nimport {\n addCollectionToConfig,\n removeCollectionFromConfig,\n updateAdminConfig,\n updateDatabaseConfig,\n updatePluginsConfig,\n} from '../../helpers/config.js'\nimport { toolSchemas } from '../schemas.js'\n\nexport const updateConfig = (\n req: PayloadRequest,\n verboseLogs: boolean,\n configFilePath: string,\n updateType: string,\n collectionName?: string,\n adminConfig?: any,\n databaseConfig?: any,\n pluginUpdates?: any,\n newContent?: string,\n) => {\n const payload = req.payload\n if (verboseLogs) {\n payload.logger.info(`[payload-mcp] Updating config with update type: ${updateType}`)\n }\n\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 try {\n // Read current config\n let currentContent: string\n try {\n currentContent = readFileSync(configFilePath, 'utf8')\n } catch (_ignore) {\n return {\n content: [\n {\n type: 'text' as const,\n text: `❌ **Error**: Config file not found: ${configFilePath}`,\n },\n ],\n }\n }\n\n let updatedContent: string\n let updateSummary: string[] = []\n\n switch (updateType) {\n case 'add_collection':\n if (!collectionName) {\n return {\n content: [\n {\n type: 'text' as const,\n text: '❌ **Error**: No collection name provided for add_collection update type',\n },\n ],\n }\n }\n updatedContent = addCollectionToConfig(currentContent, collectionName)\n updateSummary = [`Added collection: ${collectionName}`]\n break\n\n case 'remove_collection':\n if (!collectionName) {\n return {\n content: [\n {\n type: 'text' as const,\n text: '❌ **Error**: No collection name provided for remove_collection update type',\n },\n ],\n }\n }\n updatedContent = removeCollectionFromConfig(currentContent, collectionName)\n updateSummary = [`Removed collection: ${collectionName}`]\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 config content']\n break\n\n case 'update_admin':\n if (!adminConfig) {\n return {\n content: [\n {\n type: 'text' as const,\n text: '❌ **Error**: No admin config provided for update_admin update type',\n },\n ],\n }\n }\n updatedContent = updateAdminConfig(currentContent, adminConfig)\n updateSummary = Object.keys(adminConfig).map((key) => `Updated admin config: ${key}`)\n break\n\n case 'update_database':\n if (!databaseConfig) {\n return {\n content: [\n {\n type: 'text' as const,\n text: '❌ **Error**: No database config provided for update_database update type',\n },\n ],\n }\n }\n updatedContent = updateDatabaseConfig(currentContent, databaseConfig)\n updateSummary = Object.keys(databaseConfig).map((key) => `Updated database config: ${key}`)\n break\n\n case 'update_plugins':\n if (!pluginUpdates) {\n return {\n content: [\n {\n type: 'text' as const,\n text: '❌ **Error**: No plugin updates provided for update_plugins update type',\n },\n ],\n }\n }\n updatedContent = updatePluginsConfig(currentContent, pluginUpdates)\n updateSummary = []\n if (pluginUpdates.add) {\n updateSummary.push(`Added plugins: ${pluginUpdates.add.join(', ')}`)\n }\n if (pluginUpdates.remove) {\n updateSummary.push(`Removed plugins: ${pluginUpdates.remove.join(', ')}`)\n }\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(configFilePath, updatedContent, 'utf8')\n if (verboseLogs) {\n payload.logger.info(`[payload-mcp] Successfully updated config file: ${configFilePath}`)\n }\n\n return {\n content: [\n {\n type: 'text' as const,\n text: `✅ **Config updated successfully!**\n\n**File**: \\`${configFilePath}\\`\n**Update Type**: ${updateType}\n\n**Changes Made**:\n${updateSummary.map((summary) => `- ${summary}`).join('\\n')}\n\n**Updated Config Content:**\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 config: ${errorMessage}`)\n return {\n content: [\n {\n type: 'text' as const,\n text: `❌ **Error updating config**: ${errorMessage}`,\n },\n ],\n }\n }\n}\n\nexport const updateConfigTool = (\n server: McpServer,\n req: PayloadRequest,\n verboseLogs: boolean,\n configFilePath: string,\n) => {\n const tool = ({\n adminConfig,\n collectionName,\n databaseConfig,\n newContent,\n pluginUpdates,\n updateType,\n }: {\n adminConfig?: any\n collectionName?: string\n databaseConfig?: any\n newContent?: string\n pluginUpdates?: any\n updateType: string\n }) => {\n const payload = req.payload\n\n if (verboseLogs) {\n payload.logger.info(`[payload-mcp] Updating config: ${updateType}`)\n }\n\n try {\n const result = updateConfig(\n req,\n verboseLogs,\n configFilePath,\n updateType,\n collectionName,\n adminConfig,\n databaseConfig,\n pluginUpdates,\n newContent,\n )\n\n if (verboseLogs) {\n payload.logger.info(`[payload-mcp] Config update completed for: ${updateType}`)\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 updating config: ${errorMessage}`)\n\n return {\n content: [\n {\n type: 'text' as const,\n text: `Error updating config: ${errorMessage}`,\n },\n ],\n }\n }\n }\n\n server.registerTool(\n 'updateConfig',\n {\n description: toolSchemas.updateConfig.description,\n inputSchema: toolSchemas.updateConfig.parameters.shape,\n },\n (args) => {\n return tool(args)\n },\n )\n}\n"],"names":["readFileSync","writeFileSync","addCollectionToConfig","removeCollectionFromConfig","updateAdminConfig","updateDatabaseConfig","updatePluginsConfig","toolSchemas","updateConfig","req","verboseLogs","configFilePath","updateType","collectionName","adminConfig","databaseConfig","pluginUpdates","newContent","payload","logger","info","startsWith","process","cwd","error","content","type","text","currentContent","_ignore","updatedContent","updateSummary","Object","keys","map","key","add","push","join","remove","summary","errorMessage","message","updateConfigTool","server","tool","result","Error","registerTool","description","inputSchema","parameters","shape","args"],"mappings":"AAGA,SAASA,YAAY,EAAEC,aAAa,QAAQ,KAAI;AAEhD,SACEC,qBAAqB,EACrBC,0BAA0B,EAC1BC,iBAAiB,EACjBC,oBAAoB,EACpBC,mBAAmB,QACd,0BAAyB;AAChC,SAASC,WAAW,QAAQ,gBAAe;AAE3C,OAAO,MAAMC,eAAe,CAC1BC,KACAC,aACAC,gBACAC,YACAC,gBACAC,aACAC,gBACAC,eACAC;IAEA,MAAMC,UAAUT,IAAIS,OA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M;wBACNC,MAAM,CAAC,uBAAuB,EAAEc,cAAc;oBAChD;iBACD;YACH;QACF;IACF;IAEAG,OAAOI,YAAY,CACjB,gBACA;QACEC,aAAa1C,YAAYC,YAAY,CAACyC,WAAW;QACjDC,aAAa3C,YAAYC,YAAY,CAAC2C,UAAU,CAACC,KAAK;IACxD,GACA,CAACC;QACC,OAAOR,KAAKQ;IACd;AAEJ,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"update.d.ts","sourceRoot":"","sources":["../../../../src/mcp/tools/global/update.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAA;AACxE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAC9C,OAAO,KAAK,EAAE,cAAc,EAAc,SAAS,EAAE,MAAM,SAAS,CAAA;AAIpE,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAA;
|
|
1
|
+
{"version":3,"file":"update.d.ts","sourceRoot":"","sources":["../../../../src/mcp/tools/global/update.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAA;AACxE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAC9C,OAAO,KAAK,EAAE,cAAc,EAAc,SAAS,EAAE,MAAM,SAAS,CAAA;AAIpE,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAA;AAU9D,eAAO,MAAM,gBAAgB,WACnB,SAAS,OACZ,cAAc,QACb,SAAS,eACF,OAAO,cACR,MAAM,WACT,qBAAqB,CAAC,SAAS,CAAC,UACjC,WAAW,SAuLpB,CAAA"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import { toCamelCase } from '../../../utils/camelCase.js';
|
|
3
|
+
import { getGlobalVirtualFieldNames, stripVirtualFields } from '../../../utils/getVirtualFieldNames.js';
|
|
3
4
|
import { convertCollectionSchemaToZod } from '../../../utils/schemaConversion/convertCollectionSchemaToZod.js';
|
|
4
5
|
import { toolSchemas } from '../schemas.js';
|
|
5
6
|
export const updateGlobalTool = (server, req, user, verboseLogs, globalSlug, globals, schema)=>{
|
|
@@ -13,6 +14,8 @@ export const updateGlobalTool = (server, req, user, verboseLogs, globalSlug, glo
|
|
|
13
14
|
let parsedData;
|
|
14
15
|
try {
|
|
15
16
|
parsedData = JSON.parse(data);
|
|
17
|
+
const virtualFieldNames = getGlobalVirtualFieldNames(payload.config, globalSlug);
|
|
18
|
+
parsedData = stripVirtualFields(parsedData, virtualFieldNames);
|
|
16
19
|
if (verboseLogs) {
|
|
17
20
|
payload.logger.info(`[payload-mcp] Parsed data for ${globalSlug}: ${JSON.stringify(parsedData)}`);
|
|
18
21
|
}
|