{"record":{"id":"785572683b5be5c6","repo":"mastra-ai/mastra","slug":"get-workflow-requires-a-mastra-context","errorCode":null,"errorMessage":"get-workflow requires a Mastra context.","messagePattern":"get-workflow requires a Mastra context\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"mastracode/sdk/src/tools/workflows/get-workflow.ts","lineNumber":24,"sourceCode":"import { z } from 'zod';\nimport { getWorkflow } from '../../workflows/service.js';\n\nexport const getWorkflowTool = createTool({\n  id: 'get-workflow',\n  description: 'Return the full stored definition of a workflow (input/output schemas + the step graph).',\n  inputSchema: z.object({\n    id: z.string().describe('The workflow id.'),\n  }),\n  outputSchema: z.object({\n    id: z.string(),\n    description: z.string().optional(),\n    status: z.enum(['active', 'archived']),\n    inputSchema: z.any().optional(),\n    outputSchema: z.any().optional(),\n    graph: z.array(z.any()).optional(),\n  }),\n  execute: async ({ id }, { mastra }) => {\n    if (!mastra) throw new Error('get-workflow requires a Mastra context.');\n    const def = await getWorkflow(mastra as Mastra, id);\n    if (!def) throw new Error(`No workflow with id \"${id}\".`);\n    return {\n      id: def.id,\n      description: def.description,\n      status: def.status,\n      inputSchema: def.inputSchema,\n      outputSchema: def.outputSchema,\n      graph: def.graph,\n    };\n  },\n});\n","sourceCodeStart":6,"sourceCodeEnd":37,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/mastracode/sdk/src/tools/workflows/get-workflow.ts#L6-L37","documentation":"get-workflow's execute needs the Mastra instance from the execution context to load the workflow definition. If mastra is undefined, this error is thrown before the storage lookup. It means the tool ran outside a properly initialized Mastra runtime.","triggerScenarios":"Calling get-workflow with an execution context where { mastra } is undefined — direct execute() invocation or non-Mastra runner.","commonSituations":"Unit tests with incomplete contexts; standalone scripts calling tool.execute(); tool consumed outside the Mastra server.","solutions":["Run the tool through the Mastra runtime so mastra is injected into the context.","In tests, supply { mastra: mastraInstance } as the execution context.","Ensure the tool is registered on and fetched from the Mastra instance."],"exampleFix":"// before\nawait getWorkflowTool.execute({ id }, {} as any);\n// after\nawait getWorkflowTool.execute({ id }, { mastra });","handlingStrategy":"try-catch","validationCode":"if (!mastra) throw new Error('get-workflow invoked without a Mastra instance');","typeGuard":"function hasMastraContext(ctx: unknown): ctx is { mastra: Mastra } { return !!ctx && typeof ctx === 'object' && 'mastra' in ctx && ctx.mastra != null; }","tryCatchPattern":"try { const def = await tool.execute({ id }, { mastra }); } catch (e) { if (e.message.includes('requires a Mastra context')) { /* re-run inside the Mastra runtime */ } else throw e; }","preventionTips":["Register the tool on the Mastra instance and call it via the runtime.","Use a shared test fixture providing { mastra } contexts.","Avoid ad-hoc execute() calls in scripts."],"tags":["mastra-context","misconfiguration","workflows"],"backgroundTag":"missing-mastra-context","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}