mastra-ai/mastra · error · Error
Failed to fetch resources from server ${this.client.name}: $
Error message
Failed to fetch resources from server ${this.client.name}: ${e instanceof Error ? e.stack || e.message : String(e)} What it means
InternalMastraMCPClient's resources.list() wraps any failure from the MCP resources/list request in this Error, logging the underlying message first. The thrown error preserves the original stack or message, indicating the resource listing round-trip with the named server failed.
Source
Thrown at packages/mcp/src/client/actions/resource.ts:67
if (response && response.resources && Array.isArray(response.resources)) {
return response.resources;
} else {
this.logger.warn('Resources response did not have expected structure', {
server: this.client.name,
response,
});
return [];
}
} catch (e: any) {
// MCP Server might not support resources, so we return an empty array
if (e.code === ProtocolErrorCode.MethodNotFound) {
return [];
}
this.logger.error('Error getting resources from server', {
server: this.client.name,
error: e instanceof Error ? e.message : String(e),
});
throw new Error(
`Failed to fetch resources from server ${this.client.name}: ${e instanceof Error ? e.stack || e.message : String(e)}`,
);
}
}
/**
* Retrieves all available resource templates from the connected MCP server.
*
* Resource templates are URI templates (RFC 6570) that describe dynamic resources.
* Returns an empty array if the server doesn't support resource templates.
*
* @returns Promise resolving to array of resource templates
* @throws {Error} If fetching resource templates fails (excluding MethodNotFound)
*
* @example
* ```typescript
* const templates = await client.resources.templates();
* templates.forEach(template => {View on GitHub (pinned to 75dd419e61)
Solutions
- Inspect the wrapped inner error for the root cause
- Confirm the server connection is alive (reconnect if needed)
- Check that the server declares the resources capability before listing
- Retry with backoff for transient connectivity problems
Example fix
// before
const resources = await client.resources.list();
// after
if (client.isConnected()) {
const resources = await client.resources.list();
} else {
await client.connect();
} Defensive patterns
Strategy: retry
Validate before calling
if (!client.isConnected()) await client.connect();
Try / catch
try {
const resources = await client.resources.list();
} catch (e) {
const cause = e instanceof Error ? e.stack || e.message : String(e);
logger.error('resources/list failed:', cause);
// retry with backoff or reconnect
} Prevention
- Add exponential backoff retries around resource listing
- Verify the server supports the resources capability before calling
- Reconnect the client on repeated failures
When it happens
Trigger: Calling client.resources.list() when the resources/list MCP request throws or returns an error — unreachable server, closed transport, JSON-RPC error response, or timeout.
Common situations: Remote MCP server temporarily down; auth token expired mid-session; stdio server exited; calling resources.list() on a server that never connected.
Related errors
- Failed to fetch resource templates from server ${this.client
- Failed to fetch prompts from server ${this.client.name}: ${e
- Could not connect to server with any available HTTP transpor
- MCP_CLIENT_READ_RESOURCE_FAILED
- MCP_CLIENT_SUBSCRIBE_RESOURCE_FAILED
AI-assisted analysis of mastra-ai/mastra@75dd419e61 (2026-08-30).
Data as JSON: /api/errors/fa87b4b7be509124.
Report an issue: GitHub.