Your Mastra workflows can now run on Temporal. The new Temporal integration gives you retries, scheduling, durable state, and execution that survives worker restarts.
Workflow code stays identical. Under the hood, createWorkflow() becomes a Temporal workflow and createStep() becomes a Temporal activity.
Reach for Temporal when your workflows call external APIs, stretch over hours or days, or have to outlive a worker restart. You can self-host it or use the hosted version.
Get started
Install the Temporal packages:
npm install @mastra/temporal @temporalio/client @temporalio/worker @temporalio/envconfigRequires @mastra/core@1.32.0 or later, added in PR #15789.
Running Mastra workflows on Temporal consists of three parts:
- A Temporal client instance to convert the workflow functions
- An import swap in workflow files
- A long-lived worker process to run them
Temporal client instance
Create a Temporal client instance that binds Mastra's createWorkflow and createStep to a Temporal task queue. (typically created at src/mastra/temporal/index.ts)
Import swap
Import createWorkflow and createStep from the Temporal client instance:
// resolves to src/mastra/temporal/index.ts
import { createWorkflow, createStep } from "../temporal";
const incrementStep = createStep({
id: "increment-step"
//...
});
export const incrementWorkflow = createWorkflow({
id: "increment-workflow"
// ...
})
.then(incrementStep)
.commit();Worker process
Create a worker process that polls the Temporal task queue and runs your workflows.
Config-wise, both the Temporal instance and worker accept knobs like startToCloseTimeout, maxConcurrentActivityTaskExecutions, and shutdownForceTime — see the Temporal deployment guide for the full list.
@mastra/temporal is still experimental and the API may change between releases. The package README has the current state.
