class documentation

Workflow-side handle for a stateful MCP toolset.

Warning

This class is experimental and may change in future versions. Use with caution in production environments.

Use it as an async context manager inside a workflow so the dedicated -server-session worker is started on connect and torn down on cleanup:

async with TemporalStatefulMcpToolSet("my-tools") as toolset:
    agent = Agent(..., tools=[toolset])
    await runner.run(...)

The connection (and any MCP subprocess) lives for the duration of the async with block and is reused across every tool call in that block, then closed on exit. Callers must be prepared to handle ApplicationError(type="DedicatedWorkerFailure") should the dedicated worker die mid-run.

Async Method __aenter__ Connects the toolset and returns it for use as a context manager.
Async Method __aexit__ Cleans up the toolset when exiting the context manager.
Method __init__ Initializes the stateful Temporal MCP toolset handle.
Async Method cleanup Cancels the dedicated session activity and awaits its teardown.
Async Method close BaseToolset teardown hook; delegates to cleanup.
Async Method connect Starts the dedicated -server-session activity for this run.
Async Method get_tools Retrieves available tools from the stateful MCP toolset.
Instance Variable _config Undocumented
Instance Variable _connect_handle Undocumented
Instance Variable _factory_argument Undocumented
Instance Variable _name Undocumented
Instance Variable _not_in_workflow_toolset Undocumented
Instance Variable _server_session_config Undocumented
async def __aenter__(self) -> TemporalStatefulMcpToolSet: (source)

Connects the toolset and returns it for use as a context manager.

async def __aexit__(self, exc_type: type[BaseException] | None, exc_value: BaseException | None, traceback: TracebackType | None): (source)

Cleans up the toolset when exiting the context manager.

def __init__(self, name: str, config: ActivityConfig | None = None, server_session_config: ActivityConfig | None = None, factory_argument: Any | None = None, not_in_workflow_toolset: Callable[[(Any | None)], McpToolset] | None = None): (source)

Initializes the stateful Temporal MCP toolset handle.

Parameters
name:strBase name of the toolset. Must match the name passed to the TemporalStatefulMcpToolSetProvider (the -stateful suffix is applied here automatically).
config:ActivityConfig | NoneOptional activity configuration for the per-operation (-list-tools/-call-tool) activities. A schedule_to_start_timeout is used to detect a dead dedicated worker.
server_session_config:ActivityConfig | NoneOptional activity configuration for the long-running -server-session activity.
factory_argument:Any | NoneOptional argument passed once to the toolset factory when the session connects.
not_in_workflow_toolset:Callable[[(Any | None)], McpToolset] | NoneOptional factory that returns the underlying McpToolset to use when this wrapper executes outside workflow.in_workflow(), such as local ADK runs.
async def cleanup(self): (source)

Cancels the dedicated session activity and awaits its teardown.

async def close(self): (source)

BaseToolset teardown hook; delegates to cleanup.

async def connect(self): (source)

Starts the dedicated -server-session activity for this run.

@_handle_worker_failure
async def get_tools(self, readonly_context: ReadonlyContext | None = None) -> list[BaseTool]: (source)

Retrieves available tools from the stateful MCP toolset.

Undocumented

_connect_handle: ActivityHandle | None = (source)

Undocumented

_factory_argument = (source)

Undocumented

Undocumented

_not_in_workflow_toolset = (source)

Undocumented

_server_session_config = (source)

Undocumented