{"record":{"id":"849843b0ca5d6aae","repo":"mastra-ai/mastra","slug":"delete-workflow-requires-a-mastra-context","errorCode":null,"errorMessage":"delete-workflow requires a Mastra context.","messagePattern":"delete-workflow requires a Mastra context\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"mastracode/sdk/src/tools/workflows/delete-workflow.ts","lineNumber":23,"sourceCode":" */\nimport type { Mastra } from '@mastra/core/mastra';\nimport { createTool } from '@mastra/core/tools';\nimport { z } from 'zod';\nimport { deleteWorkflow } from '../../workflows/service.js';\n\nexport const deleteWorkflowTool = createTool({\n  id: 'delete-workflow',\n  description:\n    'Remove a saved workflow from storage and unregister the live in-process Workflow instance. Idempotent. Subsequent save-workflow calls with the same id re-register cleanly.',\n  inputSchema: z.object({\n    id: z.string().describe('The workflow id to delete.'),\n  }),\n  outputSchema: z.object({\n    ok: z.literal(true),\n    id: z.string(),\n  }),\n  execute: async ({ id }, { mastra }) => {\n    if (!mastra) throw new Error('delete-workflow requires a Mastra context.');\n    return deleteWorkflow(mastra as Mastra, id);\n  },\n});\n","sourceCodeStart":5,"sourceCodeEnd":27,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/mastracode/sdk/src/tools/workflows/delete-workflow.ts#L5-L27","documentation":"delete-workflow's execute requires the Mastra instance from the tool execution context to perform the deletion. If mastra is undefined, this error is thrown before any lookup. It signals the tool ran outside an initialized Mastra runtime.","triggerScenarios":"Invoking delete-workflow with an execution context lacking mastra — direct execute() calls in tests or scripts, or running outside the Mastra server.","commonSituations":"Hand-rolled test harnesses with stub contexts; calling tool execute() directly; tool used in a non-Mastra runner.","solutions":["Execute the tool via the Mastra server/runtime so { mastra } is provided.","In tests, pass { mastra: mastraInstance } (real or mocked) as the second execute argument.","Register delete-workflow on the Mastra instance instead of invoking it standalone."],"exampleFix":"// before\nawait deleteWorkflowTool.execute({ id }, {} as any);\n// after\nawait deleteWorkflowTool.execute({ id }, { mastra });","handlingStrategy":"try-catch","validationCode":"if (!mastra) throw new Error('delete-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 { 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":["Invoke tools through the Mastra server, never standalone execute().","Pass a real/mocked Mastra instance in test contexts.","Centralize tool invocation in one helper that guarantees the context."],"tags":["mastra-context","misconfiguration","workflows"],"backgroundTag":"missing-mastra-context","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T08:17:16.595Z"}