Skip to content

MCP tools turn upstream HTTP errors into AgentsException, crashing the run #879

Open
@Manouchehri

Description

@Manouchehri

Description

If an MCP tool call receives a non-2xx response from its upstream service, the wrapper raises an AgentsException. Because the tool never returns a result object, the agent cannot handle the failure and the entire turn aborts.


Steps to Reproduce

  1. Invoke any MCP tool with parameters that make the upstream API reply with an error (e.g., an invalid search query).
  2. Observe that the run terminates with an uncaught AgentsException.

Expected Result

The tool returns a structured error payload so the agent can decide how to respond.

Actual Result

An AgentsException is raised and the run stops.


Sanitized Traceback

Error invoking MCP tool <tool_name>: GET <service-url>?q=<masked_query>: 422 <service-error>

Traceback (most recent call last):
  File "<site-packages>/agents/mcp/util.py", line 104, in invoke_mcp_tool
    result = await server.call_tool(tool.name, json_data)
  ...
mcp.shared.exceptions.McpError: GET <service-url>: 422 <service-error>
agents.exceptions.AgentsException: Error invoking MCP tool <tool_name>: ...

Metadata

Metadata

Assignees

No one assigned

    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