@simonecoelhosfo/optimizely-mcp-server
Version:
Optimizely MCP Server for AI assistants with integrated CLI tools
107 lines • 5.65 kB
JavaScript
/**
* Migrate Entities Tool - Individual Module
* @description Delegates to EntityMigrationOrchestrator for entity migrations
* @since 2025-08-04
* @author Tool Modularization Team
*
* Migration Status: COMPLETED
* Original Method: OptimizelyMCPTools.migrateEntities
* Complexity: HIGH
* Dependencies: logger, errorMapper, EntityMigrationOrchestrator
*/
import { EntityMigrationOrchestrator } from '../../migration/EntityMigrationOrchestrator.js';
/**
* Creates the Migrate Entities tool with injected dependencies
* @param deps - Injected dependencies (storage, logger, errorMapper, etc.)
* @returns Tool definition with handler
*/
export function createMigrateEntitiesTool(deps) {
return {
name: 'migrate_entities',
requiresCache: true,
category: 'operations',
description: 'Migrates entities from source to destination project with intelligent dependency resolution and reference transformation',
handler: async (config) => {
try {
deps.logger.debug({
source: config.source.projectId,
destination: config.destination.projectId,
entityTypes: config.entities?.types,
dryRun: config.options?.dryRun
}, 'OptimizelyMCPTools.migrateEntities: Starting entity migration');
const logger = deps.logger;
// Use the existing cache manager - no need for temporary databases!
// We're just reading from source and writing to destination via API
// For source, always use the existing cache (read-only operations)
logger.info('MIGRATION DEBUG: About to create source tools');
const sourceTools = deps.toolsInstance;
logger.info('MIGRATION DEBUG: Created source tools successfully');
// For destination, if a different token is provided, create a new tools instance
// Otherwise use the same instance
let destTools = deps.toolsInstance;
if (config.destination.token) {
// Only create new instance if destination has different auth token
// Note: We can't create a new OptimizelyMCPTools instance directly
// because it only accepts a CacheManager in the constructor
// For now, we'll use the same instance and note this limitation
deps.logger.warn('Different destination token provided, but using same auth context. This is a known limitation.');
// TODO: Refactor OptimizelyMCPTools to support multiple API tokens
}
// Create migration orchestrator
logger.info('MIGRATION DEBUG: About to create EntityMigrationOrchestrator instance');
const orchestrator = new EntityMigrationOrchestrator(sourceTools, destTools, config // Type conversion
);
logger.info('MIGRATION DEBUG: Created EntityMigrationOrchestrator instance successfully');
// Track migration progress
const migrationId = `migration-${Date.now()}`;
const progressUpdates = [];
orchestrator.setProgressCallback((progress) => {
progressUpdates.push({
timestamp: new Date().toISOString(),
phase: progress.phase,
message: `${progress.overall.completedEntities}/${progress.overall.totalEntities} entities migrated`,
percent: Math.round((progress.overall.completedEntities / progress.overall.totalEntities) * 100),
details: progress.currentEntity
});
// Log progress
deps.logger.debug({
migrationId,
phase: progress.phase,
completed: progress.overall.completedEntities,
total: progress.overall.totalEntities,
failed: progress.overall.failedEntities,
skipped: progress.overall.skippedEntities
}, 'Migration progress update');
});
// Execute migration
logger.info('MIGRATION DEBUG: About to call orchestrator.execute()');
const result = await orchestrator.execute();
logger.info('MIGRATION DEBUG: orchestrator.execute() completed');
deps.logger.debug({
migrationId,
success: result.success,
summary: result.summary,
duration: result.duration
}, 'OptimizelyMCPTools.migrateEntities: Migration completed');
return {
result: result.success ? 'success' : 'error',
data: result,
metadata: {
migration_id: result.id,
progress_updates: progressUpdates
}
};
}
catch (error) {
deps.logger.error({
source: config.source.projectId,
destination: config.destination.projectId,
error: error.message,
stack: error.stack
}, 'OptimizelyMCPTools.migrateEntities: Migration failed');
throw deps.errorMapper.toMCPError(error, 'Entity migration failed');
}
}
};
}
//# sourceMappingURL=MigrateEntities.js.map