Skip to main content
Glama

Models MCP

按价格、上下文窗口和功能搜索、比较和检查 AI 模型。一个基于 models.dev 目录(models.dev/api.json)的 MCP 服务器,让你的代理始终拥有最新的模型数据,无需手动维护列表。

models.dev 本身不提供 MCP 服务器,只有 JSON API 和用于读取它的 TypeScript SDK。本项目填补了这一空白。

同一套工具代码支持两种运行方式:

  • stdio(src/index.ts):用于本地 MCP 客户端

  • Cloudflare Worker(src/worker.ts):作为 /mcp 上的远程 Streamable HTTP 端点

工具

工具

功能

list_providers

列出所有提供商(anthropic、openai、google 等)及其模型数量

find_models

按名称、提供商、最小上下文窗口、最大输入成本或能力标志(reasoning、tool_call、attachment)筛选模型

get_model

按 provider/model id 获取单个模型的完整元数据

compare_models

并排比较 2-6 个模型的价格、上下文和能力

refresh_catalog

强制重新获取,绕过 1 小时缓存

Related MCP server: TokenLab Model Explorer

安装

npm install
npm run build

通过 stdio 独立运行(用于测试)

npm start

它通过 stdio 使用 MCP 协议通信,所以你不会直接看到太多输出;请使用 MCP Inspector 来探查它:

npx @modelcontextprotocol/inspector node dist/index.js

托管在 Cloudflare Workers 上

Worker 入口(src/worker.ts)通过 /mcp 上的 Streamable HTTP 提供相同的工具,并具备:

  • 目录缓存:使用 Workers Cache API(caches.default)进行缓存,TTL 为 1 小时,跨请求和隔离区共享。

  • 按 IP 限流:通过 Workers 限流绑定实现,每个 IP 每分钟 60 个请求,按 Cloudflare 位置强制执行。超出限制的请求会收到 429 响应,并带有 Retry-After: 60。

# local dev at http://localhost:8787/mcp
npm run dev:worker

# deploy
npm run deploy

部署后,你的端点是 https://models-mcp.<your-subdomain>.workers.dev/mcp。

将 MCP 客户端指向它:

Claude Code:

claude mcp add --transport http models-mcp https://models-mcp.<your-subdomain>.workers.dev/mcp

通用客户端配置(任何支持 Streamable HTTP 的客户端):

{
  "mcpServers": {
    "models-mcp": {
      "url": "https://models-mcp.<your-subdomain>.workers.dev/mcp"
    }
  }
}

对于仅支持 stdio 的客户端(Claude Desktop),使用 mcp-remote 进行桥接:

{
  "mcpServers": {
    "models-mcp": {
      "command": "npx",
      "args": ["mcp-remote", "https://models-mcp.<your-subdomain>.workers.dev/mcp"]
    }
  }
}

任何地方都不需要 API 密钥。所有数据都来自公开的 models.dev/api.json 端点。

测试

npm test

涵盖目录客户端(扁平化、TTL 缓存、强制刷新、失败时使用过期数据回退、id 解析)以及全部五个工具的端到端测试,通过内存传输上的真实 MCP 客户端会话进行。

关于数据的说明

  • 目录缓存 1 小时:托管时使用 Workers Cache API,stdio 时使用进程内存。调用 refresh_catalog 强制更新。如果重新获取失败,将继续提供上次成功的目录。

  • models.dev 没有为消费者发布带版本号的模式,因此 src/types.ts 中的类型有意保持宽松(索引签名保留任何未显式类型化的字段)。

  • 模型 id 遵循 AI SDK 和 OpenCode 使用的 provider/model 约定,例如 anthropic/claude-sonnet-4-5。如果模型 id 在提供商之间无歧义,get_model 和 compare_models 也接受裸模型 id。

可能的扩展

  • 一个 list_facets 工具(模态、分词器),类似于其他模型目录 MCP 所暴露的功能。

  • 一个 test_model 工具,通过你配置的任何提供商密钥进行实时调用,用于延迟/成本合理性检查。

  • 如果你希望 Worker 保持私有,可以在其前面加上 OAuth 或 Cloudflare Access。

Available Tools

8 tools
compare_modelsCompare modelsA

Diff 2-6 models side by side on pricing, context window, and capabilities. Accepts 'provider/model' ids, or bare model ids when unambiguous across providers. Ids resolving to the same model are compared once.

Inputs: ids (required).

estimate_costEstimate costA

Estimate the USD cost of a request to one model from its published per-million-token rates. Use get_model first if you need to pick an id.

Inputs: id (required), inputTokens, outputTokens, cacheReadTokens, +1 more.

find_modelsFind modelsA

Search and filter models across all providers by name, provider, capability, context window, or price. Returns a compact summary per model; use get_model for full details on one.

Inputs: limit, query, provider, minContext, +4 more.

get_modelGet modelA

Fetch full metadata for one model. Accepts 'provider/model' (preferred, e.g. 'anthropic/claude-sonnet-4-5') or a bare model id if unambiguous across providers.

Inputs: id (required).

get_providerGet providerA

Fetch metadata for one provider: display name, AI SDK package name, API base URL, docs link, and a compact list of its models. Accepts the provider id ('anthropic') or display name ('Anthropic'). Use get_model for full per-model detail.

Inputs: id (required).

list_providersList providersA

List every provider in the models.dev catalog (e.g. anthropic, openai, google) with its model count. Use this to see what's available before narrowing with find_models.

Inputs: no named parameters.

refresh_catalogRefresh catalogA

Force a fresh fetch of the models.dev catalog, bypassing the in-memory cache. Use if you suspect the data is stale. If the refetch fails, the last good catalog keeps being served and servedStale is reported as true.

Inputs: no named parameters.

top_modelsTop modelsA

Rank models by one criterion: cheapest input/output price per million tokens, largest context window, most context per input dollar, or newest release. Supports the same filters as find_models.

Inputs: sortBy (required), limit, query, provider, +5 more.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    A4.2/5.0

    Scored across 8 tools

    Disambiguation5/5

    Each tool targets a distinct operation: listing providers, searching models, fetching details, comparing, refreshing, estimating cost, ranking, and provider metadata. Even where two tools support similar filters, their purposes are clearly differentiated by descriptions.

    Naming Consistency4/5

    Tool names mostly follow a clear verb_noun pattern such as list_providers, find_models, get_model, and estimate_cost. The exception is top_models, which reads more like a noun phrase than an imperative verb action, a minor deviation from the otherwise consistent convention.

    Tool Count5/5

    Eight tools is a well-scoped size for a model catalog server. Each tool covers a meaningful workflow without redundancy or bloat, from discovery and search to comparison and cost estimation.

    Completeness5/5

    The surface covers the full read-only lifecycle of interacting with the models.dev catalog: list, search, detail, compare, rank, and cost estimation, plus provider-level metadata and cache refresh. No obvious dead ends or missing core operations are present.

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      Not graded
      quality
      C
      maintenance
      Enables AI agents to browse, inspect, and compare LLMs from OpenRouter's catalog with normalized per-million-token pricing, context windows, and modalities. Supports filtering by search, free-only status, minimum context, or modality.
      316 npm
      MIT
    • A
      license
      Not graded
      quality
      B
      maintenance
      Enables checking OpenAI, Claude, Gemini and other LLM model IDs against a live catalog to identify deprecated or unknown names and suggest newer replacements. Also lets users search current models by provider, price, context size or tool support, and scan files or folders for outdated IDs.
      72 npm
      MIT