feat(resources): add unraid://live/{action} MCP resources for 9 snapshot subscriptions

Registers cpu, memory, cpu_telemetry, array_state, parity_progress,
ups_status, notifications_overview, owner, and server_status as MCP
resources under unraid://live/{action}. Each opens a transient WebSocket
via subscribe_once() and returns JSON; exceptions degrade gracefully to
an error JSON dict rather than raising. Skips log_tail and
notification_feed (require params, not suitable as resources).
This commit is contained in:
Jacob Magar
2026-03-15 21:51:20 -04:00
parent 7c99fe1527
commit f5978d67ec
2 changed files with 117 additions and 0 deletions

View File

@@ -14,6 +14,8 @@ from fastmcp import FastMCP
from ..config.logging import logger
from .manager import subscription_manager
from .queries import SNAPSHOT_ACTIONS
from .snapshot import subscribe_once
# Global flag to track subscription startup
@@ -102,4 +104,22 @@ def register_subscription_resources(mcp: FastMCP) -> None:
}
)
def _make_resource_fn(action: str, query: str):
async def _live_resource() -> str:
await ensure_subscriptions_started()
try:
data = await subscribe_once(query)
return json.dumps(data, indent=2)
except Exception as exc:
return json.dumps({"error": str(exc), "action": action})
_live_resource.__name__ = f"{action}_resource"
_live_resource.__doc__ = (
f"Real-time {action.replace('_', ' ')} data via WebSocket subscription."
)
return _live_resource
for _action, _query in SNAPSHOT_ACTIONS.items():
mcp.resource(f"unraid://live/{_action}")(_make_resource_fn(_action, _query))
logger.info("Subscription resources registered successfully")