Overview
Smart Routing is MCPHub’s intelligent tool discovery system that uses vector semantic search to automatically find the most relevant tools for any given task. Instead of manually specifying which tools to use, AI clients can describe what they want to accomplish, and Smart Routing will identify and provide access to the most appropriate tools.How Smart Routing Works
1. Tool Indexing
When servers start up, Smart Routing automatically:- Discovers all available tools from MCP servers
- Extracts tool metadata (names, descriptions, parameters)
- Converts tool information to vector embeddings
- Stores embeddings in PostgreSQL with pgvector
2. Semantic Search
When a query is made:- User queries are converted to vector embeddings
- Similarity search finds matching tools using cosine similarity
- Dynamic thresholds filter out irrelevant results
- Results are ranked by relevance score
3. Intelligent Filtering
Smart Routing applies several filters:- Relevance Threshold: Only returns tools above similarity threshold
- Context Awareness: Considers conversation context
- Tool Availability: Ensures tools are currently accessible
- Permission Filtering: Respects user access permissions
4. Tool Execution
Found tools can be directly executed:- Parameter validation ensures correct tool usage
- Error handling provides helpful feedback
- Response formatting maintains consistency
- Logging tracks tool usage for analytics
Prerequisites
Smart Routing requires additional setup compared to basic MCPHub usage:Required Components
- PostgreSQL with pgvector: Vector database for embeddings storage
- Embedding Service: OpenAI API or compatible service
- Environment Configuration: Proper configuration variables
Using Smart Routing
Smart Routing Endpoint
Access Smart Routing through the special$smart
endpoint:
- HTTP MCP
- SSE (Legacy)
Troubleshooting
Database Connection Issues
Database Connection Issues
Symptoms:
- Smart Routing not available
- Database connection errors
- Embedding storage failures
- Verify PostgreSQL is running
- Check DATABASE_URL format
- Ensure pgvector extension is installed
- Test connection manually:
Embedding Service Problems
Embedding Service Problems
Symptoms:
- Tool indexing failures
- Query processing errors
- API rate limit errors
- Verify API key validity
- Check network connectivity
- Monitor rate limits
- Test embedding service:
Poor Search Results
Poor Search Results
Symptoms:
- Irrelevant tools returned
- Low relevance scores
- Missing expected tools
- Adjust similarity threshold
- Re-index tools with better descriptions
- Use more specific queries
- Check tool metadata quality
Performance Issues
Performance Issues
Symptoms:
- Slow query responses
- High database load
- Memory usage spikes
- Optimize database configuration
- Increase cache sizes
- Reduce batch sizes
- Monitor system resources
Best Practices
Query Writing
Be Descriptive: Use specific, descriptive language in queries for better tool matching.
Include Context: Provide relevant context about your task or domain for more accurate results.
Use Natural Language: Write queries as you would describe the task to a human.
Tool Descriptions
Quality Metadata: Ensure MCP servers provide high-quality tool descriptions and metadata.
Regular Updates: Keep tool descriptions current as functionality evolves.
Consistent Naming: Use consistent naming conventions across tools and servers.
System Maintenance
Regular Re-indexing: Periodically re-index tools to ensure embedding quality.
Monitor Performance: Track query patterns and optimize based on usage.
Update Models: Consider updating to newer embedding models as they become available.