Skip to content

Commit 99836c4

Browse files
feat: better health check (#64)
1 parent afa6fe8 commit 99836c4

3 files changed

Lines changed: 13 additions & 4 deletions

File tree

.env.example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
MCP_HOST=127.0.0.1
22
MCP_PORT="8000"
33
MCP_ENV="local"
4-
DATAGOUV_ENV="prod"
4+
DATAGOUV_API_ENV="prod"
55
LOG_LEVEL="INFO"
66

77
# Matomo tracking

main.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
init_sentry()
1919

20+
SERVER_START_TIME = datetime.now(timezone.utc)
21+
2022
# Configure logging
2123
LOGGER_NAME = "datagouv_mcp"
2224

@@ -69,15 +71,20 @@ async def app(scope, receive, send):
6971

7072
# Handle /health endpoint (no tracking)
7173
if path == "/health":
72-
timestamp = datetime.now(timezone.utc).isoformat()
7374
# Get version from package metadata (managed by setuptools-scm)
7475
try:
7576
app_version = version("datagouv-mcp")
7677
except PackageNotFoundError:
7778
app_version = "unknown"
7879

7980
body = json.dumps(
80-
{"status": "ok", "timestamp": timestamp, "version": app_version}
81+
{
82+
"status": "ok",
83+
"uptime_since": SERVER_START_TIME.isoformat(),
84+
"version": app_version,
85+
"env": os.getenv("MCP_ENV", "unknown"),
86+
"data_env": os.getenv("DATAGOUV_API_ENV", "unknown"),
87+
}
8188
).encode("utf-8")
8289
headers = [
8390
(b"content-type", b"application/json"),

tests/test_health_endpoint.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ async def test_health_endpoint_returns_ok_status():
1313
assert response.status_code == 200
1414
payload = response.json()
1515
assert payload.get("status") == "ok"
16-
assert "timestamp" in payload
16+
assert "uptime_since" in payload
1717
assert "version" in payload
1818
assert isinstance(payload.get("version"), str)
19+
assert "env" in payload
20+
assert "data_env" in payload

0 commit comments

Comments
 (0)