Skip to main content
Glama
metrxbots

Metrx MCP Server

by metrxbots

Create Model Experiment

metrx_create_model_experiment

Launch an A/B test to compare LLM models for an agent, routing traffic between models while tracking performance metrics until statistical significance is reached.

Instructions

Start an A/B test comparing two LLM models for a specific agent. Routes a percentage of traffic to the treatment model and tracks cost, latency, error rate, and quality metrics. The experiment runs until statistical significance is reached or the max duration expires. Do NOT use for one-off model comparisons — use compare_models for static pricing data.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
agent_idYesAgent to run the experiment on
nameYesHuman-readable experiment name
treatment_modelYesThe candidate model to test (e.g., "gpt-4o-mini", "claude-haiku-4-20250414")
traffic_pctNoPercentage of traffic to route to the treatment model (default: 10%)
primary_metricNoThe primary metric to optimize for (default: cost_per_call)cost_per_call
max_duration_daysNoMaximum experiment duration in days (default: 14)
auto_promoteNoAutomatically apply the winning model when the experiment concludes

Implementation Reference

  • The async handler function that executes the create_model_experiment tool. It extracts parameters, builds the request body, calls the API client to create an experiment, and formats the response.
    async ({
      agent_id,
      name,
      treatment_model,
      traffic_pct,
      primary_metric,
      max_duration_days,
      auto_promote,
    }) => {
      const body: Record<string, unknown> = {
        agent_id,
        name,
        treatment_model,
        traffic_pct: traffic_pct ?? 10,
        primary_metric: primary_metric ?? 'cost_per_call',
        max_duration_days: max_duration_days ?? 14,
        auto_promote: auto_promote ?? false,
      };
    
      const result = await client.post<ModelRoutingExperiment>('/experiments', body);
    
      if (result.error) {
        return {
          content: [{ type: 'text', text: `Error creating experiment: ${result.error}` }],
          isError: true,
        };
      }
    
      const exp = result.data!;
      const text = [
        `✅ Experiment "${exp.name}" created.`,
        '',
        formatExperiment(exp),
        '',
        'The experiment will start routing traffic immediately. Use get_experiment_results to check progress.',
      ].join('\n');
    
      return {
        content: [{ type: 'text', text }],
      };
    }
  • Zod input schema defining all parameters for the create_model_experiment tool including agent_id, name, treatment_model, traffic_pct, primary_metric, max_duration_days, and auto_promote with validation rules and defaults.
    inputSchema: {
      agent_id: z.string().uuid().describe('Agent to run the experiment on'),
      name: z.string().min(1).max(100).describe('Human-readable experiment name'),
      treatment_model: z
        .string()
        .describe('The candidate model to test (e.g., "gpt-4o-mini", "claude-haiku-4-20250414")'),
      traffic_pct: z
        .number()
        .int()
        .min(1)
        .max(50)
        .default(10)
        .describe('Percentage of traffic to route to the treatment model (default: 10%)'),
      primary_metric: z
        .enum(['cost_per_call', 'latency_p50', 'latency_p95', 'error_rate', 'quality_score'])
        .default('cost_per_call')
        .describe('The primary metric to optimize for (default: cost_per_call)'),
      max_duration_days: z
        .number()
        .int()
        .min(1)
        .max(30)
        .default(14)
        .describe('Maximum experiment duration in days (default: 14)'),
      auto_promote: z
        .boolean()
        .default(false)
        .describe('Automatically apply the winning model when the experiment concludes'),
    },
  • Complete tool registration via server.registerTool including metadata (title, description), input schema, annotations, and the handler function for create_model_experiment.
    server.registerTool(
      'create_model_experiment',
      {
        title: 'Create Model Experiment',
        description:
          'Start an A/B test comparing two LLM models for a specific agent. ' +
          'Routes a percentage of traffic to the treatment model and tracks ' +
          'cost, latency, error rate, and quality metrics. The experiment runs ' +
          'until statistical significance is reached or the max duration expires. ' +
          'Do NOT use for one-off model comparisons — use compare_models for static pricing data.',
        inputSchema: {
          agent_id: z.string().uuid().describe('Agent to run the experiment on'),
          name: z.string().min(1).max(100).describe('Human-readable experiment name'),
          treatment_model: z
            .string()
            .describe('The candidate model to test (e.g., "gpt-4o-mini", "claude-haiku-4-20250414")'),
          traffic_pct: z
            .number()
            .int()
            .min(1)
            .max(50)
            .default(10)
            .describe('Percentage of traffic to route to the treatment model (default: 10%)'),
          primary_metric: z
            .enum(['cost_per_call', 'latency_p50', 'latency_p95', 'error_rate', 'quality_score'])
            .default('cost_per_call')
            .describe('The primary metric to optimize for (default: cost_per_call)'),
          max_duration_days: z
            .number()
            .int()
            .min(1)
            .max(30)
            .default(14)
            .describe('Maximum experiment duration in days (default: 14)'),
          auto_promote: z
            .boolean()
            .default(false)
            .describe('Automatically apply the winning model when the experiment concludes'),
        },
        annotations: {
          readOnlyHint: false,
          destructiveHint: false,
          idempotentHint: false,
          openWorldHint: false,
        },
      },
      async ({
        agent_id,
        name,
        treatment_model,
        traffic_pct,
        primary_metric,
        max_duration_days,
        auto_promote,
      }) => {
        const body: Record<string, unknown> = {
          agent_id,
          name,
          treatment_model,
          traffic_pct: traffic_pct ?? 10,
          primary_metric: primary_metric ?? 'cost_per_call',
          max_duration_days: max_duration_days ?? 14,
          auto_promote: auto_promote ?? false,
        };
    
        const result = await client.post<ModelRoutingExperiment>('/experiments', body);
    
        if (result.error) {
          return {
            content: [{ type: 'text', text: `Error creating experiment: ${result.error}` }],
            isError: true,
          };
        }
    
        const exp = result.data!;
        const text = [
          `✅ Experiment "${exp.name}" created.`,
          '',
          formatExperiment(exp),
          '',
          'The experiment will start routing traffic immediately. Use get_experiment_results to check progress.',
        ].join('\n');
    
        return {
          content: [{ type: 'text', text }],
        };
      }
    );
  • TypeScript interface defining the ModelRoutingExperiment data structure returned by the API, including experiment metadata, model configurations, traffic settings, and results tracking fields.
    export interface ModelRoutingExperiment {
      id: string;
      name: string;
      agent_id: string;
      control_model: string;
      treatment_model: string;
      traffic_pct: number;
      status: string;
      primary_metric: string;
      control_samples: number;
      treatment_samples: number;
      is_significant: boolean;
      winner?: string;
    }
