fix(core): send an error response when a request handler rejects with a nullish reason#2521
Draft
lntutor wants to merge 1 commit into
Draft
fix(core): send an error response when a request handler rejects with a nullish reason#2521lntutor wants to merge 1 commit into
lntutor wants to merge 1 commit into
Conversation
… a nullish reason Protocol's inbound-request error path read error['code'] directly. When a handler rejects with null/undefined (a bare reject() or throw null), that indexing throws a TypeError inside the rejection callback, which propagates to the outer .catch — so no JSON-RPC error response is ever sent and the requester hangs until its own timeout. Coalesce the reason to a safe object before reading the code/message/data, so a -32603 Internal error response is always returned. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01N6RtoHuxrDqTUo9Mw9h4Cv
🦋 Changeset detectedLatest commit: e3cf478 The changes in this PR will be included in the next version bump. This PR includes changesets to release 6 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
@modelcontextprotocol/client
@modelcontextprotocol/codemod
@modelcontextprotocol/core
@modelcontextprotocol/server
@modelcontextprotocol/server-legacy
@modelcontextprotocol/express
@modelcontextprotocol/fastify
@modelcontextprotocol/hono
@modelcontextprotocol/node
commit: |
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.
What's broken
Protocol's inbound-request error path readserror['code']directly. When a handler rejects withnull/undefined(a barereject()orthrow nullin library code), that indexing throws aTypeErrorinside the rejection callback, which propagates to the outer.catch— so no JSON-RPC error response is ever sent and the requester hangs until its own timeout.Fix
Coalesce the rejection reason to a safe object before reading
code/message/data, so a-32603Internal error response is always returned.Tests
New test in
packages/core-internal/test/shared/protocol.test.ts: a handler thatPromise.reject(undefined)now produces an error response for the request id (before the fix, none was sent). Full core-internal suite passes (1376 tests), typecheck + lint clean. Changeset included.🤖 Generated with Claude Code