Skip to content

fix: keep HTTP client handler exception details local - #664

Merged
koic merged 1 commit into
modelcontextprotocol:mainfrom
atesgoral:fix/http-client-handler-error-echo
Nov 7, 2026
Merged

koic merged 1 commit into
modelcontextprotocol:mainfrom
atesgoral:fix/http-client-handler-error-echo

Conversation

@atesgoral

@atesgoral atesgoral commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Motivation and Context

When an HTTP server-request handler raised an unexpected exception, the client sent the exception message back to the server. Messages can hold local paths and other application details that the server should not receive. The client now sends -32603, Internal error, and writes the exception class and quoted, escaped message to local stderr. String#dump keeps control characters from creating or recoloring log lines. Explicit ServerRequestError responses are unchanged. This matches the server-side fix in #486. I used stderr instead of a new reporter callback to keep the transport API unchanged.

Fixes #660.

How Has This Been Tested?

test/mcp/client/http_test.rb. The regression expects an exact generic error body instead of the handler's message. The handler raises server-request text containing a newline and a terminal escape sequence; stderr must keep that text quoted and escaped on one line. The changed regression fails on the previous PR head because it writes the control characters raw. It passes with this change, including under Rake's -W0 -W:deprecated flags.

The HTTP client test file passes (143 runs, 432 assertions), and so does the full suite (2,500 runs, 8,266 assertions). RuboCop is clean on the changed files.

Breaking Changes

None. Responses to unexpected handler exceptions carry a generic message instead of the exception text. Intended ServerRequestError replies are unchanged.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

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

@atesgoral
atesgoral force-pushed the fix/http-client-handler-error-echo branch from a0be545 to d954129 Compare November 6, 2026 06:38
@atesgoral
atesgoral marked this pull request as ready for review November 6, 2026 06:46
@atesgoral
atesgoral marked this pull request as draft November 6, 2026 07:54
@atesgoral
atesgoral force-pushed the fix/http-client-handler-error-echo branch from d954129 to d49394f Compare November 6, 2026 13:58
@atesgoral
atesgoral marked this pull request as ready for review November 6, 2026 14:16
@koic
koic merged commit 529dd8b into modelcontextprotocol:main Nov 7, 2026
13 checks passed
@atesgoral
atesgoral deleted the fix/http-client-handler-error-echo branch November 7, 2026 14:51
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.

HTTP client sends handler exception messages back to the server

2 participants