Repository navigation
Treat a null or false error member of a client reply as an error on stdio - #732
Merged
Conversation
…r on stdio
## Motivation and Context
While the stdio transport waits for the reply to a request it sent to the client, it decides whether the reply is
an error by the truthiness of its `error` member. A reply such as `{"jsonrpc":"2.0","id":1,"error":null}` or one
with `"error": false` is therefore taken for a success, and `send_request` returns `nil`, the `result` the reply
does not have. The Streamable HTTP transport decides by the presence of the member, so the same reply ends
the request there with the "Client returned an error" `StandardError`.
The stdio transport now decides by the presence of the member too. A reply that carries an `error` member of any value
raises that `StandardError`, with an empty code and message when the member is not an object.
Follow-up to modelcontextprotocol#716, which made both transports treat an `error` member that is not an object as an error reply.
## How Has This Been Tested?
New tests in `test/mcp/server/transports/stdio_transport_test.rb` for an `error` member of `null` and of `false`.
Before the change `send_request` returns `nil` for both.
Further tests there for a reply that carries `result` together with such a member. Before the change it is returned
as a success.
## Breaking Changes
None for a client that follows JSON-RPC 2.0. A reply that carries both `result` and an `error` member of `null` or `false`,
which JSON-RPC 2.0 does not allow, was returned as a success on stdio and is now an error, as it is on Streamable HTTP.
koic
deleted the
treat_a_null_or_false_error_member_of_a_client_reply_as_an_error_on_stdio
branch
November 30, 2026 17:03
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.
Motivation and Context
While the stdio transport waits for the reply to a request it sent to the client, it decides whether the reply is an error by the truthiness of its
errormember. A reply such as{"jsonrpc":"2.0","id":1,"error":null}or one with"error": falseis therefore taken for a success, andsend_requestreturnsnil, theresultthe reply does not have. The Streamable HTTP transport decides by the presence of the member, so the same reply ends the request there with the "Client returned an error"StandardError.The stdio transport now decides by the presence of the member too. A reply that carries an
errormember of any value raises thatStandardError, with an empty code and message when the member is not an object.Follow-up to #716, which made both transports treat an
errormember that is not an object as an error reply.How Has This Been Tested?
New tests in
test/mcp/server/transports/stdio_transport_test.rbfor anerrormember ofnulland offalse. Before the changesend_requestreturnsnilfor both. Further tests there for a reply that carriesresulttogether with such a member. Before the change it is returned as a success.Breaking Changes
None for a client that follows JSON-RPC 2.0. A reply that carries both
resultand anerrormember ofnullorfalse, which JSON-RPC 2.0 does not allow, was returned as a success on stdio and is now an error, as it is on Streamable HTTP.Types of changes
Checklist