Repository navigation
mcp: fail a tool result the MCP client rejects without retrying it - #437
Merged
Merged
Conversation
The MCP client checks a tool's result against the tool's output schema and raises RuntimeError when the result has no structured content or doesn't match the schema. It raises InputRequiredRoundsExceededError when a call runs past its round limit. temporalio-mcp passed these through, so Temporal retried them, forever under the default retry policy, and a factory argument wrapped them in an ExceptionGroup that was retried the same way. These now fail the Activity with a non-retryable MCPProtocolError, like the other errors a retry can't fix. mcp gives the schema errors no type of their own, so they're matched by their messages, which are the same from mcp 2.0.0 to 2.3.0. Fixes #376
campoy
marked this pull request as ready for review
November 6, 2026 22:03
brianstrauch
approved these changes
Nov 6, 2026
campoy
added a commit
that referenced
this pull request
Nov 13, 2026
## What was changed - OpenAI Agents and Strands (Python) require `temporalio-mcp>=0.4.0,<0.5` instead of `>=0.2.0,<0.3`, in their `mcp` extra and dev group. - Both `uv.lock` files now resolve the published 0.4.0. No other locked package changes. - The `temporal_mcp_server()` docstring now says its MCP operations get a 10-second heartbeat timeout by default, and how to turn it off. ## Why? The `temporalio-mcp` 0.3.0 release notes say OpenAI Agents and Strands keep 0.2.0 behavior until their pins move: both plugins pin `<0.3`. This PR makes them require 0.4, which includes 0.3.0's changes, before GA. 0.3.0 changes how these plugins' MCP calls fail. I ran each change through each plugin's own MCP wiring, against an in-process streamable-HTTP MCP server, on 0.2.0 and 0.3.0: | Case | OpenAI Agents (`mcp_servers`) | Strands (`mcp_clients`) | |---|---|---| | A tool result the MCP client rejects (#437) | Retried forever → fails at once | Retried forever → fails at once | | A lost session, HTTP 404 (#379) | No session in my test (see below) | Failed at once → retried with a new session | | Repeated pagination cursor, MCP error | Already failed at once | Already failed at once | - The rejected-result fix reaches both plugins, with and without a factory argument. Strands turns the failure into a tool error the model sees, instead of the run hanging. - #379 is Caller-breaking for Strands: a lost session used to become a tool error; now the run waits for a new session under its retry policy. Taking it after GA would mean a new major, so before GA is the cheapest moment. - With OpenAI Agents, the Agents SDK used the current MCP protocol, which has no sessions, so I couldn't trigger the 404 path. - The factory-argument `ExceptionGroup` fixes (#411, #433, #455) don't change either plugin: Strands' factories take no argument, and OpenAI Agents' backend doesn't wrap errors in groups. 0.4.0 adds one more change (#494): MCP operations heartbeat while they run, with a 10-second `heartbeat_timeout` when the Activity config leaves it out. So a cancel reaches a running MCP request, and a request longer than a `heartbeat_timeout` you set no longer fails with a heartbeat timeout. - OpenAI Agents: `workflow.temporal_mcp_server()` passes `activity_config` to `TemporalMCPClient` as it is, so its MCP operations now heartbeat by default. In Temporal Cloud, that's at most one Action every 8 seconds of a running request. `heartbeat_timeout=None` turns it off. - Strands: `TemporalMCPClient` always passes `heartbeat_timeout`, `None` unless you set it, so heartbeats stay off by default. If you set it, long requests stop failing with a heartbeat timeout. Why not allow 0.2 or 0.3 too? Every GA install should get the same retry behavior, and CI only tests the locked version, so nobody would test older versions with the GA plugins. The cost: if you use an older `temporalio-mcp` with these plugins, you upgrade it together with the plugin. Does OpenAI Agents need code changes? No. It imports `temporalio.mcp._backend`, which is unchanged since 0.2.0, and `temporalio.mcp._activities._MCPActivities`, whose constructor and Activities are unchanged; 0.3.0 changes only how they classify errors, and 0.4.0 only adds the heartbeats. ## What's left? - Add a Breaking line to both plugins' release notes: they now require `temporalio-mcp` 0.4, with its lost-session retry and its default heartbeat timeout. ## Checklist 1. Closes: no issue. 2. How was this tested: - On this branch, with uv 0.12.24: `make sync`, `make lint` and `make test` pass in both plugins with `temporalio-mcp` 0.4.0 installed (OpenAI Agents: 626 passed, 2 skipped; Strands: 279 passed, 1 skipped). - Before the release, I re-ran the analysis' 178 feature and defect checks for both plugins with the 0.4.0 wheel the release dry run built, which is byte for byte the one on PyPI. Only the intended #494 change shows up: a `heartbeat_timeout` set on Strands' `TemporalMCPClient` no longer times out MCP requests, and `temporal_mcp_server()` operations are scheduled with a 10-second heartbeat timeout. Everything else matches the 0.3.0 run. - At `main` 10f9082, both suites give the same per-test results on 0.2.0 and 0.3.0 (OpenAI Agents: 565 passed, 1 skipped; Strands: 245 passed). 3. Any docs updates needed? The `temporal_mcp_server()` docstring is updated here; no README changes. The release notes need the Breaking line under "What's left?".
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 was changed
When the MCP client rejects a tool's result,
temporalio-mcplet the error through, and Temporal retried it forever. A retry can't fix it, so this PR makes it fail at once, asMCPProtocolError, like the other errors a retry can't fix._MCPActivities._runnow turns the client's rejections into a non-retryableApplicationError(type="MCPProtocolError")with the client's message:RuntimeError);InputRequiredRoundsExceededError, aRuntimeErrorsubclass).It handles both the bare error and the
ExceptionGroups a factory-argument client wraps it in, the same way mcp: fail an MCPError wrapped in an ExceptionGroup without retrying it #411 and mcp: fail an invalid response wrapped in an ExceptionGroup without retrying it #433 handleMCPErrorandValidationError.How do we tell these apart from other
RuntimeErrors? mcp gives the schema errors no type of their own, so I match their messages, as Breaking: retry an MCP operation whose session the server lost (HTTP 404) #379 does for lost sessions. They're the same in mcp 2.0.0, 2.2.0 (our lock), 2.3.0 and on mcp'smain.A new test,
test_rejected_tool_result_fails_without_retry, runs the call-tool Activity through mcp's realClientfor all three rejections, with and without a factory argument.The
python/mcpREADME's "Errors and retries" section now lists these rejections as non-retryable.Why?
Follow-up to the review of #190, which found #376.
The rejection wasn't an
ApplicationError, so under the default retry policy the Activity retried with no limit. Each failed attempt also retires the pooled connection, so with stdio every retry started a new server process. This reachesMCPPlugin, andOpenAIAgentsPlugin(mcp_servers=...)andStrandsPlugin(mcp_clients=...)once they use this release.Is it breaking? I don't think so: these calls never finished before. With a bounded retry policy, the call now fails after one attempt as
MCPProtocolError, instead of after its last attempt asRuntimeError.#377 adds a line to the Strands README that says these results are retried. Whichever of the two merges second should drop or update it.
Checklist
Closes [Bug] mcp: an MCP tool result the client rejects, such as one that breaks its output schema, retries forever #376.
How was this tested:
I ran the reproduction from [Bug] mcp: an MCP tool result the client rejects, such as one that breaks its output schema, retries forever #376 on
main, then with this fix (Python 3.12, temporalio 1.34.0, mcp 2.2.0):Without the fix, all 6 cases of the new test fail with the raw
RuntimeError,InputRequiredRoundsExceededErrororExceptionGroup. With it, they pass.The whole
python/mcpsuite passes (112 tests), andmake lintis clean. I ran both with uv 0.12.24 in Docker.python/mcpREADME's "Errors and retries" section. The Strands README line from [strands-agents-python] breaking: refuse misconfigured MCP factories and correct the MCP README #377 needs the follow-up noted above.