Skip to content

[Client] Throw InvalidArgumentException for unencodable request params - #592

Merged
chr-hertel merged 1 commit into
modelcontextprotocol:mainfrom
chr-hertel:fix-client-json-encode-error
Oct 14, 2026
Merged

chr-hertel merged 1 commit into
modelcontextprotocol:mainfrom
chr-hertel:fix-client-json-encode-error

Conversation

@chr-hertel

Copy link
Copy Markdown
Member

Request params with invalid UTF-8 made the client throw a native \JsonException, outside of ExceptionInterface. A request handler result with invalid UTF-8 left the server's request without an answer.

  • Protocol::send() wraps the \JsonException in an InvalidArgumentException naming the method
  • Protocol::sendResponse() logs it and answers with an internal error instead
  • @throws and the client error docs list the new case

Fixes chr-hertel#79

🤖 Generated with Claude Code

@chr-hertel chr-hertel added this to the 0.9.0 milestone Oct 13, 2026
@chr-hertel chr-hertel added bug Something isn't working Client Issues & PRs related to the Client component labels Oct 13, 2026
@chr-hertel
chr-hertel requested a balanced review from Copilot October 13, 2026 22:57

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The implementation safely handles both encoding paths and includes focused regression coverage.

0 open findings

What changed in this PR

Ensures JSON encoding failures remain within the SDK exception model and server requests receive an error response.

Changes:

  • Wraps request encoding failures in InvalidArgumentException.
  • Returns internal errors for unencodable handler responses.
  • Adds tests and updates API/error documentation.
File Description
src/​Client/​Protocol.php Handles JSON encoding failures.
src/​Client.php Documents the new exception case.
tests/​Unit/​Client/​ProtocolTest.php Tests request and response failures.
docs/​client/​errors.md Documents client behavior.
CHANGELOG.md Records the fix.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@chr-hertel
chr-hertel force-pushed the fix-client-json-encode-error branch from bf3c947 to f091ecc Compare October 13, 2026 23:43
@chr-hertel
chr-hertel merged commit bc3b124 into modelcontextprotocol:main Oct 14, 2026
28 checks passed
@chr-hertel
chr-hertel deleted the fix-client-json-encode-error branch October 14, 2026 22:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working Client Issues & PRs related to the Client component

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Client] Invalid UTF-8 in request params escapes as native \JsonException

2 participants