Skip to content

Self-hosted homelab infrastructure visualizer — interactive network diagram with live status monitoring

feat(mcp): expose edge styling on create_edge and update_edge

Pouzorac8aea746711
diff --git a/mcp/app/tools.py b/mcp/app/tools.py
index dfcc75f..90f3823 100644
--- a/mcp/app/tools.py
+++ b/mcp/app/tools.py
@@ -106,6 +106,21 @@ _ZONE_COLOR_FIELDS = {
#
# The node must already have the connection point — left/right default to none —
# or the backend answers 422 rather than storing an edge the canvas cannot draw.
+# Presentation, mirroring the backend EdgeBase (backend/app/schemas/edges.py) and
+# the EdgeData types the canvas draws from (frontend/src/types/index.ts). Every one
+# is optional: an omitted field keeps the edge type's own preset.
+_EDGE_STYLE_FIELDS = {
+ "animated": {"type": "string", "enum": ["none", "basic", "snake", "flow"], "description": "Line animation. 'basic' is the dashed march, 'snake' a travelling segment, 'flow' a continuous drift."},
+ "custom_color": {"type": "string", "description": "Line colour override, e.g. '#00d4ff'. Omit to use the edge type's colour."},
+ "path_style": {"type": "string", "enum": ["bezier", "smooth"], "description": "How the line is routed between the two connection points."},
+ "line_style": {"type": "string", "enum": ["solid", "dashed", "dotted"], "description": "How the line itself is stroked."},
+ "width_mult": {"type": "number", "minimum": 1, "maximum": 4, "description": "Stroke-width multiplier (1-4x) on the edge type's base width."},
+ "marker_start": {"type": "string", "enum": ["none", "arrow", "arrow-open", "circle", "diamond", "square"], "description": "Marker drawn at the source end."},
+ "marker_end": {"type": "string", "enum": ["none", "arrow", "arrow-open", "circle", "diamond", "square"], "description": "Marker drawn at the target end."},
+ "vlan_id": {"type": "integer", "description": "VLAN tag carried by the link. Shown on the edge for a 'vlan' type."},
+ "speed": {"type": "string", "description": "Link speed as it should read on the canvas, e.g. '10G' or '2.5 Gbps'."},
+}
+
_EDGE_HANDLE_FIELDS = {
"source_handle": {"type": "string", "description": "Connection point on the source node, e.g. 'bottom' or 'right-2'. The node must have it already — raise that side's *_handles first, or the call is rejected. Omit to let the server pick."},
"target_handle": {"type": "string", "description": "Connection point on the target node, e.g. 'top' or 'left-3'. The node must have it already — raise that side's *_handles first, or the call is rejected. Omit to let the server pick."},
@@ -158,17 +173,19 @@ def _build_tools() -> list[Tool]:
"target": {"type": "string"},
"type": {"type": "string", "enum": EDGE_TYPES, "default": "ethernet"},
"label": {"type": "string"},
+ **_EDGE_STYLE_FIELDS,
**_EDGE_HANDLE_FIELDS,
**_DESIGN_ID_FIELD,
},
}),
- Tool(name="update_edge", description="Update an existing link: its type, label, or which connection points it attaches to. Call get_canvas to discover edge ids.", inputSchema={
+ Tool(name="update_edge", description="Update an existing link: its type, label, styling (animation, colour, line/path style, width, endpoint markers), or which connection points it attaches to. Call get_canvas to discover edge ids.", inputSchema={
"type": "object",
"required": ["id"],
"properties": {
"id": {"type": "string", "description": "Edge id."},
"type": {"type": "string", "enum": EDGE_TYPES},
"label": {"type": "string"},
+ **_EDGE_STYLE_FIELDS,
**_EDGE_HANDLE_FIELDS,
},
}),
diff --git a/mcp/tests/test_tools.py b/mcp/tests/test_tools.py
index eb60be6..6157100 100644
--- a/mcp/tests/test_tools.py
+++ b/mcp/tests/test_tools.py
@@ -763,3 +763,45 @@ async def test_list_edges_returns_the_unslimmed_edges(mock_backend):
mock_backend.get.assert_called_once_with("/api/v1/edges")
assert result == [edge]
+
+
+def test_edge_schemas_expose_the_styling_fields():
+ # The backend has always accepted these; only the canvas UI could set them.
+ for tool_name in ("create_edge", "update_edge"):
+ props = _tool_schema(tool_name)
+ for field in ("animated", "custom_color", "path_style", "line_style",
+ "width_mult", "marker_start", "marker_end", "vlan_id", "speed"):
+ assert field in props, f"{tool_name} schema missing {field}"
+
+
+def test_edge_style_enums_match_what_the_backend_normalizes():
+ # normalize_animated / normalize_marker (backend/app/schemas/utils.py) coerce
+ # anything outside these sets to 'none', so an advertised value that isn't
+ # there would silently do nothing.
+ props = _tool_schema("create_edge")
+ assert set(props["animated"]["enum"]) == {"none", "basic", "snake", "flow"}
+ markers = {"none", "arrow", "arrow-open", "circle", "diamond", "square"}
+ assert set(props["marker_start"]["enum"]) == markers
+ assert set(props["marker_end"]["enum"]) == markers
+ assert set(props["path_style"]["enum"]) == {"bezier", "smooth"}
+ assert set(props["line_style"]["enum"]) == {"solid", "dashed", "dotted"}
+ assert (props["width_mult"]["minimum"], props["width_mult"]["maximum"]) == (1, 4)
+
+
+async def test_create_edge_forwards_the_styling_fields(mock_backend):
+ args = {
+ "source": "1", "target": "2", "type": "wifi",
+ "animated": "basic", "custom_color": "#00d4ff", "line_style": "dashed",
+ "width_mult": 2, "marker_end": "arrow", "vlan_id": 20, "speed": "10G",
+ }
+ await _dispatch("create_edge", dict(args))
+ mock_backend.post.assert_called_once_with("/api/v1/edges", args)
+
+
+async def test_update_edge_forwards_the_styling_fields(mock_backend):
+ await _dispatch("update_edge", {"id": "e7", "animated": "flow", "path_style": "smooth"})
+ mock_backend.patch.assert_called_once_with(
+ "/api/v1/edges/e7", {"animated": "flow", "path_style": "smooth"}
+ )