haive.mcp.tools.server_tester

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

Example

Testing server configurations:

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.

Classes

HealthMonitor

Continuous health monitoring for MCP servers.

HealthStatus

Health status for a server.

MCPServerTester

Main testing interface for MCP servers.

TestResult

Result from testing an MCP server.

Module Contents

class haive.mcp.tools.server_tester.HealthMonitor(check_interval=60)[source]

Continuous health monitoring for MCP servers.

Initialize health monitor.

Parameters:

check_interval (int) – Seconds between health checks

get_health_report()[source]

Get current health status for all monitored servers.

Return type:

dict[str, HealthStatus]

get_unhealthy_servers()[source]

Get list of unhealthy server names.

Return type:

list[str]

async start_monitoring(servers)[source]

Start monitoring the specified servers.

Parameters:

servers (list[haive.mcp.config.MCPServerConfig]) – List of server configurations to monitor

async stop_monitoring()[source]

Stop health monitoring.

class haive.mcp.tools.server_tester.HealthStatus[source]

Health status for a server.

class haive.mcp.tools.server_tester.MCPServerTester[source]

Main testing interface for MCP servers.

Initialize server tester.

create_health_monitor(check_interval=60)[source]

Create a health monitor instance.

Parameters:

check_interval (int) – Seconds between health checks

Returns:

HealthMonitor instance

Return type:

HealthMonitor

generate_test_report()[source]

Generate a comprehensive test report.

Returns:

Dictionary with test statistics and details

Return type:

dict[str, Any]

get_success_rate(server_name=None)[source]

Get success rate for a server or overall.

Parameters:

server_name (str | None) – Specific server name, or None for overall

Returns:

Success rate as percentage (0.0 to 100.0)

Return type:

float

get_test_history()[source]

Get history of all test results.

Return type:

list[TestResult]

async test_config(config)[source]

Test an entire MCP configuration.

Parameters:

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

Returns:

Dictionary mapping server names to test results

Return type:

dict[str, TestResult]

async test_multiple_servers(servers, timeout=60, parallel=True)[source]

Test multiple servers.

Parameters:
Returns:

List of TestResult objects

Return type:

list[TestResult]

async test_server(server_config, timeout=60)[source]

Test a single MCP server configuration.

Parameters:
Returns:

TestResult with test outcome

Return type:

TestResult

class haive.mcp.tools.server_tester.TestResult[source]

Result from testing an MCP server.