{"record":{"id":"e69d806043c516e1","repo":"crewAIInc/crewAI","slug":"you-are-missing-the-mongodb-crewai-tool","errorCode":null,"errorMessage":"You are missing the 'mongodb' crewai tool.","messagePattern":"You are missing the 'mongodb' crewai tool\\.","errorType":"exception","errorClass":"ImportError","httpStatus":null,"severity":"error","filePath":"lib/crewai-tools/src/crewai_tools/tools/mongodb_vector_search_tool/vector_search.py","lineNumber":121,"sourceCode":"            ),\n        ]\n    )\n    package_dependencies: list[str] = Field(default_factory=lambda: [\"pymongo\"])\n\n    def __init__(self, **kwargs: Any) -> None:\n        super().__init__(**kwargs)\n        if not MONGODB_AVAILABLE:\n            import click\n\n            if click.confirm(\n                \"You are missing the 'mongodb' crewai tool. Would you like to install it?\"\n            ):\n                import subprocess\n\n                subprocess.run([\"uv\", \"add\", \"pymongo\"], check=True)  # noqa: S607\n\n            else:\n                raise ImportError(\"You are missing the 'mongodb' crewai tool.\")\n\n        self._openai_client: AzureOpenAI | Client\n        if \"AZURE_OPENAI_ENDPOINT\" in os.environ:\n            self._openai_client = AzureOpenAI()\n        elif \"OPENAI_API_KEY\" in os.environ:\n            self._openai_client = Client()\n        else:\n            raise ValueError(\n                \"OPENAI_API_KEY environment variable is required for MongoDBVectorSearchTool and it is mandatory to use the tool.\"\n            )\n\n        from pymongo import MongoClient\n        from pymongo.driver_info import DriverInfo\n\n        self._client: MongoClient[dict[str, Any]] = MongoClient(\n            self.connection_string,\n            driver=DriverInfo(name=\"CrewAI\", version=version(\"crewai-tools\")),\n        )","sourceCodeStart":103,"sourceCodeEnd":139,"githubUrl":"https://github.com/crewAIInc/crewAI/blob/754d7323beb2fd042e33444a115ea2d5a47193f0/lib/crewai-tools/src/crewai_tools/tools/mongodb_vector_search_tool/vector_search.py#L103-L139","documentation":"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.","triggerScenarios":"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.","commonSituations":"Installing crewai-tools without pymongo; Docker images trimmed of dev deps; fresh environments where the interactive path was never exercised locally.","solutions":["Install the driver: `pip install pymongo` (or `uv add pymongo`) into the runtime environment","Add pymongo to your dependency list so CI is non-interactive","Pre-check availability in deployment scripts: python -c \"import pymongo\""],"exampleFix":"# before\ntool = MongoDBVectorSearchTool(...)  # ImportError: missing 'mongodb' tool\n\n# after\n# pip install pymongo\nfrom crewai_tools.tools.mongodb_vector_search_tool.vector_search import MongoDBVectorSearchTool\ntool = MongoDBVectorSearchTool(\n    collection_name=\"docs\",\n    index_name=\"vector_index\",\n)","handlingStrategy":"validation","validationCode":"def pymongo_available() -> bool:\n    try:\n        import pymongo  # noqa: F401\n        return True\n    except ImportError:\n        return False\n\nassert pymongo_available(), \"pip install pymongo\"","typeGuard":null,"tryCatchPattern":"try:\n    tool = MongoDBVectorSearchTool(collection_name=\"docs\", index_name=\"idx\")\nexcept ImportError as e:\n    raise RuntimeError(\"MongoDBVectorSearchTool needs pymongo: pip install pymongo\") from e","preventionTips":["Pre-install pymongo in the deployment image","Never depend on interactive click.confirm prompts in automation","Add optional dependencies to the same lockfile as crewai-tools"],"tags":["dependency","pymongo","mongodb","interactive-prompt","ci"],"backgroundTag":null,"analyzedSha":"754d7323beb2fd042e33444a115ea2d5a47193f0","analyzedAt":"2026-08-15T04:06:56.746Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}