{"record":{"id":"0039ac022e8fb2c5","repo":"mastra-ai/mastra","slug":"resource-not-found-uri","errorCode":null,"errorMessage":"Resource not found: ${uri}","messagePattern":"Resource not found: (.+?)","errorType":"exception","errorClass":"ProtocolError","httpStatus":null,"severity":"error","filePath":"packages/mcp/src/server/server.ts","lineNumber":1313,"sourceCode":"      });\n    }\n\n    // Read resource handler\n    if (capturedResourceOptions.getResourceContent) {\n      serverInstance.setRequestHandler('resources/read', async (request, ctx) => {\n        const startTime = Date.now();\n        const uri = request.params.uri;\n        this.logger.debug('Handling ReadResource request', { uri });\n\n        // Resolve the resource list for the current caller's `extra` on every request\n        // rather than from a shared cache, so URI resolution respects per-caller auth.\n        const resources = await capturedResourceOptions.listResources?.({ extra: toMCPRequestHandlerExtra(ctx) });\n        if (!resources) throw new Error('Failed to load resources');\n        const resource = resources.find(r => r.uri === uri);\n\n        if (!resource) {\n          this.logger.warn('Unknown resource URI requested', { uri });\n          throw new ProtocolError(ProtocolErrorCode.InvalidParams, `Resource not found: ${uri}`);\n        }\n\n        try {\n          const resourcesOrResourceContent = await capturedResourceOptions.getResourceContent({\n            uri,\n            extra: toMCPRequestHandlerExtra(ctx),\n          });\n          const resourcesContent = Array.isArray(resourcesOrResourceContent)\n            ? resourcesOrResourceContent\n            : [resourcesOrResourceContent];\n          // Preserve the resource's `_meta` on the read contents. MCP Apps hosts\n          // read the UI CSP (connectDomains) from `contents[]._meta.ui.csp`, so\n          // dropping it here silently ignores appResources CSP config.\n          const resourceMeta = resource._meta ? { _meta: resource._meta } : {};\n          const contents: (TextResourceContents | BlobResourceContents)[] = resourcesContent.map(resourceContent => {\n            if ('text' in resourceContent && resourceContent.text !== undefined) {\n              return {\n                uri: resource.uri,","sourceCodeStart":1295,"sourceCodeEnd":1331,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/mcp/src/server/server.ts#L1295-L1331","documentation":"After successfully listing resources, the server finds the resource whose `uri` matches the read request. If no entry matches, it logs a warning and throws an MCP ProtocolError with code InvalidParams and message `Resource not found: <uri>`.","triggerScenarios":"A `resources/read` for a URI that the server's `listResources` did not return — the URI is unknown, was filtered out by per-caller auth in listResources, or contains a typo/case mismatch.","commonSituations":"Clients caching a resource list from before the resource was removed, auth-scoped listResources hiding the resource from the current caller, or URI formatting differences (trailing slash, scheme case).","solutions":["Call resources/list as the same caller and confirm the URI appears; use that exact string.","Check listResources auth logic — the resource may be intentionally hidden for this caller's `extra`.","Compare URIs byte-for-byte (scheme, slashes, query, case) between the client request and the registered resource."],"exampleFix":"// before\nawait client.readResource({ uri: 'config://app/settings/' });\n// after: use the exact registered URI\nawait client.readResource({ uri: 'config://app/settings' });","handlingStrategy":"validation","validationCode":"const { resources } = await client.listResources(); if (!resources.find(r => r.uri === uri)) throw new Error(`unknown resource uri: ${uri}`);","typeGuard":"function resourceExists(uri: string, resources: { uri: string }[]): resources is { uri: string }[] { return resources.some(r => r.uri === uri); }","tryCatchPattern":"try { return await client.readResource({ uri }); } catch (e) { if (String(e?.message).startsWith('Resource not found')) { const { resources } = await client.listResources(); const match = resources.find(r => r.uri === uri); if (!match) logger.warn(`uri ${uri} not in current resource list`); } throw e; }","preventionTips":["Refresh the resource list rather than caching URIs across sessions.","Copy URIs exactly (including case, slashes, and query) from resources/list.","Remember listResources is auth-scoped: verify permissions for the calling identity."],"tags":["mcp","resources","not-found","protocol-error"],"backgroundTag":"resource-not-found","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}