{"record":{"id":"fa0627eea3111778","repo":"mastra-ai/mastra","slug":"failed-to-load-prompts","errorCode":null,"errorMessage":"Failed to load prompts","messagePattern":"Failed to load prompts","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/mcp/src/server/server.ts","lineNumber":1438,"sourceCode":"        } catch (error) {\n          this.logger.error('Error fetching prompts via listPrompts():', {\n            error: error instanceof Error ? error.message : String(error),\n          });\n          throw error;\n        }\n      });\n    }\n\n    // Get prompt handler\n    if (capturedPromptOptions.getPromptMessages) {\n      serverInstance.setRequestHandler(\n        'prompts/get',\n        async (request: { params: { name: string; arguments?: any } }, ctx) => {\n          const startTime = Date.now();\n          const { name, arguments: args } = request.params;\n          const extra = toMCPRequestHandlerExtra(ctx);\n          const prompts = await capturedPromptOptions.listPrompts?.({ extra });\n          if (!prompts) throw new Error('Failed to load prompts');\n          for (const definedPrompt of prompts) {\n            PromptSchema.parse(definedPrompt);\n          }\n          // Select prompt by name\n          const prompt = prompts.find(p => p.name === name);\n          if (!prompt) throw new Error(`Prompt \"${name}\" not found`);\n          // Validate required arguments\n          if (prompt.arguments) {\n            for (const arg of prompt.arguments) {\n              if (arg.required && (args?.[arg.name] === undefined || args?.[arg.name] === null)) {\n                throw new ProtocolError(ProtocolErrorCode.InvalidParams, `Missing required argument: ${arg.name}`);\n              }\n            }\n          }\n          try {\n            let messages: any[] = [];\n            if (capturedPromptOptions.getPromptMessages) {\n              messages = await capturedPromptOptions.getPromptMessages({","sourceCodeStart":1420,"sourceCodeEnd":1456,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/mcp/src/server/server.ts#L1420-L1456","documentation":"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'.","triggerScenarios":"`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.","commonSituations":"listPrompts implementations that await a failing fetch inside try/catch then fall through without returning, or async functions conditionally returning only on success.","solutions":["Make `listPrompts` always return an array of prompts (return `[]` when none).","Inspect logs for errors inside listPrompts that were swallowed, causing the undefined return.","Confirm the prompts option is passed to the MCPServer if clients call prompts/get."],"exampleFix":"// before\nlistPrompts: async ({ extra }) => { try { return await fetchPrompts(); } catch {} }\n// after\nlistPrompts: async ({ extra }) => { try { return await fetchPrompts(); } catch (e) { logger.error(e); return []; } }","handlingStrategy":"validation","validationCode":"const result = await listPrompts({ extra }); if (!Array.isArray(result)) throw new Error('listPrompts must return an array');","typeGuard":"function returnsPromptList(v: unknown): v is { name: string }[] { return Array.isArray(v) && v.every(p => !!p && typeof (p as any).name === 'string'); }","tryCatchPattern":"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; }","preventionTips":["Always return an array from listPrompts, even on empty or degraded states.","Log and rethrow (or return []) rather than letting errors fall through to undefined.","Verify prompts/get works in integration tests before exposing prompts to clients."],"tags":["mcp","prompts","callback"],"backgroundTag":"callback-returned-undefined","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}