mcp.tools.server_selector¶
Intelligent MCP server selection and filtering tools for AI agents.
This module provides sophisticated tools for filtering, selecting, and recommending MCP servers based on various criteria including prefixes, capabilities, task analysis, and performance metrics. Designed to help AI agents make intelligent decisions about which servers to use for specific tasks.
- The server selector provides:
Namespace/prefix-based filtering for organized server groups
Capability-based server recommendations
Task analysis for automatic server selection
Performance-aware server ranking
Interactive selection interfaces
Smart server combinations and workflows
- Classes:
MCPServerSelector: Main class for intelligent server selection ServerFilter: Flexible filtering system for servers TaskAnalyzer: Analyzes tasks to recommend appropriate servers ServerRecommender: Provides smart server recommendations
Example
Basic server selection:
from haive.mcp.tools import MCPServerSelector
from haive.mcp.documentation import MCPDocumentationLoader
# Create selector with all available servers
loader = MCPDocumentationLoader()
all_servers = loader.load_all_mcp_documents()
selector = MCPServerSelector(all_servers)
# Filter by prefix (organization/namespace)
anthropic_servers = selector.filter_by_prefix("anthropic/")
openai_servers = selector.filter_by_prefix("openai/")
# Get recommendations for a task
task = "I need to analyze a GitHub repository for security issues"
recommendations = selector.recommend_for_task(task)
# Interactive selection
chosen_servers = await selector.interactive_select(
"Choose servers for code analysis",
categories=["development", "security"]
)
Note
This system is designed to make server selection intelligent and context-aware, reducing the need for manual server configuration.
Attributes¶
Classes¶
Intelligent MCP server selection and recommendation system. |
|
Flexible filtering system for MCP servers. |
|
Score and metadata for a server recommendation. |
|
Analyzes task descriptions to determine server requirements. |
|
Analyzed requirements from a task description. |
Module Contents¶
- class mcp.tools.server_selector.MCPServerSelector(servers: list[dict[str, Any]] | None = None)¶
Intelligent MCP server selection and recommendation system.
- create_config_for_selection(selected_servers: list[str], lazy_init: bool = True) haive.mcp.config.MCPConfig ¶
Create MCPConfig for selected servers.
- Parameters:
selected_servers – List of server names to include
lazy_init – Whether to use lazy initialization
- Returns:
MCPConfig with selected servers
- filter_by_prefix(prefix: str) list[dict[str, Any]] ¶
Filter servers by prefix/namespace.
- Parameters:
prefix – Prefix to filter by (e.g., “modelcontextprotocol/”)
- Returns:
List of servers with matching prefix
- get_available_categories() list[str] ¶
Get all available server categories.
- Returns:
List of unique categories
- get_available_prefixes() list[str] ¶
Get all available server prefixes/namespaces.
- Returns:
List of unique prefixes found in server names
- get_selection_summary(selected_servers: list[str]) dict[str, Any] ¶
Get summary of selected servers.
- Parameters:
selected_servers – List of selected server names
- Returns:
Summary dictionary with statistics and details
- async interactive_select(prompt: str = 'Select MCP servers to use:', categories: list[str] | None = None, prefixes: list[str] | None = None, max_selections: int | None = None) list[str] ¶
Interactive server selection interface.
- Parameters:
prompt – Prompt to display to user
categories – Filter by categories
prefixes – Filter by prefixes
max_selections – Maximum number of selections allowed
- Returns:
List of selected server names
- recommend_for_task(task_description: str, max_servers: int = 5, include_experimental: bool = False) list[ServerScore] ¶
Recommend servers for a specific task.
- Parameters:
task_description – Natural language description of the task
max_servers – Maximum number of servers to recommend
include_experimental – Whether to include experimental servers
- Returns:
List of ServerScore objects ranked by relevance
- analyzer¶
- filter¶
- server_map¶
- servers = None¶
- class mcp.tools.server_selector.ServerFilter(servers: list[dict[str, Any]])¶
Flexible filtering system for MCP servers.
- filter_by_capability_keyword(keyword: str) list[dict[str, Any]] ¶
Filter servers by capability keyword in description.
- Parameters:
keyword – Keyword to search for
- Returns:
List of servers mentioning the keyword
- filter_by_category(category: str) list[dict[str, Any]] ¶
Filter servers by category.
- Parameters:
category – Category to filter by
- Returns:
List of servers in the category
- filter_by_multiple_criteria(prefixes: list[str] | None = None, categories: list[str] | None = None, keywords: list[str] | None = None, exclude_prefixes: list[str] | None = None) list[dict[str, Any]] ¶
Filter servers by multiple criteria.
- Parameters:
prefixes – List of prefixes to include
categories – List of categories to include
keywords – List of capability keywords
exclude_prefixes – List of prefixes to exclude
- Returns:
List of servers matching all criteria
- filter_by_prefix(prefix: str) list[dict[str, Any]] ¶
Filter servers by name prefix (namespace).
- Parameters:
prefix – Prefix to filter by (e.g., “anthropic/”, “openai/”)
- Returns:
List of servers matching the prefix
- servers¶
- class mcp.tools.server_selector.ServerScore¶
Score and metadata for a server recommendation.
- class mcp.tools.server_selector.TaskAnalyzer¶
Analyzes task descriptions to determine server requirements.
- analyze_task(task_description: str) TaskRequirements ¶
Analyze a task description to determine requirements.
- Parameters:
task_description – Natural language task description
- Returns:
TaskRequirements with analyzed needs
- capability_patterns¶
- server_patterns¶
- class mcp.tools.server_selector.TaskRequirements¶
Analyzed requirements from a task description.
- mcp.tools.server_selector.logger¶