fix: reply -32700 on stdio parse errors instead of closing#833
fix: reply -32700 on stdio parse errors instead of closing#833alexhancock merged 2 commits intomainfrom
Conversation
69b254b to
93873ad
Compare
| // Hardcoded bytes because `RequestId` has no `Null` variant — we can't | ||
| // build an `id: null` JsonRpcError through the typed codec. | ||
| const PARSE_ERROR_RESPONSE: &[u8] = | ||
| b"{\"jsonrpc\":\"2.0\",\"error\":{\"code\":-32700,\"message\":\"Parse error\"},\"id\":null}\n"; |
There was a problem hiding this comment.
is there really no way to build something we can serialize to get this value instead of hardcoding it?
There was a problem hiding this comment.
Great question, @alexhancock! This was a workaround because JsonRpcError requires its id field and RequestId has no null variant.
I looked into the JSON RPC spec and the MCP spec. I noticed that the MCP spec separated the Response schema into ResultResponse and ErrorResponse in the 2025-11-25 version to match the JSON RPC spec.
| 2025-06-18 | 2025-11-25 |
|---|---|
![]() |
![]() |
As seen above, the id field is required for ResultResponse while is optional for ErrorResponse. I checked other SDKs, and they all follow this, so I updated our JsonRpcError::id struct to be optional.
rust-sdk/crates/rmcp/src/model.rs
Lines 462 to 470 in 690df59
cc503e7 to
b3858c0
Compare
3295a39 to
bebee77
Compare
bebee77 to
690df59
Compare


Fixes #825
Motivation and Context
The RMCP stdio transport used to close the stream silently when it encountered a malformed line. This made it hard for clients to tell the difference between a parse failure and a normal end-of-file initiated by the peer. Just one bad byte could bring down the entire session.
Now, the stdio transport responds with a JSON-RPC
-32700 Parse errorwhen it receives a malformed line, instead of closing the stream silently. It also removes a leading UTF-8 BOM, so messages from Windows tools that have a BOM prefix can be parsed correctly.How Has This Been Tested?
Added new tests
Breaking Changes
None.
Types of changes
Checklist
Additional context