{"record":{"id":"e80c3490f1b7cdd6","repo":"microsoft/aspire","slug":"internalerror-errormessage-failed-to-fetch-structured-logs","errorCode":"InternalError","errorMessage":"{errorMessage: 'Failed to fetch structured logs: {ex.Message}' or dashboard API error message}","messagePattern":"(.+?)' or dashboard API error message\\}","errorType":"error_code","errorClass":"McpProtocolException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Cli/Mcp/Tools/ListStructuredLogsTool.cs","lineNumber":141,"sourceCode":"                {limitMessage}\n\n                # STRUCTURED LOGS DATA\n\n                {logsData}\n                \"\"\";\n\n            return new CallToolResult\n            {\n                Content = [new TextContentBlock { Text = text }]\n            };\n        }\n        catch (HttpRequestException ex)\n        {\n            logger.LogError(ex, \"Failed to fetch structured logs from Dashboard API\");\n            var errorMessage = dashboardInfoProvider.IsDirectConnection\n                ? await TelemetryCommandHelpers.GetDashboardApiErrorMessageAsync(ex, apiBaseUrl, httpClientFactory, logger, cancellationToken)\n                : $\"Failed to fetch structured logs: {ex.Message}\";\n            throw new McpProtocolException(errorMessage, McpErrorCode.InternalError);\n        }\n    }\n}\n","sourceCodeStart":123,"sourceCodeEnd":145,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Cli/Mcp/Tools/ListStructuredLogsTool.cs#L123-L145","documentation":"Thrown by ListStructuredLogsTool.CallToolAsync when the HTTP request to the Dashboard telemetry API fails with HttpRequestException. In direct-connection mode the error message is fetched from the dashboard API error helper; otherwise it becomes 'Failed to fetch structured logs: <ex.Message>'. Code is InternalError (-32603).","triggerScenarios":"The GET to the dashboard structured-logs endpoint throws HttpRequestException — dashboard not reachable, wrong apiBaseUrl, TLS failure, or the proxied (non-direct) connection dropped mid-request.","commonSituations":"Dashboard port changed or app restarted between discovery and the call; firewall/proxy blocking the dashboard URL; API token/endpoint stale after AppHost restart; container networking prevents reaching the dashboard base URL.","solutions":["Verify the dashboard URL is reachable (curl the apiBaseUrl) and the AppHost is running.","Restart the AppHost and retry so fresh dashboard URLs/token are obtained.","Check proxy/firewall/DNS settings blocking the dashboard endpoint.","Inspect the logged HttpRequestException ('Failed to fetch structured logs from Dashboard API') for the underlying socket/TLS error."],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// Verify the dashboard API endpoint answers before fetching logs\nusing var ping = await httpClient.GetAsync($\"{apiBaseUrl}\", HttpCompletionOption.ResponseHeadersRead, ct);\nif (!ping.IsSuccessStatusCode) { /* refresh dashboard info or restart AppHost */ }","typeGuard":null,"tryCatchPattern":"try\n{\n    await ListStructuredLogsAsync();\n}\ncatch (McpProtocolException ex) when (ex.Message.StartsWith(\"Failed to fetch structured logs\"))\n{\n    // Re-fetch dashboard info (URLs/token may be stale) and retry once\n    await RefreshDashboardInfoAsync();\n    await ListStructuredLogsAsync();\n}","preventionTips":["Refresh dashboard URLs/token after every AppHost restart.","Check network/proxy/firewall access to the dashboard endpoint.","Add bounded retry with backoff for transient HttpRequestExceptions.","Correlate failures with the CLI log line for the underlying socket/TLS error."],"tags":["mcp","http","dashboard-api","network","aspire-cli"],"backgroundTag":"http-request-failed","analyzedSha":"25830f84bd145686607ad00c057b3f84e2e51d43","analyzedAt":"2026-09-16T11:10:06.193Z","contentChangedAt":"2026-09-16T11:10:06.193Z","schemaVersion":2},"datasetVersion":"2026-09-21T04:17:39.646Z"}