Google Flights MCP, CLI and Python Library
fix(mcp): add /health route for the docker-compose healthcheck (#240)
Punit Arani466b253508f6
diff --git a/docs/guides/mcp.md b/docs/guides/mcp.mdindex a6c85d9..89b49f8 100644--- a/docs/guides/mcp.md+++ b/docs/guides/mcp.md@@ -40,6 +40,10 @@ run_http(host="0.0.0.0", port=8000)Once running, the MCP endpoint is served at `/mcp/`, for example: `http://127.0.0.1:8000/mcp/`.+A liveness probe is available at `/health` (returns `{"status": "ok"}`). It is what the+`docker-compose.yml` healthcheck calls, and it does not contact Google Flights, so an upstream+outage will not cause a healthy container to be restarted.+## Claude Desktop ConfigurationAdd this configuration to your `claude_desktop_config.json`:diff --git a/fli/mcp/server.py b/fli/mcp/server.pyindex f7adcd6..2b9f439 100755--- a/fli/mcp/server.py+++ b/fli/mcp/server.py@@ -14,6 +14,8 @@ from fastmcp import FastMCPfrom mcp.types import Iconfrom pydantic import BaseModel, Field, ValidationErrorfrom pydantic_settings import BaseSettings, SettingsConfigDict+from starlette.requests import Request+from starlette.responses import JSONResponsefrom fli.core import (build_date_search_segments,@@ -92,6 +94,16 @@ mcp = FastMCP()[email protected]_route("/health", methods=["GET"])+async def health_check(_request: Request) -> JSONResponse:+ """Liveness probe for container healthchecks (see ``docker-compose.yml``).++ Deliberately does not call Google Flights: an upstream outage should not+ make the orchestrator restart an otherwise healthy server.+ """+ return JSONResponse({"status": "ok"})++# =============================================================================# Request/Response Models# =============================================================================diff --git a/pyproject.toml b/pyproject.tomlindex d672dd2..0a729c2 100644--- a/pyproject.toml+++ b/pyproject.toml@@ -41,6 +41,7 @@ mcp = ["fastmcp>=3.2","mcp>=1.2.0","pydantic-settings>=2.0.0",+ "starlette>=0.27","uvicorn>=0.34.0",]all = [diff --git a/tests/mcp/test_mcp_http.py b/tests/mcp/test_mcp_http.pyindex 4173b86..eac14ff 100644--- a/tests/mcp/test_mcp_http.py+++ b/tests/mcp/test_mcp_http.py@@ -106,3 +106,32 @@ class TestMCPHTTP:for tool in tools:assert tool.description, f"{tool.name} is missing a description"assert tool.inputSchema, f"{tool.name} is missing inputSchema"+++# ---------------------------------------------------------------------------+# Test C: /health liveness endpoint (used by the docker-compose healthcheck)+# ---------------------------------------------------------------------------+++class TestHealthEndpoint:+ """The HTTP server must answer ``GET /health`` for container healthchecks."""++ def test_health_matches_the_compose_probe(self, http_mcp_url):+ """``urllib.request.urlopen(.../health)`` succeeds, exactly as docker-compose runs it."""+ import json+ import urllib.request++ base_url = http_mcp_url.removesuffix("/mcp/")+ with urllib.request.urlopen(f"{base_url}/health", timeout=5) as response:+ assert response.status == 200+ assert json.loads(response.read()) == {"status": "ok"}++ def test_health_does_not_shadow_the_mcp_endpoint(self, http_mcp_url):+ """Adding the route must leave the MCP transport itself working."""+ import asyncio++ async def list_tool_names() -> set[str]:+ async with Client(http_mcp_url) as client:+ return {tool.name for tool in await client.list_tools()}++ assert EXPECTED_TOOLS <= asyncio.run(list_tool_names())diff --git a/uv.lock b/uv.lockindex 2e08336..04a4ab7 100644--- a/uv.lock+++ b/uv.lock@@ -695,6 +695,7 @@ all = [{ name = "fastmcp" },{ name = "mcp" },{ name = "pydantic-settings" },+ { name = "starlette" },{ name = "uvicorn" },]dev = [@@ -712,6 +713,7 @@ mcp = [{ name = "fastmcp" },{ name = "mcp" },{ name = "pydantic-settings" },+ { name = "starlette" },{ name = "uvicorn" },]@@ -737,6 +739,7 @@ requires-dist = [{ name = "ratelimit", specifier = ">=2.2.1" },{ name = "rich", specifier = ">=13.8.0" },{ name = "ruff", marker = "extra == 'dev'", specifier = ">=0.8.4" },+ { name = "starlette", marker = "extra == 'mcp'", specifier = ">=0.27" },{ name = "tenacity", specifier = ">=9.0.0" },{ name = "twine", marker = "extra == 'dev'", specifier = ">=6.0.0" },{ name = "typer", specifier = ">=0.15.1" },