Skip to content

Conversation

@codewithkenzo
Copy link

Summary

Fixes #1395 - Transport errors are silently swallowed due to missing onerror callback usage.

This PR adds this.onerror?.() calls before every createJsonErrorResponse in WebStandardStreamableHTTPServerTransport, ensuring that all transport errors are properly reported to the error callback.

Changes

packages/server/src/server/streamableHttp.ts

Added this.onerror?.(new Error(...)) calls at 15 locations:

  • handleGetRequest: Missing Accept header (406), concurrent SSE stream conflict (409)
  • replayEvents: Event store not configured (400), invalid event ID format (400), stream conflict (409)
  • handlePostRequest: Invalid Accept header (406), unsupported Content-Type (415), JSON parse error (400), invalid JSON-RPC message (400), re-initialization attempt (400), multiple init requests (400)
  • validateSession: Server not initialized (400), missing session ID (400), session ID mismatch (404)
  • validateProtocolVersion: Unsupported protocol version (400)

packages/server/test/server/streamableHttp.test.ts

Added 10 test cases to verify onerror is called for various error conditions:

  • Invalid JSON
  • Invalid JSON-RPC message
  • Missing Accept header on POST
  • Unsupported Content-Type
  • Server not initialized
  • Invalid session ID
  • Re-initialization attempt
  • Missing Accept header on GET
  • Concurrent SSE streams
  • Unsupported protocol version

Testing

# All 91 tests pass (76 existing + 10 new in the describe block)
pnpm -r --filter @modelcontextprotocol/server test

# Build succeeds
pnpm build:all

# Lint passes
pnpm -r --filter @modelcontextprotocol/server lint

Pattern Used

Follows the existing pattern already present at lines 296, 306, etc.:

this.onerror?.(new Error('Error message here'));
return this.createJsonErrorResponse(status, code, 'Error message here');

Adds missing onerror callback invocations before every createJsonErrorResponse
call in WebStandardStreamableHTTPServerTransport. This ensures that transport
errors are no longer silently swallowed and can be observed via the onerror
callback.

Changes:
- Add this.onerror?.() calls to 15 locations in streamableHttp.ts
- Add 10 test cases to verify onerror is called for various error conditions

Fixes modelcontextprotocol#1395
@codewithkenzo codewithkenzo requested a review from a team as a code owner February 2, 2026 01:40
@changeset-bot
Copy link

changeset-bot bot commented Feb 2, 2026

🦋 Changeset detected

Latest commit: a4e1e5a

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 4 packages
Name Type
@modelcontextprotocol/server Patch
@modelcontextprotocol/express Patch
@modelcontextprotocol/hono Patch
@modelcontextprotocol/node Patch

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

@pkg-pr-new
Copy link

pkg-pr-new bot commented Feb 2, 2026

Open in StackBlitz

@modelcontextprotocol/client

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/client@1433

@modelcontextprotocol/server

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/server@1433

@modelcontextprotocol/express

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/express@1433

@modelcontextprotocol/hono

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/hono@1433

@modelcontextprotocol/node

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/node@1433

commit: a4e1e5a

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.

Some transport errors are silently swallowed due to missing onerror callback usage

1 participant