fix: don't respond to unparseable messages#940
Open
tsouth89 wants to merge 2 commits into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #938.
When rmcp receives invalid JSON on the stdio / async-read-write transport, it replies with
{"jsonrpc":"2.0","id":null,"error":{"code":-32700,"message":"Parse error"}}. As reported in the issue, rmcp is the only official MCP SDK that responds to unparseable input, and responding can cause an error storm: if the peer treats the response itself as invalid data and answers with another error, the two sides bounce parse errors back and forth. The reporter hit this against a stdio server that accidentally wrote a log line to stdout.This makes the transport ignore unparseable messages instead of responding. It still logs at
debugand continues reading the next message, which matches the behavior of the other official SDKs. The now-unusedErrorDataimport is removed, and the existing test is updated to assert that no response is sent (and that the following valid message is still delivered).Verified locally:
cargo test -p rmcp --features server,transport-async-rw(the updatedreceive_ignores_parse_errortest passes)cargo clippy -p rmcp --all-features --all-targets -- -D warningscargo +nightly fmt --check