From 823ad2417589d47dcb4e1dc0452887740e3f997a Mon Sep 17 00:00:00 2001 From: lorenzejay Date: Mon, 29 Dec 2025 10:50:56 -0800 Subject: [PATCH] Refactor EventListener and ConsoleFormatter for improved clarity and consistency - Removed the MCPToolExecutionCompletedEvent handler from EventListener to streamline event processing. - Updated ConsoleFormatter to enhance output formatting by adding line breaks for better readability in status content. - Renamed status messages for MCP Tool execution to provide clearer context during tool operations. --- .../src/crewai/events/event_listener.py | 12 ----- .../crewai/events/utils/console_formatter.py | 47 ++----------------- 2 files changed, 5 insertions(+), 54 deletions(-) diff --git a/lib/crewai/src/crewai/events/event_listener.py b/lib/crewai/src/crewai/events/event_listener.py index f36d8372d..069d700c4 100644 --- a/lib/crewai/src/crewai/events/event_listener.py +++ b/lib/crewai/src/crewai/events/event_listener.py @@ -621,18 +621,6 @@ class EventListener(BaseEventListener): event.tool_args, ) - @crewai_event_bus.on(MCPToolExecutionCompletedEvent) - def on_mcp_tool_execution_completed( - _: Any, event: MCPToolExecutionCompletedEvent - ) -> None: - self.formatter.handle_mcp_tool_execution_completed( - event.server_name, - event.tool_name, - event.tool_args, - event.result, - event.execution_duration_ms, - ) - @crewai_event_bus.on(MCPToolExecutionFailedEvent) def on_mcp_tool_execution_failed( _: Any, event: MCPToolExecutionFailedEvent diff --git a/lib/crewai/src/crewai/events/utils/console_formatter.py b/lib/crewai/src/crewai/events/utils/console_formatter.py index e22ed8e54..bc4b896bb 100644 --- a/lib/crewai/src/crewai/events/utils/console_formatter.py +++ b/lib/crewai/src/crewai/events/utils/console_formatter.py @@ -77,16 +77,16 @@ To enable tracing, do any one of these: """Create standardized status content with consistent formatting.""" content = Text() content.append(f"{title}\n", style=f"{status_style} bold") - content.append("Name: ", style="white") + content.append("Name: \n", style="white") content.append(f"{name}\n", style=status_style) for label, value in fields.items(): - content.append(f"{label}: ", style="white") + content.append(f"{label}: \n", style="white") content.append( f"{value}\n", style=fields.get(f"{label}_style", status_style) ) if tool_args: - content.append("Tool Args: ", style="white") + content.append("Tool Args: \n", style="white") content.append(f"{tool_args}\n", style=status_style) return content @@ -1255,8 +1255,6 @@ To enable tracing, do any one of these: content = Text() reconnect_text = " (Reconnecting)" if is_reconnect else "" content.append(f"MCP Connection Started{reconnect_text}\n\n", style="cyan bold") - content.append("Server: ", style="white") - content.append(f"{server_name}\n", style="cyan") if server_url: content.append("URL: ", style="white") @@ -1359,49 +1357,14 @@ To enable tracing, do any one of these: return content = self.create_status_content( - "MCP Tool Execution Started", + "MCP Tool Started", tool_name, "yellow", tool_args=tool_args or {}, Server=server_name, ) - panel = self.create_panel(content, "🔧 MCP Tool", "yellow") - self.print(panel) - self.print() - - def handle_mcp_tool_execution_completed( - self, - server_name: str, - tool_name: str, - tool_args: dict[str, Any] | None = None, - result: Any | None = None, - execution_duration_ms: float | None = None, - ) -> None: - """Handle MCP tool execution completed event.""" - if not self.verbose: - return - - content = self.create_status_content( - "MCP Tool Execution Completed", - tool_name, - "green", - tool_args=tool_args or {}, - Server=server_name, - ) - - if execution_duration_ms is not None: - content.append("Duration: ", style="white") - content.append(f"{execution_duration_ms:.2f}ms\n", style="green") - - if result is not None: - result_str = str(result) - if len(result_str) > 500: - result_str = result_str[:497] + "..." - content.append("\nResult: ", style="white bold") - content.append(f"{result_str}\n", style="green") - - panel = self.create_panel(content, "✅ MCP Tool Completed", "green") + panel = self.create_panel(content, "🔧 MCP Tool Started", "yellow") self.print(panel) self.print()