Skip to main content
Glama
ankit-aglawe

tokencost-mcp-server

by ankit-aglawe

tokencost_list_models

Retrieve available AI models with pricing data to compare costs across providers and select models for token usage calculations.

Instructions

List all available LLM models with pricing data, optionally filtered by provider.

Args:

  • provider (string, optional): Filter by provider (e.g., "OpenAI", "Anthropic", "Google")

Returns: List of all models with IDs, names, and providers. Use model IDs with other tools.

Examples:

  • {} → All 60+ models

  • { provider: "Anthropic" } → All Anthropic Claude models

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
providerNoFilter by provider name

Implementation Reference

  • Handler function for tokencost_list_models tool that filters models by provider, groups them by provider, generates markdown-formatted output, and returns both text and structured content
      async ({ provider }) => {
        let filtered = models;
        if (provider) {
          const p = provider.toLowerCase();
          filtered = models.filter(m => m.provider.toLowerCase() === p);
        }
    
        const byProvider = new Map<string, ModelPricing[]>();
        for (const m of filtered) {
          const list = byProvider.get(m.provider) ?? [];
          list.push(m);
          byProvider.set(m.provider, list);
        }
    
        const lines = [`# Available Models (${filtered.length})`, ""];
        for (const [prov, ms] of byProvider) {
          lines.push(`## ${prov}`);
          for (const m of ms) {
            lines.push(`- **${m.name}** (\`${m.id}\`) — $${m.inputPer1M}/$${m.outputPer1M} per 1M tokens`);
          }
          lines.push("");
        }
        lines.push(`*Full pricing at [TokenCost](https://tokencost.app)*`);
    
        return {
          content: [{ type: "text", text: lines.join("\n") }],
          structuredContent: {
            total: filtered.length,
            providers: [...byProvider.keys()],
            models: filtered.map(m => ({ id: m.id, name: m.name, provider: m.provider })),
          },
        };
      }
    );
  • Schema definition for tokencost_list_models including title, description, inputSchema with optional provider parameter, and annotations (readOnlyHint, destructiveHint, idempotentHint, openWorldHint)
      {
        title: "List All Models",
        description: `List all available LLM models with pricing data, optionally filtered by provider.
    
    Args:
      - provider (string, optional): Filter by provider (e.g., "OpenAI", "Anthropic", "Google")
    
    Returns:
      List of all models with IDs, names, and providers. Use model IDs with other tools.
    
    Examples:
      - {} → All 60+ models
      - { provider: "Anthropic" } → All Anthropic Claude models`,
        inputSchema: {
          provider: z.string().optional().describe("Filter by provider name"),
        },
        annotations: {
          readOnlyHint: true,
          destructiveHint: false,
          idempotentHint: true,
          openWorldHint: false,
        },
      },
  • src/index.ts:351-409 (registration)
    Complete registration of tokencost_list_models tool with server.registerTool(), including schema definition and handler implementation
    server.registerTool(
      "tokencost_list_models",
      {
        title: "List All Models",
        description: `List all available LLM models with pricing data, optionally filtered by provider.
    
    Args:
      - provider (string, optional): Filter by provider (e.g., "OpenAI", "Anthropic", "Google")
    
    Returns:
      List of all models with IDs, names, and providers. Use model IDs with other tools.
    
    Examples:
      - {} → All 60+ models
      - { provider: "Anthropic" } → All Anthropic Claude models`,
        inputSchema: {
          provider: z.string().optional().describe("Filter by provider name"),
        },
        annotations: {
          readOnlyHint: true,
          destructiveHint: false,
          idempotentHint: true,
          openWorldHint: false,
        },
      },
      async ({ provider }) => {
        let filtered = models;
        if (provider) {
          const p = provider.toLowerCase();
          filtered = models.filter(m => m.provider.toLowerCase() === p);
        }
    
        const byProvider = new Map<string, ModelPricing[]>();
        for (const m of filtered) {
          const list = byProvider.get(m.provider) ?? [];
          list.push(m);
          byProvider.set(m.provider, list);
        }
    
        const lines = [`# Available Models (${filtered.length})`, ""];
        for (const [prov, ms] of byProvider) {
          lines.push(`## ${prov}`);
          for (const m of ms) {
            lines.push(`- **${m.name}** (\`${m.id}\`) — $${m.inputPer1M}/$${m.outputPer1M} per 1M tokens`);
          }
          lines.push("");
        }
        lines.push(`*Full pricing at [TokenCost](https://tokencost.app)*`);
    
        return {
          content: [{ type: "text", text: lines.join("\n") }],
          structuredContent: {
            total: filtered.length,
            providers: [...byProvider.keys()],
            models: filtered.map(m => ({ id: m.id, name: m.name, provider: m.provider })),
          },
        };
      }
    );
  • ModelPricing interface defining the data structure for model pricing information (id, name, provider, inputPer1M, outputPer1M, contextWindow, maxOutput, notes)
    export interface ModelPricing {
      id: string;
      name: string;
      provider: string;
      inputPer1M: number;
      outputPer1M: number;
      contextWindow: number;
      maxOutput: number;
      notes?: string;
    }
  • Helper utilities including providers constant and findModel/findModels functions used to query and filter model data
    export const providers = [...new Set(models.map((m) => m.provider))];
    
    export function findModel(query: string): ModelPricing | undefined {
      const q = query.toLowerCase();
      return models.find(m => m.id === q || m.name.toLowerCase() === q) ??
        models.find(m => m.id.includes(q) || m.name.toLowerCase().includes(q));
    }
    
    export function findModels(query: string): ModelPricing[] {
      const q = query.toLowerCase();
      return models.filter(m =>
        m.id.includes(q) || m.name.toLowerCase().includes(q) || m.provider.toLowerCase().includes(q)
      );
    }

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/ankit-aglawe/tokencost-mcp-server'

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