execution_engine: temporal and your existing workflows, tools, and agents keep working.
Outside of configuration (and starting a Temporal worker), you rarely need to touch your code. The same
@app.workflow, @app.workflow_run, @app.async_tool, Agent, and AugmentedLLM APIs behave identically with Temporal behind the scenes.When to choose Temporal
| Reach for Temporal when… | Asyncio alone is enough when… |
|---|---|
| Workflows must survive restarts, deploys, or worker crashes. | Runs are short-lived and you can re-trigger them on failure. |
| Human approvals, scheduled delays, or days-long research loops are in scope. | The agent answers a single request synchronously. |
| You need history, querying, and signal support from the Temporal UI or CLI. | You only need to fan out a few tasks inside one process. |
Enable the Temporal engine
Switch the execution engine and point at a Temporal cluster (the examples assumetemporal server start-dev):
@app.workflow_run) are re-executed after a crash, while non-deterministic work—LLM calls, MCP tool calls, HTTP requests—is automatically offloaded to Temporal activities by the executor. mcp-agent handles that split for you; you keep writing straightforward async Python.
Run a worker
Workers poll Temporal for workflow/activity tasks. The helpercreate_temporal_worker_for_app wires your MCPApp into a worker loop:
Launch workflows (or tools) durably
The executor API is unchanged—Temporal persists the state machine behind the scenes:@app.async_tool so clients invoke a single tool call while Temporal handles retries and state:
Human approvals, pause, and resume
Temporal signals map directly toexecutor.wait_for_signal and executor.signal_workflow. The pause/resume workflow shipped in examples/mcp_agent_server/temporal demonstrates the flow:
mcp-agent workflows resume):
app.context.executor.signal_bus, so you can prototype locally and switch to Temporal when you need durability.
Nested tools and elicitation
The Temporal server example also shows how durable workflows call nested MCP servers and trigger MCP elicitation when a human response is required. Activities such ascall_nested_elicitation log progress via app.app.logger so the request trace and Temporal history stay aligned.
Operating durable agents
- Temporal Web UI (http://localhost:8233) lets you inspect history, replay workflow code, and emit signals.
- Workflow handles expose
describe(),query(), andlist()helpers for custom dashboards or integrations. - Observability: enable OpenTelemetry (
otel.enabled: true) to stream spans + logs while Temporal provides event history. - Deployment: mcp-agent Cloud uses the same configuration. Once deployed, Cloud exposes CLI commands (
mcp-agent workflows list,resume,cancel) that call the same signal/query APIs shown above.
Deeper dives
- Temporal example suite – side-by-side asyncio vs. Temporal workflows (basic, router, parallel, evaluator-optimizer) plus a detailed README walking through setup.
- Temporal MCP server – exposes durable workflows as MCP tools, demonstrates
workflows-resume, and includes a client script for pause/resume flows. - Temporal tracing example – shows the same code running with Jaeger exports once you flip the
execution_engine.
Example projects
- examples/temporal – basic workflow, evaluator-optimizer, router, and orchestrator patterns on Temporal.
- examples/mcp_agent_server/temporal – MCP server with durable human approvals, nested servers, and elicitation.
- examples/oauth/pre_authorize – demonstrates pre-authorised credentials for background Temporal workflows.
