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.

AttributesΒΆ

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 mcp.tools.server_tester.HealthMonitor(check_interval: int = 60)ΒΆ

Continuous health monitoring for MCP servers.

get_health_report() dict[str, HealthStatus]ΒΆ

Get current health status for all monitored servers.

get_unhealthy_servers() list[str]ΒΆ

Get list of unhealthy server names.

async start_monitoring(servers: list[haive.mcp.config.MCPServerConfig])ΒΆ

Start monitoring the specified servers.

Parameters:

servers – List of server configurations to monitor

async stop_monitoring()ΒΆ

Stop health monitoring.

check_interval = 60ΒΆ
health_status: dict[str, HealthStatus]ΒΆ
monitor_task = NoneΒΆ
monitoring = FalseΒΆ
class mcp.tools.server_tester.HealthStatusΒΆ

Health status for a server.

average_response_time: float = 0.0ΒΆ
consecutive_failures: int = 0ΒΆ
healthy: boolΒΆ
last_check: floatΒΆ
server_name: strΒΆ
uptime_percentage: float = 100.0ΒΆ
class mcp.tools.server_tester.MCPServerTesterΒΆ

Main testing interface for MCP servers.

create_health_monitor(check_interval: int = 60) HealthMonitorΒΆ

Create a health monitor instance.

Parameters:

check_interval – Seconds between health checks

Returns:

HealthMonitor instance

generate_test_report() dict[str, Any]ΒΆ

Generate a comprehensive test report.

Returns:

Dictionary with test statistics and details

get_success_rate(server_name: str | None = None) floatΒΆ

Get success rate for a server or overall.

Parameters:

server_name – Specific server name, or None for overall

Returns:

Success rate as percentage (0.0 to 100.0)

get_test_history() list[TestResult]ΒΆ

Get history of all test results.

async test_config(config: haive.mcp.config.MCPConfig) dict[str, TestResult]ΒΆ

Test an entire MCP configuration.

Parameters:

config – MCP configuration to test

Returns:

Dictionary mapping server names to test results

async test_multiple_servers(servers: list[haive.mcp.config.MCPServerConfig], timeout: int = 60, parallel: bool = True) list[TestResult]ΒΆ

Test multiple servers.

Parameters:
  • servers – List of server configurations to test

  • timeout – Timeout per server in seconds

  • parallel – Whether to test servers in parallel

Returns:

List of TestResult objects

async test_server(server_config: haive.mcp.config.MCPServerConfig, timeout: int = 60) TestResultΒΆ

Test a single MCP server configuration.

Parameters:
  • server_config – Server configuration to test

  • timeout – Timeout in seconds for the test

Returns:

TestResult with test outcome

test_history: list[TestResult] = []ΒΆ
class mcp.tools.server_tester.TestResultΒΆ

Result from testing an MCP server.

__post_init__()ΒΆ

Post Init .

capabilities_found: list[str] = NoneΒΆ
error: str | None = NoneΒΆ
response_time: floatΒΆ
server_name: strΒΆ
success: boolΒΆ
tools_discovered: int = 0ΒΆ
warnings: list[str] = NoneΒΆ
mcp.tools.server_tester.loggerΒΆ