mastra-ai/mastra · error · Error
Failed to load resources
Error message
Failed to load resources
What it means
On a `resources/read` request, the MCPServer calls the configured `listResources` callback (per-caller, respecting auth) to resolve the resource list. If that callback returns undefined/null, the server cannot resolve any resources and throws 'Failed to load resources'.
Source
Thrown at packages/mcp/src/server/server.ts:1308
return { resources };
} catch (error) {
this.logger.error('Error fetching resources', { error });
throw error;
}
});
}
// Read resource handler
if (capturedResourceOptions.getResourceContent) {
serverInstance.setRequestHandler('resources/read', async (request, ctx) => {
const startTime = Date.now();
const uri = request.params.uri;
this.logger.debug('Handling ReadResource request', { uri });
// Resolve the resource list for the current caller's `extra` on every request
// rather than from a shared cache, so URI resolution respects per-caller auth.
const resources = await capturedResourceOptions.listResources?.({ extra: toMCPRequestHandlerExtra(ctx) });
if (!resources) throw new Error('Failed to load resources');
const resource = resources.find(r => r.uri === uri);
if (!resource) {
this.logger.warn('Unknown resource URI requested', { uri });
throw new ProtocolError(ProtocolErrorCode.InvalidParams, `Resource not found: ${uri}`);
}
try {
const resourcesOrResourceContent = await capturedResourceOptions.getResourceContent({
uri,
extra: toMCPRequestHandlerExtra(ctx),
});
const resourcesContent = Array.isArray(resourcesOrResourceContent)
? resourcesOrResourceContent
: [resourcesOrResourceContent];
// Preserve the resource's `_meta` on the read contents. MCP Apps hosts
// read the UI CSP (connectDomains) from `contents[]._meta.ui.csp`, so
// dropping it here silently ignores appResources CSP config.View on GitHub (pinned to 75dd419e61)
Solutions
- Ensure your `listResources` callback always returns an array of resources (return `[]` when there are none).
- Check server logs above this error for an exception inside listResources that was caught and turned into a bare return.
- Verify the resources option is actually passed when constructing the MCPServer if clients will call resources/read.
Example fix
// before
listResources: async ({ extra }) => { await db.connect(); }
// after
listResources: async ({ extra }) => { const rows = await db.getResources(); return rows.map(toMcpResource); } Defensive patterns
Strategy: validation
Validate before calling
if (typeof listResources !== 'function') throw new Error('listResources must be provided'); const result = await listResources({ extra }); if (!Array.isArray(result)) throw new Error('listResources must return an array'); Type guard
function returnsResourceList(v: unknown): v is { resources: { uri: string }[] } { return !!v && Array.isArray((v as any).resources ?? v); } Try / catch
try { const content = await client.readResource({ uri }); } catch (e) { if (String(e?.message) === 'Failed to load resources') { logger.error('server listResources returned undefined; check server callback'); } throw e; } Prevention
- Always `return []` from listResources instead of falling through after errors.
- Never swallow exceptions inside listResources without returning.
- Smoke-test resources/list before advertising resources/read to clients.
When it happens
Trigger: `capturedResourceOptions.listResources?.({ extra })` returns undefined — i.e. your listResources implementation has no return statement, returns undefined on an error path, or no listResources was provided but a read was attempted on a handler path requiring it.
Common situations: Custom listResources implementations that swallow errors in a try/catch and fall through without returning, async callbacks whose result is discarded, or resources option omitted while clients still issue resources/read.
Related errors
- Failed to fetch resources from server ${this.client.name}: $
- Failed to fetch resource templates from server ${this.client
- MCP_CLIENT_READ_RESOURCE_FAILED
- MCP_CLIENT_SUBSCRIBE_RESOURCE_FAILED
- MCP_CLIENT_UNSUBSCRIBE_RESOURCE_FAILED
AI-assisted analysis of mastra-ai/mastra@75dd419e61 (2026-08-30).
Data as JSON: /api/errors/4e5c3a06b9adc1ac.
Report an issue: GitHub.