mastra-ai/mastra · error · Error
Failed to fetch resource templates from server ${this.client
Error message
Failed to fetch resource templates from server ${this.client.name}: ${e instanceof Error ? e.stack || e.message : String(e)} What it means
InternalMastraMCPClient's resources.templates() wraps any failure from the MCP resources/templates/list request in this Error after logging it. It signals the resource-template listing round-trip with the named server did not succeed, with the underlying error preserved in the message/stack.
Source
Thrown at packages/mcp/src/client/actions/resource.ts:111
if (response && response.resourceTemplates && Array.isArray(response.resourceTemplates)) {
return response.resourceTemplates;
} else {
this.logger.warn('Resource templates 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 resource templates from server', {
server: this.client.name,
error: e instanceof Error ? e.message : String(e),
});
throw new Error(
`Failed to fetch resource templates from server ${this.client.name}: ${e instanceof Error ? e.stack || e.message : String(e)}`,
);
}
}
/**
* Reads the content of a specific resource from the MCP server.
*
* @param uri - URI of the resource to read (e.g., 'file://path/to/file.txt')
* @returns Promise resolving to the resource content
* @throws {Error} If reading the resource fails or resource not found
*
* @example
* ```typescript
* const result = await client.resources.read('file://data/config.json');
* console.log(result.contents[0].text); // Resource text content
* ```
*/View on GitHub (pinned to 75dd419e61)
Solutions
- Check the inner error for the true cause
- Confirm the server advertises resource template support; fall back to resources.list() if not
- Reconnect the client if the transport dropped
- Retry with backoff on transient failures
Example fix
// before
const templates = await client.resources.templates();
// after
try {
var templates = await client.resources.templates();
} catch (e) {
templates = await client.resources.list(); // fallback
} Defensive patterns
Strategy: fallback
Validate before calling
if (!client.isConnected()) await client.connect();
Try / catch
let templates;
try {
templates = await client.resources.templates();
} catch (e) {
logger.warn('templates/list failed, falling back to resources.list()', e instanceof Error ? e.message : e);
templates = await client.resources.list();
} Prevention
- Check server capabilities for resource template support before calling
- Provide a fallback to plain resources.list() for older servers
- Retry transient network failures with backoff
When it happens
Trigger: Calling client.resources.templates() when resources/templates/list throws — server unreachable, transport closed, JSON-RPC error, or the server does not support resource templates.
Common situations: Older MCP servers that predate the resource-templates capability; flaky network to a remote server; server restarted between connect() and the templates call.
Related errors
- Failed to fetch resources from server ${this.client.name}: $
- 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/eca7ba2fd7a32d44.
Report an issue: GitHub.