{"record":{"id":"2a78014ea126cd7f","repo":"mastra-ai/mastra","slug":"list-workflows-requires-a-mastra-context","errorCode":null,"errorMessage":"list-workflows requires a Mastra context.","messagePattern":"list-workflows requires a Mastra context\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"mastracode/sdk/src/tools/workflows/list-workflows.ts","lineNumber":24,"sourceCode":"import { z } from 'zod';\nimport { listWorkflows } from '../../workflows/service.js';\n\nexport const listWorkflowsTool = createTool({\n  id: 'list-workflows',\n  description: 'List active Dynamic Workflows persisted to storage. Returns id + description + status for each.',\n  inputSchema: z.object({}),\n  outputSchema: z.object({\n    workflows: z.array(\n      z.object({\n        id: z.string(),\n        description: z.string().optional(),\n        status: z.enum(['active', 'archived']),\n      }),\n    ),\n    total: z.number(),\n  }),\n  execute: async (_input, { mastra }) => {\n    if (!mastra) throw new Error('list-workflows requires a Mastra context.');\n    const { workflows, total } = await listWorkflows(mastra as Mastra);\n    return {\n      workflows: workflows.map(wf => ({ id: wf.id, description: wf.description, status: wf.status })),\n      total,\n    };\n  },\n});\n","sourceCodeStart":6,"sourceCodeEnd":32,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/mastracode/sdk/src/tools/workflows/list-workflows.ts#L6-L32","documentation":"list-workflows delegates to `listWorkflows(mastra)` (the storage-backed listing, including archived workflows) and requires a Mastra instance for storage access. It throws this Error when `mastra` is absent from the runtime context, because persisted workflow metadata cannot be read without it.","triggerScenarios":"Executing list-workflows with an executionContext lacking `mastra` — manual execute calls, custom runners, or tests with partial context mocks. Unlike list-available-workflows this also needs Mastra's storage layer, so an instance without configured storage may fail downstream too.","commonSituations":"Invoking the tool outside Mastra's server/agent runtime; test scaffolds that stub `{ requestContext }` only; running the tool in scripts that construct tools without ever creating a Mastra instance.","solutions":["Execute within a Mastra runtime so the context includes `mastra`.","For manual calls, pass `{ mastra }` in the second argument of execute.","Ensure the Mastra instance has storage configured, since this tool lists persisted workflows (active/archived).","In tests, initialize Mastra with storage (e.g. LibSQL/pg) and include it in the context."],"exampleFix":"// before\nawait listWorkflowsTool.execute({ status: 'active' }, { requestContext });\n// after\nconst mastra = new Mastra({ storage: new LibSQLStore({ url: 'file:./mastra.db' }) });\nawait listWorkflowsTool.execute({ status: 'active' }, { mastra, requestContext });","handlingStrategy":"try-catch","validationCode":"if (!ctx?.mastra) {\n  console.warn('Skipping list-workflows: no Mastra context (storage-backed listing unavailable).');\n} else if (!ctx.mastra.getConfig?.()?.storage) {\n  console.warn('Mastra instance has no storage; list-workflows may return nothing or fail.');\n}","typeGuard":"function canListStoredWorkflows(ctx: unknown): ctx is { mastra: Mastra } {\n  return (\n    typeof ctx === 'object' &&\n    ctx !== null &&\n    'mastra' in ctx &&\n    (ctx as any).mastra instanceof Mastra\n  );\n}","tryCatchPattern":"try {\n  const { workflows, total } = await listWorkflowsTool.execute({ status: 'active' }, ctx);\n} catch (err) {\n  if (err instanceof Error && err.message.includes('requires a Mastra context')) {\n    // initialize Mastra with storage and re-invoke, or degrade gracefully\n  } else throw err;\n}","preventionTips":["Configure storage on the Mastra instance before listing persisted workflows.","Always pass the same Mastra instance that owns your workflows into the tool context.","In scripts/tests, bootstrap Mastra (with storage) before tool execution.","Wrap tool executions in a helper that validates context presence and logs actionable errors."],"tags":["mastra","configuration","runtime-context","workflows"],"backgroundTag":"missing-mastra-context","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}