Skip to main content
Glama
metrxbots

Metrx MCP Server

by metrxbots

Route Model Selection

metrx_route_model
Read-onlyIdempotent

Route AI tasks to cost-effective models based on complexity. Uses performance data to match simple tasks with cheaper models and complex tasks with premium models.

Instructions

Get a model routing recommendation for a specific task based on complexity. Uses the agent's historical performance data and cost analysis to suggest the optimal model for each task complexity level. Helps reduce costs by routing simple tasks to cheaper models while keeping complex tasks on premium models. Do NOT use for comparing all models at once — use compare_models for static pricing.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
agent_idYesThe agent to get routing recommendations for
task_complexityYesEstimated task complexity: low (simple lookups/formatting), medium (analysis/summarization), high (reasoning/generation)
current_modelNoCurrently configured model (e.g., "gpt-4o"). If omitted, uses agent primary model.

Implementation Reference

  • The handler function for route_model (metrx_route_model) that calls the API /agents/{agent_id}/route endpoint and formats the routing recommendation response with model comparisons, estimated savings, and confidence levels.
    async ({ agent_id, task_complexity, current_model }) => {
      const params: Record<string, string> = {
        task_complexity,
      };
      if (current_model) params.current_model = current_model;
    
      const result = await client.get<{
        recommended_model: string;
        current_model: string;
        task_complexity: string;
        estimated_savings_pct: number;
        confidence: string;
        reason: string;
      }>(`/agents/${agent_id}/route`, params);
    
      if (result.error) {
        return {
          content: [
            { type: 'text', text: `Error getting routing recommendation: ${result.error}` },
          ],
          isError: true,
        };
      }
    
      const data = result.data!;
      const lines: string[] = [
        '## Model Routing Recommendation',
        '',
        `**Task Complexity**: ${data.task_complexity}`,
        `**Current Model**: ${data.current_model}`,
        `**Recommended Model**: ${data.recommended_model}`,
        '',
      ];
    
      if (data.recommended_model !== data.current_model) {
        lines.push(
          `**Estimated Savings**: ${data.estimated_savings_pct}%`,
          `**Confidence**: ${data.confidence}`,
          '',
          `> ${data.reason}`
        );
      } else {
        lines.push(
          `> Current model is already optimal for ${data.task_complexity} complexity tasks.`
        );
      }
    
      return {
        content: [{ type: 'text', text: lines.join('\n') }],
      };
    }
  • Tool registration for 'route_model' with title, description, input schema (agent_id, task_complexity, current_model), and annotations. This gets prefixed with 'metrx_' during server initialization.
    server.registerTool(
      'route_model',
      {
        title: 'Route Model Selection',
        description:
          'Get a model routing recommendation for a specific task based on complexity. ' +
          "Uses the agent's historical performance data and cost analysis to suggest the optimal " +
          'model for each task complexity level. Helps reduce costs by routing simple tasks ' +
          'to cheaper models while keeping complex tasks on premium models. ' +
          'Do NOT use for comparing all models at once — use compare_models for static pricing.',
        inputSchema: {
          agent_id: z.string().uuid().describe('The agent to get routing recommendations for'),
          task_complexity: z
            .enum(['low', 'medium', 'high'])
            .describe(
              'Estimated task complexity: low (simple lookups/formatting), medium (analysis/summarization), high (reasoning/generation)'
            ),
          current_model: z
            .string()
            .optional()
            .describe(
              'Currently configured model (e.g., "gpt-4o"). If omitted, uses agent primary model.'
            ),
        },
        annotations: {
          readOnlyHint: true,
          destructiveHint: false,
          idempotentHint: true,
          openWorldHint: false,
        },
      },
      async ({ agent_id, task_complexity, current_model }) => {
        const params: Record<string, string> = {
          task_complexity,
        };
        if (current_model) params.current_model = current_model;
    
        const result = await client.get<{
          recommended_model: string;
          current_model: string;
          task_complexity: string;
          estimated_savings_pct: number;
          confidence: string;
          reason: string;
        }>(`/agents/${agent_id}/route`, params);
    
        if (result.error) {
          return {
            content: [
              { type: 'text', text: `Error getting routing recommendation: ${result.error}` },
            ],
            isError: true,
          };
        }
    
        const data = result.data!;
        const lines: string[] = [
          '## Model Routing Recommendation',
          '',
          `**Task Complexity**: ${data.task_complexity}`,
          `**Current Model**: ${data.current_model}`,
          `**Recommended Model**: ${data.recommended_model}`,
          '',
        ];
    
        if (data.recommended_model !== data.current_model) {
          lines.push(
            `**Estimated Savings**: ${data.estimated_savings_pct}%`,
            `**Confidence**: ${data.confidence}`,
            '',
            `> ${data.reason}`
          );
        } else {
          lines.push(
            `> Current model is already optimal for ${data.task_complexity} complexity tasks.`
          );
        }
    
        return {
          content: [{ type: 'text', text: lines.join('\n') }],
        };
      }
    );
  • Input schema definition using zod for the route_model tool: agent_id (UUID, required), task_complexity (enum: low/medium/high, required), current_model (string, optional).
    inputSchema: {
      agent_id: z.string().uuid().describe('The agent to get routing recommendations for'),
      task_complexity: z
        .enum(['low', 'medium', 'high'])
        .describe(
          'Estimated task complexity: low (simple lookups/formatting), medium (analysis/summarization), high (reasoning/generation)'
        ),
      current_model: z
        .string()
        .optional()
        .describe(
          'Currently configured model (e.g., "gpt-4o"). If omitted, uses agent primary model.'
        ),
    },
  • Registration wrapper that adds the 'metrx_' prefix to all tool names and applies rate limiting middleware. This transforms 'route_model' to 'metrx_route_model' when the tool is exposed.
    const METRX_PREFIX = 'metrx_';
    const originalRegisterTool = server.registerTool.bind(server);
    (server as any).registerTool = function (
      name: string,
      config: any,
      handler: (...handlerArgs: any[]) => Promise<any>
    ) {
      const wrappedHandler = async (...handlerArgs: any[]) => {
        if (!rateLimiter.isAllowed(name)) {
          return {
            content: [
              {
                type: 'text' as const,
                text: `Rate limit exceeded for tool '${name}'. Maximum 60 requests per minute allowed.`,
              },
            ],
            isError: true,
          };
        }
        return handler(...handlerArgs);
      };
    
      // Register with metrx_ prefix (primary name only — no deprecated aliases)
      const prefixedName = name.startsWith(METRX_PREFIX) ? name : `${METRX_PREFIX}${name}`;
      originalRegisterTool(prefixedName, config, wrappedHandler);
    };
