From 4e90d1f3a4a0602ca4e05ffbade1c02c5971e800 Mon Sep 17 00:00:00 2001 From: Siraj Luqman Date: Sun, 22 Nov 2026 17:46:17 +0800 Subject: [PATCH] Normalize MCP response Content-Type media type case-insensitively --- proofline/_mcp.py | 2 +- tests/test_http.py | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/proofline/_mcp.py b/proofline/_mcp.py index f80c5e00..1b4f43f3 100644 --- a/proofline/_mcp.py +++ b/proofline/_mcp.py @@ -49,7 +49,7 @@ def _decode(response: httpx2.Response, identity: int | None) -> dict[str, Any]: if response.content: raise _refused() return {} - if response.headers.get("content-type", "").split(";")[0].strip() != "application/json": + if response.headers.get("content-type", "").split(";")[0].strip().lower() != "application/json": raise _refused() try: value = response.json() diff --git a/tests/test_http.py b/tests/test_http.py index 0af9d60f..1264c5c4 100644 --- a/tests/test_http.py +++ b/tests/test_http.py @@ -2586,3 +2586,31 @@ def respond(request: Request, index: int) -> Reply: assert len(exported.rows) == 1 assert exported.rows[0]["claim"] == row["claim"] assert exported.next_cursor == "next-page" + + +@MODES +@pytest.mark.parametrize("content_type", ["Application/JSON", "APPLICATION/JSON; charset=utf-8"]) +async def test_mcp_accepts_case_insensitive_content_type(mode: str, content_type: str) -> None: + def respond(request: Request, index: int) -> Reply: + body = json.loads(request.body) + if body["method"] == "initialize": + return Reply( + body={"jsonrpc": "2.0", "id": 1, "result": {"protocolVersion": "2025-11-25"}}, + headers={"Content-Type": content_type}, + ) + if body["method"] == "notifications/initialized": + return Reply(status=202, body=b"") + return Reply( + body={ + "jsonrpc": "2.0", + "id": 2, + "result": {"content": [{"type": "text", "text": "ok"}]}, + }, + headers={"Content-Type": content_type}, + ) + + with Server(respond) as server: + async with session(mode, server.url) as client: + mcp_client = client.mcp if mode == "sync" else client.mcp + res = await call(mcp_client, "list_organizations") + assert res["content"] == [{"type": "text", "text": "ok"}]