class documentation

class TemporalMCPClient(ToolProvider): (source)

Constructor: TemporalMCPClient(server, cache_tools, task_queue, schedule_to_close_timeout, ...)

View In Hierarchy

Workflow-side handle to an MCP server registered on the worker.

The transport factory lives worker-side via StrandsPlugin(mcp_clients={"server": lambda: ...}). This handle carries the server name (which selects the registered factory) and the per-call activity options. Tool discovery runs as the {server}-list-tools activity, dispatched from inside the workflow by TemporalAgent before each model call.

cache_tools controls how often that listing happens. When False (the default) the tools are re-listed on every agent turn, so an MCP server restarted mid-workflow (with tools added, removed, or renamed) is picked up. When True the tools are listed once at the beginning of the workflow and reused for its lifetime.

Construct once at module level and pass to TemporalAgent(tools=[...]) inside the workflow. Multiple handles may reference the same server name with different activity options.

Method __init__ Configure the server name and activity options.
Method add_consumer No-op; consumer tracking is handled by the underlying MCP client.
Async Method load_tools Return the tools fetched by the most recent _refresh.
Method remove_consumer No-op; consumer tracking is handled by the underlying MCP client.
Property server MCP server name used as the activity prefix.
Async Method _refresh List the server's tools via the {server}-list-tools activity.
Instance Variable _cache_tools Undocumented
Instance Variable _fetched Undocumented
Instance Variable _options Undocumented
Instance Variable _server Undocumented
Instance Variable _tools Undocumented
def __init__(self, server: str, *, cache_tools: bool = False, task_queue: str | None = None, schedule_to_close_timeout: timedelta | None = None, schedule_to_start_timeout: timedelta | None = None, start_to_close_timeout: timedelta | None = None, heartbeat_timeout: timedelta | None = None, retry_policy: RetryPolicy | None = None, cancellation_type: ActivityCancellationType = ActivityCancellationType.TRY_CANCEL, versioning_intent: VersioningIntent | None = None, summary: str | None = None, priority: Priority = Priority.default): (source)

Configure the server name and activity options.

def add_consumer(self, consumer_id: Any, **_kwargs: Any): (source)

No-op; consumer tracking is handled by the underlying MCP client.

async def load_tools(self, **_kwargs: Any) -> Sequence[AgentTool]: (source)

Return the tools fetched by the most recent _refresh.

This must stay free of any workflow API: Strands invokes it once at Agent construction on a separate run_async thread that has no workflow runtime. TemporalAgent populates the tools by calling _refresh from a BeforeModelCallEvent hook before the registry is first read.

def remove_consumer(self, consumer_id: Any, **_kwargs: Any): (source)

No-op; consumer tracking is handled by the underlying MCP client.

MCP server name used as the activity prefix.

async def _refresh(self): (source)

List the server's tools via the {server}-list-tools activity.

Runs on the workflow event loop (dispatched from TemporalAgent's hook), so the activity result is recorded in history and replay-safe.

_cache_tools = (source)

Undocumented

_fetched: bool = (source)

Undocumented

_options: dict[str, Any] = (source)

Undocumented

Undocumented

_tools: list[AgentTool] = (source)

Undocumented