mastra-ai/mastra · error · Error
Mock resource content not found for ${uri}
Error message
Mock resource content not found for ${uri} What it means
This mock MCP weather server's getResourceContent looks up the requested URI in the hardcoded weatherResourceContents map and throws when the URI is absent. It means the client requested a resource URI that the mock server does not provide — a URI mismatch between client and the server's advertised definitions.
Source
Thrown at packages/mcp/src/__fixtures__/weather.ts:152
{
name: 'forecast',
version: '1.0',
description: 'Get weather forecast for a location',
},
{
name: 'historical',
version: '1.0',
description: 'Get historical weather data for a location',
},
];
const mcpServerResources: MCPServerResources = {
listResources: async () => weatherResourceDefinitions,
getResourceContent: async ({ uri }: { uri: string }) => {
if (weatherResourceContents[uri]) {
return weatherResourceContents[uri];
}
throw new Error(`Mock resource content not found for ${uri}`);
},
resourceTemplates: async () => weatherResourceTemplatesDefinitions,
};
const mcpServerPrompts: MCPServerPrompts = {
listPrompts: async () => weatherPrompts,
getPromptMessages: async ({
name,
version: _version,
}: {
name: string;
version?: string;
}): Promise<PromptMessage[]> => {
const content = weatherPromptContents[name];
if (!content) {
throw new Error(`Mock prompt not found for ${name}`);
}
return [View on GitHub (pinned to 75dd419e61)
Solutions
- List resources first (listResources) and use an exact URI from that list.
- Add the missing URI to weatherResourceContents in the fixture if your test legitimately needs it.
- Check for typos or scheme mismatches (e.g. weather:// vs https://).
- If using a resource template, verify the expanded parameters map to a registered content entry or add a fallback handler.
Example fix
// before
const content = await server.getResourceContent({ uri: "weather://current/london" });
// after
const resources = await server.listResources();
const uri = resources[0].uri; // e.g. "weather://current/san-francisco"
const content = await server.getResourceContent({ uri }); Defensive patterns
Strategy: type-guard
Validate before calling
// Before reading content, confirm the URI is advertised:
const resources = await client.listResources();
const known = new Set(resources.map(r => r.uri));
if (!known.has(uri)) throw new Error(`Unknown resource URI: ${uri}; known: ${[...known].join(', ')}`); Type guard
function isKnownResourceUri(uri: string, definitions: Array<{ uri: string }>): boolean {
return definitions.some(d => d.uri === uri);
} Try / catch
try {
const content = await client.getResourceContent({ uri });
} catch (e) {
if (e instanceof Error && e.message.startsWith('Mock resource content not found')) {
const resources = await client.listResources();
console.error(`URI ${uri} not in mock. Available:`, resources.map(r => r.uri));
return null; // or re-request with a valid URI
}
throw e;
} Prevention
- Always derive URIs from listResources()/listResourceTemplates(), never hardcode them in tests.
- Keep fixture content maps in sync with resource definitions.
- For template URIs, register content for every parameter expansion your tests exercise.
- On URI mismatch, log the available URIs to make drift obvious in CI.
When it happens
Trigger: Calling getResourceContent({ uri }) with a URI not present in weatherResourceContents: fabricated URIs, typos, URIs from a different server, or resource templates instantiated with parameter values that have no pre-baked content in the mock.
Common situations: Tests hardcoding URIs that drift from weatherResourceDefinitions; clients enumerating templates and requesting template-expanded URIs the mock never registered; copy-pasting real production URIs into the mock-based test environment.
Understand the failure class
Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.
Related errors
- Structure mismatch in snapshot: Expected: ${expectedStructu
- Snapshot has ${mismatches.length} mismatch${mismatches.lengt
- No arguments provided
- Invalid arguments for firecrawl_scrape
- Invalid arguments for firecrawl_map
AI-assisted analysis of mastra-ai/mastra@75dd419e61 (2026-08-30).
Data as JSON: /api/errors/09dfa17ab0421846.
Report an issue: GitHub.