mcp.tools.server_tester ======================= .. py:module:: mcp.tools.server_tester .. autoapi-nested-parse:: MCP server testing and validation tools. This module provides tools for testing MCP server configurations, validating connections, and ensuring servers are working correctly before use in production. The testing system provides: - Connection testing for individual servers - Batch testing for multiple servers - Health monitoring and diagnostics - Performance benchmarking - Configuration validation Classes: MCPServerTester: Main testing interface TestResult: Results from server testing HealthMonitor: Continuous health monitoring .. rubric:: Example Testing server configurations: .. code-block:: python from haive.mcp.tools import MCPServerTester from haive.mcp.config import MCPServerConfig # Test individual server tester = MCPServerTester() server_config = MCPServerConfig( name="test_server", transport="stdio", command="npx", args=["-y", "@modelcontextprotocol/server-filesystem"] ) result = await tester.test_server(server_config) if result.success: print(f"✅ {server_config.name} is working") else: print(f"❌ {server_config.name} failed: {result.error}") # Test multiple servers results = await tester.test_multiple_servers([server_config]) # Monitor health monitor = tester.create_health_monitor() await monitor.start_monitoring([server_config]) .. note:: Server testing requires the actual MCP packages to be installed and may need appropriate environment variables. Attributes ---------- .. autoapisummary:: mcp.tools.server_tester.logger Classes ------- .. autoapisummary:: mcp.tools.server_tester.HealthMonitor mcp.tools.server_tester.HealthStatus mcp.tools.server_tester.MCPServerTester mcp.tools.server_tester.TestResult Module Contents --------------- .. py:class:: HealthMonitor(check_interval: int = 60) Continuous health monitoring for MCP servers. .. py:method:: get_health_report() -> dict[str, HealthStatus] Get current health status for all monitored servers. .. py:method:: get_unhealthy_servers() -> list[str] Get list of unhealthy server names. .. py:method:: start_monitoring(servers: list[haive.mcp.config.MCPServerConfig]) :async: Start monitoring the specified servers. :param servers: List of server configurations to monitor .. py:method:: stop_monitoring() :async: Stop health monitoring. .. py:attribute:: check_interval :value: 60 .. py:attribute:: health_status :type: dict[str, HealthStatus] .. py:attribute:: monitor_task :value: None .. py:attribute:: monitoring :value: False .. py:class:: HealthStatus Health status for a server. .. py:attribute:: average_response_time :type: float :value: 0.0 .. py:attribute:: consecutive_failures :type: int :value: 0 .. py:attribute:: healthy :type: bool .. py:attribute:: last_check :type: float .. py:attribute:: server_name :type: str .. py:attribute:: uptime_percentage :type: float :value: 100.0 .. py:class:: MCPServerTester Main testing interface for MCP servers. .. py:method:: create_health_monitor(check_interval: int = 60) -> HealthMonitor Create a health monitor instance. :param check_interval: Seconds between health checks :returns: HealthMonitor instance .. py:method:: generate_test_report() -> dict[str, Any] Generate a comprehensive test report. :returns: Dictionary with test statistics and details .. py:method:: get_success_rate(server_name: str | None = None) -> float Get success rate for a server or overall. :param server_name: Specific server name, or None for overall :returns: Success rate as percentage (0.0 to 100.0) .. py:method:: get_test_history() -> list[TestResult] Get history of all test results. .. py:method:: test_config(config: haive.mcp.config.MCPConfig) -> dict[str, TestResult] :async: Test an entire MCP configuration. :param config: MCP configuration to test :returns: Dictionary mapping server names to test results .. py:method:: test_multiple_servers(servers: list[haive.mcp.config.MCPServerConfig], timeout: int = 60, parallel: bool = True) -> list[TestResult] :async: Test multiple servers. :param servers: List of server configurations to test :param timeout: Timeout per server in seconds :param parallel: Whether to test servers in parallel :returns: List of TestResult objects .. py:method:: test_server(server_config: haive.mcp.config.MCPServerConfig, timeout: int = 60) -> TestResult :async: Test a single MCP server configuration. :param server_config: Server configuration to test :param timeout: Timeout in seconds for the test :returns: TestResult with test outcome .. py:attribute:: test_history :type: list[TestResult] :value: [] .. py:class:: TestResult Result from testing an MCP server. .. py:method:: __post_init__() Post Init . .. py:attribute:: capabilities_found :type: list[str] :value: None .. py:attribute:: error :type: str | None :value: None .. py:attribute:: response_time :type: float .. py:attribute:: server_name :type: str .. py:attribute:: success :type: bool .. py:attribute:: tools_discovered :type: int :value: 0 .. py:attribute:: warnings :type: list[str] :value: None .. py:data:: logger