Skip to content

_connect_mcp_servers() outside try block crashes agent on network error #269

@stealthwhizz

Description

@stealthwhizz

Bug

In finbot/agents/base.py, _connect_mcp_servers() is called at line 78, but the try block doesn't start until line 99. If the MCP server connection fails (network timeout, DNS failure, server down), the exception propagates unhandled and crashes the entire agent loop.

# line 78 — outside try
await self._connect_mcp_servers()

# ... lines 80-98 ...

try:  # line 99
    for iteration in range(max_iterations):

Impact

  • Any network error during MCP server connection kills the agent with no recovery
  • No error event is emitted, so CTF event bus never learns the agent failed
  • Users see an unhandled exception instead of a graceful degradation

Suggested Fix

Move _connect_mcp_servers() inside the existing try block, or wrap it in its own try/except with graceful fallback:

try:
    await self._connect_mcp_servers()
except Exception as e:
    logger.error("MCP server connection failed: %s", e)
    # Continue without MCP tools, or raise a clear AgentError

Affected Files

  • finbot/agents/base.py (line 78)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions