{"record":{"id":"c080eb92a21df910","repo":"mastra-ai/mastra","slug":"failed-to-fetch-prompts-from-server-this-client","errorCode":null,"errorMessage":"Failed to fetch prompts from server ${this.client.name}: ${e instanceof Error ? e.stack || e.message : String(e)}","messagePattern":"Failed to fetch prompts from server (.+?): (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/mcp/src/client/actions/prompt.ts","lineNumber":66,"sourceCode":"      if (response && response.prompts && Array.isArray(response.prompts)) {\n        return response.prompts.map(prompt => ({ ...prompt }));\n      } else {\n        this.logger.warn('Prompts response did not have expected structure', {\n          server: this.client.name,\n          response,\n        });\n        return [];\n      }\n    } catch (e: any) {\n      // MCP Server might not support prompts, so we return an empty array\n      if (e.code === ProtocolErrorCode.MethodNotFound) {\n        return [];\n      }\n      this.logger.error('Error getting prompts from server', {\n        server: this.client.name,\n        error: e instanceof Error ? e.message : String(e),\n      });\n      throw new Error(\n        `Failed to fetch prompts from server ${this.client.name}: ${e instanceof Error ? e.stack || e.message : String(e)}`,\n      );\n    }\n  }\n\n  /**\n   * Retrieves a specific prompt with its messages from the MCP server.\n   *\n   * Prompts can accept arguments to parameterize the template. The returned messages\n   * can be used directly in AI chat completions.\n   *\n   * @param params - Parameters for the prompt request\n   * @param params.name - Name of the prompt to retrieve\n   * @param params.args - Optional arguments to populate the prompt template\n   * @returns Promise resolving to the prompt result with messages\n   * @throws {Error} If fetching the prompt fails or prompt not found\n   *\n   * @example","sourceCodeStart":48,"sourceCodeEnd":84,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/mcp/src/client/actions/prompt.ts#L48-L84","documentation":"InternalMastraMCPClient's prompts.list() calls the MCP server's prompts/list request inside a try/catch. On any failure (transport error, server error response, JSON-RPC error) it logs the error and rethrows it wrapped in this Error, preserving the original message or stack. It is a catch-all wrapper indicating the prompt listing round-trip with the named MCP server did not succeed.","triggerScenarios":"Calling client.prompts.list() when the underlying MCP request throws — server unreachable, connection dropped mid-request, server returns a JSON-RPC error, or request times out.","commonSituations":"MCP server process crashed or was restarted; stdio server binary missing; network/timeout issues with remote HTTP servers; server not fully initialized when list is called.","solutions":["Read the inner error (stack/message preserved in the thrown Error) to identify the root cause","Verify the MCP server is running and reachable (check stdio command or url)","Call list() only after the client successfully connected (await connect() / check connection state)","Add retry with backoff around prompts.list() for transient network failures"],"exampleFix":"// before\nconst prompts = await client.prompts.list();\n// after\ntry {\n  const prompts = await client.prompts.list();\n} catch (e) {\n  logger.error('prompts/list failed:', e instanceof Error ? e.stack : e);\n  // reconnect or retry\n}","handlingStrategy":"try-catch","validationCode":"if (!client.isConnected()) await client.connect();\nconst prompts = await client.prompts.list();","typeGuard":null,"tryCatchPattern":"try {\n  const prompts = await client.prompts.list();\n} catch (e) {\n  logger.error('prompts/list failed for server', e instanceof Error ? e.stack : String(e));\n  // check inner cause: reconnect or surface to caller\n  throw e;\n}","preventionTips":["Always await connect() and check connection state before listing","Wrap MCP list calls in retry-with-backoff for transient failures","Monitor server health/logs when list calls start failing"],"tags":["mcp","network","prompts","wrapped-error"],"backgroundTag":"failed-to-fetch-from-server","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}