{"record":{"id":"32e185e9cb8534be","repo":"mastra-ai/mastra","slug":"no-mastra-units-agents-workflows-tools-found-i","errorCode":null,"errorMessage":"No Mastra units (agents, workflows, tools) found in template.\n          Possible causes:\n          - Template may not follow standard Mastra structure\n          - AI agent couldn't analyze template files (model/token limits)\n          - Template is empty or in wrong branch\n\n          Debug steps:\n          - Check template has files in src/mastra/ directories\n          - Try a different branch\n          - Check template repository structure manually","messagePattern":"No Mastra units \\(agents, workflows, tools\\) found in template\\.\n          Possible causes:\n          - Template may not follow standard Mastra structure\n          - AI agent couldn't analyze template files \\(model/token limits\\)\n          - Template is empty or in wrong branch\n\n          Debug steps:\n          - Check template has files in src/mastra/ directories\n          - Try a different branch\n          - Check template repository structure manually","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/agent-builder/src/workflows/template-builder/template-builder.ts","lineNumber":302,"sourceCode":"      // Add MCP servers\n      template.mcp?.forEach((mcpId: { name: string; file: string }) => {\n        units.push({ kind: 'mcp-server', id: mcpId.name, file: mcpId.file });\n      });\n\n      // Add networks\n      template.networks?.forEach((networkId: { name: string; file: string }) => {\n        units.push({ kind: 'network', id: networkId.name, file: networkId.file });\n      });\n\n      // Add other files\n      template.other?.forEach((otherId: { name: string; file: string }) => {\n        units.push({ kind: 'other', id: otherId.name, file: otherId.file });\n      });\n\n      console.info('Discovered units:', JSON.stringify(units, null, 2));\n\n      if (units.length === 0) {\n        throw new Error(`No Mastra units (agents, workflows, tools) found in template.\n          Possible causes:\n          - Template may not follow standard Mastra structure\n          - AI agent couldn't analyze template files (model/token limits)\n          - Template is empty or in wrong branch\n\n          Debug steps:\n          - Check template has files in src/mastra/ directories\n          - Try a different branch\n          - Check template repository structure manually`);\n      }\n\n      return {\n        units,\n        success: true,\n      };\n    } catch (error) {\n      console.error('Failed to discover units:', error);\n      return {","sourceCodeStart":284,"sourceCodeEnd":320,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/agent-builder/src/workflows/template-builder/template-builder.ts#L284-L320","documentation":"After cloning a template and running AI-assisted discovery of Mastra units (agents, workflows, tools), the template-builder workflow throws this detailed error when zero units were found. It indicates the analysis produced an empty unit list — either the template has no src/mastra structure, or the AI analysis step failed to identify units within model/token limits.","triggerScenarios":"Cloning a repository that is not a Mastra template (no src/mastra directories); pointing at a wrong branch that lacks unit files; the discovery agent returning empty/partial output because of token limits or a bad model; template files failing to be read during analysis.","commonSituations":"Using the builder against a random/non-Mastra repo; a template restructured so agents/workflows/tools no longer live in src/mastra; discovery model failing silently on large repos; cloning `main` when the Mastra code is on another branch.","solutions":["Verify the repository actually is a Mastra template with files under src/mastra/ (agents, workflows, tools)","Try a different `ref`/branch — the error message itself suggests this","Inspect the repo manually and confirm agents/workflows/tools exist and are structured conventionally","Use a stronger/valid model for the discovery step (see error 837) — analysis failures may have caused the empty list","Check run logs/Studio traces for the 'Discovered units' line to see what the analysis found before concluding the template is invalid"],"exampleFix":"// before\nawait builder.start({ triggerData: { repo: 'https://github.com/user/random-repo', ref: 'main' } });\n\n// after\nawait builder.start({\n  triggerData: { repo: 'https://github.com/mastra-ai/template-weather-app', ref: 'main' }, // real Mastra template\n});","handlingStrategy":"try-catch","validationCode":"import { existsSync, readdirSync } from 'node:fs';\nimport { join } from 'node:path';\n// after cloning targetPath:\nconst mastraDir = join(targetPath, 'src', 'mastra');\nif (!existsSync(mastraDir)) {\n  throw new Error(`Target repo has no src/mastra directory; not a Mastra template`);\n}","typeGuard":null,"tryCatchPattern":"try {\n  await builder.start({ triggerData: { repo, ref } });\n} catch (e) {\n  if (e instanceof Error && e.message.includes('No Mastra units')) {\n    // verify src/mastra structure, try another branch/ref, or use a known Mastra template\n  } else throw e;\n}","preventionTips":["Only point the builder at repositories with a standard src/mastra layout","Confirm the chosen branch contains the unit files before running","Review the 'Discovered units' log line to distinguish empty templates from analysis failures","Use a capable model for template analysis to avoid token-limit failures"],"tags":["template-analysis","empty-result","workflow"],"backgroundTag":"template-analysis-empty","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}