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
| Name | Required | Description | Default |
|---|---|---|---|
| model | Yes | The model ID to validate |
Implementation Reference
- src/tool-handlers/validate-model.ts:7-50 (handler)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; }
- src/tool-handlers.ts:303-315 (registration)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'], }, },
- src/tool-handlers.ts:363-369 (registration)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);
- src/tool-handlers.ts:17-17 (registration)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';