mcp-model-router
Routes each prompt to the best-fitting Claude model via a local, zero-cost classifier, exposing a single smart_prompt tool for MCP clients.
README
MCP Model Router
An MCP server that routes each prompt to whichever Claude model best fits it.
The routing decision itself is 100% local — plain Python, no LLM call. Only one model call happens per request: the one that actually answers it. That matters, because the obvious way to build this (ask a model to classify the prompt first) doubles the number of calls and charges you for the classifier on every single request.
The tool
The server exposes one tool over MCP:
smart_prompt(prompt: str) -> str
Any MCP-capable client can discover and call it. The response comes back with the routing decision attached, so you can always audit the choice:
[routed to opus (claude-opus-5) — matched opus signals (score=2)]
<the answer>
How routing works
choose_model(prompt) in router.py returns (tier, reason). In order:
- Force tags. A prompt starting with
!opus,!sonnet,!haikuor!fablebypasses routing entirely. - Signal scoring. Four buckets are scored against the prompt:
- code patterns (fenced blocks,
def, stack traces,.py/.js/.tsx, regex, unit test) → coding tier - reasoning keywords (why, analyze, trade-off, architecture, root cause, pros and cons) → deepest tier
- creative keywords (write a story, poem, screenplay, lyrics) → narrative tier
- extraction keywords (extract, classify, translate, one sentence, tl;dr) → fastest tier
- code patterns (fenced blocks,
- Complexity escalation. Question marks, bullet lines and numbered list items are summed; three or more structural signals adds a point to the deep-reasoning tier.
- Length fallback. Only if nothing scored: ≤12 words → fastest tier, ≥150 words → deepest tier, otherwise the balanced generalist.
Keyword signals deliberately outrank the length heuristic. Without that precedence, a short prompt like "write a short story" would let the word-count bonus outvote the creative-keyword match it should lose to.
Tuning it
Every decision is appended to logs/routing_log.csv:
| timestamp | tier | reason | prompt_excerpt |
|---|
The keyword lists in router.py are a starting point, not a final answer.
Watch the log fill up and edit them directly. After any change, re-run the
offline smoke test — it asserts expected routing on seven representative
prompts and costs nothing, because it never touches the API:
python test_router.py
Setup
python -m venv .venv
.venv\Scripts\activate # Windows
pip install -r requirements.txt
cp .env.example .env # then put your real key in it
.env is gitignored — the key never leaves your machine.
Register the server with your MCP client via .mcp.json:
{
"mcpServers": {
"model-router": {
"command": "<path>\\.venv\\Scripts\\python.exe",
"args": ["<path>\\server.py"]
}
}
}
Adjust both paths to wherever you cloned this.
Files
| File | Role |
|---|---|
server.py |
MCP server, tool definition, model execution, CSV logging |
router.py |
The classifier: model registry, force tags, signal scoring, length fallback |
test_router.py |
Offline smoke test — no API calls, no cost |
.mcp.json |
Client registration |
Requirements
mcp · anthropic · python-dotenv
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。