Repository navigation
openai_agents: make MCP protocol errors non-retryable in stateless MCP activities - #548
Merged
brianstrauch merged 2 commits intoNov 15, 2026
Conversation
…P activities The stateless list-tools/call-tool/list-prompts/get-prompt activities let an McpError reach Temporal as a plain retryable failure, so a request a retry cannot fix (invalid params, invalid request, method not found, parse error) was retried without limit under the default retry policy. Map McpError to ApplicationError(type=MCPProtocolError), non-retryable for those four codes, as python/mcp and google_genai already do. Signed-off-by: Alex Castillo <[email protected]>
brianstrauch
left a comment
Member
There was a problem hiding this comment.
The required make lint check fails.
Signed-off-by: Alex Castillo <[email protected]>
Contributor
Author
|
Added the missing This comment was drafted with Claude Code. |
brianstrauch
approved these changes
Nov 15, 2026
brianstrauch
enabled auto-merge (squash)
November 15, 2026 20:36
brianstrauch
pushed a commit
that referenced
this pull request
Nov 19, 2026
…ities (#668) No separate issue: Java sibling of #549 (and #548, #449), which make MCP protocol errors non-retryable in the Python integrations. **Cause.** `McpActivitiesImpl.listMcpTools` and `callMcpTool` wrap every `RuntimeException` in a retryable `googleadk.McpError`. An `McpError` for a request a retry cannot fix (invalid params, invalid request, method not found, parse error) therefore stays retryable and, with the default retry policy, is retried until the policy gives up. **Fix.** Look up the `McpError` along the cause chain (the call may wrap it) and, for the JSON-RPC codes `PARSE_ERROR`, `INVALID_REQUEST`, `METHOD_NOT_FOUND` and `INVALID_PARAMS`, raise the same `googleadk.McpError` failure as non-retryable, matching `python/google_adk`. `INTERNAL_ERROR`, transport errors, timeouts and unknown codes stay retryable. `FailureTypes.MCP_ERROR` docs updated. The failure type is unchanged, so workflows that match on it keep working. The toolset-factory wrapper uses the same classifier, so a JSON-RPC rejection while a factory initializes its session is classified the same way; startup and transport failures stay retryable. **Test.** `McpActivitiesImplTest` gains cases for each of the four codes (raised by the listing and by the `tools/call` request), an error behind a wrapper exception, `INTERNAL_ERROR` staying retryable for both, and a protocol error raised by a toolset factory. The README's MCP failure paragraph is updated. This change was prepared with the help of an AI assistant (Claude) and submitted by the account owner.
This was referenced Nov 19, 2026
Open
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.
Follow-up to #449 (and #411): the same non-retryable mapping of MCP protocol errors, applied to the stateless MCP activities in
openai_agents.Cause. The stateless
{server}-list-tools,-call-tool-v2,-list-promptsand-get-prompt-v2activities in_mcp.pyconnect, run one operation and clean up, but let whatever the server raised escape. AnMcpErrorfor a request a retry cannot fix (invalid params, invalid request, method not found, parse error) therefore reached Temporal as a plain retryable failure and, with the default retry policy, was retried without limit.Fix. Map
McpErrortoApplicationError(type="MCPProtocolError"), non-retryable forPARSE_ERROR,INVALID_REQUEST,METHOD_NOT_FOUND,INVALID_PARAMS, aspython/mcpand (since #449)google_genaido.INTERNAL_ERROR, timeouts and unknown codes stay retryable. Unlike the stateful MCP path there is no session-lost exception: each stateless activity opens a fresh connection, so a retry already reconnects.McpErroris imported asMCPError(mcp>=2) with a fallback tomcp.shared.exceptions.McpError(mcp<2), matchinggoogle_genai.Test.
tests/test_stateless_mcp_protocol_errors.py(5 codes x 4 operations): 20 failed on main, 20 passed now.pytest tests/test_openai.py -k mcpplus the new file: 71 passed; ruff check/format clean.This change was prepared with the help of an AI assistant (Claude) and submitted by the account owner.