Skip to content

[BUG] Agent Hangs Indefinitely on Fatal MCP Server Errors (HTTP 4xx/5xx) #995

@LanaSokolova

Description

@LanaSokolova

Checks

  • I have updated to the lastest minor and patch version of Strands
  • I have checked the documentation and this is not expected behavior
  • I have searched [./issues](./issues?q=) and there are no duplicates of my issue

Strands Version

1.10.0

Python Version

3.13

Operating System

Windows

Installation Method

pip

Steps to Reproduce

  1. Configure the MCP Server Response
    MCP server hosted on an AWS Lambda function behind an API Gateway, using Lambda Proxy Integration.

    Example response from API Gateway:

    Content-Type: application/json
    MCP-Version: 0.6
    MCP-Session-Id: <sessionId>
    {
     "jsonrpc": "2.0",
     "id": 2,
     "error": {
       "code": -32603,
       "message": "Error executing tool: Simulated unexpected error"
     }
    }
  2. Run the Strands Agent

    from datetime import timedelta
    from mcp.client.streamable_http import streamablehttp_client
    from strands.tools.mcp.mcp_client import MCPClient
    from strands import Agent
    from strands.session.file_session_manager import FileSessionManager
    
    Assume other variables (model, session_id, system_prompt, prompt etc.) are defined
    
    streamable_http_mcp_client = MCPClient(lambda: streamablehttp_client(
        "https://your-api-gateway-endpoint/prod/",
        timeout=timedelta(seconds=30),
        headers={"Authorization": "your_jwt_token"}
    ))
    
    with streamable_http_mcp_client:
        tools = streamable_http_mcp_client.list_tools_sync()
        session_manager = FileSessionManager(session_id=session_id)
        agent = Agent(model=model, tools=tools, system_prompt=system_prompt, session_manager=session_manager)
        print("Attempting to call the agent...")
        # This line will hangresponse = agent(prompt="prompt)
    ​    print("This line is never reached.")

Expected Behavior

The agent call should fail fast by raising an exception. Given that the underlying httpx library raises an httpx.HTTPStatusError when response.raise_for_status() is called on a non-2xx response, it is expected that this error (or a wrapper around it) should propagate up to the caller.

Actual Behavior

The agent(prompt=...) call hangs indefinitely. The program does not exit, raise an exception, or proceed past this line.

Debugging indicates the sequence of events is as follows:

  1. The underlying httpx client receives the 500 status code from the API Gateway.
  2. A call to response.raise_for_status() is made within the transport layer, which raises an httpx.HTTPStatusError.  
  3. Immediately after the HTTPStatusError is raised, the agent's execution hangs.

The same behavior is for 400 status code.

Additional Context

No response

Possible Solution

No response

Related Issues

#922

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions