Skip to content

Commit 434a5c9

Browse files
committed
feat: add health endpoints on separate port
- Health endpoints now run on port 8001 (main port + 1) - Added separate FastAPI server for health checks alongside FastMCP - Updated documentation and Makefile to reflect correct ports - Health endpoints: /health, /health/ready, /health/live, /metrics - Added uvicorn dependency for health server Endpoints available: - Main MCP server: http://localhost:8000 - Health checks: http://localhost:8001/health - Metrics: http://localhost:8001/metrics
1 parent 05db92e commit 434a5c9

File tree

4 files changed

+26
-7
lines changed

4 files changed

+26
-7
lines changed

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,15 +130,15 @@ prometheus-open:
130130

131131
health-check:
132132
@echo "🏥 Checking service health..."
133-
@curl -s http://localhost:8000/health | jq . || echo "Service not responding"
133+
@curl -s http://localhost:8001/health | jq . || echo "Service not responding"
134134

135135
metrics-check:
136136
@echo "📊 Checking metrics..."
137-
@curl -s http://localhost:8000/metrics | head -20
137+
@curl -s http://localhost:8001/metrics | head -20
138138

139139
observability-status:
140140
@echo "📊 Observability Stack Status:"
141-
@echo "Weather MCP: $$(curl -s -o /dev/null -w "%%{http_code}" http://localhost:8000/health || echo "DOWN")"
141+
@echo "Weather MCP: $$(curl -s -o /dev/null -w "%%{http_code}" http://localhost:8001/health || echo "DOWN")"
142142
@echo "Prometheus: $$(curl -s -o /dev/null -w "%%{http_code}" http://localhost:9091/-/healthy || echo "DOWN")"
143143
@echo "Grafana: $$(curl -s -o /dev/null -w "%%{http_code}" http://localhost:3000/api/health || echo "DOWN")"
144144
@echo "Loki: $$(curl -s -o /dev/null -w "%%{http_code}" http://localhost:3100/ready || echo "DOWN")"

OBSERVABILITY.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ make observability-up
3232
- **Grafana Dashboard**: http://localhost:3000 (admin/admin)
3333
- **Prometheus**: http://localhost:9091
3434
- **AlertManager**: http://localhost:9093
35-
- **Health Check**: http://localhost:8000/health
36-
- **Metrics Endpoint**: http://localhost:8000/metrics
35+
- **Health Check**: http://localhost:8001/health (runs on port +1)
36+
- **Metrics Endpoint**: http://localhost:8001/metrics (runs on port +1)
3737

3838
### 3. Quick Health Check
3939

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ dependencies = [
4141
"cachetools>=5.3.0",
4242
"loguru>=0.7.0",
4343
"typer>=0.9.0",
44+
"uvicorn>=0.30.0",
4445
# Observability dependencies
4546
"prometheus-client>=0.19.0",
4647
"opentelemetry-api>=1.21.0",

weather_mcp/cli.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,12 @@ def run(
5353
host: str = typer.Option("0.0.0.0", help="Server host address"),
5454
port: int = typer.Option(8000, help="Server port"),
5555
):
56-
"""Run weather server with SSE endpoints"""
56+
"""Run weather server with SSE endpoints and health checks"""
57+
import threading
58+
5759
from fastmcp import FastMCP
5860

61+
from .health import create_health_app
5962
from .nws import NationalWeatherServiceClient
6063

6164
async def run_server():
@@ -75,10 +78,25 @@ async def run_server():
7578

7679
return mcp_server
7780

78-
# Initialize and run server
81+
def run_health_server():
82+
"""Run health check server on a separate port"""
83+
import uvicorn
84+
85+
health_app = create_health_app()
86+
logger.info(f"Starting health server on port {port + 1}")
87+
uvicorn.run(health_app, host=host, port=port + 1, log_level="warning")
88+
89+
# Start health server in background thread
90+
health_thread = threading.Thread(target=run_health_server, daemon=True)
91+
health_thread.start()
92+
93+
# Initialize and run main MCP server
7994
mcp_server = asyncio.run(run_server())
8095

8196
# Run FastMCP server with SSE transport
97+
logger.info(f"Weather MCP Server: http://{host}:{port}")
98+
logger.info(f"Health endpoints: http://{host}:{port + 1}/health")
99+
logger.info(f"Metrics endpoint: http://{host}:{port + 1}/metrics")
82100
mcp_server.run(transport="sse", host=host, port=port)
83101

84102

0 commit comments

Comments
 (0)