diff --git a/tests/test_snapshot.py b/tests/test_snapshot.py index d5b5343..41f6ebd 100644 --- a/tests/test_snapshot.py +++ b/tests/test_snapshot.py @@ -116,3 +116,10 @@ async def test_subscribe_collect_returns_multiple_events(mock_ws): assert len(result) == 2 assert result[0]["notificationAdded"]["id"] == "1" + + +def test_snapshot_actions_importable_from_subscriptions() -> None: + from unraid_mcp.subscriptions.queries import COLLECT_ACTIONS, SNAPSHOT_ACTIONS + + assert "cpu" in SNAPSHOT_ACTIONS + assert "log_tail" in COLLECT_ACTIONS diff --git a/unraid_mcp/subscriptions/queries.py b/unraid_mcp/subscriptions/queries.py new file mode 100644 index 0000000..73b4571 --- /dev/null +++ b/unraid_mcp/subscriptions/queries.py @@ -0,0 +1,40 @@ +"""GraphQL subscription query strings for snapshot and collect operations.""" + +SNAPSHOT_ACTIONS = { + "cpu": """ + subscription { systemMetricsCpu { id percentTotal cpus { percentTotal percentUser percentSystem percentIdle } } } + """, + "memory": """ + subscription { systemMetricsMemory { id total used free available active buffcache percentTotal swapTotal swapUsed swapFree percentSwapTotal } } + """, + "cpu_telemetry": """ + subscription { systemMetricsCpuTelemetry { id totalPower power temp } } + """, + "array_state": """ + subscription { arraySubscription { id state capacity { kilobytes { free used total } } parityCheckStatus { status progress speed errors } } } + """, + "parity_progress": """ + subscription { parityHistorySubscription { date status progress speed errors correcting paused running } } + """, + "ups_status": """ + subscription { upsUpdates { id name model status battery { chargeLevel estimatedRuntime health } power { inputVoltage outputVoltage loadPercentage } } } + """, + "notifications_overview": """ + subscription { notificationsOverview { unread { info warning alert total } archive { info warning alert total } } } + """, + "owner": """ + subscription { ownerSubscription { username url avatar } } + """, + "server_status": """ + subscription { serversSubscription { id name status guid wanip lanip localurl remoteurl } } + """, +} + +COLLECT_ACTIONS = { + "notification_feed": """ + subscription { notificationAdded { id title subject description importance type timestamp } } + """, + "log_tail": """ + subscription LogTail($path: String!) { logFile(path: $path) { path content totalLines startLine } } + """, +} diff --git a/unraid_mcp/tools/live.py b/unraid_mcp/tools/live.py index d11ece2..753ab99 100644 --- a/unraid_mcp/tools/live.py +++ b/unraid_mcp/tools/live.py @@ -15,50 +15,12 @@ from fastmcp import FastMCP from ..config.logging import logger from ..core.exceptions import ToolError, tool_error_handler +from ..subscriptions.queries import COLLECT_ACTIONS, SNAPSHOT_ACTIONS from ..subscriptions.snapshot import subscribe_collect, subscribe_once _ALLOWED_LOG_PREFIXES = ("/var/log/", "/boot/logs/", "/mnt/") -SNAPSHOT_ACTIONS = { - "cpu": """ - subscription { systemMetricsCpu { id percentTotal cpus { percentTotal percentUser percentSystem percentIdle } } } - """, - "memory": """ - subscription { systemMetricsMemory { id total used free available active buffcache percentTotal swapTotal swapUsed swapFree percentSwapTotal } } - """, - "cpu_telemetry": """ - subscription { systemMetricsCpuTelemetry { id totalPower power temp } } - """, - "array_state": """ - subscription { arraySubscription { id state capacity { kilobytes { free used total } } parityCheckStatus { status progress speed errors } } } - """, - "parity_progress": """ - subscription { parityHistorySubscription { date status progress speed errors correcting paused running } } - """, - "ups_status": """ - subscription { upsUpdates { id name model status battery { chargeLevel estimatedRuntime health } power { inputVoltage outputVoltage loadPercentage } } } - """, - "notifications_overview": """ - subscription { notificationsOverview { unread { info warning alert total } archive { info warning alert total } } } - """, - "owner": """ - subscription { ownerSubscription { username url avatar } } - """, - "server_status": """ - subscription { serversSubscription { id name status guid wanip lanip localurl remoteurl } } - """, -} - -COLLECT_ACTIONS = { - "notification_feed": """ - subscription { notificationAdded { id title subject description importance type timestamp } } - """, - "log_tail": """ - subscription LogTail($path: String!) { logFile(path: $path) { path content totalLines startLine } } - """, -} - ALL_LIVE_ACTIONS = set(SNAPSHOT_ACTIONS) | set(COLLECT_ACTIONS) LIVE_ACTIONS = Literal[