{"record":{"id":"1f8fb01598f336b9","repo":"vercel/ai","slug":"mcp-app-resource-not-found-in-read-result-uri","errorCode":null,"errorMessage":"MCP App resource not found in read result: ${uri}","messagePattern":"MCP App resource not found in read result: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/mcp/src/tool/mcp-apps.ts","lineNumber":240,"sourceCode":"        .filter((uri): uri is string => uri != null),\n    ),\n  ];\n}\n\n/**\n * Extracts app HTML and rendering metadata from a `resources/read` result.\n */\nexport function getMCPAppResourceFromReadResult({\n  uri,\n  resource,\n}: {\n  uri: string;\n  resource: ReadResourceResult;\n}): MCPAppResource {\n  const content = resource.contents.find(content => content.uri === uri);\n\n  if (content == null) {\n    throw new Error(`MCP App resource not found in read result: ${uri}`);\n  }\n\n  if (content.mimeType !== MCP_APP_MIME_TYPE) {\n    throw new Error(\n      `Unsupported MCP App resource MIME type: ${content.mimeType}`,\n    );\n  }\n\n  const html =\n    'text' in content && typeof content.text === 'string'\n      ? content.text\n      : 'blob' in content && typeof content.blob === 'string'\n        ? new TextDecoder().decode(convertBase64ToUint8Array(content.blob))\n        : undefined;\n\n  if (html == null) {\n    throw new Error(`Unsupported MCP App resource content format: ${uri}`);\n  }","sourceCodeStart":222,"sourceCodeEnd":258,"githubUrl":"https://github.com/vercel/ai/blob/69428b1f8b037e4d118fb4853428d5c4e620493c/packages/mcp/src/tool/mcp-apps.ts#L222-L258","documentation":"Thrown by getMCPAppResourceFromReadResult after calling resources/read on an MCP App UI resource: the result contents array contained no entry whose uri matches the requested uri. The read succeeded at the transport level, but the server did not return the expected resource content for that exact URI.","triggerScenarios":"Calling readMCPAppResource (or accessing an MCP App's resource) for a uri where the MCP server's read handler returns contents with a different/normalized uri, an empty contents array, or content for a substituted URI.","commonSituations":"MCP server registering the resource under one ui:// URI but returning contents with a rewritten or relative uri; server bugs where the read handler returns an empty contents array; URI string mismatches from trailing slashes, encoding, or case differences.","solutions":["Fix the MCP server's resources/read handler to return a contents entry whose uri exactly equals the requested uri.","Verify the resource is registered (resources/list) under the exact uri being read.","Check for URI normalization mismatches (encoding, trailing slash, case) between client and server.","If the server intentionally redirects/renames, return the resource under the originally requested uri instead of a substituted one."],"exampleFix":"// before (server read handler)\nreturn { contents: [{ uri: 'ui://server/app.html.js', mimeType: 'text/html', text }] };\n// after\nreturn { contents: [{ uri: requestedUri, mimeType: 'text/html', text }] };","handlingStrategy":"try-catch","validationCode":"const listed = await client.listResources();\nif (!listed.resources.some(r => r.uri === uri)) {\n  throw new Error(`Server does not expose resource ${uri}; check resources/list`);\n}","typeGuard":null,"tryCatchPattern":"let resource;\ntry {\n  resource = await readMCPAppResource({ client, uri });\n} catch (e) {\n  if (e instanceof Error && e.message.startsWith('MCP App resource not found in read result')) {\n    console.error(`MCP server returned no content for ${uri}; verify resources/read handler and URI match`);\n    throw e;\n  }\n  throw e;\n}","preventionTips":["Ensure the server's read handler echoes back the exact requested uri in contents.","Verify registration via resources/list before reading app resources.","Watch for URI normalization drift (encoding, case, trailing slashes) between client and server.","Add integration tests that read every registered ui:// resource and assert content is returned."],"tags":["mcp","resource-not-found","mcp-apps","uri"],"backgroundTag":"resource-not-found","analyzedSha":"69428b1f8b037e4d118fb4853428d5c4e620493c","analyzedAt":"2026-08-30T12:32:21.016Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}