@devries-cameron20 / t3code Mirror · read-only / commits / 36371de910
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 18:30 UTC

fix(shared): read MCP event streams whatever the case of the content type (#35815)

Julius Marminge committed Nov 12, 2026 at 18:45 UTC 36371de9106921ac61c0a3a41d13f4f985518d41
2 files changed +24 -2
packages/shared/src/mcpResponsePayloads.test.ts
+22
@@ -69,3 +69,25 @@ it.effect("reads SSE line endings across byte-chunk boundaries without splitting
69 }
70 }),
71 );
72 +
73 +it.effect("picks the SSE reader from the media type alone, whatever its case", () =>
74 + Effect.gen(function* () {
75 + const response = new Response('data: {"id":1}\n\n', {
76 + headers: { "content-type": "Text/Event-Stream; charset=utf-8" },
77 + });
78 + const payloads = yield* Stream.runCollect(
79 + responsePayloads(response, (cause) => ({ _tag: "ResponsePayloadError" as const, cause })),
80 + );
81 + expect(Array.from(payloads)).toEqual([{ id: 1 }]);
82 +
83 + const json = new Response('{"jsonrpc":"2.0","id":1,"result":{}}', {
84 + headers: {
85 + "content-type": 'application/json; profile="https://example.com/Text/Event-Stream"',
86 + },
87 + });
88 + const jsonPayloads = yield* Stream.runCollect(
89 + responsePayloads(json, (cause) => ({ _tag: "ResponsePayloadError" as const, cause })),
90 + );
91 + expect(Array.from(jsonPayloads)).toEqual([{ jsonrpc: "2.0", id: 1, result: {} }]);
92 + }),
93 +);
packages/shared/src/mcpResponsePayloads.ts
+2 -2
@@ -35,8 +35,8 @@ export function responsePayloads<E>(
35 if (response.status === 202 || response.status === 204) {
36 return Stream.unwrap(discardResponseBody(response).pipe(Effect.as(Stream.empty)));
37 }
38 - const contentType = response.headers.get("content-type") ?? "";
39 - if (contentType.includes("text/event-stream")) {
38 + const mediaType = (response.headers.get("content-type") ?? "").split(";", 1)[0]!.trim();
39 + if (mediaType.toLowerCase() === "text/event-stream") {
40 return Stream.fromAsyncIterable(sseDataLines(response), onError).pipe(
41 Stream.mapEffect((data) => Effect.try({ try: () => JSON.parse(data), catch: onError })),
42 );