{"record":{"id":"72adbdc11477aaf8","repo":"can1357/oh-my-pi","slug":"mcp-resource-read-error-message","errorCode":null,"errorMessage":"MCP resource read error: ${message}","messagePattern":"MCP resource read error: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/coding-agent/src/internal-urls/mcp-protocol.ts","lineNumber":143,"sourceCode":"\n\t\tconst uri = extractResourceUri(url);\n\t\tlet targetServer = resolveTargetServer(mcpManager, uri);\n\t\tif (!targetServer) {\n\t\t\tawait Promise.allSettled(mcpManager.getConnectedServers().map(name => mcpManager.ensureServerResources(name)));\n\t\t\ttargetServer = resolveTargetServer(mcpManager, uri);\n\t\t}\n\t\tif (!targetServer) {\n\t\t\tthrow new Error(\n\t\t\t\t`No MCP server has resource \"${uri}\".\\n\\nAvailable resources:\\n${formatAvailableResources(mcpManager)}`,\n\t\t\t);\n\t\t}\n\n\t\tlet result: MCPResourceReadResult | undefined;\n\t\ttry {\n\t\t\tresult = await mcpManager.readServerResource(targetServer, uri);\n\t\t} catch (error) {\n\t\t\tconst message = error instanceof Error ? error.message : String(error);\n\t\t\tthrow new Error(`MCP resource read error: ${message}`);\n\t\t}\n\n\t\tif (!result) {\n\t\t\tthrow new Error(`Server \"${targetServer}\" returned no content for \"${uri}\".`);\n\t\t}\n\n\t\tconst textParts: string[] = [];\n\t\tfor (const item of result.contents) {\n\t\t\tif (item.text !== undefined && item.text !== null) {\n\t\t\t\ttextParts.push(item.text);\n\t\t\t} else if (item.blob) {\n\t\t\t\ttextParts.push(`[Binary content: ${item.mimeType ?? \"unknown\"}, base64 length ${item.blob.length}]`);\n\t\t\t}\n\t\t}\n\n\t\tconst content = textParts.length > 0 ? textParts.join(\"\\n---\\n\") : \"(empty resource)\";\n\t\treturn {\n\t\t\turl: url.href,","sourceCodeStart":125,"sourceCodeEnd":161,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/coding-agent/src/internal-urls/mcp-protocol.ts#L125-L161","documentation":"The handler found a server advertising the requested URI and called MCPManager.readServerResource, but the underlying MCP read request threw. The handler wraps the original error message in 'MCP resource read error: ...' so callers see which resource-read step failed while retaining the transport/protocol cause.","triggerScenarios":"The target MCP server rejects or fails the resources/read request: server crash or restart mid-call, transport (stdio/HTTP) failure, server-side permission error, malformed resource on the server, or timeout in the underlying SDK call.","commonSituations":"MCP server process died (bad dependency, OOM) between listing and reading; server requires auth that expired; server bug when serializing that particular resource; network drop for a remote (SSE/streamable-HTTP) MCP server.","solutions":["Read the wrapped inner message — it carries the actual cause; fix that (restart server, fix auth, repair network) and retry.","Restart or redeploy the MCP server that owns the resource, then re-list resources to confirm it is healthy.","Reproduce the read directly with the MCP server's own client/inspector to confirm whether it is a server-side bug to report upstream.","Add retry with backoff around transient transport failures when issuing mcp:// reads in automation."],"exampleFix":"// before\nconst res = await handler.resolve(url); // throws raw on flaky remote server\n// after\ntry {\n  const res = await handler.resolve(url);\n} catch (e) {\n  if (/read error: .*(timeout|ECONNRESET)/i.test(e.message)) {\n    await restartMcpServer(targetServer);\n    return handler.resolve(url); // one retry after recovery\n  }\n  throw e;\n}","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"for (let attempt = 0; attempt < 3; attempt++) {\n  try {\n    return await handler.resolve(url);\n  } catch (e) {\n    const msg = e instanceof Error ? e.message : String(e);\n    if (/^MCP resource read error:/.test(msg) && /timeout|ECONNRESET|EPIPE|not connected/i.test(msg)) {\n      await Bun.sleep(2 ** attempt * 500);\n      continue;\n    }\n    throw e;\n  }\n}\nthrow new Error(`MCP read failed after retries: ${url.href}`);","preventionTips":["Monitor MCP server processes and auto-restart on crash.","Keep auth credentials for remote MCP servers refreshed.","Retry transient transport errors with backoff before surfacing failures.","Test resource reads with the MCP inspector when adopting a new server."],"tags":["mcp","network","server-error","wrapper"],"backgroundTag":"mcp-resource-read-failed","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}