Self-hosted homelab infrastructure visualizer — interactive network diagram with live status monitoring
TypeScript diagramhomelabhomelab-infrastructure-observabilitynetworkproxmox-veself-hostedzigbeezwavezwave-js
fix: sync MCP edge type enum with frontend and gate both enums in CI
Pouzor8f273e0201f7
diff --git a/.github/workflows/quality.yml b/.github/workflows/quality.ymlindex 6c8ded2..87f3b45 100644--- a/.github/workflows/quality.yml+++ b/.github/workflows/quality.yml@@ -60,3 +60,20 @@ jobs:- run: ruff check .- run: mypy app/- run: pytest++ # Also guards the NODE_TYPES / EDGE_TYPES enums in mcp/app/tools.py against+ # drift from frontend/src/types/index.ts (test_node_types_sync.py,+ # test_edge_types_sync.py) — those tests need the frontend sources, so this+ # job runs from a full checkout rather than the mcp Docker context.+ mcp:+ runs-on: ubuntu-latest+ defaults:+ run:+ working-directory: mcp+ steps:+ - uses: actions/checkout@v4+ - uses: actions/setup-python@v5+ with:+ python-version: '3.13'+ - run: pip install -r requirements.txt+ - run: pytestdiff --git a/mcp/app/tools.py b/mcp/app/tools.pyindex 5140d98..a47173a 100644--- a/mcp/app/tools.py+++ b/mcp/app/tools.py@@ -16,6 +16,12 @@ NODE_TYPES = ["light", "meter", "transformer", "load",]+# Kept in sync manually with frontend/src/types/index.ts EdgeType.+# Sync is enforced automatically by test_edge_types_in_sync_with_frontend (mcp/tests/test_edge_types_sync.py).+EDGE_TYPES = [+ "ethernet", "wifi", "iot", "vlan", "virtual", "cluster", "fibre", "electrical",+]+# Shared field schemas mirroring backend NodeBase / NodeUpdate (backend/app/schemas/nodes.py).# create_node and update_node both expose these so the MCP is symmetric with what the# backend already validates and stores. _dispatch forwards args verbatim, so any field@@ -102,7 +108,7 @@ def _build_tools() -> list[Tool]:"properties": {"source": {"type": "string"},"target": {"type": "string"},- "type": {"type": "string", "enum": ["ethernet", "wifi", "iot", "vlan", "virtual"], "default": "ethernet"},+ "type": {"type": "string", "enum": EDGE_TYPES, "default": "ethernet"},"label": {"type": "string"},**_DESIGN_ID_FIELD,},diff --git a/mcp/requirements.txt b/mcp/requirements.txtindex 8d843d7..54ff341 100644--- a/mcp/requirements.txt+++ b/mcp/requirements.txt@@ -1,5 +1,15 @@-mcp[cli]>=1.0+# Upper bound is load-bearing: mcp 2.0 dropped the low-level `Server.list_resources`+# / `Server.list_tools` decorator API that app/resources.py and app/tools.py use.+# Removing the bound breaks both the tests and the Docker image at import time.+mcp[cli]>=1.26,<2httpx>=0.27fastapi>=0.115uvicorn[standard]>=0.30pydantic-settings>=2.0++# Test-only, kept here for the same reason backend/requirements.txt carries its+# own: CI installs a single requirements file then runs pytest.+# pytest-anyio provides the `anyio` marker and parametrises asyncio + trio.+pytest>=9.0+pytest-anyio>=0.0.0+trio>=0.27diff --git a/mcp/tests/test_edge_types_sync.py b/mcp/tests/test_edge_types_sync.pynew file mode 100644index 0000000..232ebc8--- /dev/null+++ b/mcp/tests/test_edge_types_sync.py@@ -0,0 +1,26 @@+import re+from pathlib import Path++from app.tools import EDGE_TYPES++FRONTEND_TYPES_FILE = Path(__file__).resolve().parents[2] / "frontend" / "src" / "types" / "index.ts"+++def _frontend_edge_types() -> set[str]:+ src = FRONTEND_TYPES_FILE.read_text()+ match = re.search(r"export type EdgeType =([^\n]+)", src)+ assert match, (+ "Could not locate the EdgeType union in frontend/src/types/index.ts — "+ "update this parser if the file's shape changed."+ )+ return set(re.findall(r"'([^']+)'", match.group(1)))+++def test_edge_types_in_sync_with_frontend():+ frontend_types = _frontend_edge_types()+ mcp_types = set(EDGE_TYPES)+ assert mcp_types == frontend_types, (+ "mcp/app/tools.py EDGE_TYPES is out of sync with frontend/src/types/index.ts EdgeType.\n"+ f"Missing from EDGE_TYPES: {sorted(frontend_types - mcp_types)}\n"+ f"Extra in EDGE_TYPES (no longer an edge type?): {sorted(mcp_types - frontend_types)}"+ )diff --git a/mcp/tests/test_tools.py b/mcp/tests/test_tools.pyindex 12f7ca8..51f6f27 100644--- a/mcp/tests/test_tools.py+++ b/mcp/tests/test_tools.py@@ -87,6 +87,16 @@ async def test_create_edge(mock_backend):mock_backend.post.assert_called_once_with("/api/v1/edges", {"source": "1", "target": "2", "type": "ethernet"})[email protected]("edge_type", ["cluster", "fibre", "electrical"])+async def test_create_edge_accepts_previously_rejected_types(mock_backend, edge_type):+ # These types were missing from the old, stale edge type enum and were+ # rejected by the MCP schema even though the backend always accepted them.+ args = {"source": "1", "target": "2", "type": edge_type}+ await _dispatch("create_edge", dict(args))+ mock_backend.post.assert_called_once_with("/api/v1/edges", args)++@pytest.mark.anyioasync def test_create_node_with_design_id(mock_backend):# design_id is forwarded to the backend, which attaches the node to that canvas.@@ -225,6 +235,13 @@ def test_node_type_enum_excludes_canvas_annotations(tool_name):assert "firewall" in type_enum+def test_create_edge_schema_exposes_full_edge_type_enum():+ props = _tool_schema("create_edge")+ type_enum = set(props["type"]["enum"])+ assert {"cluster", "fibre", "electrical"} <= type_enum+ assert props["type"]["default"] == "ethernet"++def test_update_node_schema_exposes_full_node_fields():props = _tool_schema("update_node")for field in ("os", "notes", "services", "cpu_count", "ram_gb", "disk_gb", "properties", "mac"):