Repository navigation
Conversation
Raise the client validation error for malformed result payloads before indexing them. Keep the empty defaults used for missing results. The HTTP transport no longer indexes a non-object tools/list result while learning x-mcp-header declarations, so the client can refuse it. Fixes modelcontextprotocol#737.
This was referenced Dec 1, 2026
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.
The client raises
MCP::Client::ValidationErrorfor aresultthat is not an object, instead of leaking Ruby errors or returning it.Fixes #737
Motivation and Context
list_tools,list_resources,list_resource_templates,list_prompts,read_resource,get_promptandcompleteindex theresultwithout checking it. A non-object one raisesTypeErrororNoMethodError, comes back fromget_prompt, or reads as an empty page.The seven methods now read it through one private helper, which raises the error
discoverandpingalready raise. On a modern connectionMCP::Client::HTTPreads thex-mcp-headerdeclarations out of atools/listbody before that, so it now learns nothing from a non-objectresultand lets the client refuse it. Error responses andinput_requiredresults are handled before the check, as before.How Has This Been Tested?
Automated unit / integration tests
Tested manually
Tested in a real application
test/mcp/client_test.rb: each method refuses array, string, number and boolean results, and a response that is not a Hash. Missing andnullresults keep the empty defaults.test/mcp/client/http_test.rb:list_toolsrefuses the same results on a modern connection.All nine tests fail on
main. Reverting any one reader, the HTTP guard, or any part of the helper fails a test.bundle exec rake test(2,824 tests, 10,313 assertions),bundle exec rake rubocop,bundle exec yard --no-outputandbundle exec rake conformance:test(baseline) pass locally on Ruby 4.0.9.Breaking Changes
None for a server that sends object results.
get_promptreturns{}instead ofnilfor anullresult, as it already does for a missing one.Types of changes
Checklist