diff --git a/src/serena/agent.py b/src/serena/agent.py index d041cb3d..49c682c3 100644 --- a/src/serena/agent.py +++ b/src/serena/agent.py @@ -159,18 +159,17 @@ class Tool(Component): raise Exception(f"Missing docstring for {self}") return docstring - @staticmethod - def _log_tool_application(frame: Any) -> None: + def _log_tool_application(self, frame: Any) -> None: params = {} - tool_name = None - for name, value in frame.f_locals.items(): - if name == "ctx": + ignored_params = {"self", "log_call", "catch_exceptions", "args", "apply_fn"} + for param, value in frame.f_locals.items(): + if param in ignored_params: continue - if name.endswith("Tool"): - tool_name = name - continue - params[name] = value - log.info(f"{tool_name}: {dict_string(params)}") + if param == "kwargs": + params.update(value) + else: + params[param] = value + log.info(f"{self.get_name()}: {dict_string(params)}") @staticmethod def _limit_length(result: str, max_answer_chars: int) -> str: @@ -200,7 +199,7 @@ class Tool(Component): log.error(f"Error executing tool: {e}", exc_info=e) result = msg if log_call: - log.info("Result: {}") + log.info(f"Result: {result}") return result diff --git a/src/serena/mcp.py b/src/serena/mcp.py index 89bf2fb4..f240e851 100644 --- a/src/serena/mcp.py +++ b/src/serena/mcp.py @@ -6,6 +6,7 @@ import sys from collections.abc import AsyncIterator from contextlib import asynccontextmanager from dataclasses import dataclass +from logging import Formatter, Logger, StreamHandler from mcp.server.fastmcp import server from mcp.server.fastmcp.server import FastMCP, Settings @@ -23,7 +24,10 @@ LOG_LEVEL = logging.INFO def configure_logging(*args, **kwargs) -> None: # type: ignore # configure logging to stderr (will be captured by Claude Desktop); stdio is the MCP communication stream and cannot be used! - logging.basicConfig(level=LOG_LEVEL, stream=sys.stderr, format=LOG_FORMAT) + Logger.root.setLevel(LOG_LEVEL) + handler = StreamHandler(stream=sys.stderr) + handler.formatter = Formatter(LOG_FORMAT) + Logger.root.addHandler(handler) # patch the logging configuration function in fastmcp, because it's hard-coded and broken