Behavior4/5

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

The description adds valuable behavioral context beyond annotations: it explains the tool's optimization logic ('Uses the agent's historical performance data and cost analysis to suggest the optimal model') and business goal ('Helps reduce costs by routing simple tasks to cheaper models while keeping complex tasks on premium models'). Annotations cover read-only, non-destructive, and idempotent traits, but the description enriches this with operational insights 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 front-loaded with the core purpose, followed by supporting details and exclusions. Every sentence adds value: the first defines the tool, the second explains its logic, the third states the benefit, and the fourth provides critical usage guidance. No wasted words, and structure aids quick comprehension.

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 moderate complexity (3 parameters, no output schema), the description is largely complete: it covers purpose, usage, and behavioral context. However, it lacks details on output format or error handling, which could be useful for an agent. Annotations provide safety profile, but without an output schema, some gaps remain in operational expectations.

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?

Schema description coverage is 100%, so parameters are well-documented in the schema. The description does not add significant semantic details beyond the schema, such as explaining parameter interactions or edge cases. It implies cost-based routing but doesn't elaborate on how parameters influence this. Baseline 3 is appropriate given high schema 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 ('get a model routing recommendation') and resources ('for a specific task based on complexity'). It explicitly distinguishes from sibling 'compare_models' by stating 'Do NOT use for comparing all models at once — use compare_models for static pricing,' making the differentiation unambiguous.

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 guidelines: it specifies when to use ('for a specific task based on complexity') and when not to use ('Do NOT use for comparing all models at once'), while naming an alternative tool ('compare_models'). This gives clear context for selection versus 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