model-router
Provides cost-aware routing to OpenAI-compatible endpoints, enabling automatic fallback between free and paid models for tasks of varying difficulty.
Click on "Install Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@model-routersmart_call 'summarize the quarterly report'"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
Model Router โ Cost-Aware Multi-LLM Routing with Free-First Fallback Chain
Route every task to the best model automatically โ free providers first, paid providers as fallback.
๐ฏ Why Model Router?
Most LLM integration code hard-codes a single model or uses a single API provider. This means:
โ Expensive: every request (even trivial ones) goes to a paid frontier model
โ Fragile: one provider outage = total failure
โ Inflexible: no way to match model capability to task difficulty
Model Router solves all three with a simple, dependency-light design:
โ Task Difficulty Classification: 5 levels (
vision/long/complex/medium/simple) via keyword + content-length heuristics (zero cost, no LLM involved)โ Free-First Fallback Chain: each route level defines an ordered candidate chain โ free providers (Zhipu, SiliconFlow, OpenRouter free models) are tried first; on any failure, the next candidate (eventually paid DeepSeek/Qwen/GLM/Kimi) is tried automatically
โ Zero Third-Party Dependencies: core library only needs
requests; the MCP server is pure stdlib (JSON-RPC 2.0 over stdio)โ Multiple Interfaces: Python API ยท CLI ยท MCP server (any MCP client: Claude, Qoder, Cursorโฆ) ยท File-watch daemon
๐ Architecture
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ router_core.py โ
โ โ
task_desc โโโถโ classify_task() โ 5 difficulty levels โ
content โโโถโ _get_candidates() โ ordered provider chainโ
image โโโโโโโถโ route_and_call() โ free-first, fallback โ
โ โ
โโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโ
โผ โผ โผ
auto_router.py mcp_server.py Python API
(CLI + daemon) (MCP tools) (import router_core)Routing Levels
Level | Trigger | Typical Models |
| image/screenshot/OCR | Qwen-VL, GLM-4V |
| content > 2000 chars, full documents | 128K-context models |
| analysis/code/data/stats/reasoning | DeepSeek, Qwen3-32B |
| writing/translation/polish | GLM, Qwen |
| daily chat / quick queries | small free models |
Fallback semantics: candidates are tried in order; the response reports tier (free/paid), attempts, fallback_used, and per-provider errors for full observability.
๐ Quick Start
# 1. Install (only requests is required)
pip install requests
# 2. Configure
cp config.example.json config.json
# โ fill in your API keys
# 3. CLI โ analyze only (zero cost, no model call)
python router_core.py analyze "ๅๆ่ฟไปฝๆฐ่ฑกๆฐๆฎ"
# 4. CLI โ route and call
python router_core.py call "็ฟป่ฏไปฅไธๆฎต่ฝ" --content "Hello world" --system "ไฝ ๆฏไธไธ็ฟป่ฏ"
# 5. Python API
from router_core import route_and_call, analyze_task
result = analyze_task("ๅไธไปฝ่ฎบๆๆ่ฆ", content_len=300)
print(result["primary"]) # first candidate
print(result["candidates"]) # full fallback chain
text = route_and_call("ๆป็ป่ฆ็น", "long text...")["content"]๐ฅ MCP Server (for any MCP client)
python mcp_server.pyTool | Description |
| Auto-route + call (free-first, fallback on failure) |
| Analyze difficulty + return candidate chain (zero cost) |
| List all configured providers, models and chains |
Register in your MCP client (e.g. Claude Desktop claude_desktop_config.json):
{
"mcpServers": {
"model-router": {
"command": "python",
"args": ["/path/to/model-router/mcp_server.py"],
"env": {"PYTHONIOENCODING": "utf-8"}
}
}
}โฑ Task-Triggered Daemon (file-watch mode)
# One-shot
python auto_router.py "ไปปๅกๆ่ฟฐ" -c "ๅ
ๅฎน" --image photo.png
# Daemon: drop task files into inbox/, results appear in outbox/
python auto_router.py --watch --dir ./tasks๐ง Configuration
config.json structure (see config.example.json):
providers: OpenAI-compatible endpoints with
tier(free/paid) and optionalenabled: falserouting: per-level ordered
candidateschains โ free first, paid as safety netlevels: human-readable descriptions per level
Add or remove providers freely โ the router is fully data-driven.
๐ License
MIT โ free for personal and commercial use. See LICENSE.
Inspired by real-world cost optimization: ~90% of everyday tasks can be served by free tier models, while hard tasks still get frontier-model quality through automatic fallback.
This server cannot be installed
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Related MCP Connectors
Hosted MCP server for LLM cost estimation, model comparison, and budget-aware routing.
Agent Cost Allocator MCP โ multi-tenant LLM cost attribution for chargeback billing. Companion to
MCP server providing access to the Scorecard API to evaluate and optimize LLM systems.
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
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/yaowanxiang/model-router'
If you have feedback or need assistance with the MCP directory API, please join our Discord server