{"record":{"id":"91c42135f24cd4c6","repo":"Tencent/WeKnora","slug":"failed-to-list-tools-w","errorCode":null,"errorMessage":"failed to list tools: %w","messagePattern":"failed to list tools: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/mcp/client.go","lineNumber":426,"sourceCode":"\t\t\tTitle:       result.ServerInfo.Title,\n\t\t\tDescription: result.ServerInfo.Description,\n\t\t},\n\t}, nil\n}\n\n// ListTools retrieves the list of available tools\nfunc (c *mcpGoClient) ListTools(ctx context.Context) ([]*types.MCPTool, error) {\n\tif !c.initialized {\n\t\treturn nil, ErrNotConnected\n\t}\n\n\treq := mcp.ListToolsRequest{}\n\tresult, err := oauthCall(ctx, c, func() (*mcp.ListToolsResult, error) {\n\t\treturn c.client.ListTools(ctx, req)\n\t})\n\tif err != nil {\n\t\tc.checkErrorAndDisconnectIfNeeded(err)\n\t\treturn nil, fmt.Errorf(\"failed to list tools: %w\", err)\n\t}\n\n\t// Convert to our types\n\ttools := make([]*types.MCPTool, len(result.Tools))\n\tfor i, tool := range result.Tools {\n\t\tdata, _ := json.Marshal(tool.InputSchema)\n\t\ttools[i] = &types.MCPTool{\n\t\t\tName:        tool.Name,\n\t\t\tDescription: tool.Description,\n\t\t\tInputSchema: data,\n\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) {","sourceCodeStart":408,"sourceCodeEnd":444,"githubUrl":"https://github.com/Tencent/WeKnora/blob/988cbb03305e055d8ebb7d46d9ac6cc0803cd074/internal/mcp/client.go#L408-L444","documentation":"ListTools wraps errors from c.client.ListTools after a successful initialize. It indicates the tools/list RPC failed: the connection dropped, the server returned a JSON-RPC error, the request timed out, or the server does not support the tools capability. checkErrorAndDisconnectIfNeeded runs first and may mark the client disconnected on fatal errors.","triggerScenarios":"ListTools called on an initialized client whose session has since expired/been closed by the server, whose context deadline expired mid-RPC, or whose server replies with a JSON-RPC error (e.g. capability not implemented).","commonSituations":"Long-lived client reused past the server's session timeout; server restarted between initialize and list tools; calling ListTools against a server that doesn't advertise the tools capability; idle SSE connection severed by a proxy/load balancer.","solutions":["Reconnect: call Connect + Initialize again (check for ErrNotConnected / disconnected state) and retry ListTools","Increase the AdvancedConfig.Timeout or use a shorter-lived context appropriate to the RPC","Verify the server advertises the tools capability in its initialize response","Check proxy/LB idle timeouts that kill long-lived SSE/streamable sessions"],"exampleFix":"// before\ntools, err := c.ListTools(ctx)\nif err != nil { return nil, err }\n// after\ntools, err := c.ListTools(ctx)\nif err != nil {\n    if rerr := reconnectAndInit(ctx, c); rerr != nil { return nil, rerr }\n    tools, err = c.ListTools(ctx)\n    if err != nil { return nil, err }\n}","handlingStrategy":"retry","validationCode":"func listToolsWithReconnect(ctx context.Context, c MCPClient) ([]*types.MCPTool, error) {\n    tools, err := c.ListTools(ctx)\n    if err == nil { return tools, nil }\n    _ = c.Disconnect()\n    if err := c.Connect(ctx); err != nil { return nil, err }\n    if _, err := c.Initialize(ctx); err != nil { return nil, err }\n    return c.ListTools(ctx)\n}","typeGuard":"func isListToolsFailure(err error) bool {\n    return err != nil && strings.Contains(err.Error(), \"failed to list tools\")\n}","tryCatchPattern":"tools, err := c.ListTools(ctx)\nif err != nil {\n    if errors.Is(err, ErrNotConnected) || isListToolsFailure(err) {\n        return listToolsWithReconnect(ctx, c) // single reconnect+retry\n    }\n    return nil, err\n}","preventionTips":["Keep clients short-lived or add periodic reconnects before server session expiry","Set proxy/LB idle timeouts longer than the longest expected RPC","Verify server tools capability in InitializeResult before listing"],"tags":["go","mcp","rpc","tools","connection-lost"],"backgroundTag":"mcp-request-failed","analyzedSha":"988cbb03305e055d8ebb7d46d9ac6cc0803cd074","analyzedAt":"2026-09-02T14:41:08.344Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}