haive.mcp.tools.ai_assistant

AI-friendly MCP server selection and configuration assistant.

This module provides tools specifically designed for AI agents to automatically select, configure, and use MCP servers based on task analysis and intelligent recommendations. It minimizes the need for manual configuration while maximizing the effectiveness of server selection.

The assistant provides:
  • Automatic server selection based on task analysis

  • Smart configuration generation with minimal setup

  • Performance-aware server combinations

  • Fallback strategies for failed servers

  • Context-aware capability matching

Classes:

MCPAssistant: Main AI-friendly server selection assistant SmartConfig: Intelligent configuration generator TaskMatcher: Advanced task-to-server matching system

Example

AI agent usage:

from haive.mcp.tools import MCPAssistant

# Create assistant
assistant = MCPAssistant()

# Automatically select servers for a task
task = "I need to analyze Python code in a GitHub repo for security issues"
config = await assistant.auto_configure_for_task(task)

# Create agent with optimal configuration
agent = MCPAgent(
    engine=engine,
    mcp_config=config,
    name="security_analysis_agent"
)

# Assistant provides reasoning
reasoning = assistant.get_selection_reasoning()
print(f"Selected servers because: {reasoning}")

Note

Designed to work seamlessly with AI agents that need to dynamically adapt their capabilities based on task requirements.

Classes

MCPAssistant

AI-friendly MCP server selection and configuration assistant.

ServerRecommendation

A server recommendation with detailed reasoning.

SmartConfiguration

A complete MCP configuration with metadata.

TaskMatcher

Advanced task-to-server matching with learning capabilities.

Module Contents

class haive.mcp.tools.ai_assistant.MCPAssistant(cache_enabled=True)

AI-friendly MCP server selection and configuration assistant.

Initialize MCP assistant.

Parameters:

cache_enabled (bool) – Whether to cache server information

async auto_configure_for_task(task_description, prefer_simple_setup=True, max_servers=3, include_fallbacks=True)[source]

Automatically configure MCP servers for a task.

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

  • prefer_simple_setup (bool) – Prefer servers with easier setup

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

  • include_fallbacks (bool) – Whether to include fallback servers

Returns:

SmartConfiguration with optimized setup

Return type:

SmartConfiguration

explain_recommendation(server_name)[source]

Get detailed explanation for a server recommendation.

Parameters:

server_name (str) – Name of the server to explain

Returns:

Dictionary with detailed explanation

Return type:

dict[str, Any]

get_selection_reasoning()[source]

Get the reasoning for the last selection.

Return type:

str

async validate_configuration(config)[source]

Validate a configuration and provide feedback.

Parameters:

config (haive.mcp.config.MCPConfig) – MCP configuration to validate

Returns:

Validation results with issues and suggestions

Return type:

dict[str, Any]

class haive.mcp.tools.ai_assistant.ServerRecommendation[source]

A server recommendation with detailed reasoning.

class haive.mcp.tools.ai_assistant.SmartConfiguration[source]

A complete MCP configuration with metadata.

class haive.mcp.tools.ai_assistant.TaskMatcher[source]

Advanced task-to-server matching with learning capabilities.

Initialize task matcher.

get_server_recommendation_score(server_name, task_pattern, task_description)[source]

Calculate recommendation score for a server.

Parameters:
  • server_name (str) – Name of the server

  • task_pattern (str | None) – Matched task pattern

  • task_description (str) – Original task description

Returns:

Score from 0.0 to 1.0

Return type:

float

match_task_to_pattern(task_description)[source]

Match a task description to a known pattern.

Parameters:

task_description (str) – Natural language task description

Returns:

Pattern name if matched, None otherwise

Return type:

str | None