diff --git a/src/mcp_client.py b/src/mcp_client.py index dd531059..7652bb68 100644 --- a/src/mcp_client.py +++ b/src/mcp_client.py @@ -1652,19 +1652,26 @@ class StdioMCPServer: async def stop(self): """ [C: tests/test_performance_monitor.py:test_perf_monitor_basic_timing, tests/test_performance_monitor.py:test_perf_monitor_component_timing, tests/test_performance_monitor.py:test_perf_monitor_extended_metrics, tests/test_performance_monitor.py:test_perf_monitor_scope_context_manager, tests/test_websocket_server.py:test_websocket_subscription_and_broadcast] + + Best-effort cleanup. Errors during cleanup are accumulated as ErrorInfo and + surfaced via the [MCP::stop-warning] drain (consistent with _read_stderr + which also uses print() as a stderr/stdout drain for visibility). """ if self.proc: - try: - if self.proc.stdin: + errors: list[ErrorInfo] = [] + if self.proc.stdin: + try: self.proc.stdin.close() await self.proc.stdin.wait_closed() - except Exception: - pass + except Exception as e: + errors.append(ErrorInfo(kind=ErrorKind.INTERNAL, message=f"stdin close: {e}", source="mcp.StdioMCPServer.stop", original=e)) try: self.proc.terminate() await self.proc.wait() - except Exception: - pass + except Exception as e: + errors.append(ErrorInfo(kind=ErrorKind.INTERNAL, message=f"terminate: {e}", source="mcp.StdioMCPServer.stop", original=e)) + for err in errors: + print(f"[MCP:{self.name}:stop-warning] {err.ui_message()}") self.proc = None self.status = 'idle'