mastra-ai/mastra · error · Error

Prompt "${name}" not found

Error message

Prompt "${name}" not found

What it means

MCPServer.getPrompt() looks up a registered prompt by exact name match from the prompt definitions loaded by the server's getPrompts callback. This plain Error is thrown when no prompt whose `name` property equals the requested `name` exists. The library throws it early so the request fails before argument validation or prompt rendering is attempted.

Source

Thrown at packages/mcp/src/server/server.ts:1444

      });
    }

    // Get prompt handler
    if (capturedPromptOptions.getPromptMessages) {
      serverInstance.setRequestHandler(
        'prompts/get',
        async (request: { params: { name: string; arguments?: any } }, ctx) => {
          const startTime = Date.now();
          const { name, arguments: args } = request.params;
          const extra = toMCPRequestHandlerExtra(ctx);
          const prompts = await capturedPromptOptions.listPrompts?.({ extra });
          if (!prompts) throw new Error('Failed to load prompts');
          for (const definedPrompt of prompts) {
            PromptSchema.parse(definedPrompt);
          }
          // Select prompt by name
          const prompt = prompts.find(p => p.name === name);
          if (!prompt) throw new Error(`Prompt "${name}" not found`);
          // Validate required arguments
          if (prompt.arguments) {
            for (const arg of prompt.arguments) {
              if (arg.required && (args?.[arg.name] === undefined || args?.[arg.name] === null)) {
                throw new ProtocolError(ProtocolErrorCode.InvalidParams, `Missing required argument: ${arg.name}`);
              }
            }
          }
          try {
            let messages: any[] = [];
            if (capturedPromptOptions.getPromptMessages) {
              messages = await capturedPromptOptions.getPromptMessages({
                name,
                version: prompt.version,
                args,
                extra,
              });
            }

View on GitHub (pinned to 75dd419e61)

Solutions

  1. Call the prompts/list (or getPrompts result) and verify the exact prompt name before requesting it
  2. Fix the name spelling/casing to match the prompt's `name` field exactly
  3. If you own the server, confirm the getPrompts callback still returns the prompt and that PromptSchema.parse succeeded for it (a malformed sibling prompt throws earlier with 'Failed to load prompts' or schema errors)
  4. If the client caches prompt lists, refresh the list after server restarts or deploys

Example fix

// before
const { messages } = await server.getPrompt('code_review', { file: 'a.ts' });
// after
const prompts = await server.listPrompts(); // or handle prompts/list first
if (!prompts.some(p => p.name === 'code_review')) {
  throw new Error('code_review prompt is not registered on this server');
}
const { messages } = await server.getPrompt('code_review', { file: 'a.ts' });
Defensive patterns

Strategy: validation

Validate before calling

const prompts = await getPrompts(); // same source the server uses
if (!prompts?.some(p => p.name === requestedName)) {
  throw new Error(`Prompt '${requestedName}' is not available. Available: ${prompts?.map(p => p.name).join(', ')}`);
}

Try / catch

try {
  const result = await server.getPrompt(name, args);
} catch (e) {
  if (e instanceof Error && e.message.includes('not found')) {
    // fall back to refreshed prompt list / user-facing 'prompt unavailable'
  } else throw e;
}

Prevention

When it happens

Trigger: Calling server.getPrompt(name, args) (or handling an MCP prompts/get request) with a prompt name that is not among the names returned by the getPrompts callback; typos or casing differences (matching is exact ===) between the requested name and the defined prompt name.

Common situations: Client requests a prompt that was renamed or removed; prompt names are generated dynamically (e.g. prefixed) while the client caches an old list; case mismatch like 'CodeReview' vs 'codereview'; a listPrompts response was stale after the server restarted with different prompt definitions.

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/b4dc99205ae59acd. Report an issue: GitHub.