RouteMCP — AI Model Router MCP Server
Servidor MCP que clasifica tareas y enruta prompts al mejor modelo de IA disponible. Soporta Google Gemini, Groq y Cerebras con failover automático.
How It Works / Cómo Funciona
- Classify — Analiza el prompt usando IA (Groq
llama-3.1-8b) con un fallback inteligente a palabras clave para detectar el tipo de tarea (code, math, reasoning, creative, vision, long_context, multilingual, general). - Route — Selecciona el mejor modelo según la tarea usando las prioridades configuradas en
config.json. - Fallback — Si el mejor modelo falla (API error, timeout, rate limit 429 con Retry-After), prueba el siguiente en la lista.
- Ask — Envía el prompt directamente a un modelo específico.
- Compare — Envía el mismo prompt a múltiples modelos en paralelo (concurrencia) y compara resultados rápidamente.
Routing Logic / Lógica de Enrutamiento (Vía config.json)
| Task Type | Preferred Models |
|---|---|
| code | gemini-2.5-pro → llama-3.3-70b → gemini-2.5-flash → cerebras-llama-3.3-70b |
| reasoning | gemini-2.5-pro → llama-3.3-70b → gemini-2.5-flash |
| math | gemini-2.5-pro → gemini-2.5-flash → llama-3.3-70b |
| creative | gemini-2.0-flash → gemini-3-flash-preview → mixtral-8x7b |
| general | gemini-2.0-flash → gemini-2.5-flash → llama-3.3-70b → gemini-3-flash-preview |
| vision | gemini-2.5-pro → gemini-2.0-flash → gemini-2.5-flash → gemini-3-flash-preview |
| long_context | gemini-2.5-pro → gemini-2.0-flash → gemini-2.5-flash → gemini-3-flash-preview |
| speed | llama-3.1-8b → cerebras-llama-3.3-70b → llama-3.3-70b → gemini-2.0-flash |
| multilingual | gemini-2.0-flash → mixtral-8x7b → gemini-2.5-flash |
Features / Funcionalidades
| Tool / Herramienta | Description / Descripción |
|---|---|
ask |
Envía un prompt a un modelo específico |
models |
Lista modelos disponibles con capacidades, contexto y costo |
classify_task |
Clasifica un prompt y muestra los modelos recomendados |
route |
Enruta automáticamente al mejor modelo según la tarea |
compare |
Compara respuestas de múltiples modelos para un mismo prompt (Ejecución en paralelo) |
Nota sobre Configuración: Toda la lógica de enrutamiento, lista de modelos y palabras clave se genera y lee desde un archivo
config.jsonen la raíz del proyecto. ¡Puedes editarlo para personalizar tus modelos sin tocar el código fuente!
Providers / Proveedores
| Provider | API Key | Models |
|---|---|---|
| Google Gemini | GEMINI_API_KEY |
gemini-2.5-pro, gemini-2.0-flash, gemini-2.5-flash, gemini-3-flash-preview |
| Groq | GROQ_API_KEY |
llama-3.3-70b, llama-3.1-8b, mixtral-8x7b |
| Cerebras | CEREBRAS_API_KEY |
cerebras-llama-3.3-70b |
Tech Stack
- Python —
>=3.11 - Framework:
mcp(FastMCP) via stdio JSON-RPC - HTTP:
httpx(async) con manejo de límites de tasa (Retry-After) - Classifier: Híbrido (LLM basado en Groq
llama-3.1-8b+ Keyword-based fallback) - Configuration: Externa vía
config.json
🔧 Recent Improvements
- Cerebras Model Fixed — Model parameter is now properly mapped (was always sending
llama3.3-70bregardless of input) - Retry Logic Deduplicated — Shared
retry_ask()helper inbase.pyreplaces 3 copies of identical retry code is_available()Cached — Provider availability cached for 60s TTL (no HTTP call on every routing decision)- Configurable Temperature/Max Tokens —
ask()andcompare()tools now accepttemperatureandmax_tokensparameters - Lazy Provider Init — Providers are created only when first needed, not at server startup
- Provider-Model Validation — Engine validates that the requested model belongs to the correct provider before forwarding
- Prompt Injection Mitigation — Classifier truncates user input to 1000 chars with clear delimiters
- Atomic Config Write —
config.jsonuses.tmp+os.replace()to prevent corruption on concurrent writes - Module-Level Imports —
classify_taskno longer re-imports modules on every call
Quick Start
# Configurar API keys
export GEMINI_API_KEY="..."
export GROQ_API_KEY="..."
export CEREBRAS_API_KEY="..."
# Instalar
pip install mcp httpx
# Ejecutar servidor
python server.py
Ejemplos
# Listar modelos disponibles
result = await session.call_tool("models", {})
# Clasificar tarea
result = await session.call_tool("classify_task", {"prompt": "write a Python function"})
# Enrutar automáticamente
result = await session.call_tool("route", {"prompt": "explain quantum computing"})
# Preguntar a un modelo específico
result = await session.call_tool("ask", {"model": "gemini-2.0-flash", "prompt": "hello"})
# Comparar modelos
result = await session.call_tool("compare", {
"prompt": "solve 2+2",
"models": "gemini-2.0-flash,llama-3.3-70b"
})
Project Structure
routemcp/
├── server.py # MCP server entry point (tools)
├── router/
│ ├── __init__.py
│ ├── engine.py # RouterEngine: routing & fallback logic, async compare
│ ├── classifier.py # Task classifier (LLM Hybrid + keyword scoring)
│ ├── models.py # Model definitions & config.json loader
│ └── providers/
│ ├── __init__.py
│ ├── base.py # AIProvider base class & ProviderError
│ ├── google_provider.py # Google Gemini API
│ ├── groq_provider.py # Groq API
│ └── cerebras_provider.py # Cerebras API
├── client.py # Test client CLI
└── pyproject.toml
Metadata
Release files for routemcp 1.27.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| routemcp-1.27.1.tar.gz | 13.0 kB | Without provenance | Details for routemcp-1.27.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| routemcp-1.27.1-py3-none-any.whl | Python 3 | none | any | Details for routemcp-1.27.1-py3-none-any.whl |
Total release size: 48.1 kB
Release files / routemcp-1.27.1.tar.gz
| Download URL | routemcp-1.27.1.tar.gz |
|---|---|
| Size | 13.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f48b5eda6aec8ba424c8a3a2984ee5ef2fbf0830ba19d30beadaddf5c1e17cd9
|
|
BLAKE2b-256 checksum How to use checksums |
455cadd324b813922f7207a3993afe4b12fe2a8114d3a6cb15e2eda49e519734
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.4
|
Release files / routemcp-1.27.1-py3-none-any.whl
| Download URL | routemcp-1.27.1-py3-none-any.whl |
|---|---|
| Size | 35.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c2b3aac5abc63285fdf34bc843595ca88bf8fa206a5ad7c07317eb32a3dcd44e
|
|
BLAKE2b-256 checksum How to use checksums |
8d2afb015f0c42cf22db47dd9264c60ede7b313959320efff76d0ce45631a91c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.4
|
Security for routemcp 1.27.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.