PrefectHQ/fastmcp · error · RuntimeError

Failed to add requirements: {e.stderr}

Error message

Failed to add requirements: {e.stderr}

What it means

prepare() runs `uv add -r <requirements.txt> --no-sync --project <dir>` and raises this RuntimeError when uv exits nonzero. It means uv could not read or resolve the requirements file configured as environment.requirements. uv's stderr is in the message.

Source

Thrown at fastmcp_slim/fastmcp/utilities/mcp_server_config/v1/environments/uv.py:231

            req_path = Path(self.requirements).resolve()
            try:
                subprocess.run(
                    [
                        "uv",
                        "add",
                        "-r",
                        str(req_path),
                        "--no-sync",
                        "--project",
                        str(output_dir),
                    ],
                    check=True,
                    capture_output=True,
                    text=True,
                )
            except subprocess.CalledProcessError as e:
                logger.error(f"Failed to add requirements: {e.stderr}")
                raise RuntimeError(f"Failed to add requirements: {e.stderr}") from e

        # Add editable packages if specified
        if self.editable:
            editable_paths = [str(Path(e).resolve()) for e in self.editable]
            logger.debug(f"Adding editable packages: {', '.join(editable_paths)}")
            try:
                subprocess.run(
                    [
                        "uv",
                        "add",
                        "--editable",
                        *editable_paths,
                        "--no-sync",
                        "--project",
                        str(output_dir),
                    ],
                    check=True,
                    capture_output=True,

View on GitHub (pinned to 1f02114297)

Solutions

  1. Check the file exists at the resolved absolute path: `ls -l $(realpath requirements.txt)`; fix the path in the config — remember it resolves from the process CWD.
  2. Read e.stderr for the offending line number and fix that line's specifier or remove uv-unsupported options.
  3. Test `uv add -r requirements.txt --no-sync --project /tmp/t` directly to reproduce.
  4. Resolve pin conflicts between requirements.txt and environment.dependencies reported in stderr.
  5. Freeze from a known-good env if versions drift: `uv pip freeze > requirements.txt`.

Example fix

// before
"requirements": "../requirements/prod.txt"  # run from repo root: file not found

// after
"requirements": "requirements/prod.txt"  // correct relative to CWD, or use absolute path
Defensive patterns

Strategy: validation

Validate before calling

import pathlib

req = cfg.environment.requirements
if req:
    p = pathlib.Path(req).resolve()
    assert p.is_file(), f"requirements file missing: {p}"
    for i, line in enumerate(p.read_text().splitlines(), 1):
        s = line.strip()
        if s and not s.startswith("#"):
            assert not s.startswith("-e "), f"uv add -r may reject option line {i}: {s}"

Try / catch

try:
    await env.prepare(output_dir)
except RuntimeError as e:
    if str(e).startswith("Failed to add requirements"):
        print(e)  # stderr names the bad line/conflict in requirements.txt
    else:
        raise

Prevention

When it happens

Trigger: prepare() with environment.requirements set to a file that does not exist, is not readable, contains an invalid line (bad PEP 508 spec, bad -e/-r line), or whose pins conflict with the already-added dependencies + fastmcp.

Common situations: Path typo or requirements.txt resolved from the wrong working directory (paths resolve relative to CWD, not the config file); a requirements file generated for pip with uv-unsupported flags; conflicting pins between requirements.txt and environment.dependencies; file edited by a teammate with an unparsable line.

Related errors


AI-assisted analysis of PrefectHQ/fastmcp@1f02114297 (2026-08-29). Data as JSON: /api/errors/1ede028f94023fd9. Report an issue: GitHub.