From 4620cfa8d6561aa54e487aa512b0480cec9d5a3e Mon Sep 17 00:00:00 2001 From: leex279 Date: Sat, 8 Nov 2025 22:34:09 +0100 Subject: [PATCH] Fix: Address CodeRabbit suggestions for health endpoint MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Use context.startup_time for consistent uptime tracking - Prefer context.startup_time when available (matches MCP health_check tool) - Fallback to module-level _server_start_time during startup - Add exc_info=True to exception logging for full stack traces - Follows coding guidelines for error message preservation 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- python/src/mcp_server/mcp_server.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/python/src/mcp_server/mcp_server.py b/python/src/mcp_server/mcp_server.py index 0d84eb7b..f4796acb 100644 --- a/python/src/mcp_server/mcp_server.py +++ b/python/src/mcp_server/mcp_server.py @@ -29,7 +29,6 @@ from pathlib import Path from typing import Any from dotenv import load_dotenv - from mcp.server.fastmcp import Context, FastMCP from starlette.requests import Request from starlette.responses import JSONResponse @@ -557,11 +556,10 @@ async def http_health_endpoint(request: Request): """HTTP health check endpoint for monitoring systems.""" logger.info("Health endpoint called via HTTP") try: - # Calculate uptime from module load time - uptime = time.time() - _server_start_time - # Try to get the shared context for detailed health info if _shared_context and hasattr(_shared_context, "health_status"): + # Use actual server startup time for consistency with MCP health_check tool + uptime = time.time() - _shared_context.startup_time await perform_health_checks(_shared_context) return JSONResponse({ @@ -571,7 +569,8 @@ async def http_health_endpoint(request: Request): "timestamp": datetime.now().isoformat(), }) else: - # Server starting up or no MCP connections yet - still return uptime + # Server starting up or no MCP connections yet - use module load time as fallback + uptime = time.time() - _server_start_time return JSONResponse({ "success": True, "status": "ready", @@ -580,7 +579,7 @@ async def http_health_endpoint(request: Request): "timestamp": datetime.now().isoformat(), }) except Exception as e: - logger.error(f"HTTP health check failed: {e}") + logger.error(f"HTTP health check failed: {e}", exc_info=True) return JSONResponse({ "success": False, "error": f"Health check failed: {str(e)}",