From c4fa6937abf21c63a49c5cf18c383f578097ea4b Mon Sep 17 00:00:00 2001 From: Jacob Magar Date: Sun, 15 Feb 2026 16:44:40 -0500 Subject: [PATCH] fix: resolve ruff lint issues in storage tool and tests - Move _ALLOWED_LOG_PREFIXES to module level (N806: constant naming) - Use f-string conversion flag {e!s} instead of {str(e)} (RUF010) - Fix import block sorting in both files (I001) --- tests/test_storage.py | 1 + unraid_mcp/tools/storage.py | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/tests/test_storage.py b/tests/test_storage.py index 2ab656b..e115dfe 100644 --- a/tests/test_storage.py +++ b/tests/test_storage.py @@ -8,6 +8,7 @@ from conftest import make_tool_fn from unraid_mcp.core.exceptions import ToolError from unraid_mcp.tools.storage import format_bytes + # --- Unit tests for helpers --- diff --git a/unraid_mcp/tools/storage.py b/unraid_mcp/tools/storage.py index b614edd..ad46dcb 100644 --- a/unraid_mcp/tools/storage.py +++ b/unraid_mcp/tools/storage.py @@ -13,6 +13,9 @@ from ..config.logging import logger from ..core.client import DISK_TIMEOUT, make_graphql_request from ..core.exceptions import ToolError + +_ALLOWED_LOG_PREFIXES = ("/var/log/", "/boot/logs/", "/mnt/") + QUERIES: dict[str, str] = { "shares": """ query GetSharesInfo { @@ -99,7 +102,6 @@ def register_storage_tool(mcp: FastMCP) -> None: if action == "logs": if not log_path: raise ToolError("log_path is required for 'logs' action") - _ALLOWED_LOG_PREFIXES = ("/var/log/", "/boot/logs/", "/mnt/") # Normalize path to prevent traversal attacks (e.g. /var/log/../../etc/shadow) normalized = posixpath.normpath(log_path) if not any(normalized.startswith(p) for p in _ALLOWED_LOG_PREFIXES): @@ -165,6 +167,6 @@ def register_storage_tool(mcp: FastMCP) -> None: raise except Exception as e: logger.error(f"Error in unraid_storage action={action}: {e}", exc_info=True) - raise ToolError(f"Failed to execute storage/{action}: {str(e)}") from e + raise ToolError(f"Failed to execute storage/{action}: {e!s}") from e logger.info("Storage tool registered successfully")