Skip to content

openai_agents: make MCP protocol errors non-retryable in stateless MCP activities - #548

Merged
brianstrauch merged 2 commits into
temporalio:mainfrom
pcbeingused333:fix/openai-agents-mcp-stateless-mcperror
Nov 15, 2026
Merged

brianstrauch merged 2 commits into
temporalio:mainfrom
pcbeingused333:fix/openai-agents-mcp-stateless-mcperror

Conversation

@pcbeingused333

Copy link
Copy Markdown
Contributor

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-prompts and -get-prompt-v2 activities in _mcp.py connect, run one operation and clean up, but let whatever the server raised escape. An McpError for 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 McpError to ApplicationError(type="MCPProtocolError"), non-retryable for PARSE_ERROR, INVALID_REQUEST, METHOD_NOT_FOUND, INVALID_PARAMS, as python/mcp and (since #449) google_genai do. 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. McpError is imported as MCPError (mcp>=2) with a fallback to mcp.shared.exceptions.McpError (mcp<2), matching google_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 mcp plus 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.

…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]>
@pcbeingused333
pcbeingused333 requested a review from a team as a code owner November 14, 2026 09:08

@brianstrauch brianstrauch left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The required make lint check fails.

@pcbeingused333

Copy link
Copy Markdown
Contributor Author

Added the missing attr-defined suppression to the MCP v1 fallback import in the test, matching the production fallback, and renamed unused test-double parameters. make lint and all 71 selected MCP tests pass.

This comment was drafted with Claude Code.

@brianstrauch
brianstrauch enabled auto-merge (squash) November 15, 2026 20:36
@brianstrauch
brianstrauch merged commit fff372c into temporalio:main Nov 15, 2026
16 checks passed
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants