Skip to content

Treat a null or false error member of a client reply as an error on stdio - #732

Merged
koic merged 1 commit into
modelcontextprotocol:mainfrom
koic:treat_a_null_or_false_error_member_of_a_client_reply_as_an_error_on_stdio
Nov 30, 2026
Merged

koic merged 1 commit into
modelcontextprotocol:mainfrom
koic:treat_a_null_or_false_error_member_of_a_client_reply_as_an_error_on_stdio

Conversation

@koic

@koic koic commented Nov 30, 2026

Copy link
Copy Markdown
Member

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 #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.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Test update (non-breaking change which adds or updates tests)
  • Refactoring (non-breaking change which makes things better)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update
  • CI/build script update (update CI workflow or build scripts)

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • I have added automated tests for my change
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

…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
koic merged commit bafdca4 into modelcontextprotocol:main Nov 30, 2026
13 checks passed
@koic
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant