From 607ccb0e72a51e12add23f0798c7951ce6a0f733 Mon Sep 17 00:00:00 2001 From: Sergio Duran Date: Fri, 20 Nov 2026 14:52:33 -0700 Subject: [PATCH 1/2] Compare Content-Type media types case-insensitively --- src/bridge.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/bridge.js b/src/bridge.js index a351220..73a299d 100644 --- a/src/bridge.js +++ b/src/bridge.js @@ -5,6 +5,8 @@ const REQUEST_LIMIT = 8192; const RESPONSE_LIMIT = 8 * 1024 * 1024; const object = (value) => value !== null && typeof value === "object" && !Array.isArray(value); const identity = (value) => typeof value === "string" || Number.isSafeInteger(value); +// RFC 9110: media types are case-insensitive. Parameters after ';' are ignored. +const mediaType = (value) => value?.split(";")[0].trim().toLowerCase(); class BridgeError extends Error { constructor(category, code = -32000, status) { @@ -75,7 +77,7 @@ async function post(frame, config, protocol, notification) { throw new BridgeError("http", -32000, response.status); } if (response.headers.has("mcp-session-id") || (!notification && - response.headers.get("content-type")?.split(";")[0].trim() !== "application/json")) { + mediaType(response.headers.get("content-type")) !== "application/json")) { await response.body?.cancel(); throw new BridgeError("transport"); } From e66ea2af2d7f2465edc6779f74446a5c0244f4f4 Mon Sep 17 00:00:00 2001 From: Sergio Duran Date: Fri, 20 Nov 2026 14:52:44 -0700 Subject: [PATCH 2/2] Compare Content-Type media types case-insensitively --- tests/bridge.test.js | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/tests/bridge.test.js b/tests/bridge.test.js index ec6a9ad..67c1f3e 100644 --- a/tests/bridge.test.js +++ b/tests/bridge.test.js @@ -135,3 +135,41 @@ test("pre-initialize probes are answered without ending the session", async (t) assert.deepEqual(outcome.responses[3], { jsonrpc: "2.0", id: 3, result: tools }); assert.deepEqual(fixture.requests.map((request) => request.method), ["initialize", "notifications/initialized", "tools/list"]); }); + +test("JSON Content-Type is compared case-insensitively, including a charset parameter", async (t) => { + const tools = { tools: [] }; + const result = { content: [{ type: "text", text: "ok" }] }; + const fixture = await server(t, (body, response) => { + const type = body.method === "tools/list" + ? "Application/JSON" + : "APPLICATION/JSON; charset=utf-8"; + response.writeHead(200, { "content-type": type }); + response.end(JSON.stringify({ + jsonrpc: "2.0", + id: body.id, + result: body.method === "tools/list" ? tools : result, + })); + }); + const outcome = await run(fixture.origin, [ + initialize, notification, + { jsonrpc: "2.0", id: 3, method: "tools/list" }, + call, + ]); + assert.equal(outcome.code, 0); + assert.equal(outcome.stderr, ""); + assert.deepEqual(outcome.responses[1].result, tools); + assert.deepEqual(outcome.responses[2].result, result); +}); + +test("SSE Content-Type is still refused when the media type differs only by case", async (t) => { + const fixture = await server(t, (_body, response) => { + response.writeHead(200, { "content-type": "TEXT/EVENT-STREAM" }); + return response.end("private-upstream-canary"); + }); + const outcome = await run(fixture.origin, [initialize, notification, call]); + assert.equal(outcome.code, 1); + assert.equal(outcome.responses.at(-1).error.code, -32000); + assert.equal(outcome.responses.at(-1).error.data.category, "transport"); + assert.ok(!JSON.stringify(outcome).includes("private-upstream-canary")); +}); +