{"record":{"id":"63d1635589ee2586","repo":"can1357/oh-my-pi","slug":"server-targetserver-returned-no-content-for","errorCode":null,"errorMessage":"Server \"${targetServer}\" returned no content for \"${uri}\".","messagePattern":"Server \"(.+?)\" returned no content for \"(.+?)\"\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/coding-agent/src/internal-urls/mcp-protocol.ts","lineNumber":147,"sourceCode":"\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,\n\t\t\tcontent,\n\t\t\tcontentType: \"text/plain\",\n\t\t\tsize: Buffer.byteLength(content, \"utf-8\"),\n\t\t\tnotes: [`MCP server: ${targetServer}`],","sourceCodeStart":129,"sourceCodeEnd":165,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/coding-agent/src/internal-urls/mcp-protocol.ts#L129-L165","documentation":"readServerResource returned without throwing but yielded undefined — the MCP server that advertised the resource gave back no read result at all. The handler treats a missing result as a distinct failure from a thrown error, naming the specific server and URI so the misbehaving server is identifiable.","triggerScenarios":"A server whose resources/read handler returns nothing (undefined) instead of a contents array — typically a partially implemented or buggy MCP server, or a race where the server dropped the resource after advertising it and responds with an empty/absent result.","commonSituations":"Custom/in-house MCP servers where resources/read is stubbed or unimplemented; servers that advertise resources via templates but return nothing for unresolvable instances; version drift where a server upgrade changed read semantics.","solutions":["Inspect the server's resources/read implementation and make it return { contents: [...] } (use an empty contents array for genuinely empty resources) — this is a server bug.","Verify with the MCP inspector that the same URI also returns an empty read there, confirming the fault is server-side, then report/fix upstream.","If the resource was removed server-side, refresh the resource list and use a currently advertised URI.","On the client side, treat this message as 'server advertised but cannot serve' and fall back to re-listing resources."],"exampleFix":"// server side — before\nasync readResource(uri) { /* TODO */ }\n// after\nasync readResource(uri) {\n  const text = await loadResourceText(uri);\n  return { contents: [{ uri, text: text ?? \"\" }] };\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  return await handler.resolve(url);\n} catch (e) {\n  if (e instanceof Error && /^Server \".+\" returned no content/.test(e.message)) {\n    const server = e.message.match(/Server \"(.+)\" returned/)?.[1];\n    logger.warn(\"MCP server advertised resource but returned no result\", { server, url: url.href });\n    return null;\n  }\n  throw e;\n}","preventionTips":["Implement resources/read fully in custom MCP servers; never return undefined.","Validate new MCP servers with the inspector before relying on their resources.","Un-advertise resources the server cannot actually serve.","Pin and test server versions — upgrades can change read semantics."],"tags":["mcp","empty-response","server-bug"],"backgroundTag":"empty-server-response","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}