Skip to main content
Glama
hoangdn3
by hoangdn3

validate_model

Verify if a model ID is valid before using it for text chat or image analysis tasks in the OpenRouter ecosystem.

Instructions

Check if a model ID is valid

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
modelYesThe model ID to validate

Implementation Reference

  • The main handler function that implements the 'validate_model' tool logic. It checks if the model cache is valid and if the specified model exists in the cache, returning a JSON response with validity status or an error.
    export async function handleValidateModel( request: { params: { arguments: ValidateModelToolRequest } }, modelCache: ModelCache ) { const args = request.params.arguments; try { if (!modelCache.isCacheValid()) { return { content: [ { type: 'text', text: 'Model cache is empty or expired. Please call search_models first to populate the cache.', }, ], isError: true, }; } const isValid = modelCache.hasModel(args.model); return { content: [ { type: 'text', text: JSON.stringify({ valid: isValid }), }, ], }; } catch (error) { if (error instanceof Error) { return { content: [ { type: 'text', text: `Error validating model: ${error.message}`, }, ], isError: true, }; } throw error; } }
  • TypeScript interface defining the expected input structure for the 'validate_model' tool request.
    export interface ValidateModelToolRequest { model: string; }
  • Registers the 'validate_model' tool in the list of available tools provided to MCP clients, including its JSON input schema.
    name: 'validate_model', description: 'Check if a model ID is valid', inputSchema: { type: 'object', properties: { model: { type: 'string', description: 'The model ID to validate', }, }, required: ['model'], }, },
  • Registers the handler dispatch for the 'validate_model' tool in the CallToolRequestSchema switch statement.
    case 'validate_model': return handleValidateModel({ params: { arguments: request.params.arguments as unknown as ValidateModelToolRequest } }, this.modelCache);
  • Imports the 'validate_model' handler function and request type for use in tool registration and dispatching.
    import { handleValidateModel, ValidateModelToolRequest } from './tool-handlers/validate-model.js';

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