crewAIInc/crewAI · error · ImportError

You are missing the 'mongodb' crewai tool.

Error message

You are missing the 'mongodb' crewai tool.

What it means

MongoDBVectorSearchTool requires pymongo; if it is missing, the constructor offers an interactive `uv add pymongo` install via click.confirm. Declining (or running non-interactively where confirm fails) raises this ImportError. The message text ('mongodb' crewai tool) is slightly misleading — the actual missing package is pymongo.

Source

Thrown at lib/crewai-tools/src/crewai_tools/tools/mongodb_vector_search_tool/vector_search.py:121

            ),
        ]
    )
    package_dependencies: list[str] = Field(default_factory=lambda: ["pymongo"])

    def __init__(self, **kwargs: Any) -> None:
        super().__init__(**kwargs)
        if not MONGODB_AVAILABLE:
            import click

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

                subprocess.run(["uv", "add", "pymongo"], check=True)  # noqa: S607

            else:
                raise ImportError("You are missing the 'mongodb' crewai tool.")

        self._openai_client: AzureOpenAI | Client
        if "AZURE_OPENAI_ENDPOINT" in os.environ:
            self._openai_client = AzureOpenAI()
        elif "OPENAI_API_KEY" in os.environ:
            self._openai_client = Client()
        else:
            raise ValueError(
                "OPENAI_API_KEY environment variable is required for MongoDBVectorSearchTool and it is mandatory to use the tool."
            )

        from pymongo import MongoClient
        from pymongo.driver_info import DriverInfo

        self._client: MongoClient[dict[str, Any]] = MongoClient(
            self.connection_string,
            driver=DriverInfo(name="CrewAI", version=version("crewai-tools")),
        )

View on GitHub (pinned to 754d7323be)

Solutions

  1. Install the driver: `pip install pymongo` (or `uv add pymongo`) into the runtime environment
  2. Add pymongo to your dependency list so CI is non-interactive
  3. Pre-check availability in deployment scripts: python -c "import pymongo"

Example fix

# before
tool = MongoDBVectorSearchTool(...)  # ImportError: missing 'mongodb' tool

# after
# pip install pymongo
from crewai_tools.tools.mongodb_vector_search_tool.vector_search import MongoDBVectorSearchTool
tool = MongoDBVectorSearchTool(
    collection_name="docs",
    index_name="vector_index",
)
Defensive patterns

Strategy: validation

Validate before calling

def pymongo_available() -> bool:
    try:
        import pymongo  # noqa: F401
        return True
    except ImportError:
        return False

assert pymongo_available(), "pip install pymongo"

Try / catch

try:
    tool = MongoDBVectorSearchTool(collection_name="docs", index_name="idx")
except ImportError as e:
    raise RuntimeError("MongoDBVectorSearchTool needs pymongo: pip install pymongo") from e

Prevention

When it happens

Trigger: Constructing MongoDBVectorSearchTool() without pymongo installed; CI/container runs with no TTY so click.confirm gets EOF; answering 'no' to the prompt; `uv` not on PATH making even acceptance fail.

Common situations: Installing crewai-tools without pymongo; Docker images trimmed of dev deps; fresh environments where the interactive path was never exercised locally.

Related errors


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