Skip to content

Plan, apply and roll back changes to a production ontology, with a blast radius report and a proof an auditor can re-check.

feat(serve-http): add an unauthenticated /health liveness route

Nicolas Geysse91c3b84ed9b3
diff --git a/README.md b/README.md
index e4f4fab8..70e39348 100644
--- a/README.md
+++ b/README.md
@@ -191,6 +191,28 @@ Add to `.cursor/mcp.json` or equivalent:
</details>
+<details>
+<summary><strong>HTTP transport (<code>serve-http</code>)</strong></summary>
+
+For clients that speak MCP over HTTP rather than stdio:
+
+```bash
+open-ontologies serve-http --host 127.0.0.1 --port 8080
+```
+
+| Route | Auth | Purpose |
+|---|---|---|
+| `/mcp` | bearer, if a token is configured | MCP Streamable HTTP — the `onto_*` tools |
+| `/api/*` | bearer, if a token is configured | stats, events and other introspection |
+| `/health` | never | liveness probe |
+
+`/health` returns `{"status":"ok","version":"<crate version>"}` and is
+deliberately outside the bearer layer, so an orchestrator can probe the process
+without holding API credentials. It reports nothing about loaded state — use
+`/api/stats` for that.
+
+</details>
+
### Build your first ontology
```text
diff --git a/src/main.rs b/src/main.rs
index becfaf87..21a5b857 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1143,6 +1143,25 @@ async fn async_main() -> anyhow::Result<()> {
} else {
router
};
+ // Liveness probe. Registered AFTER the bearer layer on purpose:
+ // `Router::layer` only wraps the routes already present, so adding
+ // /health here leaves it outside the auth middleware while /api and
+ // /mcp stay behind it. Putting it inside the `if let` branch above,
+ // or before the layer call, would make it require credentials in the
+ // one deployment where an unauthenticated probe is the point.
+ //
+ // The body is deliberately limited to status and version: an
+ // unauthenticated endpoint should not describe loaded state, which is
+ // exactly why /api/stats is not the right thing to probe.
+ let router = router.route(
+ "/health",
+ axum::routing::get(|| async {
+ axum::Json(serde_json::json!({
+ "status": "ok",
+ "version": env!("CARGO_PKG_VERSION"),
+ }))
+ }),
+ );
let router = router.layer(tower_http::cors::CorsLayer::permissive());
let addr = format!("{host}:{port}");
let listener = tokio::net::TcpListener::bind(&addr).await?;