{"record":{"id":"f0c0fd9dd5db9854","repo":"crewAIInc/crewAI","slug":"failed-to-install-mcp-package","errorCode":null,"errorMessage":"Failed to install mcp package","messagePattern":"Failed to install mcp package","errorType":"exception","errorClass":"ImportError","httpStatus":null,"severity":"error","filePath":"lib/crewai-tools/src/crewai_tools/adapters/mcp_adapter.py","lineNumber":171,"sourceCode":"        self._adapter = None\n        self._tools = None\n        self._tool_names = (\n            [sanitize_tool_name(name) for name in tool_names] if tool_names else None\n        )\n\n        if not MCP_AVAILABLE:\n            import click\n\n            if click.confirm(\n                \"You are missing the 'mcp' package. Would you like to install it?\"\n            ):\n                import subprocess\n\n                try:\n                    subprocess.run([\"uv\", \"add\", \"mcp crewai-tools'[mcp]'\"], check=True)  # noqa: S607\n\n                except subprocess.CalledProcessError as e:\n                    raise ImportError(\"Failed to install mcp package\") from e\n            else:\n                raise ImportError(\n                    \"`mcp` package not found, please run `uv add crewai-tools[mcp]`\"\n                )\n\n        try:\n            self._serverparams = serverparams\n            self._adapter = MCPAdapt(\n                self._serverparams, CrewAIToolAdapter(), connect_timeout\n            )\n            self.start()\n\n        except Exception as e:\n            if self._adapter is not None:\n                try:\n                    self.stop()\n                except Exception as stop_e:\n                    logger.error(f\"Error during stop cleanup: {stop_e}\")","sourceCodeStart":153,"sourceCodeEnd":189,"githubUrl":"https://github.com/crewAIInc/crewAI/blob/754d7323beb2fd042e33444a115ea2d5a47193f0/lib/crewai-tools/src/crewai_tools/adapters/mcp_adapter.py#L153-L189","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Run the command manually to see the real error: uv add \"crewai-tools[mcp]\".","If not using uv, install directly: pip install 'crewai-tools[mcp]'.","Pre-install mcp in the image/requirements so the interactive prompt path is never taken."],"exampleFix":"# before\nMCPServerAdapter(serverparams)  # prompt -> uv add fails -> ImportError\n\n# after\n# pre-install dependency (no prompt, no subprocess):\n# pip install 'crewai-tools[mcp]'\nadapter = MCPServerAdapter(serverparams=...)","handlingStrategy":"try-catch","validationCode":"import importlib.util\n\nif importlib.util.find_spec(\"mcp\") is None:\n    raise RuntimeError(\"pre-install with: pip install 'crewai-tools[mcp]'\")","typeGuard":null,"tryCatchPattern":"try:\n    MCPServerAdapter(serverparams=...)\nexcept ImportError as e:\n    if \"Failed to install mcp\" in str(e):\n        # run manually to see uv's real error\n        raise RuntimeError(\"run: uv add 'crewai-tools[mcp]'\") from e\n    raise","preventionTips":["Never rely on the interactive runtime prompt in CI/containers; pre-install mcp.","Ensure uv exists on PATH and the project has a uv-compatible manifest before relying on it.","Prefer pip install 'crewai-tools[mcp]' in non-uv environments."],"tags":["mcp","install","uv","subprocess","import-error","crewai-tools"],"backgroundTag":null,"analyzedSha":"754d7323beb2fd042e33444a115ea2d5a47193f0","analyzedAt":"2026-08-15T04:06:56.746Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}