Skip to content

fix(client): reject empty, error, and payment-required tool results - #20

Merged
adamdecaf-bot merged 1 commit into
masterfrom
fix/validate-tool-results
Nov 29, 2026
Merged

adamdecaf-bot merged 1 commit into
masterfrom
fix/validate-tool-results

Conversation

@adamdecaf-bot

Copy link
Copy Markdown
Collaborator

Why

When a tool result wasn't flagged isError, callTool decoded 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 empty Recall, with no error.

What

  • callTool now checks the body before decoding: it must be a JSON object containing the expected key (recalls for searches, id for get_product_recall), with no non-null error field and no x402 accepts/x402Version fields.
  • GetProductRecall also requires a non-empty recall id.
  • Failures return the new ErrInvalidResponse (wrapped with the tool name).
  • An empty search ("recalls": [] or null) 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.

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.
@adamdecaf-bot
adamdecaf-bot merged commit 0b5851f into master Nov 29, 2026
1 check passed
@adamdecaf-bot
adamdecaf-bot deleted the fix/validate-tool-results branch November 29, 2026 20:36
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