MCP Based Routing
This guide shows you how to implement custom classification logic using the Model Context Protocol (MCP). MCP routing lets you integrate external services, LLMs, or custom business logic for classification decisions while keeping your data private and your routing logic extensible.
Key Advantagesâ
- Baseline/High Accuracy: Use powerful LLMs (GPT-4, Claude) for classification with in-context learning
- Extensible: Easily integrate custom classification logic without modifying router code
- Private: Keep classification logic and data in your own infrastructure
- Flexible: Combine LLM reasoning with business rules, user context, and external data
What Problem Does It Solve?â
Built-in classifiers are limited to predefined models and logic. MCP routing enables:
- LLM-powered classification: Use GPT-4/Claude for complex, nuanced categorization
- In-context learning: Provide examples and context to improve classification accuracy
- Custom business logic: Implement routing rules based on user tier, time, location, history
- External data integration: Query databases, APIs, feature flags during classification
- Rapid experimentation: Update classification logic without redeploying router
When to Useâ
- High-accuracy requirements where LLM-based classification outperforms BERT/embeddings
- Complex domains needing nuanced understanding beyond keyword/embedding matching
- Custom business rules (user tiers, A/B tests, time-based routing)
- Private/sensitive data where classification must stay in your infrastructure
- Rapid iteration on classification logic without code changes
Configurationâ
Configure MCP classifier in your config.yaml:
classifier:
# Disable in-tree classifier
category_model:
model_id: ""
# Enable MCP classifier
mcp_category_model:
enabled: true
transport_type: "http"
url: "http://localhost:8090/mcp"
threshold: 0.6
timeout_seconds: 30
# tool_name: "classify_text" # Optional: auto-discovers if not specified
categories: [] # Categories loaded from MCP server
default_model: openai/gpt-oss-20b
vllm_endpoints:
- name: endpoint1
address: 127.0.0.1
port: 8000
weight: 1
model_config:
openai/gpt-oss-20b:
reasoning_family: gpt-oss
preferred_endpoints: [endpoint1]
How It Worksâ
- Startup: Router connects to MCP server and calls
list_categoriestool - Category Loading: MCP returns categories, system prompts, and descriptions
- Classification: For each request, router calls
classify_texttool - Routing: MCP response includes category, model, and reasoning settings
MCP Response Formatâ
list_categories:
{
"categories": ["math", "science", "technology"],
"category_system_prompts": {
"math": "You are a mathematics expert...",
"science": "You are a science expert..."
},
"category_descriptions": {
"math": "Mathematical and computational queries",
"science": "Scientific concepts and queries"
}
}
classify_text:
{
"class": 3,
"confidence": 0.85,
"model": "openai/gpt-oss-20b",
"use_reasoning": true
}