fix: error response for MCP - #341
Merged
Merged
Conversation
cassiofariasmachado
previously approved these changes
Sep 15, 2026
NicoleMGomes
marked this pull request as ready for review
September 16, 2026 11:56
jplbrun
approved these changes
Sep 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes a crash in
call_mcp_tool_lobandcall_mcp_tool_customerwhen an MCP tool returns an error response (isError=True).Previously, when an MCP tool signalled a business error via the MCP protocol error flag, the SDK only logged the error and silently returned the error text as a successful result. This caused two problems:
AttributeError: 'NoneType' object has no attribute 'isError'— whenlangchain-mcp-adapters(≥0.3.x) intercepts aCallToolResultwithisError=Trueand raises aToolExceptionbefore returning to the SDK, the SDK receivedNonefromsession.call_tool()and crashed on the.contentaccess.langchain-mcp-adapters, an MCP tool error was silently swallowed and returned to the agent as a normal string, making the agent believe the tool call succeeded.Fix: Both
call_mcp_tool_lob(_lob.py) andcall_mcp_tool_customer(_customer.py) now:Noneresult fromsession.call_tool()and raiseAgentGatewayServerErrorwith a descriptive message.AgentGatewayServerError(instead of logging) whenmcp_is_error(result)isTrue, so the error propagates correctly up toagw_client.call_mcp_tool()where it is caught and re-raised asAgentGatewaySDKError.Related Issue
Closes #
Type of Change
How to Test
AttributeError: 'NoneType' object has no attribute 'isError'(when usinglangchain-mcp-adapters) or silently returns the error text as a success.AgentGatewaySDKError: Tool invocation failed for '<name>': Tool '<name>' on '<url>' returned an error: <error text>— the agent framework receives a proper exception and can handle or surface it to the user.Unit tests:
Checklist
Additional Notes
The
AgentGatewayServerErrorexception class already existed and was already documented as the correct exception forisError=Truetool results (exceptions.py:33). This fix aligns the actual behavior with the documented intent.The outer
except Exceptionhandler inAgwClient.call_mcp_tool(agw_client.py) catchesAgentGatewayServerErrorand wraps it inAgentGatewaySDKErrorwith aTool invocation failed for '<name>'prefix, so callers only need to handleAgentGatewaySDKError.