mastra-ai/mastra · error · Error
Failed to fetch prompts from server ${this.client.name}: ${e
Error message
Failed to fetch prompts from server ${this.client.name}: ${e instanceof Error ? e.stack || e.message : String(e)} What it means
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.
Source
Thrown at packages/mcp/src/client/actions/prompt.ts:66
if (response && response.prompts && Array.isArray(response.prompts)) {
return response.prompts.map(prompt => ({ ...prompt }));
} else {
this.logger.warn('Prompts response did not have expected structure', {
server: this.client.name,
response,
});
return [];
}
} catch (e: any) {
// MCP Server might not support prompts, so we return an empty array
if (e.code === ProtocolErrorCode.MethodNotFound) {
return [];
}
this.logger.error('Error getting prompts from server', {
server: this.client.name,
error: e instanceof Error ? e.message : String(e),
});
throw new Error(
`Failed to fetch prompts from server ${this.client.name}: ${e instanceof Error ? e.stack || e.message : String(e)}`,
);
}
}
/**
* Retrieves a specific prompt with its messages from the MCP server.
*
* Prompts can accept arguments to parameterize the template. The returned messages
* can be used directly in AI chat completions.
*
* @param params - Parameters for the prompt request
* @param params.name - Name of the prompt to retrieve
* @param params.args - Optional arguments to populate the prompt template
* @returns Promise resolving to the prompt result with messages
* @throws {Error} If fetching the prompt fails or prompt not found
*
* @exampleView on GitHub (pinned to 75dd419e61)
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
Example fix
// before
const prompts = await client.prompts.list();
// after
try {
const prompts = await client.prompts.list();
} catch (e) {
logger.error('prompts/list failed:', e instanceof Error ? e.stack : e);
// reconnect or retry
} Defensive patterns
Strategy: try-catch
Validate before calling
if (!client.isConnected()) await client.connect(); const prompts = await client.prompts.list();
Try / catch
try {
const prompts = await client.prompts.list();
} catch (e) {
logger.error('prompts/list failed for server', e instanceof Error ? e.stack : String(e));
// check inner cause: reconnect or surface to caller
throw e;
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Failed to fetch resources from server ${this.client.name}: $
- Failed to fetch resource templates from server ${this.client
- Could not connect to server with any available HTTP transpor
- MCP_CLIENT_GET_PROMPT_FAILED
- MCP_CLIENT_ON_LIST_CHANGED_PROMPT_FAILED
AI-assisted analysis of mastra-ai/mastra@75dd419e61 (2026-08-30).
Data as JSON: /api/errors/c080eb92a21df910.
Report an issue: GitHub.