mastra-ai/mastra · error · Error

Failed to load prompts

Error message

Failed to load prompts

What it means

On a `prompts/get` request, the server resolves the prompt list by invoking the configured `listPrompts` callback with the caller's extra. If the callback returns undefined, no prompts can be resolved and the server throws 'Failed to load prompts'.

Source

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

        } catch (error) {
          this.logger.error('Error fetching prompts via listPrompts():', {
            error: error instanceof Error ? error.message : String(error),
          });
          throw error;
        }
      });
    }

    // 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({

View on GitHub (pinned to 75dd419e61)

Solutions

  1. Make `listPrompts` always return an array of prompts (return `[]` when none).
  2. Inspect logs for errors inside listPrompts that were swallowed, causing the undefined return.
  3. Confirm the prompts option is passed to the MCPServer if clients call prompts/get.

Example fix

// before
listPrompts: async ({ extra }) => { try { return await fetchPrompts(); } catch {} }
// after
listPrompts: async ({ extra }) => { try { return await fetchPrompts(); } catch (e) { logger.error(e); return []; } }
Defensive patterns

Strategy: validation

Validate before calling

const result = await listPrompts({ extra }); if (!Array.isArray(result)) throw new Error('listPrompts must return an array');

Type guard

function returnsPromptList(v: unknown): v is { name: string }[] { return Array.isArray(v) && v.every(p => !!p && typeof (p as any).name === 'string'); }

Try / catch

try { return await client.getPrompt({ name }); } catch (e) { if (String(e?.message) === 'Failed to load prompts') { logger.error('server listPrompts returned undefined; fix the callback return'); } throw e; }

Prevention

When it happens

Trigger: `capturedPromptOptions.listPrompts?.({ extra })` returns undefined — a custom listPrompts implementation with a missing return, an early return on an error path, or prompts options not supplied while a prompts/get arrives.

Common situations: listPrompts implementations that await a failing fetch inside try/catch then fall through without returning, or async functions conditionally returning only on success.

Related errors


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