Redirect output of webbrowser (can contaminate stdout otherwise) #257

This commit is contained in:
Dominik Jain authored and Dominik Jain committed 2025-07-02 19:03:05 +02:00
1 parent e61f1a29a6
commit a1c972f2e7
2 files changed
+7 -1

No files matched your search

+1
View File
@@ -224,6 +224,7 @@ ignore = [
"TID252", # forbids relative imports
"B904", # forces use of raise from other_exception
"RUF012", # forbids mutable attributes as ClassVar
"SIM117", # forbids nested with statements
]
unfixable = ["F841", "F601", "F602", "B018"]
extend-fixable = ["F401", "B905", "W291"]
+6 -1
View File
@@ -2,6 +2,7 @@
The Serena Model Context Protocol (MCP) Server
"""
import contextlib
import inspect
import json
import os
@@ -795,7 +796,11 @@ class SerenaAgent:
Logger.root.addHandler(dashboard_log_handler)
self._dashboard_thread, port = SerenaDashboardAPI(dashboard_log_handler, tool_names).run_in_thread()
if self.serena_config.web_dashboard_open_on_launch:
webbrowser.open(f"http://localhost:{port}/dashboard/index.html")
# open the dashboard URL in the default web browser, making sure to redirect output,
# as this can print to stdout (contaminating the MCP server stream)
with open(os.devnull, "w") as fnull:
with contextlib.redirect_stdout(fnull), contextlib.redirect_stderr(fnull):
webbrowser.open(f"http://localhost:{port}/dashboard/index.html")
log.info(f"Starting Serena server (version={serena_version()}, process id={os.getpid()}, parent process id={os.getppid()})")
log.info("Available projects: {}".format(", ".join(self.serena_config.project_names)))