From 47fa4a18bb6888ea8f4cd00c1de3957334672c8b Mon Sep 17 00:00:00 2001 From: Alex Date: Wed, 1 Apr 2026 18:09:12 -0700 Subject: [PATCH] fix: add tool repository credentials to crewai install crewai install (uv sync) was failing with 401 Unauthorized when the project depends on tools from a private package index (e.g. AMP tool repository). The credentials were already injected for 'crewai run' and 'crewai tool publish' but were missing from 'crewai install'. Reads [tool.uv.sources] from pyproject.toml and injects UV_INDEX_* credentials into the subprocess environment, matching the pattern already used in run_crew.py. --- lib/crewai/src/crewai/cli/install_crew.py | 24 ++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/lib/crewai/src/crewai/cli/install_crew.py b/lib/crewai/src/crewai/cli/install_crew.py index aa10902aa..21bd0a35b 100644 --- a/lib/crewai/src/crewai/cli/install_crew.py +++ b/lib/crewai/src/crewai/cli/install_crew.py @@ -1,7 +1,10 @@ +import os import subprocess import click +from crewai.cli.utils import build_env_with_tool_repository_credentials, read_toml + # Be mindful about changing this. # on some environments we don't use this command but instead uv sync directly @@ -13,7 +16,26 @@ def install_crew(proxy_options: list[str]) -> None: """ try: command = ["uv", "sync", *proxy_options] - subprocess.run(command, check=True, capture_output=False, text=True) # noqa: S603 + + # Inject tool repository credentials so uv can authenticate + # against private package indexes (e.g. crewai tool repository). + # Without this, `uv sync` fails with 401 Unauthorized when the + # project depends on tools from a private index. + env = os.environ.copy() + try: + pyproject_data = read_toml() + sources = pyproject_data.get("tool", {}).get("uv", {}).get("sources", {}) + + for source_config in sources.values(): + if isinstance(source_config, dict): + index = source_config.get("index") + if index: + index_env = build_env_with_tool_repository_credentials(index) + env.update(index_env) + except Exception: # noqa: S110 + pass + + subprocess.run(command, check=True, capture_output=False, text=True, env=env) # noqa: S603 except subprocess.CalledProcessError as e: click.echo(f"An error occurred while running the crew: {e}", err=True)