Chaining Jobs into Workflows
Checked against FrontMCP 1.12.2 on
The help desk's nightly report is three jobs: collect the day's tickets, find the ones that broke their SLA, and write the report. A model could run them one by one with execute_job, copying each result into the next call. A workflow does that on the server: it names the jobs, says which ones need which, and says what each one gets as input. FrontMCP runs the steps in order, runs the ones that don't depend on each other at the same time, and returns what every step produced.
You will learn
- How to declare a workflow with
@Workflowandsteps, and run it withexecute_workflow - How to pass one step's output to the next
- Which steps run at the same time, and what
maxConcurrencydoes - What a failing step does to the rest, and how to change it with
retry,continueOnErrorandcondition - How to run a workflow in the background, and read its steps afterwards
One job at a time
With three jobs and no workflow, the report takes three round trips through the model. It calls execute_job for collect-tickets, reads the list of tickets, copies all of it into a call to check-sla, then copies the day, the count and the breaches into a call to write-report. Every ticket passes through the model's context twice, the model can copy something wrong at each step, and nothing happens on the server while the model is thinking. And if the report should be written every night, there may be no model around at all.
Declaring a workflow
@Workflow lists the steps. Each step runs one job, and says which steps it depends on and where its input comes from. Open the Tests tab:
import { Workflow } from "@frontmcp/sdk";
import type { Ticket } from "./store";
@Workflow({
name: "nightly-ticket-report",
description: "Collect a day's tickets, find the ones that broke their SLA, and write the report.",
steps: [
// No `input`: the step gets the workflow's input, { day }.
{ id: "collect", jobName: "collect-tickets" },
{
id: "breaches",
jobName: "check-sla",
dependsOn: ["collect"],
input: (steps) => ({ tickets: steps.get("collect").outputs.tickets }),
},
{
id: "report",
jobName: "write-report",
dependsOn: ["collect", "breaches"],
input: (steps) => ({
day: steps.get("collect").outputs.day,
total: (steps.get("collect").outputs.tickets as Ticket[]).length,
breaches: steps.get("breaches").outputs.breaches,
}),
},
],
})
export class NightlyTicketReport {}Starting FrontMCP in your browser…
FrontMCP starts when this example comes into view.
Change day in the Call tab to 2026-09-27 and call it again. Each step takes:
| Field | What it does |
|---|---|
id | The step's name within this workflow. Other steps use it in dependsOn and steps.get(). |
jobName | The name of the job the step runs. If no job has that name, the step fails when the workflow runs. |
dependsOn | The steps that must be done before this one starts. Without it, the step starts right away. |
input | What the job gets. See below. |
retry, timeout | Override the job's own. See When a step fails and Timeouts. |
continueOnError, condition | Let a step fail, or skip it. See Optional steps. |
A workflow is registered like a job, with workflows: [...] on @App, and its jobs go in jobs. (Most examples below leave main.ts out, and the Playground registers their jobs and workflows for you.) The class itself stays empty: everything is in the decorator. A client runs it with execute_workflow, which takes name, input and background, like execute_job, and answers with the run:
{
"runId": "0c8f1a52-…",
"state": "completed",
"result": {
"workflowName": "nightly-ticket-report",
"state": "completed",
"stepResults": {
"collect": { "outputs": { "day": "2026-09-26", "tickets": [/* … */] }, "state": "completed" },
"breaches": { "outputs": { "breaches": ["T-1", "T-2"] }, "state": "completed" },
"report": { "outputs": { "report": "2026-09-26: 2 of 4 tickets broke their SLA: T-1, T-2." }, "state": "completed" }
},
"startedAt": 1790467200000,
"completedAt": 1790467200004
}
}
stepResults has every step's outputs, what its job returned, and its state. There are no logs: the steps' this.log() lines only go to the server's log. So the model gets the whole report in one call, and so does a client that runs the workflow every night with no model involved.
Passing data between steps
A step's input can be three things:
input | The job gets |
|---|---|
| Left out | The workflow's input: the input passed to execute_workflow, or {}. |
| An object | That object, on every run. |
| A function | What the function returns. FrontMCP calls it just before the step starts, with (steps, input). |
steps.get(id) returns a finished step's { outputs, state }. An input function also receives the parsed workflow input as its second argument. The workflow's inputSchema is checked before any step starts; each job checks its own input too. Changed in 1.11.3: before, workflow input was not validated or passed to input functions.
Steps that run at the same time
Steps that don't depend on each other don't wait for each other. The report now also counts tickets per customer, which has nothing to do with the SLA check, so both depend only on collect and run side by side. Paging the on-call agent needs the breaches, and nothing else:
import { Workflow } from "@frontmcp/sdk";
@Workflow({
name: "nightly-ticket-report",
steps: [
{ id: "collect", jobName: "collect-tickets" },
{ id: "breaches", jobName: "check-sla", dependsOn: ["collect"] }, // 100 ms
{ id: "customers", jobName: "count-by-customer", dependsOn: ["collect"] }, // 300 ms
{ id: "page", jobName: "page-on-call", dependsOn: ["breaches"] },
{ id: "report", jobName: "write-report", dependsOn: ["breaches", "customers"] },
],
})
export class NightlyTicketReport {}
@Workflow({
name: "one-at-a-time",
maxConcurrency: 1,
steps: [
{ id: "breaches", jobName: "check-sla" },
{ id: "customers", jobName: "count-by-customer" },
],
})
export class OneAtATime {}Starting FrontMCP in your browser…
FrontMCP starts when this example comes into view.
FrontMCP runs a workflow in batches. It takes every step whose dependsOn are all done, starts up to maxConcurrency of them at once (5 by default), and waits until the whole batch has finished before it looks for the next steps. So check-sla and count-by-customer overlap, and the run takes about 300 ms instead of 400. But page-on-call could start after 100 ms, when check-sla is done, and instead it waits for count-by-customer: a batch is as slow as its slowest step.
maxConcurrency on @Workflow caps the batch. Steps beyond it wait for the next batch, in the order you declared them, and maxConcurrency: 1 runs the steps one at a time. Lower it when the steps share something that can't take much at once, like a rate-limited API.
When a step fails
The pager service is down tonight, so page-on-call fails. Two steps come after it: marking the late tickets as escalated, and emailing their customers that they were. Without a retry policy, each step runs once:
import { Workflow } from "@frontmcp/sdk";
@Workflow({
name: "nightly-ticket-report",
steps: [
{ id: "breaches", jobName: "check-sla" },
{ id: "page", jobName: "page-on-call", dependsOn: ["breaches"] },
{ id: "escalate", jobName: "mark-escalated", dependsOn: ["page"] },
{ id: "email", jobName: "email-customers", dependsOn: ["escalate"] },
{ id: "report", jobName: "write-report", dependsOn: ["breaches"] },
],
})
export class NightlyTicketReport {}Starting FrontMCP in your browser…
FrontMCP starts when this example comes into view.
The run shows how failures travel through dependencies:
- The step ran once. Neither the step nor its job has a
retrypolicy. - The failed step's direct dependents were skipped.
escalatenever ran, and its state is"skipped". - Everything else ran.
reportdoesn't depend onpage, so the report was written. - The workflow failed, but the call didn't.
execute_workflowreturned normally, withstate: "failed"in the run. A client has to checkstate, not just whether the call succeeded. - The reason is gone. A failed step's result is
{ outputs: {}, state: "failed" }, whatever went wrong.Pager service unavailableis only in the server's log. emailwas skipped too. It depends onescalate, which was skipped because of the failure.
Changed in 1.11.3: before, a step without retry ran three times, and only direct dependents of a failure were skipped. You can still list all prerequisites explicitly and set maxAttempts: 1 to override a job's retry policy:
import { Workflow } from "@frontmcp/sdk";
@Workflow({
name: "nightly-ticket-report",
steps: [
{ id: "breaches", jobName: "check-sla" },
{ id: "page", jobName: "page-on-call", dependsOn: ["breaches"], retry: { maxAttempts: 1 } }, // ✅ fail at once
{ id: "escalate", jobName: "mark-escalated", dependsOn: ["page"] },
{ id: "email", jobName: "email-customers", dependsOn: ["page", "escalate"] }, // ✅ needs both to succeed
{ id: "report", jobName: "write-report", dependsOn: ["breaches"] },
],
})
export class NightlyTicketReport {}Starting FrontMCP in your browser…
FrontMCP starts when this example comes into view.
A step's retry takes the same fields as a job's, and replaces the job's own for that step. Without a step or job policy, the job runs once.
Optional steps
Two options make a step optional, in different ways:
continueOnError: truelets a step fail without failing the workflow. Its state is still"failed", but its dependents run, and the workflow can complete.condition: (steps) => booleandecides whether a step runs at all. It's called withstepsonce the step'sdependsOnare done, and when it returnsfalsethe step is"skipped".
Posting the report to the team's chat is nice to have, and the chat service is down. Paging on-call only makes sense when something broke:
import { Workflow } from "@frontmcp/sdk";
@Workflow({
name: "nightly-ticket-report",
steps: [
{ id: "breaches", jobName: "check-sla" },
{
id: "page",
jobName: "page-on-call",
dependsOn: ["breaches"],
condition: (steps) => (steps.get("breaches").outputs.breaches as string[]).length > 0,
input: (steps) => ({ tickets: steps.get("breaches").outputs.breaches }),
},
{
id: "report",
jobName: "write-report",
dependsOn: ["breaches", "page"],
input: (steps) => ({ breaches: steps.get("breaches").outputs.breaches, paged: steps.get("page").state === "completed" }),
},
{
id: "post",
jobName: "post-to-chat",
dependsOn: ["report"],
input: (steps) => ({ text: steps.get("report").outputs.report }),
continueOnError: true,
retry: { maxAttempts: 1 },
},
],
})
export class NightlyTicketReport {}Starting FrontMCP in your browser…
FrontMCP starts when this example comes into view.
report depends on page, which is skipped on a quiet night, and runs anyway: a skipped step, when a condition skipped it, counts as done for the steps after it. So a step after an optional one has to handle both cases. report does that in its input function: steps.get("page").state is "completed", "failed" or "skipped".
Timeouts
A step can't run forever. It gets the job's timeout, jobs.defaultTimeoutMs (5 minutes) unless the job sets one, or the step's own timeout, and when that runs out the step fails. The job's signal aborts when the deadline passes. Work that ignores the signal keeps going. Changed in 1.11.0: before, only workflow steps enforced the job's timeout. execute_job now does too:
import { Job, JobContext, Workflow, z } from "@frontmcp/sdk";
export const exports: string[] = [];
@Job({
name: "export-tickets",
description: "Export every ticket as CSV.",
inputSchema: {},
outputSchema: { rows: z.number() },
timeout: 200,
})
export class ExportTickets extends JobContext {
async execute() {
await new Promise((resolve) => setTimeout(resolve, 500)); // takes longer than its timeout
exports.push(new Date().toISOString());
return { rows: 5 };
}
}
@Workflow({
name: "nightly-export",
steps: [{ id: "export", jobName: "export-tickets", retry: { maxAttempts: 1 } }],
})
export class NightlyExport {}Starting FrontMCP in your browser…
FrontMCP starts when this example comes into view.
Since a timed-out job isn't stopped, a step with a timeout and a retry can start its next attempt while the last one is still running. As with retries, make such a job safe to run twice.
Running a workflow in the background
execute_workflow takes background: true, like execute_job, and returns { runId, state: "pending" } at once. The same rule decides who can read the run: the owner or a caller passing an explicit read rule. Without that rule, under 2026-07-28 anonymous callers cannot read their runs. Also, reading it with get_workflow_status leaves out the steps:
import { test, expect } from "@frontmcp/testing";
import { FrontMcpInstance } from "@frontmcp/sdk";
import { config } from "./main";
const asNour = { authContext: { user: { sub: "nour" } } };
const wait = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));
test("get_workflow_status has no steps; get_job_status has them all", async () => {
const server = await FrontMcpInstance.createDirect(config);
const started = await server.callTool("execute_workflow", { name: "nightly-ticket-report", input: { day: "2026-09-26" }, background: true }, asNour);
const { runId } = started.structuredContent as { runId: string };
await wait(100);
const workflowStatus = (await server.callTool("get_workflow_status", { runId }, asNour)).structuredContent;
const jobStatus = (await server.callTool("get_job_status", { runId }, asNour)).structuredContent as any;
await server.dispose();
expect(workflowStatus).toMatchObject({ runId, workflowName: "nightly-ticket-report", state: "completed", stepResults: {} });
expect(jobStatus).toMatchObject({ runId, jobName: "nightly-ticket-report", state: "completed" });
expect(jobStatus.result.stepResults.report.outputs).toEqual({ report: "2026-09-26: 2 tickets broke their SLA." });
});
test("a webhook workflow can also be called manually", async ({ mcp }) => {
const { workflows } = (await mcp.tools.call("list_workflows", {})).json();
expect(workflows).toEqual([expect.objectContaining({ name: "nightly-ticket-report", trigger: "webhook", stepCount: 2 })]);
const run = await mcp.tools.call("execute_workflow", { name: "nightly-ticket-report", input: { day: "2026-09-26" } });
expect(run.json().state).toBe("completed");
});Starting FrontMCP in your browser…
FrontMCP starts when this example comes into view.
get_workflow_status returns the run's state, times and name, with stepResults always empty. A workflow's run is stored like a job's, and get_job_status with the same runId returns all of it: jobName is the workflow's name, and result is what execute_workflow would have returned inline, stepResults included. Until that's fixed, read workflow runs with get_job_status.
Recap
@Workflow({ name, steps }), orworkflow({...}), chains jobs. Register it with@App({ workflows }), next to its jobs, and run it withexecute_workflow { name, input }. The result'sstepResultshas each step'soutputsandstate.- A step's
inputis the workflow's input when left out, a fixed object, or a function of(steps, input). Read earlier results withsteps.get(id)and list them independsOn. - Steps run in batches of up to
maxConcurrency(5). Independent steps overlap, and each batch waits for its slowest step. - A failed step runs once without a retry policy. Its direct and indirect dependents are skipped, independent steps run, and the run's
stateis"failed"in a successful call. The error is only in the server log. continueOnErrorlets a step fail without failing the workflow, andconditionskips a step. Steps after either one run, so checksteps.get(id).state.- Steps time out after their job's
timeout(5 minutes by default), and work that ignores the aborted signal keeps running. Read background workflow runs withget_job_status:get_workflow_statushas no steps.
Try some challenges
Each challenge runs hidden checks against your code. Edit the code, then press Check.
Read all challenge instructions
Hand the breaches to the report
This challenge is open below.
Check both at once
Counting tickets per customer doesn't need the SLA check, but the workflow runs one after the other, and the run takes more than 600 ms. Make the two run at the same time. The report still needs both.
import { Workflow } from "@frontmcp/sdk";
@Workflow({
name: "nightly-ticket-report",
steps: [
{ id: "collect", jobName: "collect-tickets" },
{ id: "breaches", jobName: "check-sla", dependsOn: ["collect"] },
{ id: "customers", jobName: "count-by-customer", dependsOn: ["breaches"] },
{
id: "report",
jobName: "write-report",
dependsOn: ["customers"],
input: (steps) => ({ breaches: steps.get("breaches").outputs.breaches, customers: steps.get("customers").outputs.customers }),
},
],
})
export class NightlyTicketReport {}import { Job, JobContext, z } from "@frontmcp/sdk";
const slow = () => new Promise((resolve) => setTimeout(resolve, 300));
@Job({ name: "collect-tickets", inputSchema: {}, outputSchema: {} })
export class CollectTickets extends JobContext {
async execute() {
return {};
}
}
@Job({ name: "check-sla", inputSchema: {}, outputSchema: { breaches: z.number() } })
export class CheckSla extends JobContext {
async execute() {
await slow();
return { breaches: 2 };
}
}
@Job({ name: "count-by-customer", inputSchema: {}, outputSchema: { customers: z.number() } })
export class CountByCustomer extends JobContext {
async execute() {
await slow();
return { customers: 3 };
}
}
@Job({ name: "write-report", inputSchema: { breaches: z.number(), customers: z.number() }, outputSchema: { report: z.string() } })
export class WriteReport extends JobContext {
async execute({ breaches, customers }: { breaches: number; customers: number }) {
return { report: `${breaches} SLA breaches across ${customers} customers.` };
}
}Keep the report when paging fails
The pager is down, so page fails, and with it the whole workflow: the report is skipped. Make the workflow complete with a report that says on-call wasn't paged.
import { Workflow } from "@frontmcp/sdk";
@Workflow({
name: "nightly-ticket-report",
steps: [
{ id: "breaches", jobName: "check-sla" },
{ id: "page", jobName: "page-on-call", dependsOn: ["breaches"] },
{
id: "report",
jobName: "write-report",
dependsOn: ["breaches", "page"],
input: (steps) => ({ breaches: steps.get("breaches").outputs.breaches, paged: steps.get("page").state === "completed" }),
},
],
})
export class NightlyTicketReport {}import { Job, JobContext, z } from "@frontmcp/sdk";
@Job({ name: "check-sla", inputSchema: {}, outputSchema: { breaches: z.array(z.string()) } })
export class CheckSla extends JobContext {
async execute() {
return { breaches: ["T-1", "T-2"] };
}
}
@Job({ name: "page-on-call", inputSchema: {}, outputSchema: { paged: z.boolean() } })
export class PageOnCall extends JobContext {
async execute() {
throw new Error("Pager service unavailable");
}
}
@Job({
name: "write-report",
inputSchema: { breaches: z.array(z.string()), paged: z.boolean() },
outputSchema: { report: z.string() },
})
export class WriteReport extends JobContext {
async execute({ breaches, paged }: { breaches: string[]; paged: boolean }) {
return { report: `${breaches.length} tickets broke their SLA. On-call was ${paged ? "" : "not "}paged.` };
}
}Only page when something broke
On-call gets paged every night, even when no ticket broke its SLA. Skip the page step when check-sla finds no breaches, and keep paging when it finds some.
import { Workflow } from "@frontmcp/sdk";
@Workflow({
name: "nightly-ticket-report",
steps: [
{ id: "breaches", jobName: "check-sla" },
{
id: "page",
jobName: "page-on-call",
dependsOn: ["breaches"],
input: (steps) => ({ tickets: steps.get("breaches").outputs.breaches }),
},
],
})
export class NightlyTicketReport {}import { Job, JobContext, z } from "@frontmcp/sdk";
const breachesByDay: Record<string, string[]> = { "2026-09-26": ["T-1", "T-2"], "2026-09-27": [] };
export const pages: string[][] = [];
@Job({ name: "check-sla", inputSchema: { day: z.string() }, outputSchema: { breaches: z.array(z.string()) } })
export class CheckSla extends JobContext {
async execute({ day }: { day: string }) {
return { breaches: breachesByDay[day] ?? [] };
}
}
@Job({ name: "page-on-call", inputSchema: { tickets: z.array(z.string()) }, outputSchema: { paged: z.boolean() } })
export class PageOnCall extends JobContext {
async execute({ tickets }: { tickets: string[] }) {
pages.push(tickets);
return { paged: true };
}
}Challenge 1 of 4
Hand the breaches to the report
The report always says "0 of 0 tickets broke their SLA", because its step has a fixed input. Make report run after collect and breaches, and give it the day, the number of tickets and the breaches from those steps.
import { Workflow } from "@frontmcp/sdk";
@Workflow({
name: "nightly-ticket-report",
steps: [
{ id: "collect", jobName: "collect-tickets" },
{ id: "breaches", jobName: "check-sla", dependsOn: ["collect"], input: (steps) => ({ tickets: steps.get("collect").outputs.tickets }) },
{ id: "report", jobName: "write-report", input: { day: "", total: 0, breaches: [] } },
],
})
export class NightlyTicketReport {}Starting FrontMCP in your browser…
FrontMCP starts when this example comes into view.