validate_model
Verify if a model ID is compatible with OpenRouter's multimodal AI ecosystem before use.
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 core handler function that implements the validate_model tool logic: checks if the model cache is valid, verifies if the specified model exists using modelCache.hasModel, and returns JSON {valid: boolean} or an error response.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; } }
- src/tool-handlers.ts:302-315 (registration)Tool registration in the ListToolsRequest handler, defining the tool name, description, and input schema for MCP clients.{ 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)Dispatch logic in the CallToolRequest switch statement that invokes the validate_model handler with the request arguments and modelCache instance.case 'validate_model': return handleValidateModel({ params: { arguments: request.params.arguments as unknown as ValidateModelToolRequest } }, this.modelCache);
- TypeScript type definition for the tool's input parameters, matching the JSON schema in registration.export interface ValidateModelToolRequest { model: string; }
- src/tool-handlers.ts:305-314 (schema)JSON Schema for input validation in the MCP tool specification.inputSchema: { type: 'object', properties: { model: { type: 'string', description: 'The model ID to validate', }, }, required: ['model'], },