list_models
Retrieve available AI models from OpenAI, Anthropic, or Google providers to identify suitable options for your project needs.
Instructions
List all available models from a specific provider
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| provider | Yes | The AI provider to list models from |
Implementation Reference
- src/index.ts:36-50 (registration)Tool registration for 'list_models' including name, description, and input schema.{ name: 'list_models', description: 'List all available models from a specific provider', inputSchema: { type: 'object', properties: { provider: { type: 'string', enum: ['openai', 'anthropic', 'google'], description: 'The AI provider to list models from', }, }, required: ['provider'], }, },
- src/index.ts:39-49 (schema)Input schema for the list_models tool, specifying the required 'provider' parameter.inputSchema: { type: 'object', properties: { provider: { type: 'string', enum: ['openai', 'anthropic', 'google'], description: 'The AI provider to list models from', }, }, required: ['provider'], },
- src/index.ts:87-136 (handler)Handler logic for the list_models tool: validates provider, calls the corresponding provider's listModels method, and returns the models as JSON text content.case 'list_models': { const { provider } = args as { provider: string }; switch (provider) { case 'openai': if (!openaiProvider) { throw new McpError(ErrorCode.InvalidRequest, 'OpenAI API key not configured'); } const openaiModels = await openaiProvider.listModels(); return { content: [ { type: 'text', text: JSON.stringify(openaiModels, null, 2), }, ], }; case 'anthropic': if (!anthropicProvider) { throw new McpError(ErrorCode.InvalidRequest, 'Anthropic API key not configured'); } const anthropicModels = await anthropicProvider.listModels(); return { content: [ { type: 'text', text: JSON.stringify(anthropicModels, null, 2), }, ], }; case 'google': if (!googleProvider) { throw new McpError(ErrorCode.InvalidRequest, 'Google API key not configured'); } const googleModels = await googleProvider.listModels(); return { content: [ { type: 'text', text: JSON.stringify(googleModels, null, 2), }, ], }; default: throw new McpError(ErrorCode.InvalidRequest, `Unknown provider: ${provider}`); } }
- src/providers/openai.ts:18-33 (helper)OpenAI provider's listModels helper: fetches models from OpenAI API using axios.async listModels(): Promise<OpenAIModel[]> { try { const response = await axios.get(`${this.baseURL}/models`, { headers: { 'Authorization': `Bearer ${this.apiKey}`, 'Content-Type': 'application/json' } }); return response.data.data; } catch (error) { if (axios.isAxiosError(error)) { throw new Error(`OpenAI API error: ${error.response?.data?.error?.message || error.message}`); } throw error; }
- src/providers/anthropic.ts:18-34 (helper)Anthropic provider's listModels helper: fetches models from Anthropic API using axios.async listModels(): Promise<AnthropicModel[]> { try { const response = await axios.get(`${this.baseURL}/models`, { headers: { 'x-api-key': this.apiKey, 'anthropic-version': '2023-06-01', 'Content-Type': 'application/json' } }); return response.data.data; } catch (error) { if (axios.isAxiosError(error)) { throw new Error(`Anthropic API error: ${error.response?.data?.error?.message || error.message}`); } throw error; }
- src/providers/google.ts:22-36 (helper)Google provider's listModels helper: fetches models from Google AI API using axios.async listModels(): Promise<GoogleModel[]> { try { const response = await axios.get(`${this.baseURL}/models`, { params: { key: this.apiKey } }); return response.data.models || []; } catch (error) { if (axios.isAxiosError(error)) { throw new Error(`Google AI API error: ${error.response?.data?.error?.message || error.message}`); } throw error; }