mirror of
https://github.com/lukaszraczylo/traefik-llmgateway.git
synced 2026-10-13 04:58:50 +00:00
The federated /mcp endpoint ignored the Accept header and always returned application/json. A real MCP client that sends Accept: application/json, text/event-stream expects SSE framing. It fails with no data line in SSE response when it receives plain JSON instead. handleMCPFederated now negotiates the response format once per request from the Accept header. It threads the result through writeJSONRPCEnvelope, writeJSONRPCResult, and writeJSONRPCErrorResponse as an explicit parameter. A request with no Accept header, or one that omits text/event-stream, still gets byte-identical plain JSON. Only an explicit text/event-stream token in the Accept list switches the response to SSE framing. SSE framing is one data line carrying the JSON-RPC envelope, terminated by the required blank line. Error responses and every method path honor the negotiated format. Notification responses stay 202 with no body regardless of Accept. The SSE branch reuses sse.go newSSEWriter and writeData instead of a second encoder. writeData already writes the single-frame, correctly terminated shape this route needs. Adds a compiled test file with a captured pre-change JSON byte baseline. It also adds explicit SSE negotiation and framing tests. A new yaegi-check probe exercises both framings under the real interpreter.