class TemporalStatefulMcpToolSetProvider: (source)
Constructor: TemporalStatefulMcpToolSetProvider(name, toolset_factory)
Provider for a stateful, pooled MCP toolset backed by a dedicated worker.
Warning
This class is experimental and may change in future versions. Use with caution in production environments.
Unlike TemporalMcpToolSetProvider (which builds and closes a fresh
McpToolset per activity call), this provider maintains a single
McpToolset for the lifetime of a workflow run. The workflow-side
TemporalStatefulMcpToolSet starts a dedicated -server-session
activity on a task queue scoped to that specific run
(name@run_id); that activity builds the toolset once via
toolset_factory(factory_argument), holds it open, and runs a nested
temporalio.worker.Worker serving the -list-tools/-call-tool
activities off the same run-scoped queue. The toolset is closed when the
workflow cancels the session activity on cleanup.
Because state lives in a dedicated worker's memory, the caller must handle
the case where that worker fails, as Temporal cannot seamlessly recreate the
lost toolset. Failure surfaces as an ApplicationError with
type="DedicatedWorkerFailure". Prefer the stateless
TemporalMcpToolSetProvider unless a persistent connection is
genuinely required.
| Method | __init__ |
Initializes the stateful toolset provider. |
| Property | name |
The activity-name prefix (base name with the -stateful suffix). |
| Method | _get |
Undocumented |
| Instance Variable | _name |
Undocumented |
| Instance Variable | _toolset |
Undocumented |
| Instance Variable | _toolsets |
Undocumented |
Initializes the stateful toolset provider.
| Parameters | |
name:str | Name prefix for the generated activities. It is suffixed with -stateful so it never collides with a stateless provider of the same base name registered on the same worker. |
toolsetCallable[ | Factory function that creates McpToolset instances. It should return a new toolset each time so that no state is shared between workflow runs. |