{"record":{"id":"1dd64e1354d06f80","repo":"Tencent/WeKnora","slug":"failed-to-list-resources-w-1dd64e","errorCode":null,"errorMessage":"failed to list resources: %w","messagePattern":"failed to list resources: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/mcp/client.go","lineNumber":455,"sourceCode":"\t\t}\n\t}\n\n\treturn tools, nil\n}\n\n// ListResources retrieves the list of available resources\nfunc (c *mcpGoClient) ListResources(ctx context.Context) ([]*types.MCPResource, error) {\n\tif !c.initialized {\n\t\treturn nil, ErrNotConnected\n\t}\n\n\treq := mcp.ListResourcesRequest{}\n\tresult, err := oauthCall(ctx, c, func() (*mcp.ListResourcesResult, error) {\n\t\treturn c.client.ListResources(ctx, req)\n\t})\n\tif err != nil {\n\t\tc.checkErrorAndDisconnectIfNeeded(err)\n\t\treturn nil, fmt.Errorf(\"failed to list resources: %w\", err)\n\t}\n\n\t// Convert to our types\n\tresources := make([]*types.MCPResource, len(result.Resources))\n\tfor i, resource := range result.Resources {\n\t\tresources[i] = &types.MCPResource{\n\t\t\tURI:         resource.URI,\n\t\t\tName:        resource.Name,\n\t\t\tDescription: resource.Description,\n\t\t\tMimeType:    resource.MIMEType,\n\t\t}\n\t}\n\n\treturn resources, nil\n}\n\n// CallTool calls a tool on the MCP service\nfunc (c *mcpGoClient) CallTool(ctx context.Context, name string, args map[string]interface{}) (*CallToolResult, error) {","sourceCodeStart":437,"sourceCodeEnd":473,"githubUrl":"https://github.com/Tencent/WeKnora/blob/988cbb03305e055d8ebb7d46d9ac6cc0803cd074/internal/mcp/client.go#L437-L473","documentation":"ListResources wraps errors from c.client.ListResources after initialize. The resources/list RPC failed — dropped session, JSON-RPC error (most often 'method not supported' because the server doesn't implement resources), timeout, or transport failure. The client may have been marked disconnected by checkErrorAndDisconnectIfNeeded before returning.","triggerScenarios":"ListResources called on an initialized client where the server does not support the resources capability, the session/connection was lost, or the context timed out during the RPC.","commonSituations":"Calling ListResources against a tools-only MCP server (very common — many servers implement tools but not resources); expired session on a reused long-lived client; proxy cutting idle streamable connections.","solutions":["Check the server's initialize capabilities include resources before calling; treat 'not supported' as an empty result rather than an error","Reconnect (Connect + Initialize) and retry if the session was lost","Raise the timeout if the resource listing is slow","Verify proxy/LB idle-timeout settings for long-lived connections"],"exampleFix":"// before\nresources, err := c.ListResources(ctx)\nif err != nil { return nil, err }\n// after\nif !c.serverSupportsResources() { // check InitializeResult capabilities\n    return []*types.MCPResource{}, nil\n}\nresources, err := c.ListResources(ctx)\nif err != nil { return nil, fmt.Errorf(\"list resources: %w\", err) }","handlingStrategy":"fallback","validationCode":"func listResourcesIfSupported(ctx context.Context, c MCPClient) ([]*types.MCPResource, error) {\n    resources, err := c.ListResources(ctx)\n    if err != nil && (errors.Is(err, ErrNotConnected) || strings.Contains(err.Error(), \"failed to list resources\")) {\n        // treat unsupported/failed resource listing as empty rather than fatal\n        return []*types.MCPResource{}, nil\n    }\n    return resources, err\n}","typeGuard":"func isListResourcesFailure(err error) bool {\n    return err != nil && strings.Contains(err.Error(), \"failed to list resources\")\n}","tryCatchPattern":"resources, err := c.ListResources(ctx)\nif err != nil {\n    if isListResourcesFailure(err) && !c.capabilities.Resources {\n        log.Info(\"server does not support resources; skipping\")\n        return nil, nil\n    }\n    return reconnectAndListResources(ctx, c)\n}","preventionTips":["Check the resources capability from the initialize result before calling ListResources","Handle tools-only servers gracefully in discovery code","Reconnect-and-retry once on session-loss errors before surfacing the failure"],"tags":["go","mcp","rpc","resources","capability"],"backgroundTag":"mcp-request-failed","analyzedSha":"988cbb03305e055d8ebb7d46d9ac6cc0803cd074","analyzedAt":"2026-09-02T14:41:08.344Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}