Skip to content

Commit 67bc972

Browse files
committed
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
1 parent d639cf7 commit 67bc972

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

‎tests/server/test_streamable_http_modern.py‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1139,8 +1139,9 @@ async def broken_list(ctx: ServerRequestContext, params: PaginatedRequestParams
11391139

11401140

11411141
async def test_modern_post_with_deeply_nested_body_is_parse_error_not_a_crash() -> None:
1142-
"""Deep nesting makes json.loads raise RecursionError; still an unparseable body: 400 + PARSE_ERROR."""
1143-
body = b"[" * 100_000 + b"]" * 100_000
1142+
"""Unterminated deep nesting makes json.loads raise RecursionError or, where the stack is deep enough
1143+
to reach the end of input, JSONDecodeError; an unparseable body either way: 400 + PARSE_ERROR."""
1144+
body = b"[" * 100_000
11441145
async with _asgi_client(_x_mcp_server()) as http:
11451146
response = await http.post("/mcp", content=body, headers={"content-type": "application/json"})
11461147
assert response.status_code == 400

0 commit comments

Comments
 (0)