trigger_catalog_sync
Sync catalog data between versions in SAP Commerce Cloud. Specify catalog ID, source version, and target version to update product information.
Instructions
Trigger a catalog synchronization between versions
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| catalogId | Yes | Catalog ID to sync | |
| sourceVersion | Yes | Source catalog version (e.g., "Staged") | |
| targetVersion | Yes | Target catalog version (e.g., "Online") |
Implementation Reference
- src/hybris-client.ts:761-846 (handler)The core handler function for trigger_catalog_sync. It constructs and executes a Groovy script via HAC to find the appropriate CatalogVersionSyncJob, create a CatalogVersionSyncCronJobModel, save it, and perform the cron job to synchronize the catalog versions.async triggerCatalogSync( catalogId: string, sourceVersion: string, targetVersion: string ): Promise<{ success: boolean; message: string }> { // Use Groovy script to trigger catalog sync by creating a properly configured CronJob const escapedCatalogId = this.escapeGroovyString(catalogId); const escapedSource = this.escapeGroovyString(sourceVersion); const escapedTarget = this.escapeGroovyString(targetVersion); const script = ` import de.hybris.platform.catalog.model.synchronization.CatalogVersionSyncCronJobModel import de.hybris.platform.cronjob.enums.JobLogLevel try { def catalogVersionService = spring.getBean("catalogVersionService") def modelService = spring.getBean("modelService") def cronJobService = spring.getBean("cronJobService") def flexibleSearchService = spring.getBean("flexibleSearchService") def sourceCatalogVersion = catalogVersionService.getCatalogVersion("${escapedCatalogId}", "${escapedSource}") def targetCatalogVersion = catalogVersionService.getCatalogVersion("${escapedCatalogId}", "${escapedTarget}") if (sourceCatalogVersion == null) { println "ERROR: Source catalog version not found: ${escapedCatalogId}:${escapedSource}" return "SOURCE_NOT_FOUND" } if (targetCatalogVersion == null) { println "ERROR: Target catalog version not found: ${escapedCatalogId}:${escapedTarget}" return "TARGET_NOT_FOUND" } // Find sync job using flexible search def query = "SELECT {pk} FROM {CatalogVersionSyncJob} WHERE {sourceVersion} = ?source AND {targetVersion} = ?target" def params = [source: sourceCatalogVersion, target: targetCatalogVersion] def searchResult = flexibleSearchService.search(query, params) if (searchResult.result.isEmpty()) { println "ERROR: No sync job found for ${escapedCatalogId} ${escapedSource} -> ${escapedTarget}" println "Available sync jobs:" def allJobs = flexibleSearchService.search("SELECT {pk}, {code} FROM {CatalogVersionSyncJob}").result allJobs.each { job -> println " - " + job.code } return "SYNC_JOB_NOT_FOUND" } def syncJob = searchResult.result[0] println "Found sync job: " + syncJob.code // Create a new CronJob with all mandatory attributes def syncCronJob = modelService.create(CatalogVersionSyncCronJobModel.class) syncCronJob.setJob(syncJob) syncCronJob.setCode("mcp_sync_" + System.currentTimeMillis()) // Set all mandatory attributes syncCronJob.setCreateSavedValues(false) syncCronJob.setForceUpdate(false) syncCronJob.setLogToDatabase(false) syncCronJob.setLogToFile(false) syncCronJob.setLogLevelDatabase(JobLogLevel.WARNING) syncCronJob.setLogLevelFile(JobLogLevel.WARNING) modelService.save(syncCronJob) println "Created sync cronjob: " + syncCronJob.code // Trigger the cronjob cronJobService.performCronJob(syncCronJob, true) println "SUCCESS: Catalog sync triggered: ${escapedCatalogId} ${escapedSource} -> ${escapedTarget}" return "SUCCESS" } catch (Exception e) { println "ERROR: " + e.getMessage() e.printStackTrace() return "ERROR: " + e.getMessage() } `; const result = await this.executeGroovyScript(script); const output = result.output || ''; const execResult = String(result.result || ''); const success = output.includes('SUCCESS:') || execResult === 'SUCCESS'; const errorMatch = output.match(/ERROR: (.+)/); return { success, message: success ? `Catalog sync triggered: ${catalogId} ${sourceVersion} -> ${targetVersion}` : errorMatch ? errorMatch[1] : `Failed to sync: ${output || execResult || 'Unknown error'}`, }; }
- src/index.ts:302-321 (schema)Input schema definition for the trigger_catalog_sync tool, defining the required parameters and their descriptions for MCP tool validation.name: 'trigger_catalog_sync', description: 'Trigger a catalog synchronization between versions', inputSchema: { type: 'object', properties: { catalogId: { type: 'string', description: 'Catalog ID to sync', }, sourceVersion: { type: 'string', description: 'Source catalog version (e.g., "Staged")', }, targetVersion: { type: 'string', description: 'Target catalog version (e.g., "Online")', }, }, required: ['catalogId', 'sourceVersion', 'targetVersion'], },
- src/index.ts:454-460 (registration)Registration and dispatching logic in the MCP server request handler switch statement, which maps the tool name to the HybrisClient.triggerCatalogSync method call with input validation.case 'trigger_catalog_sync': result = await hybrisClient.triggerCatalogSync( validateString(args, 'catalogId', true), validateString(args, 'sourceVersion', true), validateString(args, 'targetVersion', true) ); break;