{"record":{"id":"b446f63db01eadcb","repo":"mastra-ai/mastra","slug":"list-available-workflows-requires-a-mastra-context","errorCode":null,"errorMessage":"list-available-workflows requires a Mastra context.","messagePattern":"list-available-workflows requires a Mastra context\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"mastracode/sdk/src/tools/workflows/list-available-workflows.ts","lineNumber":28,"sourceCode":"import { extractJsonSchema } from './extract-json-schema.js';\n\nexport const listAvailableWorkflowsTool = createTool({\n  id: 'list-available-workflows',\n  description:\n    'Returns the workflows currently registered on the Mastra instance (both code-defined and dynamic). The ids returned here are the only valid values you can put in `{ type: \"workflow\", workflowId }` graph entries. Each row includes `inputSchema` and `outputSchema` as JSON Schema — read them to know what shape the nested workflow expects and produces; never invent field names.',\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        inputSchema: z.any().optional(),\n        outputSchema: z.any().optional(),\n      }),\n    ),\n  }),\n  execute: async (_input, { mastra }) => {\n    if (!mastra) throw new Error('list-available-workflows requires a Mastra context.');\n    const all = (mastra as Mastra).listWorkflows?.() ?? {};\n    return {\n      workflows: Object.entries(all).map(([id, wf]) => {\n        const w = wf as { description?: string; inputSchema?: unknown; outputSchema?: unknown } | undefined;\n        return {\n          id,\n          description: w?.description,\n          inputSchema: extractJsonSchema(w?.inputSchema, 'input'),\n          outputSchema: extractJsonSchema(w?.outputSchema, 'output'),\n        };\n      }),\n    };\n  },\n});\n","sourceCodeStart":10,"sourceCodeEnd":43,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/mastracode/sdk/src/tools/workflows/list-available-workflows.ts#L10-L43","documentation":"list-available-workflows reads workflow definitions via `mastra.listWorkflows()`. Its execute throws this Error when the runtime context does not contain a `mastra` instance, since there is no workflow registry to inspect. The guard ensures the tool only runs inside a Mastra-managed runtime.","triggerScenarios":"Calling the tool's execute with a context object missing `mastra` — direct/manual invocation, non-Mastra harnesses, or test doubles without the Mastra instance.","commonSituations":"Embedding the SDK workflow tools in custom automation that bypasses Mastra's context injection; integration tests stubbing executionContext; invoking tools before Mastra is constructed (workflows not yet registered).","solutions":["Run the tool through a Mastra agent/server/Studio so `mastra` is present in the context.","When invoking manually, pass `{ mastra: new Mastra({ workflows: ... }) }` in the executionContext.","Register your workflows on the Mastra instance before executing the tool.","In tests, use a real Mastra instance in the context instead of an empty object."],"exampleFix":"// before\nawait tool.execute({}, {} as any);\n// after\nconst mastra = new Mastra({ workflows: { myWorkflow } });\nawait tool.execute({}, { mastra, requestContext });","handlingStrategy":"validation","validationCode":"const ok =\n  executionContext &&\n  typeof executionContext === 'object' &&\n  'mastra' in executionContext &&\n  executionContext.mastra != null &&\n  typeof executionContext.mastra.listWorkflows === 'function';\nif (!ok) throw new Error('Provide a Mastra instance in the execution context.');","typeGuard":"function isMastraExecContext(ctx: unknown): ctx is { mastra: Mastra; requestContext?: RequestContext } {\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 } = await tool.execute(input, ctx);\n} catch (err) {\n  if (err instanceof Error && err.message === 'list-available-workflows requires a Mastra context.') {\n    // inject a Mastra instance (with workflows registered) and retry\n  } else throw err;\n}","preventionTips":["Construct `new Mastra({ workflows: ... })` before executing workflow-related tools.","Never call tool.execute with an empty/partial context object in production code.","Centralize context creation (mastra + requestContext) in one helper.","Add an integration test asserting tools run with a fully-populated context."],"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"}