activate_project
Activate a registered project or directory by specifying its name, enabling seamless integration and management within the Serena MCP server environment.
Instructions
Activates the project with the given name.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| project | Yes | The name of a registered project to activate or a path to a project directory. |
Implementation Reference
- src/serena/tools/config_tools.py:5-19 (handler)The ActivateProjectTool handler class. The apply method executes the tool logic by calling the agent's activate_project_from_path_or_name and appending a manual reminder.class ActivateProjectTool(Tool, ToolMarkerDoesNotRequireActiveProject): """ Activates a project based on the project name or path. """ def apply(self, project: str) -> str: """ Activates the project with the given name or path. :param project: the name of a registered project to activate or a path to a project directory """ active_project = self.agent.activate_project_from_path_or_name(project) result = active_project.get_activation_message() result += "\nIMPORTANT: If you have not yet read the 'Serena Instructions Manual', do it now before continuing!" return result
- src/serena/agent.py:547-564 (helper)Core helper method activate_project_from_path_or_name in SerenaAgent that loads and activates the project, called by the tool handler.def activate_project_from_path_or_name(self, project_root_or_name: str) -> Project: """ Activate a project from a path or a name. If the project was already registered, it will just be activated. If the argument is a path at which no Serena project previously existed, the project will be created beforehand. Raises ProjectNotFoundError if the project could neither be found nor created. :return: a tuple of the project instance and a Boolean indicating whether the project was newly created """ project_instance: Project | None = self.load_project_from_path_or_name(project_root_or_name, autogenerate=True) if project_instance is None: raise ProjectNotFoundError( f"Project '{project_root_or_name}' not found: Not a valid project name or directory. " f"Existing project names: {self.serena_config.project_names}" ) self._activate_project(project_instance) return project_instance
- src/serena/agent.py:513-529 (helper)Internal _activate_project method that sets the active project, updates tools, and initializes language server.def _activate_project(self, project: Project) -> None: log.info(f"Activating {project.project_name} at {project.project_root}") self._active_project = project self._update_active_tools() def init_language_server_manager() -> None: # start the language server with LogTime("Language server initialization", logger=log): self.reset_language_server_manager() # initialize the language server in the background (if in language server mode) if self.is_using_language_server(): self.issue_task(init_language_server_manager) if self._project_activation_callback is not None: self._project_activation_callback()
- src/serena/agent.py:214-215 (registration)In SerenaAgent __init__, all tools including ActivateProjectTool are instantiated from ToolRegistry.get_all_tool_classes()self._all_tools: dict[type[Tool], Tool] = {tool_class: tool_class(self) for tool_class in ToolRegistry().get_all_tool_classes()} tool_names = [tool.get_name_from_cls() for tool in self._all_tools.values()]
- Tool base class method to derive tool name 'activate_project' from class name, and metadata extraction for schema.def get_name_from_cls(cls) -> str: name = cls.__name__ if name.endswith("Tool"): name = name[:-4] # convert to snake_case name = "".join(["_" + c.lower() if c.isupper() else c for c in name]).lstrip("_") return name