mastra-ai/mastra · error

Template "${slug}" not found. Available templates: ${templat

Error message

Template "${slug}" not found. Available templates: ${templates.map(t => t.slug).join(', ')}

What it means

getMastraTemplate looks up a template by slug in the list returned by fetchMastraTemplates and throws 'Template "<slug>" not found. Available templates: ...' when no entry matches. The error message enumerates valid slugs, making it self-diagnosing.

Source

Thrown at packages/agent-builder/src/utils.ts:250

      description: string;
      githubUrl: string;
      tags: string[];
      agents: string[];
      workflows: string[];
      tools: string[];
    }>;
    return data;
  } catch (error) {
    throw new Error(`Failed to fetch Mastra templates: ${error instanceof Error ? error.message : String(error)}`);
  }
}

// Helper to get a specific template by slug
export async function getMastraTemplate(slug: string) {
  const templates = await fetchMastraTemplates();
  const template = templates.find(t => t.slug === slug);
  if (!template) {
    throw new Error(`Template "${slug}" not found. Available templates: ${templates.map(t => t.slug).join(', ')}`);
  }
  return template;
}

// Git commit tracking utility
export async function logGitState(targetPath: string, label: string): Promise<void> {
  try {
    // Skip if not a git repo
    if (!(await isInsideGitRepo(targetPath))) return;
    const gitStatusResult = await git(targetPath, 'status', '--porcelain');
    const gitLogResult = await git(targetPath, 'log', '--oneline', '-3');
    const gitCountResult = await git(targetPath, 'rev-list', '--count', 'HEAD');

    console.info(`📊 Git state ${label}:`);
    console.info('Status:', gitStatusResult.stdout.trim() || 'Clean working directory');
    console.info('Recent commits:', gitLogResult.stdout.trim());
    console.info('Total commits:', gitCountResult.stdout.trim());
  } catch (gitError) {

View on GitHub (pinned to 75dd419e61)

Solutions

  1. Read the 'Available templates:' list in the error and use one of the listed slugs exactly
  2. Call fetchMastraTemplates (or the templates tool) first and pick a slug from the live list at runtime
  3. Check for typos and exact casing in the slug
  4. If the slug worked before, refresh the templates list — the catalog may have changed; pin the agent-builder version matching that catalog

Example fix

// before
const tpl = await getMastraTemplate('weather-agent-template'); // guessed slug

// after
const all = await fetchMastraTemplates();
const tpl = all.find(t => t.slug === 'weather-agent-template') ?? all[0];
Defensive patterns

Strategy: validation

Validate before calling

const templates = await fetchMastraTemplates();
const valid = new Set(templates.map(t => t.slug));
if (!valid.has(slug)) {
  throw new Error(`Unknown template slug '${slug}'. Valid: ${[...valid].join(', ')}`);
}
const template = await getMastraTemplate(slug);

Prevention

When it happens

Trigger: Requesting a template (via the `template` tool or direct call) with a slug that does not exist in the fetched registry: a typo, a slug from an older/newer templates listing, or an assumption the slug equals the repo name rather than the registry's slug field.

Common situations: Agents hallucinating template slugs; hard-coded slugs from blog posts or old versions; the templates service updated its catalog so previously valid slugs disappeared; case sensitivity ('Weather-App' vs 'weather-app').

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


AI-assisted analysis of mastra-ai/mastra@75dd419e61 (2026-08-30). Data as JSON: /api/errors/3ece20a1ad3db6db. Report an issue: GitHub.