fix(agentgateway): raise AgentGatewayServerError on isError tool results - #327
Open
wangzhengzhuo05 wants to merge 1 commit into
Open
Conversation
MCP tools that return a spec-compliant error response (isError=true) were silently flattened to the raw text, so callers checking result.isError crashed with AttributeError. Raise the documented AgentGatewayServerError with the server message instead, in both the LoB and customer call paths. Fixes SAP#326
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.
What
AgentGatewayClient.call_mcp_toolsilently swallowed MCP tool errors. When the MCP server returns a spec-compliant error response (isError: true, HTTP 200, SSEevent: messagewithresult.isError == true), bothcall_mcp_tool_lob(LoB flow) andcall_mcp_tool_customer(customer flow) logged the error and returned the raw error text as if it were a successful tool result. Callers could not distinguish success from failure — any caller inspectingresult.isErroron the return value crashed withAttributeError(reported as'NoneType' object has no attribute 'isError').Why
The SDK already documents the intended contract in
src/sap_cloud_sdk/agentgateway/exceptions.py:AgentGatewayServerErroris raised when "A tool invocation returns an error result (isError=True)". The implementation violated its own documented contract — the exception was never raised on this path. Silently returning a value that crashes.isErroraccessors is never a valid outcome for a tool call that failed server-side.How
src/sap_cloud_sdk/agentgateway/_lob.py: incall_mcp_tool_lob, replace the log-and-return block withraise AgentGatewayServerError(f"Tool '{tool.name}' on '{tool.url}' returned an error: {text}")whenmcp_is_error(result)is true.src/sap_cloud_sdk/agentgateway/_customer.py: identical fix incall_mcp_tool_customerso both flows behave consistently."").test_raises_server_error_on_is_errortoTestCallMcpToolLobandTestCallMcpToolCustomer; set explicitis_error=False/isError=Falseon the existing success-path mocks (a plainMagicMockis truthy, so those tests were implicitly passing through the error branch before).Verification
event: message/data: {"result": {"content": [...], "isError": true}, "jsonrpc": "2.0", "id": 3}) againstcall_mcp_tool_lobreturned the error text as a plainstrand.isErrorraisedAttributeError: 'str' object has no attribute 'isError'.pytest tests/agentgateway/unit/test_lob.py tests/agentgateway/unit/test_customer.py→ 103 passed.test_converters.pyand pre-exist on a cleanorigin/maincheckout (verified via a fresh worktree: same 24 failures, unrelated to this change)._lob.py(restored log-and-return) →test_raises_server_error_on_is_errorfails (1 failed); restored the fix → passes. The new test guards this behavior.Notes
'NoneType' object has no attribute 'isError') comes from an older SDK version; on current main the returned value is astr, producing'str' object has no attribute 'isError'— same class of defect, same fix.Fixes #326
AI-generated code disclosure
This change was implemented with AI assistance (OpenCode + muse-spark) and reviewed/verified for correctness, security, and license compatibility per SAP GenAI guidelines.