@simonecoelhosfo/optimizely-mcp-server
Version:
Optimizely MCP Server for AI assistants with integrated CLI tools
82 lines • 4.07 kB
JavaScript
/**
* Orchestrate Template Tool - Individual Module
* @description Handles template orchestration and entity creation workflows
* @since 2025-08-04
* @author Tool Modularization Team
*
* Migration Status: COMPLETED
* Original Method: OptimizelyMCPTools.orchestrateTemplate
* Complexity: HIGH
* Dependencies: logger, errorMapper, TemplateOrchestrationEngine, TemplateStore, entityRouter, cacheManager
*/
/**
* Creates the Orchestrate Template tool with injected dependencies
* @param deps - Injected dependencies (storage, logger, errorMapper, etc.)
* @returns Tool definition with handler
*/
export function createOrchestrateTemplateTool(deps) {
return {
name: 'orchestrate_template',
requiresCache: true,
category: 'operations',
description: 'Execute a Direct Template Architecture orchestration template. Templates must use template_format_version: 2 with entity_type fields. No system_template_id translation - direct entity creation',
handler: async (params) => {
const logger = deps.logger;
try {
// Lazy load orchestration components
const { TemplateOrchestrationEngine } = await import('../../orchestration/core/TemplateOrchestrationEngine.js');
const { TemplateStore } = await import('../../orchestration/storage/TemplateStore.js');
// Create orchestration context
const context = {
template_id: params.template_id || '',
execution_id: '',
project_id: params.options?.project_id,
environment: params.options?.environment,
entityRouter: deps.entityRouter,
logger,
cacheManager: deps.cacheManager,
mcpTools: deps.toolsInstance,
dry_run: params.options?.dry_run,
debug: params.options?.debug
};
// Initialize engine
const engine = new TemplateOrchestrationEngine(context);
// 🚀 NEW: Check for direct mode with inline template
const isDirectMode = params.options?.mode === 'direct' || params.template;
if (isDirectMode && params.template) {
logger.info('🚀 DIRECT MODE: Executing inline template, bypassing database');
// Execute orchestration with inline template
const result = await engine.executeOrchestrationDirect(params.template, params.parameters, context);
return result;
}
// Original database mode logic
let templateId = params.template_id;
if (!templateId && params.template_name) {
const store = new TemplateStore();
await store.initialize();
const template = await store.getTemplateByName(params.template_name);
if (!template) {
throw new Error(`Template not found: ${params.template_name}`);
}
templateId = template.id;
}
if (!templateId) {
throw new Error('Either template_id, template_name, or inline template must be provided');
}
logger.info('📂 DATABASE MODE: Executing stored template from database');
// Execute orchestration
const result = await engine.executeOrchestration(templateId, params.parameters, context);
return result;
}
catch (error) {
logger.error({
error: error.message,
templateId: params.template_id,
templateName: params.template_name
}, 'Failed to execute orchestration template');
throw deps.errorMapper.toMCPError(error);
}
}
};
}
//# sourceMappingURL=OrchestrateTemplate.js.map