Behavior4/5

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

The description adds valuable behavioral context beyond annotations, such as the experiment's duration logic ('runs until statistical significance is reached or the max duration expires') and tracked metrics (cost, latency, error rate, quality). While annotations cover basic safety (non-destructive, non-idempotent), the description enhances understanding of operational behavior without contradiction.

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

Conciseness5/5

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

The description is efficiently structured in two sentences, front-loading the core purpose and following with clear usage constraints. Every phrase adds value without redundancy, making it easy to parse and understand quickly.

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

Completeness4/5

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

Given the tool's complexity (7 parameters, no output schema) and rich annotations, the description is largely complete, covering purpose, usage, and behavioral details. However, it lacks explicit information on output format or error handling, which could aid agent invocation, leaving minor gaps.

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?

With 100% schema description coverage, the input schema already documents all parameters thoroughly. The description adds minimal semantic context (e.g., 'percentage of traffic' for traffic_pct), but does not significantly enhance parameter understanding beyond the schema, meeting the baseline for high coverage.

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

Purpose5/5

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

The description clearly states the tool's purpose with specific verbs ('start an A/B test', 'routes traffic', 'tracks metrics') and resources ('LLM models', 'agent'), and explicitly distinguishes it from the sibling tool 'compare_models' for one-off comparisons, providing clear differentiation.

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

Usage Guidelines5/5

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

The description provides explicit usage guidance by stating when NOT to use this tool ('Do NOT use for one-off model comparisons') and naming the alternative ('use compare_models for static pricing data'), offering clear context for selection among siblings.

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/metrxbots/metrx-mcp-server'

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