You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Several error paths in WebStandardStreamableHTTPServerTransport returned error responses via createJsonErrorResponse() without calling the onerror callback, making these errors unobservable for debugging and logging purposes.
As described in #1395, nested try/catch blocks in handlePostRequest and other methods return error responses without calling this.onerror?.(). The outer catch block at the end of handlePostRequest does call it, but inner early-return paths bypass it entirely. This makes it impossible to log or observe errors like invalid JSON, bad headers, session validation failures, etc.
The validateRequestHeaders method already correctly calls this.onerror?.() before returning error responses — this PR makes the rest of the codebase consistent with that pattern.
validateSession: server not initialized (400), missing session ID (400), invalid session ID (404)
validateProtocolVersion: unsupported version (400)
handleUnsupportedRequest: method not allowed (405)
replayEvents: event store not configured (400), invalid event ID (400), stream conflict (409)
How Has This Been Tested?
Added 13 new tests in packages/server/test/server/streamableHttp.test.ts under a new HTTPServerTransport - onerror callback describe block. Each test sets an onerror spy on the transport and verifies it is called with the expected error message for each error condition. All 50 server tests pass. Full test suite passes (383/384 — single failure is a pre-existing Cloudflare Workers timeout unrelated to this change). Lint passes.
Breaking Changes
None. The onerror callback is optional (this.onerror?.()) and this only adds calls where none existed before. Existing code that doesn't set onerror is unaffected.
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)
Several error paths in WebStandardStreamableHTTPServerTransport returned
error responses via createJsonErrorResponse() without calling the
onerror callback, making these errors unobservable for debugging and
logging purposes.
Fixesmodelcontextprotocol#1395
Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.
This PR includes no changesets
When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types
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
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.
Several error paths in
WebStandardStreamableHTTPServerTransportreturned error responses viacreateJsonErrorResponse()without calling theonerrorcallback, making these errors unobservable for debugging and logging purposes.Fixes#1395
Motivation and Context
As described in #1395, nested
try/catchblocks inhandlePostRequestand other methods return error responses without callingthis.onerror?.(). The outer catch block at the end ofhandlePostRequestdoes call it, but inner early-return paths bypass it entirely. This makes it impossible to log or observe errors like invalid JSON, bad headers, session validation failures, etc.The
validateRequestHeadersmethod already correctly callsthis.onerror?.()before returning error responses — this PR makes the rest of the codebase consistent with that pattern.Affected locations:
handlePostRequest: Accept header (406), Content-Type (415), invalid JSON (400), invalid JSON-RPC message (400), duplicate initialization (400), batch initialization (400)handleGetRequest: Accept header (406), duplicate SSE stream (409)validateSession: server not initialized (400), missing session ID (400), invalid session ID (404)validateProtocolVersion: unsupported version (400)handleUnsupportedRequest: method not allowed (405)replayEvents: event store not configured (400), invalid event ID (400), stream conflict (409)How Has This Been Tested?
Added 13 new tests in
packages/server/test/server/streamableHttp.test.tsunder a newHTTPServerTransport - onerror callbackdescribe block. Each test sets anonerrorspy on the transport and verifies it is called with the expected error message for each error condition. All 50 server tests pass. Full test suite passes (383/384 — single failure is a pre-existing Cloudflare Workers timeout unrelated to this change). Lint passes.Breaking Changes
None. The
onerrorcallback is optional (this.onerror?.()) and this only adds calls where none existed before. Existing code that doesn't setonerroris unaffected.Types of changes