Health Check
health_checkMonitor container health and verify operational status through Prometheus metrics, enabling proactive system maintenance and issue detection.
Instructions
Health check endpoint for container monitoring and status verification
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- The main handler function for the health_check tool. It checks the status of the MCP server and tests connectivity to Prometheus if configured, returning a health status dictionary.
async def health_check() -> Dict[str, Any]: """Return health status of the MCP server and Prometheus connection. Returns: Health status including service information, configuration, and connectivity """ try: health_status = { "status": "healthy", "service": "prometheus-mcp-server", "version": "1.5.2", "timestamp": datetime.utcnow().isoformat(), "transport": config.mcp_server_config.mcp_server_transport if config.mcp_server_config else "stdio", "configuration": { "prometheus_url_configured": bool(config.url), "authentication_configured": bool(config.username or config.token), "org_id_configured": bool(config.org_id) } } # Test Prometheus connectivity if configured if config.url: try: # Quick connectivity test make_prometheus_request("query", params={"query": "up", "time": str(int(time.time()))}) health_status["prometheus_connectivity"] = "healthy" health_status["prometheus_url"] = config.url except Exception as e: health_status["prometheus_connectivity"] = "unhealthy" health_status["prometheus_error"] = str(e) health_status["status"] = "degraded" else: health_status["status"] = "unhealthy" health_status["error"] = "PROMETHEUS_URL not configured" logger.info("Health check completed", status=health_status["status"]) return health_status except Exception as e: logger.error("Health check failed", error=str(e)) return { "status": "unhealthy", "service": "prometheus-mcp-server", "error": str(e), "timestamp": datetime.utcnow().isoformat() } - src/prometheus_mcp_server/server.py:27-37 (registration)The @mcp.tool decorator registers the health_check function as an MCP tool with description and annotations specifying its properties.
@mcp.tool( description="Health check endpoint for container monitoring and status verification", annotations={ "title": "Health Check", "icon": "❤️", "readOnlyHint": True, "destructiveHint": False, "idempotentHint": True, "openWorldHint": True } )