health_check
Verifies render and export dependencies by testing PNG, SVG, STEP, and STL outputs. Returns JSON with pass/fail status for each capability.
Instructions
Verify that render and export dependencies are working. Tests PNG render (VTK), SVG render (build123d HLR), STEP export, and STL export with a trivial shape. Returns JSON with ok/error per capability. Run at session start if you suspect a missing dependency.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |
Implementation Reference
- The core handler function that performs the health check. It tests PNG render (VTK), SVG render (HLR projection), STEP export, and STL export with a trivial Box shape, returning JSON with ok/error per capability.
def health_check(_session) -> str: results: dict = {} # PNG render (VTK + display) try: from build123d import Box from build123d_mcp.tools.render import _QUALITY, _do_render_png img_bytes, _warnings = _do_render_png([("test", Box(1, 1, 1), None)], _QUALITY["standard"], "iso", "", None, 0.0, 0.0) results["render_png"] = {"ok": True, "bytes": len(img_bytes)} except Exception as e: results["render_png"] = {"ok": False, "error": str(e)} # SVG render (build123d HLR projection) try: from build123d import Box from build123d_mcp.tools.render import _do_render_svg svg = _do_render_svg([("test", Box(1, 1, 1), None)], "iso", "", None, 0.0, 0.0) results["render_svg"] = {"ok": True, "bytes": len(svg)} except Exception as e: results["render_svg"] = {"ok": False, "error": str(e)} # STEP export try: from build123d import Box, export_step fd, path = tempfile.mkstemp(suffix=".step") os.close(fd) export_step(Box(1, 1, 1), path) results["export_step"] = {"ok": True, "bytes": os.path.getsize(path)} os.unlink(path) except Exception as e: results["export_step"] = {"ok": False, "error": str(e)} # STL export try: from build123d import Box, Mesher fd, path = tempfile.mkstemp(suffix=".stl") os.close(fd) m = Mesher() m.add_shape(Box(1, 1, 1)) m.write(path) results["export_stl"] = {"ok": True, "bytes": os.path.getsize(path)} os.unlink(path) except Exception as e: results["export_stl"] = {"ok": False, "error": str(e)} results["ok"] = all(v["ok"] for v in results.values() if isinstance(v, dict) and "ok" in v) return json.dumps(results, indent=2) - src/build123d_mcp/server.py:123-126 (registration)MCP tool registration via @mcp.tool() decorator. The server-level health_check() delegates to _session.health_check().
@mcp.tool() def health_check() -> str: """Verify that render and export dependencies are working. Tests PNG render (VTK), SVG render (build123d HLR), STEP export, and STL export with a trivial shape. Returns JSON with ok/error per capability. Run at session start if you suspect a missing dependency.""" return _session.health_check() - src/build123d_mcp/worker.py:121-123 (registration)Worker dispatch: routes the 'health_check' operation string to the health_check function from tools/health_check.py.
if op == "health_check": from build123d_mcp.tools.health_check import health_check return health_check(session) - src/build123d_mcp/worker.py:290-291 (registration)WorkerSession.health_check() method that sends a 'health_check' RPC call with RENDER_TIMEOUT.
def health_check(self) -> str: return self._call("health_check", {}, self._RENDER_TIMEOUT) - tests/test_tools.py:916-925 (helper)Test for health_check: verifies it returns valid JSON with all expected keys (ok, export_step, export_stl, render_svg) and that export checks pass.
def test_health_check_returns_json(session): data = json.loads(health_check(session)) assert "ok" in data assert "export_step" in data assert "export_stl" in data assert "render_svg" in data assert data["export_step"]["ok"] is True assert data["export_stl"]["ok"] is True assert data["render_svg"]["ok"] is True