{"record":{"id":"f6413154c8dac15e","repo":"mastra-ai/mastra","slug":"no-workspace","errorCode":"NO_WORKSPACE","errorMessage":"Workspace not available. Ensure the agent has a workspace configured.","messagePattern":"Workspace not available\\. Ensure the agent has a workspace configured\\.","errorType":"error_code","errorClass":"WorkspaceNotAvailableError","httpStatus":null,"severity":"error","filePath":"packages/core/src/workspace/tools/helpers.ts","lineNumber":38,"sourceCode":" * strings (e.g. `\"10\"` instead of `10`), and a strict `z.number()` rejects\n * the call outright. Coerce unambiguous numeric strings; anything else\n * passes through unchanged so schema validation still reports it.\n */\nexport function coerceNumericString(value: unknown): unknown {\n  if (typeof value !== 'string') {\n    return value;\n  }\n  const trimmed = value.trim();\n  return NUMERIC_STRING_REGEX.test(trimmed) ? Number(trimmed) : value;\n}\n\n/**\n * Extract workspace from tool execution context.\n * Throws if workspace is not available.\n */\nexport function requireWorkspace(context: ToolExecutionContext): Workspace {\n  if (!context?.workspace) {\n    throw new WorkspaceNotAvailableError();\n  }\n  return context.workspace;\n}\n\n/**\n * Extract filesystem from workspace in tool execution context.\n * Throws if workspace or filesystem is not available.\n */\nexport function requireFilesystem(context: ToolExecutionContext): {\n  workspace: Workspace;\n  filesystem: WorkspaceFilesystem;\n} {\n  const workspace = requireWorkspace(context);\n  if (!workspace.filesystem) {\n    throw new FilesystemNotAvailableError();\n  }\n  return { workspace, filesystem: workspace.filesystem };\n}","sourceCodeStart":20,"sourceCodeEnd":56,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/core/src/workspace/tools/helpers.ts#L20-L56","documentation":"Thrown by requireWorkspace when tool execution context has no workspace. Every workspace tool calls this first; without a workspace there is no filesystem/sandbox to act on. WorkspaceNotAvailableError carries code NO_WORKSPACE.","triggerScenarios":"Executing a workspace tool via an agent (or directly) whose ToolExecutionContext lacks `workspace` — e.g. agent created without a workspace option, or tool invoked outside the standard agent pipeline.","commonSituations":"Forgetting `new Agent({ workspace })` configuration; calling tool.execute manually with a bare context; older integration paths that predate workspace injection.","solutions":["Pass a workspace when creating the agent: `new Agent({ name, model, workspace })`","If invoking the tool directly, include `workspace` in the execution context","Verify the agent pipeline/version actually injects workspace into tool context","Catch NO_WORKSPACE and return a clear setup message to the caller"],"exampleFix":"// before\nconst agent = new Agent({ name: 'a', model: 'openai/gpt-4o' });\n// after\nconst agent = new Agent({ name: 'a', model: 'openai/gpt-4o', workspace: myWorkspace });","handlingStrategy":"type-guard","validationCode":"if (!context?.workspace) {\n  throw new Error('Agent must be created with a workspace before using workspace tools');\n}","typeGuard":"function hasWorkspace(ctx: ToolExecutionContext | undefined): ctx is ToolExecutionContext & { workspace: Workspace } {\n  return !!ctx && !!ctx.workspace;\n}","tryCatchPattern":"try {\n  return await tool.execute(ctx);\n} catch (e: any) {\n  if (e?.code === 'NO_WORKSPACE' || /Workspace not available/i.test(e?.message ?? '')) {\n    return { error: 'Configure a workspace on the agent to use this tool.' };\n  }\n  throw e;\n}","preventionTips":["Always pass `workspace` when constructing agents that use workspace tools","Don't call tool.execute manually with partial contexts; go through the agent pipeline","Add a startup assertion that workspace injection works","Keep agent config and tool registrations in one checked module"],"tags":["configuration","workspace","missing-config","tools"],"backgroundTag":"missing-workspace-config","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}