Files
unraid-mcp/pyproject.toml
Jacob Magar 316193c04b refactor: comprehensive code review fixes across 31 files
Addresses all critical, high, medium, and low issues from full codebase
review. 494 tests pass, ruff clean, ty type-check clean.

Security:
- Add tool_error_handler context manager (exceptions.py) — standardised
  error handling, eliminates 11 bare except-reraise patterns
- Remove unused exception subclasses (ConfigurationError, UnraidAPIError,
  SubscriptionError, ValidationError, IdempotentOperationError)
- Harden GraphQL subscription query validator with allow-list and
  forbidden-keyword regex (diagnostics.py)
- Add input validation for rclone create_remote config_data: injection,
  path-traversal, and key-count limits (rclone.py)
- Validate notifications importance enum before GraphQL request (notifications.py)
- Sanitise HTTP/network/JSON error messages — no raw exception strings
  leaked to clients (client.py)
- Strip path/creds from displayed API URL via _safe_display_url (health.py)
- Enable Ruff S (bandit) rule category in pyproject.toml
- Harden container mutations to strict-only matching — no fuzzy/substring
  for destructive operations (docker.py)

Performance:
- Token-bucket rate limiter (90 tokens, 9 req/s) with 429 retry backoff (client.py)
- Lazy asyncio.Lock init via _get_client_lock() — fixes event-loop
  module-load crash (client.py)
- Double-checked locking in get_http_client() for fast-path (client.py)
- Short hex container ID fast-path skips list fetch (docker.py)
- Cap resource_data log content to 1 MB / 5,000 lines (manager.py)
- Reset reconnect counter after 30 s stable connection (manager.py)
- Move tail_lines validation to module level; enforce 10,000 line cap
  (storage.py, docker.py)
- force_terminal=True removed from logging RichHandler (logging.py)

Architecture:
- Register diagnostic tools in server startup (server.py)
- Move ALL_ACTIONS computation to module level in all tools
- Consolidate format_kb / format_bytes into shared core/utils.py
- Add _safe_get() helper in core/utils.py for nested dict traversal
- Extract _analyze_subscription_status() from health.py diagnose handler
- Validate required config at startup — fail fast with CRITICAL log (server.py)

Code quality:
- Remove ~90 lines of dead Rich formatting helpers from logging.py
- Remove dead self.websocket attribute from SubscriptionManager
- Remove dead setup_uvicorn_logging() wrapper
- Move _VALID_IMPORTANCE to module level (N806 fix)
- Add slots=True to all three dataclasses (SubscriptionData, SystemHealth, APIResponse)
- Fix None rendering as literal "None" string in info.py summaries
- Change fuzzy-match log messages from INFO to DEBUG (docker.py)
- UTC-aware datetimes throughout (manager.py, diagnostics.py)

Infrastructure:
- Upgrade base image python:3.11-slim → python:3.12-slim (Dockerfile)
- Add non-root appuser (UID/GID 1000) with HEALTHCHECK (Dockerfile)
- Add read_only, cap_drop: ALL, tmpfs /tmp to docker-compose.yml
- Single-source version via importlib.metadata (pyproject.toml → __init__.py)
- Add open_timeout to all websockets.connect() calls

Tests:
- Update error message matchers to match sanitised messages (test_client.py)
- Fix patch targets for UNRAID_API_URL → utils module (test_subscriptions.py)
- Fix importance="info" → importance="normal" (test_notifications.py, http_layer)
- Fix naive datetime fixtures → UTC-aware (test_subscriptions.py)

Co-authored-by: Claude <claude@anthropic.com>
2026-02-18 01:02:13 -05:00

295 lines
7.7 KiB
TOML

# ============================================================================
# Build System Configuration
# ============================================================================
[build-system]
requires = ["hatchling>=1.25.0"]
build-backend = "hatchling.build"
# ============================================================================
# Project Metadata
# ============================================================================
[project]
name = "unraid-mcp"
version = "0.2.0"
description = "MCP Server for Unraid API - provides tools to interact with an Unraid server's GraphQL API"
readme = "README.md"
license = {file = "LICENSE"}
requires-python = ">=3.12"
authors = [
{name = "jmagar", email = "jmagar@users.noreply.github.com"}
]
maintainers = [
{name = "jmagar", email = "jmagar@users.noreply.github.com"}
]
keywords = [
"unraid",
"mcp",
"model-context-protocol",
"graphql",
"api",
"server",
"docker",
"automation",
"monitoring",
"homelab",
]
classifiers = [
# Development Status
"Development Status :: 4 - Beta",
# Audience
"Intended Audience :: Developers",
"Intended Audience :: System Administrators",
# License
"License :: OSI Approved :: MIT License",
# Python Versions
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"Programming Language :: Python :: 3 :: Only",
# Framework
"Framework :: FastAPI",
"Framework :: Pydantic",
# Topics
"Topic :: Home Automation",
"Topic :: System :: Monitoring",
"Topic :: System :: Systems Administration",
"Topic :: Software Development :: Libraries :: Python Modules",
# Environment
"Operating System :: OS Independent",
"Environment :: Console",
"Typing :: Typed",
]
# ============================================================================
# Dependencies
# ============================================================================
dependencies = [
"python-dotenv>=1.1.1",
"fastmcp>=2.14.5",
"httpx>=0.28.1",
"fastapi>=0.115.0",
"uvicorn[standard]>=0.35.0",
"websockets>=15.0.1",
"rich>=14.1.0",
]
# ============================================================================
# Project URLs
# ============================================================================
[project.urls]
Homepage = "https://github.com/jmagar/unraid-mcp"
Documentation = "https://github.com/jmagar/unraid-mcp#readme"
Repository = "https://github.com/jmagar/unraid-mcp"
Issues = "https://github.com/jmagar/unraid-mcp/issues"
Changelog = "https://github.com/jmagar/unraid-mcp/releases"
Source = "https://github.com/jmagar/unraid-mcp"
# ============================================================================
# Entry Points
# ============================================================================
[project.scripts]
unraid-mcp-server = "unraid_mcp.main:main"
unraid-mcp = "unraid_mcp.main:main"
# ============================================================================
# Build Configuration
# ============================================================================
[tool.hatch.build.targets.wheel]
only-include = ["unraid_mcp"]
[tool.hatch.build.targets.sdist]
include = [
"/unraid_mcp",
"/tests",
"/README.md",
"/LICENSE",
"/pyproject.toml",
"/.env.example",
]
exclude = [
"/.git",
"/.github",
"/.venv",
"/.cache",
"/.docs",
"/.full-review",
"/docs",
"*.pyc",
"__pycache__",
]
# ============================================================================
# Tool Configuration: Ruff (Linting & Formatting)
# ============================================================================
[tool.ruff]
target-version = "py312"
line-length = 100
cache-dir = ".cache/.ruff_cache"
[tool.ruff.lint]
select = [
# Pyflakes
"F",
# pycodestyle
"E",
"W",
# isort
"I",
# pep8-naming
"N",
# pydocstyle
"D",
# pyupgrade
"UP",
# flake8-2020
"YTT",
# flake8-bugbear
"B",
# flake8-quotes
"Q",
# flake8-comprehensions
"C4",
# flake8-simplify
"SIM",
# flake8-type-checking
"TCH",
# flake8-use-pathlib
"PTH",
# flake8-async
"ASYNC",
# flake8-return
"RET",
# Perflint
"PERF",
# Ruff-specific rules
"RUF",
# flake8-bandit (security)
"S",
]
ignore = [
"E501", # line too long (handled by ruff formatter)
"B008", # function calls in argument defaults
"C901", # too complex
"D100", # missing docstring in public module
"D101", # missing docstring in public class
"D102", # missing docstring in public method
"D103", # missing docstring in public function
"D104", # missing docstring in public package
"D105", # missing docstring in magic method
"D107", # missing docstring in __init__
"D203", # 1 blank line required before class docstring (conflicts with D211)
"D213", # multi-line docstring summary should start at the second line (conflicts with D212)
]
[tool.ruff.lint.per-file-ignores]
"__init__.py" = ["F401", "D104"]
"tests/**/*.py" = ["D", "S101", "PLR2004"] # Allow asserts and magic values in tests
[tool.ruff.lint.pydocstyle]
convention = "google"
[tool.ruff.lint.isort]
known-first-party = ["unraid_mcp"]
force-single-line = false
lines-after-imports = 2
# ============================================================================
# Tool Configuration: ty (Type Checking)
# ============================================================================
[tool.ty.environment]
python-version = "3.12"
[tool.ty.analysis]
respect-type-ignore-comments = true
# ============================================================================
# Tool Configuration: pytest (Testing)
# ============================================================================
[tool.pytest.ini_options]
asyncio_mode = "auto"
cache_dir = ".cache/.pytest_cache"
testpaths = ["tests"]
python_files = ["test_*.py", "*_test.py"]
python_classes = ["Test*"]
python_functions = ["test_*"]
addopts = [
"-ra",
"--strict-markers",
"--strict-config",
"--tb=short",
"-v",
]
markers = [
"slow: marks tests as slow (deselect with '-m \"not slow\"')",
"integration: marks tests as integration tests",
"unit: marks tests as unit tests",
]
filterwarnings = [
"error",
"ignore::DeprecationWarning",
"ignore::PendingDeprecationWarning",
]
# ============================================================================
# Tool Configuration: Coverage
# ============================================================================
[tool.coverage.run]
source = ["unraid_mcp"]
branch = true
parallel = true
data_file = ".cache/.coverage"
omit = [
"*/tests/*",
"*/__pycache__/*",
"*/.venv/*",
]
[tool.coverage.report]
precision = 2
show_missing = true
skip_covered = false
exclude_lines = [
"pragma: no cover",
"def __repr__",
"def __str__",
"if self.debug:",
"if settings.DEBUG",
"raise AssertionError",
"raise NotImplementedError",
"if 0:",
"if False:",
"if __name__ == .__main__.:",
"if TYPE_CHECKING:",
"class .*\\bProtocol\\):",
"@(abc\\.)?abstractmethod",
"@(typing\\.)?overload",
]
[tool.coverage.html]
directory = ".cache/htmlcov"
[tool.coverage.xml]
output = ".cache/coverage.xml"
# ============================================================================
# Tool Configuration: Dependency Groups (uv-specific)
# ============================================================================
[dependency-groups]
dev = [
"pytest>=8.4.2",
"pytest-asyncio>=1.2.0",
"pytest-cov>=7.0.0",
"respx>=0.22.0",
"ty>=0.0.15",
"ruff>=0.12.8",
"build>=1.2.2",
"twine>=6.0.1",
"graphql-core>=3.2.0",
]