From ee88204cbab02b3abc2f7c7b4c9528f617073161 Mon Sep 17 00:00:00 2001 From: Dominik Jain Date: Thu, 10 Jul 2025 00:12:13 +0200 Subject: [PATCH] Remove obsolete base class ToolInterface --- src/serena/mcp.py | 8 ++++---- src/serena/tools/tools_base.py | 34 +++++----------------------------- 2 files changed, 9 insertions(+), 33 deletions(-) diff --git a/src/serena/mcp.py b/src/serena/mcp.py index 3f91819..28168b3 100644 --- a/src/serena/mcp.py +++ b/src/serena/mcp.py @@ -25,7 +25,7 @@ from serena.agent import ( ) from serena.config.context_mode import SerenaAgentContext, SerenaAgentMode from serena.constants import DEFAULT_CONTEXT, DEFAULT_MODES -from serena.tools import ToolInterface +from serena.tools import Tool from serena.util.exception import show_fatal_exception_safe log = logging.getLogger(__name__) @@ -62,7 +62,7 @@ class SerenaMCPFactory: self.project = project @staticmethod - def make_mcp_tool(tool: ToolInterface) -> MCPTool: + def make_mcp_tool(tool: Tool) -> MCPTool: func_name = tool.get_name() func_doc = tool.get_apply_docstring() or "" func_arg_metadata = tool.get_apply_fn_metadata() @@ -106,7 +106,7 @@ class SerenaMCPFactory: ) @abstractmethod - def _iter_tools(self) -> Iterator[ToolInterface]: + def _iter_tools(self) -> Iterator[Tool]: pass # noinspection PyProtectedMember @@ -204,7 +204,7 @@ class SerenaMCPFactorySingleProcess(SerenaMCPFactory): def _instantiate_agent(self, serena_config: SerenaConfig, modes: list[SerenaAgentMode]) -> None: self.agent = SerenaAgent(project=self.project, serena_config=serena_config, context=self.context, modes=modes) - def _iter_tools(self) -> Iterator[ToolInterface]: + def _iter_tools(self) -> Iterator[Tool]: assert self.agent is not None yield from self.agent.get_exposed_tool_instances() diff --git a/src/serena/tools/tools_base.py b/src/serena/tools/tools_base.py index 074119c..a68ffc3 100644 --- a/src/serena/tools/tools_base.py +++ b/src/serena/tools/tools_base.py @@ -1,7 +1,7 @@ import inspect import os import traceback -from abc import ABC, abstractmethod +from abc import ABC from collections.abc import Callable, Iterable from dataclasses import dataclass from types import TracebackType @@ -87,31 +87,7 @@ class ToolMarkerOptional: """ -class ToolInterface(ABC): - """Protocol defining the complete interface that make_tool() expects from a tool.""" - - @abstractmethod - def get_name(self) -> str: - """Get the tool name.""" - ... - - @abstractmethod - def get_apply_docstring(self) -> str: - """Get the docstring for the tool application, used by the MCP server.""" - ... - - @abstractmethod - def get_apply_fn_metadata(self) -> FuncMetadata: - """Get the metadata for the tool application function, used by the MCP server.""" - ... - - @abstractmethod - def apply_ex(self, log_call: bool = True, catch_exceptions: bool = True, **kwargs: Any) -> str: - """Apply the tool with logging and exception handling.""" - ... - - -class Tool(Component, ToolInterface): +class Tool(Component): # NOTE: each tool should implement the apply method, which is then used in # the central method of the Tool class `apply_ex`. # Failure to do so will result in a RuntimeError at tool execution time. @@ -176,11 +152,11 @@ class Tool(Component, ToolInterface): return docstring.strip() def get_apply_docstring(self) -> str: - """Get the docstring for the apply method (instance method implementing ToolProtocol).""" + """Gets the docstring for the tool application, used by the MCP server.""" return self.get_apply_docstring_from_cls() def get_apply_fn_metadata(self) -> FuncMetadata: - """Get the metadata for the apply method (instance method implementing ToolProtocol).""" + """Gets the metadata for the tool application function, used by the MCP server.""" return self.get_apply_fn_metadata_from_cls() @classmethod @@ -225,7 +201,7 @@ class Tool(Component, ToolInterface): def apply_ex(self, log_call: bool = True, catch_exceptions: bool = True, **kwargs) -> str: # type: ignore """ - Applies the tool with the given arguments + Applies the tool with logging and exception handling, using the given keyword arguments """ def task() -> str: