fix(ingest): parse docmark's SSE-framed response, not bare JSON
Found via a real live-cluster end-to-end test (POST /ingest-path with a real
.docx against the deployed ingestion + docmark): 'decode docmark response:
invalid character e looking for beginning of value'. docmark's Streamable-HTTP
transport frames every response as SSE (event: message\r\ndata: {...}\r\n\r\n,
Content-Type: text/event-stream) -- stateless_http=True removes the need for
an initialize handshake/session ID, it does NOT change the wire framing to
bare JSON. My original client + its own test mock both assumed bare JSON,
so the unit tests passed while the real call failed.
sseDataPayload() extracts the data: line before JSON-unmarshaling; falls back
to the raw body if no SSE framing is present (forward-compatible). Test mock
(docmark_test.go) now emits the SAME framing the live server actually sends,
confirmed by directly probing docmark's live response before writing the fix.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -30,9 +30,17 @@ type mcpToolResult struct {
|
||||
} `json:"error,omitempty"`
|
||||
}
|
||||
|
||||
// writeMCPResponse mirrors docmark's REAL response framing (empirically
|
||||
// confirmed against the live server): Content-Type: text/event-stream,
|
||||
// body is SSE-framed ("event: message\r\ndata: {...}\r\n\r\n"), not bare
|
||||
// JSON -- inherent to MCP Streamable-HTTP, independent of stateless_http.
|
||||
func writeMCPResponse(w http.ResponseWriter, body mcpToolResult) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
_ = json.NewEncoder(w).Encode(body)
|
||||
payload, _ := json.Marshal(body)
|
||||
w.Header().Set("Content-Type", "text/event-stream")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
_, _ = w.Write([]byte("event: message\r\ndata: "))
|
||||
_, _ = w.Write(payload)
|
||||
_, _ = w.Write([]byte("\r\n\r\n"))
|
||||
}
|
||||
|
||||
func TestExtractViaDocmark_Success(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user