switch_modes
Activate specific operational modes, such as 'editing' or 'planning', to optimize performance and functionality within the Serena MCP server for enhanced coding and project management tasks.
Instructions
Activates the desired modes, like ["editing", "interactive"] or ["planning", "one-shot"].
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| modes | Yes | The names of the modes to activate. |
Implementation Reference
- src/serena/tools/config_tools.py:37-55 (handler)The SwitchModesTool class implements the core execution logic of the 'switch_modes' tool. Its 'apply' method takes a list of mode names, loads and sets the modes on the agent, and returns a confirmation message including the active tools.class SwitchModesTool(Tool, ToolMarkerOptional): """ Activates modes by providing a list of their names """ def apply(self, modes: list[str]) -> str: """ Activates the desired modes, like ["editing", "interactive"] or ["planning", "one-shot"] :param modes: the names of the modes to activate """ mode_instances = [SerenaAgentMode.load(mode) for mode in modes] self.agent.set_modes(mode_instances) # Inform the Agent about the activated modes and the currently active tools result_str = f"Successfully activated modes: {', '.join([mode.name for mode in mode_instances])}" + "\n" result_str += "\n".join([mode_instance.prompt for mode_instance in mode_instances]) + "\n" result_str += f"Currently active tools: {', '.join(self.agent.get_active_tool_names())}" return result_str
- src/serena/tools/tools_base.py:361-369 (registration)ToolRegistry.__init__ automatically discovers and registers all subclasses of Tool in serena.tools modules, mapping SwitchModesTool to the tool name 'switch_modes'.self._tool_dict: dict[str, RegisteredTool] = {} for cls in iter_subclasses(Tool): if not cls.__module__.startswith("serena.tools"): continue is_optional = issubclass(cls, ToolMarkerOptional) name = cls.get_name_from_cls() if name in self._tool_dict: raise ValueError(f"Duplicate tool name found: {name}. Tool classes must have unique names.") self._tool_dict[name] = RegisteredTool(tool_class=cls, is_optional=is_optional, tool_name=name)
- The Tool class method get_apply_fn_metadata_from_cls extracts function metadata (parameters, docstring) from the 'apply' method to generate the MCP tool schema for SwitchModesTool.def get_apply_fn_metadata_from_cls(cls) -> FuncMetadata: """Get the metadata for the apply method from the class (static metadata). Needed for creating MCP tools in a separate process without running into serialization issues. """ # First try to get from __dict__ to handle dynamic docstring changes if "apply" in cls.__dict__: apply_fn = cls.__dict__["apply"] else: # Fall back to getattr for inherited methods apply_fn = getattr(cls, "apply", None) if apply_fn is None: raise AttributeError(f"apply method not defined in {cls}. Did you forget to implement it?") return func_metadata(apply_fn, skip_names=["self", "cls"])
- The get_name_from_cls class method converts the class name 'SwitchModesTool' to the tool name 'switch_modes' used in registration.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