contrib/strands: add cache_tools toggle to TemporalMCPClient#1571
Merged
Conversation
Replace worker-startup tool discovery with a per-server {server}-list-tools
activity executed from inside the workflow. TemporalMCPClient.cache_tools
(default True) lists tools once at the start of the workflow; cache_tools=False
re-lists on every agent turn so a mid-workflow MCP server restart is picked up.
Strands calls load_tools() once at agent construction on a separate run_async
thread with no workflow runtime, so the activity is dispatched from a
BeforeModelCallEvent hook (which runs on the workflow loop before the registry
is read each turn) that reconciles added/removed/renamed tools.
JasonSteving99
approved these changes
Jun 2, 2026
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 changed
Adds a
cache_toolsoption toTemporalMCPClientcontrolling how often an MCP server's tool list is fetched inside a workflow.cache_tools=True: tools are listed once at the beginning of the workflow and reused for its lifetime.cache_tools=False(default): tools are re-listed on every agent turn, so an MCP server restarted mid-workflow (tools added/removed/renamed) is picked up.Worker-startup tool discovery (
_TOOL_CACHE/populate_cache) is replaced by a per-server{server}-list-toolsactivity executed from inside the workflow, so the tool schema is recorded in history and replay-safe.Why the hook-based design
Strands invokes
ToolProvider.load_tools()exactly once atAgentconstruction, on a separaterun_asyncthread that has no workflow runtime — soload_tools()cannot callworkflow.execute_activity. Instead the activity is dispatched from aBeforeModelCallEventhook, which runs on the workflow loop just before the tool registry is read each turn.TemporalAgentregisters the hook perTemporalMCPClientprovider and reconciles the registry (replaceexisting,register_toolnew, delete removed).cache_tools=Truelists once (guarded by_fetched);cache_tools=Falsere-lists each turn.A nuance: with
cache_tools=Truethe listing happens on the first turn rather than literally at construction (forced by the threading constraint) — the activity history is identical to a construction-time fetch, and the registry is populated before it is ever read.Tests
test_mcp.pyfor the new leading{server}-list-toolsactivity and the lazy single-connection model.>= 1; deterministic reuse is still covered bytest_mcp_reuses_connection(factory == 1, default timeout).cache_tools=Falsetest asserting one list-tools per model call.All 13 strands tests pass;
poe lintis clean.🤖 Generated with Claude Code