{"record":{"id":"08e4ab2ac6c344ca","repo":"oraios/serena","slug":"no-active-project-please-activate-a-project-first","errorCode":null,"errorMessage":"No active project. Please activate a project first.","messagePattern":"No active project\\. Please activate a project first\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/serena/agent.py","lineNumber":928,"sourceCode":"            of tools that can be offered during the session.\n            If a client should attempt to use a tool that is dynamically disabled\n            (e.g. because a project is activated that disables it), it will receive an error.\n        \"\"\"\n        return list(self._exposed_tools.tools)\n\n    def get_active_project(self) -> Project | None:\n        \"\"\"\n        :return: the active project or None if no project is active\n        \"\"\"\n        return self._active_project\n\n    def get_active_project_or_raise(self) -> Project:\n        \"\"\"\n        :return: the active project or raises an exception if no project is active\n        \"\"\"\n        project = self.get_active_project()\n        if project is None:\n            raise ValueError(\"No active project. Please activate a project first.\")\n        return project\n\n    def get_active_modes(self) -> ActiveModes:\n        \"\"\"\n        :return: the active modes\n        \"\"\"\n        return self._active_modes\n\n    @staticmethod\n    def _create_prompt_tool_names_mapping(language_backend: LanguageBackend) -> dict[str, str]:\n        \"\"\"\n        Creates a mapping from tool names to new tool names, which take into consideration\n\n           * legacy tool names, where the name was changed and\n           * LSP tools which are functionally replaced by other tools due to the active language backend\n             (e.g. \"find_symbol\" being replaced by \"jet_brains_find_symbol\" in JetBrains mode).\n\n        The mapping is intended to be used for the generation of prompts, such that prompts can","sourceCodeStart":910,"sourceCodeEnd":946,"githubUrl":"https://github.com/oraios/serena/blob/7fcbca7e62555ec2287ddb2f083caee805848ea6/src/serena/agent.py#L910-L946","documentation":"get_active_project_or_raise() is the strict accessor for the agent's currently active project; it raises ValueError when no project has been activated yet. Serena requires an active project for most symbol-level tools (find_symbol, references, etc.). It exists so callers get a clear, actionable message instead of an AttributeError on None.","triggerScenarios":"Calling any tool/method that routes through get_active_project_or_raise (project, get_language_server_manager_or_raise, add/remove_language_server, _referencing_symbol_names, symbol tools) before activate_project / --project startup activation succeeded.","commonSituations":"Starting the MCP server without the --project flag and calling symbol tools first; a failed earlier activation (bad project name/path or backend mismatch) leaving no active project; calling add_language_server or reset_language_server_manager in a fresh session.","solutions":["Activate a project first: use the activate_project tool with a registered project name or an absolute directory path.","Start Serena with --project /path/to/project (or --project <registered-name>) so a project is active from startup.","Register the project in serena_config.yml if its name was typo'd; check the 'Existing project names' list surfaced in related errors.","In code, call agent.get_active_project() and handle None before invoking project-dependent tools."],"exampleFix":"// before\nsymbol = agent.project().find_symbol('foo')\n// after\nif agent.get_active_project() is None:\n    agent.activate_project_from_path_or_name('/path/to/project')\nsymbol = agent.project().find_symbol('foo')","handlingStrategy":"try-catch","validationCode":"def ensure_active_project(agent) -> bool:\n    return agent.get_active_project() is not None","typeGuard":"def get_project_or_none(agent):\n    p = agent.get_active_project()\n    return p if isinstance(p, Project) else None","tryCatchPattern":"try:\n    project = agent.get_active_project_or_raise()\nexcept ValueError as e:\n    agent.activate_project_from_path_or_name('/path/to/project')\n    project = agent.get_active_project_or_raise()","preventionTips":["Start the MCP server with --project so a project is active from the first tool call.","Call activate_project before any symbol-level tool in scripted workflows.","Check get_active_project() is not None as a precondition in wrappers around project-dependent tools."],"tags":["project-activation","state","mcp"],"backgroundTag":"no-active-project","analyzedSha":"7fcbca7e62555ec2287ddb2f083caee805848ea6","analyzedAt":"2026-08-29T00:04:09.619Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}