models-mcp
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 端点
工具
工具 | 功能 |
| 列出所有提供商(anthropic、openai、google 等)及其模型数量 |
| 按名称、提供商、最小上下文窗口、最大输入成本或能力标志(reasoning、tool_call、attachment)筛选模型 |
| 按 |
| 并排比较 2-6 个模型的价格、上下文和能力 |
| 强制重新获取,绕过 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 toolscompare_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
Scored across 8 tools
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.
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.
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.
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
Live registry of AI model specs, context windows, and per-token pricing.
Compare LLM API prices, search models and providers, and access reviewed benchmark results.
Look up, compare and track AI model API prices from an AI assistant. No sign-in needed.
Search curated open-weight AI model releases, licenses, architectures, and primary sources.
Related MCP Servers
- FlicenseAqualityDmaintenanceProvides up-to-date AI model names and pricing from models.dev, solving model hallucination by fetching recently released models.1-
- AlicenseNot gradedqualityCmaintenanceEnables browsing TokenLab models, comparing pricing, and generating cURL examples for various AI endpoints.MIT
- AlicenseNot gradedqualityCmaintenanceEnables 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 npmMIT
- AlicenseNot gradedqualityBmaintenanceEnables 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 npmMIT