diff --git a/internal/server/health.go b/internal/server/health.go index 8a78818..f45d94e 100644 --- a/internal/server/health.go +++ b/internal/server/health.go @@ -3,8 +3,12 @@ package server import ( "encoding/json" "net/http" + + "github.com/githubnext/gh-aw-mcpg/internal/logger" ) +var logHealth = logger.New("server:health") + // HealthResponse represents the JSON structure for the /health endpoint response // as defined in MCP Gateway Specification section 8.1.1 type HealthResponse struct { @@ -16,17 +20,22 @@ type HealthResponse struct { // BuildHealthResponse constructs a HealthResponse from the unified server's status func BuildHealthResponse(unifiedServer *UnifiedServer) HealthResponse { + logHealth.Print("Building health response") + // Get server status serverStatus := unifiedServer.GetServerStatus() + logHealth.Printf("Retrieved status for %d servers", len(serverStatus)) // Determine overall health based on server status overallStatus := "healthy" - for _, status := range serverStatus { + for serverName, status := range serverStatus { if status.Status == "error" { + logHealth.Printf("Server error detected: server=%s, marking overall status as unhealthy", serverName) overallStatus = "unhealthy" break } } + logHealth.Printf("Overall health status determined: %s", overallStatus) return HealthResponse{ Status: overallStatus, @@ -40,10 +49,13 @@ func BuildHealthResponse(unifiedServer *UnifiedServer) HealthResponse { // This function is used by both routed and unified modes to ensure consistent behavior func HandleHealth(unifiedServer *UnifiedServer) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { + logHealth.Printf("Health check request: method=%s, remote=%s", r.Method, r.RemoteAddr) + w.Header().Set("Content-Type", "application/json") w.WriteHeader(http.StatusOK) response := BuildHealthResponse(unifiedServer) + logHealth.Printf("Health response: status=%s, servers=%d", response.Status, len(response.Servers)) json.NewEncoder(w).Encode(response) } }