Repository navigation
fix(client): reject empty, error, and payment-required tool results - #20
Merged
Merged
Conversation
callTool decoded the first text result into the destination without
checking its shape, so {} or an error or x402 payment-required object in
a non-error result came back as an empty search or recall with no error.
Require a JSON object with the expected key (recalls for searches, a
non-empty id for get_product_recall) and reject error and payment
objects with ErrInvalidResponse.
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.
Why
When a tool result wasn't flagged
isError,callTooldecoded the first text item straight into the destination.{},null, an{"error": ...}object, or an x402 payment-required object all came back as a successful empty search or an emptyRecall, with no error.What
callToolnow checks the body before decoding: it must be a JSON object containing the expected key (recallsfor searches,idforget_product_recall), with no non-nullerrorfield and no x402accepts/x402Versionfields.GetProductRecallalso requires a non-empty recall id.ErrInvalidResponse(wrapped with the tool name)."recalls": []ornull) is still a valid result, matching the server's output shape.Tests
go test ./...adds tests against a local MCP server:{}, payment-required, error string/object,null,[], and non-JSON bodies all fail for all three methods; valid searches (including empty ones) and recalls still decode.Compatibility
No signature changes. Callers that got an empty result for these malformed bodies now get an error instead.