Skip to main content
Glama
sloth-wq

Prompt Auto-Optimizer MCP

by sloth-wq

gepa_recover_component

Recover malfunctioning components in the Prompt Auto-Optimizer MCP by restarting, restoring from backup, rebuilding, or resetting to defaults to restore prompt optimization functionality.

Instructions

Recover a specific GEPA component

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
componentTypeYesType of component to recover
strategyNoRecovery strategy to userestart

Implementation Reference

  • Defines the input schema, description, and parameters for the gepa_recover_component MCP tool.
      name: 'gepa_recover_component',
      description: 'Recover a specific GEPA component',
      inputSchema: {
        type: 'object',
        properties: {
          componentType: {
            type: 'string',
            enum: ['evolution_engine', 'pareto_frontier', 'llm_adapter', 'trajectory_store', 'memory_cache'],
            description: 'Type of component to recover'
          },
          strategy: {
            type: 'string',
            enum: ['restart', 'restore_from_backup', 'rebuild', 'reset_to_defaults'],
            default: 'restart',
            description: 'Recovery strategy to use'
          }
        },
        required: ['componentType']
      }
    },
  • Registers the gepa_recover_component tool in the MCP server's CallToolRequestSchema handler switch statement.
    case 'gepa_recover_component':
      return await this.recoverComponent(args as {
        componentType: string;
        strategy?: string;
      });
  • MCP server handler method for gepa_recover_component tool. Maps parameters, calls DisasterRecoverySystem.recoverComponent, handles response formatting and errors.
      private async recoverComponent(params: {
        componentType: string;
        strategy?: string;
      }): Promise<{ content: { type: string; text: string; }[] }> {
        const { componentType, strategy = 'restart' } = params;
    
        try {
          await this.disasterRecovery.initialize();
          
          // Map component types to internal types
          const componentMap: Record<string, any> = {
            'evolution_engine': 'evolution_engine',
            'pareto_frontier': 'pareto_frontier', 
            'llm_adapter': 'llm_adapter',
            'trajectory_store': 'trajectory_store',
            'memory_cache': 'memory_cache'
          };
    
          const mappedComponentType = componentMap[componentType];
          if (!mappedComponentType) {
            throw new Error(`Unknown component type: ${componentType}`);
          }
    
          const strategyMap: Record<string, any> = {
            'restart': 'restart',
            'restore_from_backup': 'restore_from_backup', 
            'rebuild': 'rebuild',
            'reset_to_defaults': 'reset_to_defaults'
          };
    
          const mappedStrategy = strategyMap[strategy];
          if (!mappedStrategy) {
            throw new Error(`Unknown recovery strategy: ${strategy}`);
          }
    
          const result = await this.disasterRecovery.recoverComponent(mappedComponentType, mappedStrategy);
    
          return {
            content: [
              {
                type: 'text',
                text: `# Component Recovery ${result.success ? 'Completed' : 'Failed'}
    
    ## Recovery Details
    - **Component**: ${componentType}
    - **Strategy**: ${strategy}
    - **Success**: ${result.success ? 'Yes' : 'No'}
    - **Duration**: ${result.duration} ms
    - **Start Time**: ${result.startTime.toISOString()}
    - **End Time**: ${result.endTime?.toISOString() || 'In progress'}
    
    ## Recovery Logs
    ${result.logs.map(log => `[${log}]`).join('\n')}
    
    ${result.preRecoveryState ? `## Pre-Recovery State
    - Status: ${result.preRecoveryState.status}
    - Last Action: ${result.preRecoveryState.lastAction}` : ''}
    
    ${result.postRecoveryState ? `## Post-Recovery State  
    - Status: ${result.postRecoveryState.status}
    - Last Action: ${result.postRecoveryState.lastAction}` : ''}
    
    ${result.error ? `## Error
    ${result.error.message}` : ''}
    
    ${result.success ? `Component ${componentType} has been successfully recovered using ${strategy} strategy.` : `Component recovery failed. Check the error details and logs above.`}`,
              },
            ],
          };
        } catch (error) {
          throw new Error(`Failed to recover component: ${error instanceof Error ? error.message : 'Unknown error'}`);
        }
      }
  • Core implementation of component recovery logic in ComponentRecoveryManager. Orchestrates the recovery process including strategy execution, health checks, and state management.
    async recoverComponent(
      componentType: ComponentType,
      strategy?: RecoveryStrategy
    ): Promise<RecoveryAttempt> {
      return this.resilience.executeWithFullProtection(
        async () => {
          // Check if component is already being recovered
          const activeRecovery = Array.from(this.activeRecoveries.values())
            .find(r => r.componentType === componentType && !r.endTime);
          
          if (activeRecovery) {
            throw new Error(`Component ${componentType} is already being recovered`);
          }
          
          // Get component configuration
          const componentConfig = this.config.componentConfigs.get(componentType);
          if (!componentConfig) {
            throw new Error(`No configuration found for component: ${componentType}`);
          }
          
          // Determine recovery strategy
          const selectedStrategy = strategy || this.selectOptimalStrategy(componentType);
          
          // Create recovery attempt
          const attempt: RecoveryAttempt = {
            id: this.generateRecoveryId(),
            componentType,
            strategy: selectedStrategy,
            startTime: new Date(),
            success: false,
            logs: [],
            preRecoveryState: await this.captureComponentState(componentType)
          };
          
          this.activeRecoveries.set(attempt.id, attempt);
          
          try {
            // Execute recovery strategy
            await this.executeRecoveryStrategy(attempt);
            
            attempt.success = true;
            attempt.endTime = new Date();
            attempt.duration = attempt.endTime.getTime() - attempt.startTime.getTime();
            attempt.postRecoveryState = await this.captureComponentState(componentType);
            
            // Update component health
            await this.updateComponentHealth(componentType);
            
            // Record recovery history
            this.recordRecoveryAttempt(attempt);
            
            this.emit('componentRecovered', attempt);
            
          } catch (error) {
            attempt.success = false;
            attempt.error = error as Error;
            attempt.endTime = new Date();
            attempt.duration = attempt.endTime.getTime() - attempt.startTime.getTime();
            attempt.logs.push(`Recovery failed: ${(error as Error).message}`);
            
            this.recordRecoveryAttempt(attempt);
            
            this.emit('componentRecoveryFailed', attempt);
            throw error;
            
          } finally {
            this.activeRecoveries.delete(attempt.id);
          }
          
          return attempt;
        },
        {
          serviceName: 'component-recovery',
          context: {
            name: 'recover-component',
            priority: 'high'
          }
        }
      );
    }
  • Proxy method in DisasterRecoverySystem that delegates to ComponentRecoveryManager.recoverComponent.
    async recoverComponent(componentType: ComponentType, strategy?: RecoveryStrategy): Promise<RecoveryAttempt> {
      return this.componentRecoveryManager.recoverComponent(componentType, strategy);
    }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/sloth-wq/prompt-auto-optimizer-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server