{ lib, python3Packages, fetchFromGitHub, fetchPypi, fetchurl, }: let # Internal dependency: pyzotero (not in nixpkgs) pyzotero = python3Packages.buildPythonPackage rec { pname = "pyzotero"; version = "1.14.0"; format = "wheel"; src = fetchPypi { inherit pname version; format = "wheel"; dist = "py3"; python = "py3"; hash = "sha256-OUoU8HTEFwVfzqopcLWUzpJaYJTJ09zIpzTgdCbs9BU="; }; propagatedBuildInputs = with python3Packages; [ feedparser bibtexparser httpx whenever ]; doCheck = false; pythonImportsCheck = [ "pyzotero" ]; meta = with lib; { description = "Python wrapper for the Zotero API"; homepage = "https://github.com/urschrei/pyzotero"; license = licenses.blueOak100; }; }; # pdf-inspector: Rust with prebuilt abi3 wheels, not in nixpkgs. # Pinned exactly (pre-1.0); no Python dependencies of its own. pdf-inspector = python3Packages.buildPythonPackage rec { pname = "pdf-inspector"; version = "0.2.6"; format = "wheel"; src = fetchurl { url = "https://files.pythonhosted.org/packages/59/af/be72ab2bd310b6532e4311cf06175eb722802ccea29dbd9281f66c645bd8/pdf_inspector-0.2.6-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl"; hash = "sha256-33bdEAUEtwXOku8sZo8VLwUnfZQqvZSn0/JSy1RI1W0="; }; doCheck = false; pythonImportsCheck = [ "pdf_inspector" ]; meta = with lib; { description = "PDF text extraction (Rust, abi3 wheels)"; homepage = "https://github.com/54yyyu/pdf-inspector"; license = licenses.mit; }; }; in python3Packages.buildPythonApplication rec { pname = "zotero-mcp"; version = "0.13.0"; pyproject = true; src = fetchFromGitHub { owner = "54yyyu"; repo = "zotero-mcp"; rev = "v${version}"; hash = "sha256-xL54SbaAczkwk4tkan+wVVTv9ACKIC6hcAADI2GTnxk="; }; build-system = with python3Packages; [ hatchling ]; # Core dependencies (from pyproject.toml v0.13.0) dependencies = with python3Packages; [ pyzotero python-dotenv pdf-inspector markdownify pydantic requests fastmcp httpx unidecode bibtexparser # Runtime deps for the annotation/layout/read tools (upstream "pdf" extra). # nix's optional-dependencies is passthru-only and installs nothing, so # anything needed at runtime must live in this list. pymupdf ebooklib # Runtime deps for the semantic-search tools (upstream "semantic" extra). # zotero_mcp.semantic_search imports chromadb unconditionally at module # scope (embeddings/providers/__init__.py, chroma_client.py), so these are # hard requirements, not truly optional at runtime. chromadb sentence-transformers openai google-genai tiktoken ]; # `zotero_get_pdf_outline` reads a PDF's table of contents in a throwaway # `sys.executable -c ...` child (tools/write.py, _extract_pdf_toc). Under the # Nix wrapper this package's dependencies are injected into the *parent* # interpreter via site.addsitedir, never exported as PYTHONPATH, so the child # gets a bare sys.path and its `import pymupdf` fails. The tool then reports # "PyMuPDF (fitz) is required..." even though PyMuPDF is a build input. # Forward the parent's sys.path so the child resolves the same modules. # Mirrors nixpkgs' python-modules/vllm/0003-propagate-pythonpath.patch. postPatch = '' substituteInPlace src/zotero_mcp/tools/write.py \ --replace-fail \ 'child_env.setdefault("PYTHONUTF8", "1")' \ 'child_env.setdefault("PYTHONUTF8", "1"); child_env["PYTHONPATH"] = os.pathsep.join(p for p in sys.path if p)' ''; pythonImportsCheck = [ "zotero_mcp" ]; meta = with lib; { description = "MCP server connecting Zotero with AI assistants for research library access"; homepage = "https://github.com/54yyyu/zotero-mcp"; license = licenses.mit; mainProgram = "zotero-mcp"; platforms = platforms.all; }; }