fix: update Subprotocol import and SSL handling in WebSocket modules

- Change Subprotocol import from deprecated websockets.legacy.protocol
  to websockets.typing (canonical location in websockets 13.x)
- Fix SSL context handling in diagnostics.py to properly build
  ssl.SSLContext objects, matching the pattern in manager.py
  (previously passed UNRAID_VERIFY_SSL directly which breaks
  when it's a CA bundle path string)
This commit is contained in:
Jacob Magar
2026-02-15 16:44:43 -05:00
parent c4fa6937ab
commit 6bbe46879e
2 changed files with 14 additions and 3 deletions

View File

@@ -7,12 +7,13 @@ development and debugging purposes.
import asyncio
import json
import ssl
from datetime import datetime
from typing import Any
import websockets
from fastmcp import FastMCP
from websockets.legacy.protocol import Subprotocol
from websockets.typing import Subprotocol
from ..config.logging import logger
from ..config.settings import UNRAID_API_KEY, UNRAID_API_URL, UNRAID_VERIFY_SSL
@@ -48,11 +49,21 @@ def register_diagnostic_tools(mcp: FastMCP) -> None:
raise ToolError("UNRAID_API_URL is not configured")
ws_url = UNRAID_API_URL.replace("https://", "wss://").replace("http://", "ws://") + "/graphql"
# Build SSL context for wss:// connections
ssl_context = None
if ws_url.startswith("wss://"):
if isinstance(UNRAID_VERIFY_SSL, str):
ssl_context = ssl.create_default_context(cafile=UNRAID_VERIFY_SSL)
elif UNRAID_VERIFY_SSL:
ssl_context = ssl.create_default_context()
else:
ssl_context = ssl._create_unverified_context()
# Test connection
async with websockets.connect(
ws_url,
subprotocols=[Subprotocol("graphql-transport-ws"), Subprotocol("graphql-ws")],
ssl=UNRAID_VERIFY_SSL,
ssl=ssl_context,
ping_interval=30,
ping_timeout=10
) as websocket: