Add /health endpoint for Docker healthcheck
All checks were successful
Build And Test / publish (push) Successful in 48s
All checks were successful
Build And Test / publish (push) Successful in 48s
The healthcheck was hitting /mcp which requires auth, causing unhealthy status. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -35,7 +35,7 @@ EXPOSE 8000
|
|||||||
|
|
||||||
# Health check
|
# Health check
|
||||||
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
|
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
|
||||||
CMD python -c "import urllib.request; urllib.request.urlopen('http://localhost:8000/mcp')" || exit 1
|
CMD python -c "import urllib.request; urllib.request.urlopen('http://localhost:8000/health')" || exit 1
|
||||||
|
|
||||||
# Use entrypoint to fix permissions, then run as mcp user
|
# Use entrypoint to fix permissions, then run as mcp user
|
||||||
ENTRYPOINT ["/entrypoint.sh"]
|
ENTRYPOINT ["/entrypoint.sh"]
|
||||||
|
|||||||
@@ -165,8 +165,15 @@ if __name__ == "__main__":
|
|||||||
import signal
|
import signal
|
||||||
import uvicorn
|
import uvicorn
|
||||||
|
|
||||||
|
from starlette.responses import JSONResponse
|
||||||
|
from starlette.routing import Route
|
||||||
|
|
||||||
from middleware import APIKeyAuthMiddleware
|
from middleware import APIKeyAuthMiddleware
|
||||||
|
|
||||||
|
async def health_check(request):
|
||||||
|
"""Health check endpoint for Docker/Traefik."""
|
||||||
|
return JSONResponse({"status": "healthy"})
|
||||||
|
|
||||||
async def main():
|
async def main():
|
||||||
await initialize()
|
await initialize()
|
||||||
|
|
||||||
@@ -176,6 +183,9 @@ if __name__ == "__main__":
|
|||||||
# Get the underlying ASGI app from FastMCP
|
# Get the underlying ASGI app from FastMCP
|
||||||
app = mcp.http_app(path="/mcp")
|
app = mcp.http_app(path="/mcp")
|
||||||
|
|
||||||
|
# Add health check route
|
||||||
|
app.routes.append(Route("/health", health_check))
|
||||||
|
|
||||||
# Add authentication middleware if API key is configured
|
# Add authentication middleware if API key is configured
|
||||||
if settings.mcp_api_key:
|
if settings.mcp_api_key:
|
||||||
app.add_middleware(
|
app.add_middleware(
|
||||||
|
|||||||
Reference in New Issue
Block a user