Skip to main content
Glama
sloth-wq

Prompt Auto-Optimizer MCP

by sloth-wq

gepa_select_optimal

Selects the best prompt candidate for a given context by balancing performance and diversity criteria, optimizing AI prompt effectiveness through evolutionary algorithms.

Instructions

Select best prompt candidate for given context

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
taskContextNoContext description for prompt selection (optional)
performanceWeightNoWeight for performance in selection criteria
diversityWeightNoWeight for diversity in selection criteria

Implementation Reference

  • The core handler function for the 'gepa_select_optimal' tool. It retrieves candidates from the Pareto frontier, samples using UCB strategy, computes weighted scores, and returns detailed selection information including metrics and recommendation.
      private async selectOptimal(params: SelectOptimalParams): Promise<{
        content: { type: string; text: string; }[];
      }> {
        const { taskContext, performanceWeight = 0.7, diversityWeight = 0.3 } = params;
    
        // Validate weights sum to 1
        if (Math.abs(performanceWeight + diversityWeight - 1.0) > 0.001) {
          throw new Error('performanceWeight and diversityWeight must sum to 1.0');
        }
    
        try {
          // Get current Pareto frontier
          const frontierCandidates = this.paretoFrontier.getFrontier();
    
          if (frontierCandidates.length === 0) {
            throw new Error('No candidates available in Pareto frontier');
          }
    
          // Sample candidate using the specified strategy
          const selectedCandidate = await this.paretoFrontier.sampleCandidate({ name: 'ucb', parameters: { confidence: 1.96 } });
    
          if (!selectedCandidate) {
            throw new Error('Failed to select optimal candidate');
          }
    
          // TypeScript assertion: selectedCandidate is not null after the check above
          const candidate = selectedCandidate as GEPAPromptCandidate;
    
          // Calculate selection metrics
          const performanceScore = candidate.averageScore;
          const diversityScore = candidate.generation / 10; // Simple diversity metric
          
          const combinedScore = (
            performanceScore * performanceWeight + 
            diversityScore * diversityWeight
          );
    
          // Get frontier statistics for context
          const stats = this.paretoFrontier.getStatistics();
    
          return {
            content: [
              {
                type: 'text',
                text: `# Optimal Candidate Selected
    
    ## Selection Context
    - **Task Context**: ${taskContext || 'General optimization'}
    - **Performance Weight**: ${(performanceWeight * 100).toFixed(1)}%
    - **Diversity Weight**: ${(diversityWeight * 100).toFixed(1)}%
    - **Selection Strategy**: Upper Confidence Bound (UCB)
    
    ## Selected Candidate
    - **Candidate ID**: ${candidate.id}
    - **Fitness Score**: ${candidate.averageScore.toFixed(3)}
    - **Combined Score**: ${combinedScore.toFixed(3)}
    
    ## Performance Breakdown
    - **Performance Score**: ${performanceScore.toFixed(3)} (${(performanceScore * 100).toFixed(1)}%)
    - **Diversity Score**: ${diversityScore.toFixed(3)} (${(diversityScore * 100).toFixed(1)}%)
    
    ## Candidate Metadata
    - **Generation**: ${candidate.generation}
    - **Parent ID**: ${candidate.parentId || 'None'}
    - **Mutation Type**: ${candidate.mutationType || 'Unknown'}
    
    ## Frontier Context
    - **Total Candidates**: ${frontierCandidates.length}
    - **Frontend Size**: ${stats.frontierSize}
    - **Average Rank**: ${stats.averageRank.toFixed(3)}
    - **Position in Frontier**: Top ${Math.ceil((1 - candidate.averageScore) * frontierCandidates.length)}
    
    ## Recommendation
    This candidate represents the optimal balance between performance (${(performanceWeight * 100).toFixed(1)}%) and diversity (${(diversityWeight * 100).toFixed(1)}%) for the given context. Use this prompt for your target task.`,
              },
            ],
          };
        } catch (error) {
          throw new Error(`Failed to select optimal candidate: ${error instanceof Error ? error.message : 'Unknown error'}`);
        }
      }
  • The input schema and metadata registration for the gepa_select_optimal tool in the TOOLS array used for MCP list tools endpoint.
    {
      name: 'gepa_select_optimal',
      description: 'Select best prompt candidate for given context',
      inputSchema: {
        type: 'object',
        properties: {
          taskContext: {
            type: 'string',
            description: 'Context description for prompt selection (optional)'
          },
          performanceWeight: {
            type: 'number',
            default: 0.7,
            description: 'Weight for performance in selection criteria'
          },
          diversityWeight: {
            type: 'number',
            default: 0.3,
            description: 'Weight for diversity in selection criteria'
          }
        }
      }
    },
  • The switch case registration that routes calls to the gepa_select_optimal tool to its handler method.
    case 'gepa_select_optimal':
      return await this.selectOptimal(args as unknown as SelectOptimalParams);
  • TypeScript interface defining the input parameters for the selectOptimal handler.
    export interface SelectOptimalParams {
      taskContext?: string;
      performanceWeight?: number;
      diversityWeight?: number;
    }
  • Constant tool name definition in TOOL_NAMES enum/object for type-safe references.
    SELECT_OPTIMAL: 'gepa_select_optimal',
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It states the tool selects based on 'best prompt candidate' but doesn't explain how selection works, what 'best' means, whether it's read-only or mutative, or any performance characteristics like rate limits. This is a significant gap for a tool with zero annotation coverage.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that directly states the purpose without unnecessary words. It's appropriately sized and front-loaded, though it could be slightly more informative without losing conciseness.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's complexity (involving selection criteria with weights), no annotations, and no output schema, the description is incomplete. It doesn't explain the selection algorithm, return values, or how weights affect outcomes, leaving critical gaps for the agent to understand the tool's behavior and results.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The schema description coverage is 100%, so the schema already documents all three parameters (taskContext, performanceWeight, diversityWeight) with descriptions. The tool description adds no additional parameter semantics beyond what's in the schema, such as explaining how weights interact or what 'context' entails. Baseline 3 is appropriate when schema does the heavy lifting.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose3/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description 'Select best prompt candidate for given context' states a clear purpose with a specific verb ('select') and resource ('prompt candidate'), but it doesn't differentiate from sibling tools like 'gepa_evaluate_prompt' or 'gepa_get_pareto_frontier' that might involve similar prompt-related operations. The purpose is understandable but lacks sibling distinction.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention prerequisites, exclusions, or compare to siblings such as 'gepa_evaluate_prompt' or 'gepa_get_pareto_frontier', leaving the agent with no usage context beyond the basic purpose.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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