mcp.tools.server_selector ========================= .. py:module:: mcp.tools.server_selector .. autoapi-nested-parse:: 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 .. rubric:: Example Basic server selection: .. code-block:: python 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 ---------- .. autoapisummary:: mcp.tools.server_selector.logger Classes ------- .. autoapisummary:: mcp.tools.server_selector.MCPServerSelector mcp.tools.server_selector.ServerFilter mcp.tools.server_selector.ServerScore mcp.tools.server_selector.TaskAnalyzer mcp.tools.server_selector.TaskRequirements Module Contents --------------- .. py:class:: MCPServerSelector(servers: list[dict[str, Any]] | None = None) Intelligent MCP server selection and recommendation system. .. py:method:: create_config_for_selection(selected_servers: list[str], lazy_init: bool = True) -> haive.mcp.config.MCPConfig Create MCPConfig for selected servers. :param selected_servers: List of server names to include :param lazy_init: Whether to use lazy initialization :returns: MCPConfig with selected servers .. py:method:: filter_by_prefix(prefix: str) -> list[dict[str, Any]] Filter servers by prefix/namespace. :param prefix: Prefix to filter by (e.g., "modelcontextprotocol/") :returns: List of servers with matching prefix .. py:method:: get_available_categories() -> list[str] Get all available server categories. :returns: List of unique categories .. py:method:: get_available_prefixes() -> list[str] Get all available server prefixes/namespaces. :returns: List of unique prefixes found in server names .. py:method:: get_selection_summary(selected_servers: list[str]) -> dict[str, Any] Get summary of selected servers. :param selected_servers: List of selected server names :returns: Summary dictionary with statistics and details .. py:method:: 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] :async: Interactive server selection interface. :param prompt: Prompt to display to user :param categories: Filter by categories :param prefixes: Filter by prefixes :param max_selections: Maximum number of selections allowed :returns: List of selected server names .. py:method:: recommend_for_task(task_description: str, max_servers: int = 5, include_experimental: bool = False) -> list[ServerScore] Recommend servers for a specific task. :param task_description: Natural language description of the task :param max_servers: Maximum number of servers to recommend :param include_experimental: Whether to include experimental servers :returns: List of ServerScore objects ranked by relevance .. py:attribute:: analyzer .. py:attribute:: filter .. py:attribute:: server_map .. py:attribute:: servers :value: None .. py:class:: ServerFilter(servers: list[dict[str, Any]]) Flexible filtering system for MCP servers. .. py:method:: filter_by_capability_keyword(keyword: str) -> list[dict[str, Any]] Filter servers by capability keyword in description. :param keyword: Keyword to search for :returns: List of servers mentioning the keyword .. py:method:: filter_by_category(category: str) -> list[dict[str, Any]] Filter servers by category. :param category: Category to filter by :returns: List of servers in the category .. py:method:: 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. :param prefixes: List of prefixes to include :param categories: List of categories to include :param keywords: List of capability keywords :param exclude_prefixes: List of prefixes to exclude :returns: List of servers matching all criteria .. py:method:: filter_by_prefix(prefix: str) -> list[dict[str, Any]] Filter servers by name prefix (namespace). :param prefix: Prefix to filter by (e.g., "anthropic/", "openai/") :returns: List of servers matching the prefix .. py:attribute:: servers .. py:class:: ServerScore Score and metadata for a server recommendation. .. py:attribute:: capabilities_match :type: list[str] .. py:attribute:: category_match :type: bool .. py:attribute:: prefix_match :type: bool .. py:attribute:: reasons :type: list[str] .. py:attribute:: score :type: float .. py:attribute:: server_name :type: str .. py:class:: TaskAnalyzer Analyzes task descriptions to determine server requirements. .. py:method:: analyze_task(task_description: str) -> TaskRequirements Analyze a task description to determine requirements. :param task_description: Natural language task description :returns: TaskRequirements with analyzed needs .. py:attribute:: capability_patterns .. py:attribute:: server_patterns .. py:class:: TaskRequirements Analyzed requirements from a task description. .. py:attribute:: complexity_score :type: float .. py:attribute:: keywords :type: list[str] .. py:attribute:: preferred_categories :type: list[str] .. py:attribute:: required_capabilities :type: list[str] .. py:attribute:: suggested_servers :type: list[str] .. py:data:: logger