From 36dbf5c681d92eb933f657f441da61c384afe54b Mon Sep 17 00:00:00 2001 From: Michael Panchenko Date: Thu, 12 Jun 2025 14:59:33 +0200 Subject: [PATCH] Possibility to override tool timeout through CLI --- src/serena/agent.py | 4 ++++ src/serena/mcp.py | 11 +++++++++++ 2 files changed, 15 insertions(+) diff --git a/src/serena/agent.py b/src/serena/agent.py index 0795e83..0a07da2 100644 --- a/src/serena/agent.py +++ b/src/serena/agent.py @@ -506,6 +506,7 @@ class SerenaAgent: enable_gui_log_window: bool | None = None, log_level: Literal["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"] | None = None, trace_lsp_communication: bool | None = None, + tool_timeout: float | None = None, ): """ :param project: the project to load immediately or None to not load any project; may be a path to the project or a name of @@ -520,6 +521,7 @@ class SerenaAgent: :param enable_gui_log_window: Whether to enable the GUI log window. It currently does not work on macOS, and setting this to True will be ignored then. If not specified, will take the value from the serena configuration. :param gui_log_level: Log level for the GUI log window. If not specified, will take the value from the serena configuration. + :param tool_timeout: Timeout in seconds for tool execution. If not specified, will take the value from the serena configuration. """ # obtain serena configuration self.serena_config = serena_config or SerenaConfig.from_config_file() @@ -533,6 +535,8 @@ class SerenaAgent: self.serena_config.log_level = logging.getLevelNamesMapping()[log_level] if trace_lsp_communication is not None: self.serena_config.trace_lsp_communication = trace_lsp_communication + if tool_timeout is not None: + self.serena_config.tool_timeout = tool_timeout # adjust log level serena_log_level = self.serena_config.log_level diff --git a/src/serena/mcp.py b/src/serena/mcp.py index 3f9d4ef..73c04fc 100644 --- a/src/serena/mcp.py +++ b/src/serena/mcp.py @@ -106,6 +106,7 @@ def create_mcp_server_and_agent( enable_gui_log_window: bool | None = None, log_level: Literal["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"] | None = None, trace_lsp_communication: bool | None = None, + tool_timeout: float | None = None, ) -> tuple[FastMCP, SerenaAgent]: """ Create an MCP server. @@ -123,6 +124,7 @@ def create_mcp_server_and_agent( :param log_level: Log level. If not specified, will take the value from the serena configuration. :param trace_lsp_communication: Whether to trace the communication between Serena and the language servers. This is useful for debugging language server issues. + :param tool_timeout: Timeout in seconds for tool execution. If not specified, will take the value from the serena configuration. """ mcp: FastMCP | None = None context_instance = SerenaAgentContext.load(context) @@ -139,6 +141,7 @@ def create_mcp_server_and_agent( enable_gui_log_window=enable_gui_log_window, log_level=log_level, trace_lsp_communication=trace_lsp_communication, + tool_timeout=tool_timeout, ) except Exception as e: show_fatal_exception_safe(e) @@ -280,6 +283,12 @@ PROJECT_TYPE = ProjectType() default=None, help="Whether to trace the communication between Serena and the language servers. This is useful for debugging language server issues.", ) +@click.option( + "--tool-timeout", + type=float, + default=None, + help="Timeout in seconds for tool execution. If not specified, will take the value from the serena configuration.", +) def start_mcp_server( project_file_opt: str | None, project_file_arg: str | None, @@ -292,6 +301,7 @@ def start_mcp_server( enable_gui_log_window: bool | None = None, log_level: Literal["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"] | None = None, trace_lsp_communication: bool | None = None, + tool_timeout: float | None = None, ) -> None: """Starts the Serena MCP server. By default, will not activate any project at startup. If you want to start with an already active project, use --project to pass the project name or path. @@ -313,6 +323,7 @@ def start_mcp_server( enable_gui_log_window=enable_gui_log_window, log_level=log_level, trace_lsp_communication=trace_lsp_communication, + tool_timeout=tool_timeout, ) # log after server creation such that the log appears in the GUI