{ lib, stdenv, fetchFromGitHub, makeWrapper, python3, }: let python = python3.withPackages ( ps: with ps; [ fastapi fastmcp httpx python-dotenv ] ); in stdenv.mkDerivation { pname = "sabnzbd-mcp"; version = "0.1.0-unstable"; src = fetchFromGitHub { # Original upstream (jmagar/sabnzbd-mcp) was deleted from GitHub. # Using jasonpaulso's fork, which preserves the same file layout # (client.py + sabnzbd-mcp-server.py at repo root) and the # /sabnzbd/api string that postPatch below rewrites. owner = "jasonpaulso"; repo = "sabnzbd-mcp"; rev = "8755e70e2634c02c24471f32962224833877dc81"; hash = "sha256-y46jTXBsOXMoFnnwyv0n+8uq2Z/kw2HbnZC85knWpUw="; }; nativeBuildInputs = [ makeWrapper ]; postPatch = '' # The upstream client hardcodes /sabnzbd/api as the API path. # Change to just /api so SABNZBD_URL can optionally include the path prefix # (e.g. http://host:9092/sabnzbd or just http://host:9092). substituteInPlace client.py \ --replace-fail '"{self.base_url}/sabnzbd/api"' '"{self.base_url}/api"' ''; installPhase = '' mkdir -p $out/lib/sabnzbd-mcp cp sabnzbd-mcp-server.py client.py $out/lib/sabnzbd-mcp/ makeWrapper ${python}/bin/python $out/bin/sabnzbd-mcp \ --add-flags "$out/lib/sabnzbd-mcp/sabnzbd-mcp-server.py" \ --set-default SABNZBD_MCP_TRANSPORT stdio ''; meta = with lib; { description = "MCP server for SABnzbd Usenet client"; homepage = "https://github.com/jmagar/sabnzbd-mcp"; license = licenses.mit; mainProgram = "sabnzbd-mcp"; platforms = platforms.all; }; }