haive.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.

Classes¶

MCPServerSelector

Intelligent MCP server selection and recommendation system.

ServerFilter

Flexible filtering system for MCP servers.

ServerScore

Score and metadata for a server recommendation.

TaskAnalyzer

Analyzes task descriptions to determine server requirements.

TaskRequirements

Analyzed requirements from a task description.

Module Contents¶

class haive.mcp.tools.server_selector.MCPServerSelector(servers=None)[source]¶

Intelligent MCP server selection and recommendation system.

Initialize server selector.

Parameters:

servers (list[dict[str, Any]] | None) – List of server documentation. If None, loads all available.

create_config_for_selection(selected_servers, lazy_init=True)[source]¶

Create MCPConfig for selected servers.

Parameters:
  • selected_servers (list[str]) – List of server names to include

  • lazy_init (bool) – Whether to use lazy initialization

Returns:

MCPConfig with selected servers

Return type:

haive.mcp.config.MCPConfig

filter_by_prefix(prefix)[source]¶

Filter servers by prefix/namespace.

Parameters:

prefix (str) – Prefix to filter by (e.g., “modelcontextprotocol/”)

Returns:

List of servers with matching prefix

Return type:

list[dict[str, Any]]

get_available_categories()[source]¶

Get all available server categories.

Returns:

List of unique categories

Return type:

list[str]

get_available_prefixes()[source]¶

Get all available server prefixes/namespaces.

Returns:

List of unique prefixes found in server names

Return type:

list[str]

get_selection_summary(selected_servers)[source]¶

Get summary of selected servers.

Parameters:

selected_servers (list[str]) – List of selected server names

Returns:

Summary dictionary with statistics and details

Return type:

dict[str, Any]

async interactive_select(prompt='Select MCP servers to use:', categories=None, prefixes=None, max_selections=None)[source]¶

Interactive server selection interface.

Parameters:
  • prompt (str) – Prompt to display to user

  • categories (list[str] | None) – Filter by categories

  • prefixes (list[str] | None) – Filter by prefixes

  • max_selections (int | None) – Maximum number of selections allowed

Returns:

List of selected server names

Return type:

list[str]

recommend_for_task(task_description, max_servers=5, include_experimental=False)[source]¶

Recommend servers for a specific task.

Parameters:
  • task_description (str) – Natural language description of the task

  • max_servers (int) – Maximum number of servers to recommend

  • include_experimental (bool) – Whether to include experimental servers

Returns:

List of ServerScore objects ranked by relevance

Return type:

list[ServerScore]

class haive.mcp.tools.server_selector.ServerFilter(servers)[source]¶

Flexible filtering system for MCP servers.

Initialize filter with server list.

Parameters:

servers (list[dict[str, Any]]) – List of server documentation dictionaries

filter_by_capability_keyword(keyword)[source]¶

Filter servers by capability keyword in description.

Parameters:

keyword (str) – Keyword to search for

Returns:

List of servers mentioning the keyword

Return type:

list[dict[str, Any]]

filter_by_category(category)[source]¶

Filter servers by category.

Parameters:

category (str) – Category to filter by

Returns:

List of servers in the category

Return type:

list[dict[str, Any]]

filter_by_multiple_criteria(prefixes=None, categories=None, keywords=None, exclude_prefixes=None)[source]¶

Filter servers by multiple criteria.

Parameters:
  • prefixes (list[str] | None) – List of prefixes to include

  • categories (list[str] | None) – List of categories to include

  • keywords (list[str] | None) – List of capability keywords

  • exclude_prefixes (list[str] | None) – List of prefixes to exclude

Returns:

List of servers matching all criteria

Return type:

list[dict[str, Any]]

filter_by_prefix(prefix)[source]¶

Filter servers by name prefix (namespace).

Parameters:

prefix (str) – Prefix to filter by (e.g., “anthropic/”, “openai/”)

Returns:

List of servers matching the prefix

Return type:

list[dict[str, Any]]

class haive.mcp.tools.server_selector.ServerScore[source]¶

Score and metadata for a server recommendation.

class haive.mcp.tools.server_selector.TaskAnalyzer[source]¶

Analyzes task descriptions to determine server requirements.

Initialize task analyzer.

analyze_task(task_description)[source]¶

Analyze a task description to determine requirements.

Parameters:

task_description (str) – Natural language task description

Returns:

TaskRequirements with analyzed needs

Return type:

TaskRequirements

class haive.mcp.tools.server_selector.TaskRequirements[source]¶

Analyzed requirements from a task description.