BUG-HUNT: [error-handling] Broad exception in MCPToolAdapter.disconnect #1317

Open
opened 2026-04-02 16:49:06 +00:00 by freemo · 0 comments
Owner

Bug Report: Error Handling — Broad exception in MCPToolAdapter.disconnect

Severity Assessment

  • Impact: Critical errors during the disconnection of an MCP server could be silently ignored, leading to resource leaks or a corrupted state that is not properly handled.
  • Likelihood: Low, as it depends on the transport implementation raising an exception during close().
  • Priority: Medium

Location

  • File: src/cleveragents/mcp/adapter.py
  • Function/Class: MCPToolAdapter.disconnect
  • Lines: 272-277

Description

The disconnect method in MCPToolAdapter uses a broad except Exception: clause to catch and log any error that occurs during the transport's close() method. This can be dangerous because it swallows all exceptions, including potentially critical ones that might require more specific handling, such as ConnectionError or other transport-specific issues. Masking these errors can hide underlying problems and prevent the system from taking appropriate recovery actions.

Evidence

            try:
                self._transport.close()
            except Exception:
                logger.warning(
                    "Error during MCP disconnect from '%s'",
                    self._config.name,
                    exc_info=True,
                )

Expected Behavior

The exception handling should be more specific, catching only expected, non-critical exceptions. For example, it might be acceptable to catch and log IOException or similar, but more critical exceptions should be allowed to propagate or be handled with more specific logic.

Suggested Fix

Refine the except clause to catch more specific exceptions that are safe to ignore. For example, if the transport is known to raise IOError on close, then catch that specifically. Let other, unexpected exceptions propagate.

Category

error-handling

## Bug Report: Error Handling — Broad exception in MCPToolAdapter.disconnect ### Severity Assessment - **Impact**: Critical errors during the disconnection of an MCP server could be silently ignored, leading to resource leaks or a corrupted state that is not properly handled. - **Likelihood**: Low, as it depends on the transport implementation raising an exception during `close()`. - **Priority**: Medium ### Location - **File**: `src/cleveragents/mcp/adapter.py` - **Function/Class**: `MCPToolAdapter.disconnect` - **Lines**: 272-277 ### Description The `disconnect` method in `MCPToolAdapter` uses a broad `except Exception:` clause to catch and log any error that occurs during the transport's `close()` method. This can be dangerous because it swallows all exceptions, including potentially critical ones that might require more specific handling, such as `ConnectionError` or other transport-specific issues. Masking these errors can hide underlying problems and prevent the system from taking appropriate recovery actions. ### Evidence ```python try: self._transport.close() except Exception: logger.warning( "Error during MCP disconnect from '%s'", self._config.name, exc_info=True, ) ``` ### Expected Behavior The exception handling should be more specific, catching only expected, non-critical exceptions. For example, it might be acceptable to catch and log `IOException` or similar, but more critical exceptions should be allowed to propagate or be handled with more specific logic. ### Suggested Fix Refine the `except` clause to catch more specific exceptions that are safe to ignore. For example, if the transport is known to raise `IOError` on close, then catch that specifically. Let other, unexpected exceptions propagate. ### Category error-handling
freemo self-assigned this 2026-04-02 18:45:23 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
cleveragents/cleveragents-core#1317
No description provided.