{"record":{"id":"16c682ec272e11bb","repo":"conductor-oss/conductor","slug":"failed-to-parse-sse-data-as-json-jsondata","errorCode":null,"errorMessage":"Failed to parse SSE data as JSON: {jsonData}","messagePattern":"Failed to parse SSE data as JSON: (.+?)","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"ai/src/main/java/org/conductoross/conductor/ai/mcp/MCPService.java","lineNumber":371,"sourceCode":"        for (String line : lines) {\n            String trimmed = line.trim();\n            if (trimmed.startsWith(\"data:\")) {\n                String data = trimmed.substring(5).trim();\n                // Skip empty data or \"[DONE]\" markers\n                if (!data.isEmpty() && !data.equals(\"[DONE]\")) {\n                    jsonData.append(data);\n                }\n            }\n        }\n\n        if (jsonData.length() == 0) {\n            throw new RuntimeException(\"No data found in SSE response: \" + sseBody);\n        }\n\n        try {\n            return objectMapper.readTree(jsonData.toString());\n        } catch (Exception e) {\n            throw new RuntimeException(\"Failed to parse SSE data as JSON: \" + jsonData, e);\n        }\n    }\n\n    /** Executes one MCP request and follows redirects while protecting sensitive headers. */\n    private ResponsePayload execute(Request initialRequest) throws Exception {\n        Request request = initialRequest;\n        for (int redirects = 0; redirects <= 5; redirects++) {\n            try (Response response = httpClient.newCall(request).execute()) {\n                if (!response.isRedirect()) {\n                    return new ResponsePayload(\n                            response.code(),\n                            response.header(\"Content-Type\", \"application/json\"),\n                            readBoundedBody(response.body()));\n                }\n                String location = response.header(\"Location\");\n                if (location == null || request.url().resolve(location) == null) {\n                    throw new RuntimeException(\n                            \"MCP server returned a redirect without a valid Location\");","sourceCodeStart":353,"sourceCodeEnd":389,"githubUrl":"https://github.com/conductor-oss/conductor/blob/cf7c3e4a8adfb158be778ab1ec525323c363cd3a/ai/src/main/java/org/conductoross/conductor/ai/mcp/MCPService.java#L353-L389","documentation":"Thrown by parseSseResponse when data: lines were found and concatenated but objectMapper.readTree failed to parse the result as JSON. The error includes the concatenated jsonData that failed. Means the SSE payload, after extraction, was not valid JSON (truncation, mixed content, or non-JSON data frames).","triggerScenarios":"SSE data: lines were partial JSON fragments that were concatenated incorrectly (this parser simply joins them, so multi-line JSON objects split across data: lines can mis-concatenate); server emitted NDJSON (multiple JSON objects) instead of one; data was truncated; data contained a non-JSON text payload.","commonSituations":"Server splits one JSON object across multiple `data:` lines without leading spaces (the code does .trim() on each, so the spec-mandated single leading space is lost and fragments may join wrong); server streaming multiple JSON values; proxy truncated the body.","solutions":["Inspect the concatenated jsonData in the message — if it looks like fragments joined without newlines, the server splits objects across data: lines and this parser mishandles them.","If multiple JSON objects appear, the server is emitting NDJSON; pick the JSON-RPC response object specifically.","Ensure the body wasn't truncated by the 10 MiB read limit (would surface as 175/176 instead).","Use a spec-compliant SSE client that reassembles multi-line data: fields correctly."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    mcpService.listTools(serverUrl, headers);\n} catch (RuntimeException e) {\n    if (e.getMessage().contains(\"Failed to parse SSE data as JSON\")) {\n        // concatenated data: lines were not valid JSON; inspect them (in message)\n    }\n    throw e;\n}","preventionTips":["Inspect the concatenated data in the message to spot multi-line-fragment or NDJSON issues.","Prefer servers that send each JSON-RPC response as a single data: line.","If the server splits objects across data: lines, consider a compliant SSE parser."],"tags":["mcp","sse","json-parse","malformed-response"],"backgroundTag":null,"analyzedSha":"cf7c3e4a8adfb158be778ab1ec525323c363cd3a","analyzedAt":"2026-08-14T03:33:19.897Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}