Skip to main content
Glama
akiojin

Model Hub MCP

by akiojin

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
NameRequiredDescriptionDefault
providerYesThe 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'],
      },
    },
  • 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'],
    },
  • 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}`);
      }
    }
  • 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;
      }
  • 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;
      }
  • 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;
      }
Install Server

Other Tools

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/akiojin/model-hub-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server