crewAIInc/crewAI · error · ImportError

Failed to install mcp package

Error message

Failed to install mcp package

What it means

ImportError raised when the user answered 'yes' to the interactive prompt about installing the missing mcp package, but the subprocess 'uv add "mcp crewai-tools'[mcp]'" exited non-zero (CalledProcessError). The install attempt itself failed — the raised error intentionally hides the underlying uv output, so re-running the command manually is the fastest diagnosis.

Source

Thrown at lib/crewai-tools/src/crewai_tools/adapters/mcp_adapter.py:171

        self._adapter = None
        self._tools = None
        self._tool_names = (
            [sanitize_tool_name(name) for name in tool_names] if tool_names else None
        )

        if not MCP_AVAILABLE:
            import click

            if click.confirm(
                "You are missing the 'mcp' package. Would you like to install it?"
            ):
                import subprocess

                try:
                    subprocess.run(["uv", "add", "mcp crewai-tools'[mcp]'"], check=True)  # noqa: S607

                except subprocess.CalledProcessError as e:
                    raise ImportError("Failed to install mcp package") from e
            else:
                raise ImportError(
                    "`mcp` package not found, please run `uv add crewai-tools[mcp]`"
                )

        try:
            self._serverparams = serverparams
            self._adapter = MCPAdapt(
                self._serverparams, CrewAIToolAdapter(), connect_timeout
            )
            self.start()

        except Exception as e:
            if self._adapter is not None:
                try:
                    self.stop()
                except Exception as stop_e:
                    logger.error(f"Error during stop cleanup: {stop_e}")

View on GitHub (pinned to 754d7323be)

Solutions

  1. Run the command manually to see the real error: uv add "crewai-tools[mcp]".
  2. If not using uv, install directly: pip install 'crewai-tools[mcp]'.
  3. Pre-install mcp in the image/requirements so the interactive prompt path is never taken.

Example fix

# before
MCPServerAdapter(serverparams)  # prompt -> uv add fails -> ImportError

# after
# pre-install dependency (no prompt, no subprocess):
# pip install 'crewai-tools[mcp]'
adapter = MCPServerAdapter(serverparams=...)
Defensive patterns

Strategy: try-catch

Validate before calling

import importlib.util

if importlib.util.find_spec("mcp") is None:
    raise RuntimeError("pre-install with: pip install 'crewai-tools[mcp]'")

Try / catch

try:
    MCPServerAdapter(serverparams=...)
except ImportError as e:
    if "Failed to install mcp" in str(e):
        # run manually to see uv's real error
        raise RuntimeError("run: uv add 'crewai-tools[mcp]'") from e
    raise

Prevention

When it happens

Trigger: Constructing MCPServerAdapter without mcp installed, confirming the click.confirm prompt, while uv is missing from PATH, the project has no uv-compatible manifest, or the dependency resolution fails.

Common situations: Running under pip/setuptools instead of uv; uv present but not on PATH in the service environment; lock conflicts resolving crewai-tools[mcp]; running the interactive prompt inside a container without write access to the project.

Related errors


AI-assisted analysis of crewAIInc/crewAI@754d7323be (2026-08-15). Data as JSON: /api/errors/f0c0fd9dd5db9854. Report an issue: GitHub.