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ΒΆ
Continuous health monitoring for MCP servers. |
|
Health status for a server. |
|
Main testing interface for MCP servers. |
|
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.
- 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.
- 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 .
- mcp.tools.server_tester.loggerΒΆ