Skip to content

Require temporalio-mcp 0.4 in OpenAI Agents and Strands - #435

Merged
campoy merged 7 commits into
mainfrom
fix/widen-temporalio-mcp-pins
Nov 13, 2026
Merged

campoy merged 7 commits into
mainfrom
fix/widen-temporalio-mcp-pins

Conversation

@campoy

@campoy campoy commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

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

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 mcp: heartbeat while an MCP operation runs, with a 10-second default heartbeat timeout #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).
  1. 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?".

Widen temporalio-mcp from >=0.2.0,<0.3 to >=0.2.0,<0.4 in the mcp extra
and dev group of both plugins, so they can pick up 0.3.0's lost-session
retry (#379) before GA. The locks stay on 0.2.0 until 0.3.0 is on PyPI.
Raise the floor from 0.2.0 to 0.3.0, so every install gets the lost-session retry (#379) and the factory-argument error fixes (#411, #433), and CI tests the only version allowed. The locks still resolve 0.2.0 and need a refresh once 0.3.0 is on PyPI.
@campoy campoy changed the title Let OpenAI Agents and Strands use temporalio-mcp 0.3 Require temporalio-mcp 0.3 in OpenAI Agents and Strands Nov 6, 2026
@campoy

campoy commented Nov 6, 2026

Copy link
Copy Markdown
Contributor Author

Here's what I ran on temporalio-mcp 0.3.0 with these pins. Once 0.3.0 is on PyPI, I'll refresh the locks and rerun on the published package.

How did I test it with the plugins?

I built a local candidate: the GA release candidate plus #433, #434 (before its test-helper change) and #435. I built temporalio-mcp from that tree as 0.3.0 and installed it over each plugin's lock. Then I reran everything we have for the two plugins that use temporalio-mcp: OpenAI Agents and Strands (both Python). I compared each result with the same check on the release candidate, which used temporalio-mcp 0.2.0.

Check OpenAI Agents Strands
Plugin CI suite on temporalio-mcp 0.3.0 544 passed, 1 skipped 230 passed
Defect fix checks 14, all the same as before 15, all the same as before
Feature evidence checks 80, all the same as before all of them, the same as before

temporalio-mcp's own CI passed on #433 and #434: macOS, Ubuntu (Python 3.10 and 3.14) and Windows.

What changed, on purpose?

What didn't change?

The items that failed on the release candidate still fail the same way here, and none of them comes from temporalio-mcp. In OpenAI Agents, two defect fix checks and five feature checks were already failing on the release candidate. Only three defect checks and one feature item in OpenAI Agents go through the temporalio-mcp route; the rest of its MCP evidence uses the deprecated providers, which don't import it.

Anything flaky, or not run?

  • A few first runs broke while my laptop was asleep or Docker restarted. Every rerun matched the earlier result.
  • Not run, as on the release candidate: the Docker and ssh routes of the credential checks (the image has neither) and two replay items that were never part of the run.

Refresh both locks with uv lock --upgrade-package temporalio-mcp now that 0.3.0 is on PyPI. It adds exceptiongroup on Python 3.10.
@campoy
campoy marked this pull request as ready for review November 9, 2026 20:55
@campoy
campoy requested a review from a team as a code owner November 9, 2026 20:55
@campoy campoy changed the title Require temporalio-mcp 0.3 in OpenAI Agents and Strands Require temporalio-mcp 0.4 in OpenAI Agents and Strands Nov 13, 2026
@campoy
campoy merged commit 09c0620 into main Nov 13, 2026
37 checks passed
@campoy
campoy deleted the fix/widen-temporalio-mcp-pins branch November 13, 2026 18:03
campoy added a commit that referenced this pull request Nov 14, 2026
… heartbeat timeout (#504)

## What was changed

`TemporalAgent`, `TemporalModel` and `TemporalSandbox` now default
`heartbeat_timeout` to 10 seconds instead of `None`, so the model and
sandbox activities heartbeat by default.

- The activities already heartbeat on a timer at half the timeout
(`auto_heartbeater`). A timeout you set wins, and
`heartbeat_timeout=None` turns heartbeats off, as before.
- The timer now starts when the activity does, not at its first `await`.
Before, a model factory that blocked the event loop for over half the
timeout made the attempt fail with a heartbeat timeout. Now it takes the
whole timeout, which is when the warning below fires.
- `strands_get_model_config` is now scheduled without a heartbeat
timeout. It builds the model and reads its config synchronously, so it
can't heartbeat, and a model factory slower than the timeout would fail
it.
- A model factory slower than the heartbeat timeout now logs a warning
on the worker. The factory runs on the worker's event loop, so the
heartbeat timer can't run while it builds the model, and that attempt
may fail with a heartbeat timeout. The next attempt reuses the built
model.
- The docstrings and the README say what the default does and how to
turn it off. They also say that a model factory or model call that
blocks the event loop longer than the timeout fails. In Strands 1.56.0,
`SageMakerAIModel` and `LlamaAPIModel` call their synchronous clients on
the loop, so they need `heartbeat_timeout=None` (or a longer timeout).

`activity_as_tool` and `activity_as_hook` run your own Activities, so
they stay as they are.

### Why not build models on a thread?

An automated review round suggested it, so a slow factory couldn't block
the heartbeat timer. But that broke factories that need a running event
loop, such as one that builds an `aiohttp` session, and the fix for that
made this PR much bigger. A factory slower than 10 seconds is rare, and
the retry reuses the model it built, so a warning that says what
happened is enough.

## Why?

Without a heartbeat timeout, these activities never heartbeat. So a
cancel never reaches a running model call or sandbox command, and it
runs to the end. A lost worker also goes unnoticed until the
start-to-close timeout. #491 has the details, and the measurements
behind 10 seconds.

Does this break anything? Not replay: when core replays a scheduled
Activity, it only compares its ID and type, and the replay tests pass.
But a call that didn't set `heartbeat_timeout` now heartbeats, which in
Temporal Cloud is at most one Action every 8 seconds of a running call.

`TemporalMCPClient` isn't in this PR. Since #435, Strands requires
`temporalio-mcp` 0.4, whose Activities heartbeat (#494). But Strands'
`TemporalMCPClient` still passes `heartbeat_timeout=None`, so its
Activities don't heartbeat yet. A follow-up can give it the 10-second
default too.

This works with #497, which makes a cancelled tool call cancel the
agent. I merged its branch on top of this one, and its cancellation
tests pass with these defaults.

## Checklist

1. Closes #498

2. How was this tested:
- `test_model` now checks the heartbeat timeouts in History: none for
`strands_get_model_config`, 10 seconds for `invoke_model`. Without the
change it fails with `assert [None, None] == [None,
datetime.timedelta(seconds=10)]`.
-
`test_sandbox_operations_are_durable_and_factory_runs_for_each_activity`
now checks that all seven sandbox Activities get 10 seconds. Without the
change, they get none.
- `test_heartbeat_timer_counts_from_the_start` blocks the event loop for
0.7 seconds under a 1-second heartbeat timeout, and checks that the
first heartbeat comes before the timeout. With the old timer, the first
heartbeat would come 1.2 seconds in, so the test fails with `assert
([])`.
- `test_slow_model_factory_logs_a_warning` builds a model with a factory
that takes 0.3 seconds, under a 0.1-second heartbeat timeout, and checks
the warning. A fast factory logs nothing. Without the warning it fails
with `assert ("Building model 'slow' took" in '') == True`.
- Locally, `make test` (262 passed, 1 skipped), `make lint` and the
conventions check pass, on Python 3.12 with uv 0.12.24. With #497 merged
in, its two cancellation test files and these tests pass (53 passed).

3. Any docs updates needed?
The docstrings and the README are updated here. Release notes should
mention the new default, and how to turn it off.
campoy added a commit that referenced this pull request Nov 16, 2026
…and correct the MCP README (#377)

## What was changed

Misconfigured Strands MCP factories can fail every Activity attempt and
retry without limit. This PR rejects factories that need arguments or
aren't callable when the plugin is built. It reports wrong client types
and function transports as typed, non-retryable Activity errors.

- `StrandsPlugin(mcp_clients=...)` refuses a factory that needs
arguments with a `TypeError` that names the server. On Python 3.14+, the
check reads the factory's parameters without evaluating its annotations,
so `-> Client` with `Client` imported only under `TYPE_CHECKING` still
works.
- It also refuses a factory that isn't callable, such as a client passed
in its place: `MCP server factory 'weather' is mcp.client.client.Client,
not callable`.
- A factory that returns something other than an `mcp.Client` fails with
type `MCPServerFactoryTypeError`. When an async factory returns a
coroutine, the coroutine is closed first, so Python doesn't warn that it
was never awaited.
- A factory that returns an `mcp.Client` built on a plain function fails
with type `MCPServerFactoryTransportError`. This catches `Client(lambda:
stdio_client(...))`, the shape an old Strands factory takes when only
its import changes.

Both Activity errors name the server and the fix, and set
`non_retryable=True`, matching the factory configuration checks in #451.

The README and plugin docstring also clarify that factories run for
every connection and must return a fresh client and transport. The
README explains the `factory_argument` limit, resumed interrupts, and
the retry, idle-timeout and connection changes from #190. It also covers
rejected MCP results. With `temporalio-mcp` 0.4, which this plugin
requires since #435, two kinds of rejected result reach the agent at
once as a failed tool result, without a retry: a malformed result the
MCP client can't parse, and a result that breaks the tool's output
schema.

The tests run the factory checks through the plugin's list-tools
Activity and check the error types and non-retryable flags. Factories
that take no arguments (a lambda, a defaulted parameter, a callable
object, a `functools.partial`, and on 3.14+ an annotation that exists
only under `TYPE_CHECKING`) list tools through the same Activity. The
tests also cover idle-timeout forwarding, tool filtering and failed tool
results. A malformed result and an output-schema mismatch go through the
call-tool Activity, with a valid result as the control. Both rejected
results fail with a non-retryable `MCPProtocolError`.

## Why?

Follow-up to the [last review of
#190](#190 (review)),
which found these factory checks and README gaps.

## Is it breaking? (Breaking)

Wrong client types and function transports already failed, but those
failures were retryable. They now stop the Activity without retries,
including on the next attempt of an in-flight Activity. Fix these
factories before upgrading: deploying a corrected Worker won't resume an
Activity that has already failed.

A factory that isn't callable used to start the worker and then fail
every MCP Activity with a retryable `TypeError`. Now
`StrandsPlugin(...)` raises, even when no workflow uses that server.

The README includes these upgrade warnings. No Workflow code changes.

## Checklist

1. Related: #320, #376, #435 and #451. No issue to close.

2. How was this tested:
- `make test PYTEST_ARGS='-n 4 -q'` on Python 3.13: 293 passed, 2
skipped.
   - The same on Python 3.14: 295 passed.
- `make lint` on Python 3.13 and 3.14: ruff import sorting and
formatting, pyright, mypy, basedpyright and pydocstyle passed. pyright,
mypy and basedpyright also passed when targeting Python 3.11 and 3.15. I
couldn't set up a 3.15 environment locally (`pydantic-core` has no 3.15
wheel yet), so the CI cell covers a real 3.15 run.
- After adding the startup check and the coroutine close: `make test` on
Python 3.12, 294 passed, and `make lint` passed. The extended factory
test fails without each of the two changes.
   - `git diff --check` passed.

3. Any docs updates needed?
   - The plugin README's MCP section is updated.
- Outside this repo, to land with the release:
`strands_plugin/mcp/run_worker.py` in temporalio/samples-python, and the
Strands page in temporalio/documentation, which renders that sample.
Both still build Strands' `MCPClient` and don't install the `mcp` extra.
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