{"record":{"id":"09dfa17ab0421846","repo":"mastra-ai/mastra","slug":"mock-resource-content-not-found-for-uri","errorCode":null,"errorMessage":"Mock resource content not found for ${uri}","messagePattern":"Mock resource content not found for (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/mcp/src/__fixtures__/weather.ts","lineNumber":152,"sourceCode":"  {\n    name: 'forecast',\n    version: '1.0',\n    description: 'Get weather forecast for a location',\n  },\n  {\n    name: 'historical',\n    version: '1.0',\n    description: 'Get historical weather data for a location',\n  },\n];\n\nconst mcpServerResources: MCPServerResources = {\n  listResources: async () => weatherResourceDefinitions,\n  getResourceContent: async ({ uri }: { uri: string }) => {\n    if (weatherResourceContents[uri]) {\n      return weatherResourceContents[uri];\n    }\n    throw new Error(`Mock resource content not found for ${uri}`);\n  },\n  resourceTemplates: async () => weatherResourceTemplatesDefinitions,\n};\n\nconst mcpServerPrompts: MCPServerPrompts = {\n  listPrompts: async () => weatherPrompts,\n  getPromptMessages: async ({\n    name,\n    version: _version,\n  }: {\n    name: string;\n    version?: string;\n  }): Promise<PromptMessage[]> => {\n    const content = weatherPromptContents[name];\n    if (!content) {\n      throw new Error(`Mock prompt not found for ${name}`);\n    }\n    return [","sourceCodeStart":134,"sourceCodeEnd":170,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/mcp/src/__fixtures__/weather.ts#L134-L170","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nconst content = await server.getResourceContent({ uri: \"weather://current/london\" });\n// after\nconst resources = await server.listResources();\nconst uri = resources[0].uri; // e.g. \"weather://current/san-francisco\"\nconst content = await server.getResourceContent({ uri });","handlingStrategy":"type-guard","validationCode":"// Before reading content, confirm the URI is advertised:\nconst resources = await client.listResources();\nconst known = new Set(resources.map(r => r.uri));\nif (!known.has(uri)) throw new Error(`Unknown resource URI: ${uri}; known: ${[...known].join(', ')}`);","typeGuard":"function isKnownResourceUri(uri: string, definitions: Array<{ uri: string }>): boolean {\n  return definitions.some(d => d.uri === uri);\n}","tryCatchPattern":"try {\n  const content = await client.getResourceContent({ uri });\n} catch (e) {\n  if (e instanceof Error && e.message.startsWith('Mock resource content not found')) {\n    const resources = await client.listResources();\n    console.error(`URI ${uri} not in mock. Available:`, resources.map(r => r.uri));\n    return null; // or re-request with a valid URI\n  }\n  throw e;\n}","preventionTips":["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."],"tags":["mcp","mock","resource-not-found","testing"],"backgroundTag":"resource-not-found","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}