{"record":{"id":"51571b6164b91733","repo":"CherryHQ/cherry-studio","slug":"failed-to-get-resource-uri-from-server-serve","errorCode":null,"errorMessage":"Failed to get resource ${uri} from server: ${server.name}: ${error.message}","messagePattern":"Failed to get resource (.+?) from server: (.+?): (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/main/ai/mcp/McpRuntimeService.ts","lineNumber":1467,"sourceCode":"    const client = await this.getOrCreateClient(server)\n    try {\n      const result = await client.readResource({ uri: uri })\n      const contents: McpResource[] = []\n      if (result.contents && result.contents.length > 0) {\n        result.contents.forEach((content: any) => {\n          contents.push({\n            ...content,\n            serverId: server.id,\n            serverName: server.name\n          })\n        })\n      }\n      return {\n        contents: contents\n      }\n    } catch (error: any) {\n      getServerLogger(server, { uri }).error(`Failed to get resource`, error as Error)\n      throw new Error(`Failed to get resource ${uri} from server: ${server.name}: ${error.message}`)\n    }\n  }\n\n  /**\n   * Get a specific resource from an MCP server with caching\n   */\n  @TraceMethod({ spanName: 'getResource', tag: 'mcp' })\n  public async getResource({ serverId, uri }: { serverId: string; uri: string }): Promise<GetResourceResponse> {\n    const server = this.getServerById(serverId)\n    const cachedGetResource = withCache<[McpServer, string], GetResourceResponse>(\n      this.getResourceImpl.bind(this),\n      (server, uri) => {\n        const serverKey = this.getServerKey(server)\n        return `mcp:get_resource:${serverKey}:${uri}`\n      },\n      30 * 60 * 1000, // 30 minutes TTL\n      `[MCP] Resource ${uri} from ${server.name}`\n    )","sourceCodeStart":1449,"sourceCodeEnd":1485,"githubUrl":"https://github.com/CherryHQ/cherry-studio/blob/726446b54cd69ffe51a276638672f6d95ca0768c/src/main/ai/mcp/McpRuntimeService.ts#L1449-L1485","documentation":"Thrown when reading a resource from an MCP server fails. The `getResourceImpl` method calls `client.readResource()` and catches any error, wrapping it with the URI and server name for context. The error is also logged via getServerLogger before being thrown.","triggerScenarios":"Calling `getResource({ serverId, uri })` where the server's readResource handler fails — invalid URI format, resource doesn't exist on the server, server-side processing error, or the client connection dropped mid-request.","commonSituations":"The URI is malformed or references a non-existent resource; the MCP server has a bug in its resource handler; the server disconnected between the resource list call and the resource read; permissions issue on the server side; the resource is temporarily unavailable.","solutions":["Check the detailed server logs (emitted before the throw) for the original error.message","Verify the URI is valid and was obtained from a prior `listResources` call","Confirm the server is still connected — a stale client may need reconnection","If the resource is server-specific, consult the server's documentation for supported URI schemes","Wrap the call in try-catch and fall back gracefully if the resource is optional"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  const result = await runtime.getResource({ serverId, uri })\n  return result\n} catch (e) {\n  if (e instanceof Error && e.message.startsWith('Failed to get resource')) {\n    logger.warn(`Resource ${uri} unavailable on ${server.name}`)\n    return { contents: [] }  // graceful degradation\n  }\n  throw e\n}","preventionTips":["Verify the URI came from a prior listResources call — don't construct URIs manually","Handle resource read failures gracefully — resources are often optional context","Cache resource lists to avoid stale URIs after server reconnection"],"tags":["mcp","resource","server-error","runtime"],"backgroundTag":null,"analyzedSha":"726446b54cd69ffe51a276638672f6d95ca0768c","analyzedAt":"2026-08-12T17:30:37.448Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}