From 67bc972e7c0e9093797e41148541abce7869ffa9 Mon Sep 17 00:00:00 2001 From: Max Isbey <224885523+maxisbey@users.noreply.github.com> Date: Thu, 1 Oct 2026 12:57:01 +0000 Subject: [PATCH] Make the deeply nested body test independent of stack size The test posted a well-formed 100,000-deep JSON array and asserted PARSE_ERROR, which only holds where json.loads hits its recursion guard. On CPython 3.14 with a large enough C stack the body parses, the server correctly answers INVALID_REQUEST, and the assertion fails. Leave the body unterminated so it is unparseable on every interpreter: RecursionError where the guard trips, JSONDecodeError where the scanner reaches the end of input. The server maps both to 400 + PARSE_ERROR. Fixes #3146 --- tests/server/test_streamable_http_modern.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/server/test_streamable_http_modern.py b/tests/server/test_streamable_http_modern.py index 11e775840f..2558872545 100644 --- a/tests/server/test_streamable_http_modern.py +++ b/tests/server/test_streamable_http_modern.py @@ -1139,8 +1139,9 @@ async def broken_list(ctx: ServerRequestContext, params: PaginatedRequestParams async def test_modern_post_with_deeply_nested_body_is_parse_error_not_a_crash() -> None: - """Deep nesting makes json.loads raise RecursionError; still an unparseable body: 400 + PARSE_ERROR.""" - body = b"[" * 100_000 + b"]" * 100_000 + """Unterminated deep nesting makes json.loads raise RecursionError or, where the stack is deep enough + to reach the end of input, JSONDecodeError; an unparseable body either way: 400 + PARSE_ERROR.""" + body = b"[" * 100_000 async with _asgi_client(_x_mcp_server()) as http: response = await http.post("/mcp", content=body, headers={"content-type": "application/json"}) assert response.status_code == 400