Repository navigation
Description
What are you really trying to do?
Run several MCP tool calls concurrently through the Strands integration against one MCP server, without one
failing call breaking the others.
Describe the bug
When a {server}-call-tool or {server}-list-tools Activity fails, its except block runs
await _evict_connection(server) right away
(python/strands_agents/src/temporalio/strands_agents/_temporal_mcp_client.py). That closes the pooled MCP
connection that every other in-flight call on the same server is using, so those calls never get their result.
In my reproduction they hang until the Activity timeout, and the Activity is then retried, which can repeat side
effects of non-idempotent tools.
Failures that trigger it include client-side ones over a healthy connection, for example non-object tool
arguments, or a result whose structured content fails the tool's output schema (the MCP client raises
RuntimeError("Invalid structured content ...")).
There is a second, smaller problem in the same file: _ConnectionRecord._run removes _CONNECTIONS[server]
without checking that the cached record is itself, so a record that dies late can drop the connection that
replaced it.
This is the Python counterpart of #100 (fixed for TypeScript in #101).
Minimal Reproduction
slow_server.py:
import asyncio
from mcp.server.fastmcp import FastMCP
mcp = FastMCP("repro")
@mcp.tool()
async def slow() -> str:
await asyncio.sleep(3)
return "slow-done"
if __name__ == "__main__":
mcp.run()
repro.py (runs the real Activity in-process, no Temporal server needed):
import asyncio, sys
from mcp import StdioServerParameters, stdio_client
from strands.tools.mcp import MCPClient
from temporalio.strands_agents import _temporal_mcp_client as m
from temporalio.testing import ActivityEnvironment
def factory() -> MCPClient:
return MCPClient(lambda: stdio_client(
StdioServerParameters(command=sys.executable, args=["slow_server.py"])))
async def main():
call = m.build_call_tool_activity("repro", factory)
slow = asyncio.create_task(
ActivityEnvironment().run(call, m._CallToolArgs("slow", {}, "t1")))
await asyncio.sleep(1.5)
# Fails client-side (arguments must be an object) over a healthy connection.
bad = await ActivityEnvironment().run(call, m._CallToolArgs("slow", "not-a-dict", "t2"))
print("bad ->", bad["status"])
try:
print("slow ->", await asyncio.wait_for(slow, 15))
except BaseException as e:
print("slow raised", repr(e))
await m._evict_connection("repro")
asyncio.run(main())
Observed:
bad -> error
slow raised TimeoutError()
The slow call never returns although the server finishes it after 3 seconds. Expected: slow returns
slow-done, and the connection is closed only after it finishes.
list-tools has the same except handler, so a failing list-tools closes the connection under an in-flight
call-tool the same way (covered by a unit-level test with a fake MCP session that fails in-flight requests with
"Connection closed" on close).
Environment/Versions
- OS and processor: macOS, Apple Silicon (not OS-specific)
- Temporal Version:
python/strands_agentsat ai-integrations main (bb34a32), temporalio 1.34.0, strands-agents 1.56.0, mcp 1.30.0, Python 3.14.7, uv 0.12.8 - Are you using Docker or Kubernetes or building Temporal from source? Unit-test level (
make test), no cluster
Additional context
This is the Python twin of #100 / #101. typescript/strands-agents now marks a failed pooled connection
broken, stops handing it out, and closes it once its last in-flight call releases it. python/mcp already
works this way: _pool.py retires the record (retire()), unmaps it, and closes it on the last release. I
propose the same here: mark the record broken and unpublish it immediately so later calls open a fresh
connection, and disconnect it when the last in-flight call releases it. I would also make _run unpublish only
its own record. I have a small patch and tests ready and will open a PR if this looks right.
python/google_genai (_mcp.py) has the same _CONNECTIONS.pop(...) pattern. I would leave that as a
possible follow-up rather than widen this change.
Activity