You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
contrib/strands: add cache_tools toggle to TemporalMCPClient (#1571)
* contrib/strands: add cache_tools toggle to TemporalMCPClient
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.
* contrib/strands: default cache_tools to False
Copy file name to clipboardExpand all lines: temporalio/contrib/strands/README.md
+9-3Lines changed: 9 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -380,7 +380,7 @@ class ChatWorkflow:
380
380
381
381
## MCP
382
382
383
-
`StrandsPlugin(mcp_clients=...)` takes a mapping of `name → MCPClient factory`, mirroring the `models=` pattern. The plugin registers a per-server `{name}-call-tool`activity and connects at worker startup to enumerate tools. Workflow-side, `TemporalMCPClient(server="name")` is a pure handle: it references the server by name and carries the per-call activity options.
383
+
`StrandsPlugin(mcp_clients=...)` takes a mapping of `name → MCPClient factory`, mirroring the `models=` pattern. The plugin registers per-server `{name}-call-tool` and `{name}-list-tools` activities. Workflow-side, `TemporalMCPClient(server="name")` is a pure handle: it references the server by name, discovers tools by running `{name}-list-tools`, and carries the per-call activity options.
384
384
385
385
```python
386
386
from mcp import StdioServerParameters, stdio_client
@@ -412,9 +412,15 @@ Worker(
412
412
)
413
413
```
414
414
415
-
Each factory returns a fully configured `MCPClient`, so you can pass options like `tool_filters`, `prefix`, `elicitation_callback`, or `tasks_config` to it. The plugin connects to each MCP server once at worker startup to enumerate tools. The schema is frozen for the worker's lifetime; restart workers to pick up MCP-server changes. If a server is unavailable at startup, the worker fails to start.
415
+
Each factory returns a fully configured `MCPClient`, so you can pass options like `tool_filters`, `prefix`, `elicitation_callback`, or `tasks_config` to it.
416
416
417
-
To amortize connection setup, the `{name}-call-tool` activity keeps a worker-process MCP connection open between calls and reuses it. The connection is disconnected after it sits idle for `mcp_connection_idle_timeout` (default 5 minutes); the timer resets on every reuse:
417
+
By default, `TemporalMCPClient` re-lists the server's tools (via `{name}-list-tools`) on every agent turn, so an MCP server that is restarted mid-workflow — with tools added, removed, or renamed — is picked up. To list the tools just once at the beginning of the workflow and reuse that schema for the workflow's lifetime (one fewer activity per turn), set `cache_tools=True`:
To amortize connection setup, the `{name}-call-tool` and `{name}-list-tools` activities share a worker-process MCP connection that is opened lazily and reused across calls. The connection is disconnected after it sits idle for `mcp_connection_idle_timeout` (default 5 minutes); the timer resets on every reuse:
0 commit comments