forked from HomeLab/unraid-mcp
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:
@@ -7,12 +7,13 @@ development and debugging purposes.
|
|||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
import json
|
import json
|
||||||
|
import ssl
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
import websockets
|
import websockets
|
||||||
from fastmcp import FastMCP
|
from fastmcp import FastMCP
|
||||||
from websockets.legacy.protocol import Subprotocol
|
from websockets.typing import Subprotocol
|
||||||
|
|
||||||
from ..config.logging import logger
|
from ..config.logging import logger
|
||||||
from ..config.settings import UNRAID_API_KEY, UNRAID_API_URL, UNRAID_VERIFY_SSL
|
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")
|
raise ToolError("UNRAID_API_URL is not configured")
|
||||||
ws_url = UNRAID_API_URL.replace("https://", "wss://").replace("http://", "ws://") + "/graphql"
|
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
|
# Test connection
|
||||||
async with websockets.connect(
|
async with websockets.connect(
|
||||||
ws_url,
|
ws_url,
|
||||||
subprotocols=[Subprotocol("graphql-transport-ws"), Subprotocol("graphql-ws")],
|
subprotocols=[Subprotocol("graphql-transport-ws"), Subprotocol("graphql-ws")],
|
||||||
ssl=UNRAID_VERIFY_SSL,
|
ssl=ssl_context,
|
||||||
ping_interval=30,
|
ping_interval=30,
|
||||||
ping_timeout=10
|
ping_timeout=10
|
||||||
) as websocket:
|
) as websocket:
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ from datetime import datetime
|
|||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
import websockets
|
import websockets
|
||||||
from websockets.legacy.protocol import Subprotocol
|
from websockets.typing import Subprotocol
|
||||||
|
|
||||||
from ..config.logging import logger
|
from ..config.logging import logger
|
||||||
from ..config.settings import UNRAID_API_KEY, UNRAID_API_URL, UNRAID_VERIFY_SSL
|
from ..config.settings import UNRAID_API_KEY, UNRAID_API_URL, UNRAID_VERIFY_SSL
|
||||||
|
|||||||
Reference in New Issue
Block a user