Running Workflows
Workflows can be run from different environments. These examples demonstrate how to execute a workflow using a command line script or by calling the Mastra Client SDK from a client-side component.
From the command line
In this example, a run script has been added to the src
directory. The inputData
matches the inputSchema
for the sequentialSteps example.
src/test-run-workflow.ts
import { mastra } from "./mastra";
const run = await mastra.getWorkflow("sequentialSteps").createRunAsync();
const result = await run.start({
inputData: {
value: 10,
},
});
console.log(result);
Run the script
Run the workflow using the following command:
npx tsx src/test-run-workflow.ts
Command line output
The output from this workflow run will look similar to the below:
{
status: 'success',
steps: {
input: { value: 10 },
'step-1': {
payload: [Object],
startedAt: 1753814259885,
status: 'success',
output: [Object],
endedAt: 1753814259885
},
'step-2': {
payload: [Object],
startedAt: 1753814259885,
status: 'success',
output: [Object],
endedAt: 1753814259885
}
},
result: { value: 10 }
}
Using Mastra Client
In this example, a client-side request is made using the Mastra Client SDK. The inputData
matches the inputSchema
for the sequentialSteps example.
src/components/test-run-workflow.tsx
import { mastraClient } from "../../lib/mastra-client";
export const TestWorkflow = () => {
async function handleClick() {
const workflow = await mastraClient.getWorkflow("sequentialSteps");
const run = await workflow.createRunAsync();
const result = await workflow.startAsync({
runId: run.runId,
inputData: {
value: 10
}
});
console.log(JSON.stringify(result, null, 2));
}
return <button onClick={handleClick}>Test Workflow</button>;
};
Mastra Client output
The output from this workflow run will look similar to the below:
{
"status": "success",
"steps": {
"input": {
"value": 10
},
"step-1": {
"payload": {
"value": 10
},
"startedAt": 1753816719202,
"status": "success",
"output": {
"value": 10
},
"endedAt": 1753816719203
},
"step-2": {
"payload": {
"value": 10
},
"startedAt": 1753816719203,
"status": "success",
"output": {
"value": 10
},
"endedAt": 1753816719203
}
},
"result": {
"value": 10
}
}