list_models
Retrieve and display all available models from OpenAI, Anthropic, or Google using a unified interface for streamlined AI model management.
Instructions
List all available models from a specific provider
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| provider | Yes | The AI provider to list models from |
Input Schema (JSON Schema)
{
"properties": {
"provider": {
"description": "The AI provider to list models from",
"enum": [
"openai",
"anthropic",
"google"
],
"type": "string"
}
},
"required": [
"provider"
],
"type": "object"
}
Implementation Reference
- src/index.ts:87-136 (handler)Main handler for the 'list_models' tool in the MCP CallToolRequestHandler. It extracts the provider from arguments, checks if the provider is configured, calls the provider's listModels method, and returns the result as JSON-formatted 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/index.ts:36-50 (registration)Registration of the 'list_models' tool in the ListToolsRequestHandler response, including its 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, defining the required 'provider' parameter with allowed values.inputSchema: { type: 'object', properties: { provider: { type: 'string', enum: ['openai', 'anthropic', 'google'], description: 'The AI provider to list models from', }, }, required: ['provider'], },
- src/providers/openai.ts:18-33 (helper)OpenAIProvider.listModels() helper method that makes an API call to list OpenAI models.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)AnthropicProvider.listModels() helper method that makes an API call to list Anthropic models.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; }