Skip to main content
Glama
hoangdn3

OpenRouter MCP Multimodal Server

by hoangdn3

search_models

Find and filter AI models on OpenRouter.ai by criteria like price, context length, provider, and capabilities including vision or function calling.

Instructions

Search and filter OpenRouter.ai models based on various criteria

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryNoOptional search query to filter by name, description, or provider
providerNoFilter by specific provider (e.g., "anthropic", "openai", "cohere")
minContextLengthNoMinimum context length in tokens
maxContextLengthNoMaximum context length in tokens
maxPromptPriceNoMaximum price per 1K tokens for prompts
maxCompletionPriceNoMaximum price per 1K tokens for completions
capabilitiesNoFilter by model capabilities
limitNoMaximum number of results to return (default: 10)

Implementation Reference

  • The main handler function that implements the core logic of the 'search_models' tool. It refreshes the model cache if necessary, performs the search using ModelCache.searchModels, formats results as JSON, and handles errors.
    export async function handleSearchModels(
      request: { params: { arguments: SearchModelsToolRequest } },
      apiClient: OpenRouterAPIClient,
      modelCache: ModelCache
    ) {
      const args = request.params.arguments;
      
      try {
        // Refresh the cache if needed
        if (!modelCache.isCacheValid()) {
          const models = await apiClient.getModels();
          modelCache.setModels(models);
        }
        
        // Search models based on criteria
        const results = modelCache.searchModels({
          query: args.query,
          provider: args.provider,
          minContextLength: args.minContextLength,
          maxContextLength: args.maxContextLength,
          maxPromptPrice: args.maxPromptPrice,
          maxCompletionPrice: args.maxCompletionPrice,
          capabilities: args.capabilities,
          limit: args.limit || 10,
        });
        
        return {
          content: [
            {
              type: 'text',
              text: JSON.stringify(results, null, 2),
            },
          ],
        };
      } catch (error) {
        if (error instanceof Error) {
          return {
            content: [
              {
                type: 'text',
                text: `Error searching models: ${error.message}`,
              },
            ],
            isError: true,
          };
        }
        throw error;
      }
    }
  • TypeScript interface defining the expected input shape (SearchModelsToolRequest) for the search_models tool, used for type checking in the handler.
    export interface SearchModelsToolRequest {
      query?: string;
      provider?: string;
      minContextLength?: number | string;
      maxContextLength?: number | string;
      maxPromptPrice?: number | string;
      maxCompletionPrice?: number | string;
      capabilities?: {
        functions?: boolean;
        tools?: boolean;
        vision?: boolean;
        json_mode?: boolean;
      };
      limit?: number | string;
    }
  • Registration of the 'search_models' tool in the ListTools response, specifying name, description, and full inputSchema matching the handler's expected arguments.
    // Search Models Tool
    {
      name: 'search_models',
      description: 'Search and filter OpenRouter.ai models based on various criteria',
      inputSchema: {
        type: 'object',
        properties: {
          query: {
            type: 'string',
            description: 'Optional search query to filter by name, description, or provider',
          },
          provider: {
            type: 'string',
            description: 'Filter by specific provider (e.g., "anthropic", "openai", "cohere")',
          },
          minContextLength: {
            type: 'number',
            description: 'Minimum context length in tokens',
          },
          maxContextLength: {
            type: 'number',
            description: 'Maximum context length in tokens',
          },
          maxPromptPrice: {
            type: 'number',
            description: 'Maximum price per 1K tokens for prompts',
          },
          maxCompletionPrice: {
            type: 'number',
            description: 'Maximum price per 1K tokens for completions',
          },
          capabilities: {
            type: 'object',
            description: 'Filter by model capabilities',
            properties: {
              functions: {
                type: 'boolean',
                description: 'Requires function calling capability',
              },
              tools: {
                type: 'boolean',
                description: 'Requires tools capability',
              },
              vision: {
                type: 'boolean',
                description: 'Requires vision capability',
              },
              json_mode: {
                type: 'boolean',
                description: 'Requires JSON mode capability',
              }
            }
          },
          limit: {
            type: 'number',
            description: 'Maximum number of results to return (default: 10)',
            minimum: 1,
            maximum: 50
          }
        }
      },
    },
  • Dispatch logic in the CallToolRequest handler that routes 'search_models' tool calls to the handleSearchModels function with appropriate parameters and dependencies.
    case 'search_models':
      return handleSearchModels({
        params: {
          arguments: request.params.arguments as SearchModelsToolRequest
        }
      }, this.apiClient, this.modelCache);
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 mentions searching and filtering but doesn't cover key aspects like whether this is a read-only operation, potential rate limits, authentication needs, or what the output format looks like (e.g., list of models with details). This leaves significant gaps for a tool with 8 parameters.

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 tool's function without unnecessary words. It's appropriately sized for a search tool, though it could be slightly more structured by front-loading key details like the resource type more prominently.

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 complexity (8 parameters, nested objects) and lack of annotations or output schema, the description is insufficient. It doesn't explain behavioral traits, return values, or usage context, making it incomplete for effective agent operation despite the clear purpose.

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 input schema fully documents all parameters. The description adds no additional parameter semantics beyond what's in the schema, such as explaining relationships between parameters or usage examples. This meets the baseline for high schema coverage.

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

Purpose4/5

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

The description clearly states the action ('search and filter') and resource ('OpenRouter.ai models'), making the purpose evident. However, it doesn't explicitly differentiate this tool from sibling tools like 'get_model_info' or 'validate_model', which likely serve different purposes but aren't contrasted here.

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 like 'get_model_info' or 'validate_model'. It mentions filtering criteria but doesn't specify scenarios or prerequisites for selecting this tool over others, leaving the agent without contextual usage direction.

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/hoangdn3/mcp-ocr-fallback'

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