Skip to main content
Glama

List Models

list_models
Read-only

List available models from LLM providers like OpenAI, Google, Groq, and Ollama. Optionally fetch the latest models directly from the API.

Instructions

List available models for LLM providers

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
providerNoProvider name (optional, lists all if not specified)
fetch_latestNoFetch latest models from API vs using cached/configured

Implementation Reference

  • Main handler function that lists available models for LLM providers. Accepts optional 'provider' (to filter) and 'fetch_latest' args. Iterates providers and formats model info with nicknames, defaults, descriptions, and context window sizes. Falls back to cached/configured models.
    export async function listModelsTool(
      providerManager: ProviderManager,
      args: Record<string, unknown>
    ) {
      const { provider, fetch_latest = false } = args as {
        provider?: string;
        fetch_latest?: boolean;
      };
    
      try {
        let response = `${duckArt.panel}\nšŸ“‹ **Available Models**\n\n`;
    
        if (provider) {
          // List models for a specific provider
          const providerInfo = providerManager.getAllProviders().find((p) => p.name === provider);
          if (!providerInfo) {
            throw new Error(`Provider "${provider}" not found`);
          }
    
          const models = await providerManager.getAvailableModels(provider);
          response += formatProviderModels(
            providerInfo.info.nickname,
            provider,
            models,
            providerInfo.info.model
          );
        } else {
          // List models for all providers
          const allProviders = providerManager.getAllProviders();
    
          for (const providerInfo of allProviders) {
            try {
              const models = await providerManager.getAvailableModels(providerInfo.name);
              response += formatProviderModels(
                providerInfo.info.nickname,
                providerInfo.name,
                models,
                providerInfo.info.model
              );
              response += '\n';
            } catch (error) {
              logger.warn(`Failed to get models for ${providerInfo.name}:`, error);
              response += `\nšŸ¦† **${providerInfo.info.nickname}** (${providerInfo.name})\n`;
              response += `   āš ļø Failed to fetch models\n\n`;
            }
          }
        }
    
        response += `\n─────────────────────────────────────\n`;
        response += fetch_latest ? 'šŸ”„ Fetched from API' : 'šŸ“‹ Using cached/configured models';
    
        logger.info(`Listed models for ${provider || 'all providers'}`);
    
        return {
          content: [
            {
              type: 'text',
              text: response,
            },
          ],
        };
      } catch (error: unknown) {
        logger.error('Error listing models:', error);
        throw error;
      }
    }
    
    function formatProviderModels(
      nickname: string,
      providerName: string,
      models: ModelInfo[],
      defaultModel: string
    ): string {
      let output = `\nšŸ¦† **${nickname}** (${providerName})\n`;
    
      if (models.length === 0) {
        output += `   šŸ“­ No models available\n`;
        return output;
      }
    
      for (const model of models) {
        const isDefault = model.id === defaultModel;
        const defaultMarker = isDefault ? ' **(default)**' : '';
    
        output += `   • ${model.id}${defaultMarker}`;
    
        if (model.description) {
          output += ` - ${model.description}`;
        } else if (model.owned_by) {
          output += ` - by ${model.owned_by}`;
        }
    
        if (model.context_window) {
          output += ` [${model.context_window} tokens]`;
        }
    
        output += '\n';
      }
    
      return output;
    }
  • formatProviderModels helper - formats a single provider's models into a readable string with nickname, model IDs, default markers, descriptions, and context window sizes.
    function formatProviderModels(
      nickname: string,
      providerName: string,
      models: ModelInfo[],
      defaultModel: string
    ): string {
      let output = `\nšŸ¦† **${nickname}** (${providerName})\n`;
    
      if (models.length === 0) {
        output += `   šŸ“­ No models available\n`;
        return output;
      }
    
      for (const model of models) {
        const isDefault = model.id === defaultModel;
        const defaultMarker = isDefault ? ' **(default)**' : '';
    
        output += `   • ${model.id}${defaultMarker}`;
    
        if (model.description) {
          output += ` - ${model.description}`;
        } else if (model.owned_by) {
          output += ` - by ${model.owned_by}`;
        }
    
        if (model.context_window) {
          output += ` [${model.context_window} tokens]`;
        }
    
        output += '\n';
      }
    
      return output;
    }
  • ModelInfo interface defining the shape of model data returned by listModels: id, created, owned_by, object, context_window, description.
    export interface ModelInfo {
      id: string;
      created?: number;
      owned_by?: string;
      object?: string;
      context_window?: number;
      description?: string;
    }
  • src/server.ts:372-400 (registration)
    Registration of the 'list_models' tool on the MCP server with title, description, inputSchema (provider enum + fetch_latest boolean), annotations, and handler wiring to listModelsTool.
    // list_models
    this.server.registerTool(
      'list_models',
      {
        title: 'List Models',
        description: 'List available models for LLM providers',
        inputSchema: {
          provider: this.providerEnum()
            .optional()
            .describe('Provider name (optional, lists all if not specified)'),
          fetch_latest: z
            .boolean()
            .default(false)
            .describe('Fetch latest models from API vs using cached/configured'),
        },
        annotations: {
          readOnlyHint: true,
          openWorldHint: true,
        },
      },
      async (args) => {
        try {
          return this.toolResult(
            await listModelsTool(this.providerManager, args as Record<string, unknown>)
          );
        } catch (error) {
          return this.toolErrorResult(error);
        }
      }
  • Base Provider class listModels implementation - fetches models from API via OpenAI client, falls back to configured availableModels list, then to default model.
    async listModels(): Promise<ModelInfo[]> {
      try {
        // Try to fetch models from the API
        const response = await this.client.models.list();
        const models: ModelInfo[] = [];
    
        for await (const model of response) {
          models.push({
            id: model.id,
            created: model.created,
            owned_by: model.owned_by,
            object: model.object,
          });
        }
    
        logger.debug(`Fetched ${models.length} models from ${this.name}`);
        return models;
      } catch (error: unknown) {
        const errorMessage = error instanceof Error ? error.message : String(error);
        logger.warn(`Failed to fetch models from ${this.name}: ${errorMessage}`);
        // Fall back to configured models
        if (this.options.availableModels && this.options.availableModels.length > 0) {
          return this.options.availableModels.map((id) => ({
            id,
            description: 'Configured model (not fetched from API)',
          }));
        }
        // Last fallback: return just the default model
        return [
          {
            id: this.options.model,
            description: 'Default configured model',
          },
        ];
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Annotations already declare readOnlyHint and openWorldHint, covering safety and variability. The description adds 'available models' scope but does not disclose behavioral details like caching defaults or API interaction beyond what the schema implies.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single concise sentence that gets the point across without wasted words. It could be slightly more informative but is not overly verbose.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the simple nature of the tool with only two optional parameters and full schema descriptions, the description adequately covers the purpose. No output schema is needed for a list operation.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 100% with both parameters having descriptions. The tool description does not add any meaning beyond the schema, so baseline 3 is appropriate.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: listing available models for LLM providers. It uses a specific verb 'List' and resource 'models', and distinguishes itself from sibling tools that focus on duck-related operations.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No explicit when-to-use or when-not-to-use guidance is provided. The description implies the tool is for listing models, but does not specify scenarios or alternatives, though no obvious alternatives exist among siblings.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

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/nesquikm/mcp-rubber-duck'

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