fix(server): answer a non-Request body with INVALID_REQUEST, not INVALID_PARAMS
Fixes #3557
Motivation and Context
A POST body that parsed as JSON but was not a JSON-RPC message was answered with -32602 (INVALID_PARAMS). There are no params to be invalid in that case, so JSON-RPC 2.0 reserves -32600 (INVALID_REQUEST) for it; -32602 misreports the failure to the client. This is the first of the two shapes in #3557.
The second shape (an unknown method answered with INVALID_PARAMS instead of METHOD_NOT_FOUND) no longer reproduces on main: request parsing moved from shared/session.py's receive loop to shared/jsonrpc_dispatcher.py, and server/runner.py answers an unknown method with METHOD_NOT_FOUND, so no change was needed there.
A batch body (a JSON array) keeps INVALID_PARAMS: the hosting conformance test test_malformed_and_batched_bodies_return_400 pins that code for unsupported batch bodies, and #3557's case is the non-Request object body.
How Has This Been Tested?
- New test
test_non_request_body_is_invalid_request(tests/shared/test_streamable_http.py): a{"foo": "bar"}body returns 400 with -32600; a batch array still returns 400 with -32602. - Full suite:
uv run --frozen pytest→ 5961 passed, 16 skipped, 1 xfailed, 0 failed. ruff check/ruff format --checkclean; pyright unchanged (34 pre-existing Windows-only diagnostics, same as unpatched main).
Breaking Changes
Clients keying on -32602 for a non-Request body will now see -32600, which is what the spec requires. The HTTP status and the message text are unchanged.
Types of changes
- Bug fix (non-breaking change which fixes an issue)
Checklist
- I am assigned to the linked issue (or it is labeled
help wanted, or I'm a maintainer) — not assigned yet - I have disclosed any AI assistance and can explain the change in my own words
AI disclosure: the diff was written with the ZCode agent; I reproduced the -32602 response with a test before the change, ran the full suite and linters locally, and verified the batch-body behavior the existing conformance test pins.