Skip to content

fix(client): remove redundant onerror in _startOrAuthSse catch#1826

Open
felixweinberger wants to merge 2 commits intomainfrom
fweinberger/fix-double-onerror-868
Open

fix(client): remove redundant onerror in _startOrAuthSse catch#1826
felixweinberger wants to merge 2 commits intomainfrom
fweinberger/fix-double-onerror-868

Conversation

@felixweinberger
Copy link
Copy Markdown
Contributor

Removes the redundant onerror call in _startOrAuthSse's catch block.

Motivation and Context

Fixes #868. _startOrAuthSse's catch block fired onerror then threw. All three callers (streamableHttp.ts:344, :531, :642) already .catch(error => this.onerror?.(error)), so every failure double-fired.

This is the approach from #880 (closed for inactivity). @Anil567849 is credited as co-author.

How Has This Been Tested?

Added a regression test that triggers _startOrAuthSse via the initialized-notification path (202 response → GET fails) and asserts onerror fires exactly once. Test fails on main (expected 1 times, but got 2 times), passes with the fix.

Breaking Changes

None.

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

Additional context

Two other methods have the same fire-then-throw pattern (_send at :681, terminateSession at :730), but their callers await rather than .catch(onerror), so the redundancy there is less clear-cut. Scoping this PR to the verified double-fire.

felixweinberger and others added 2 commits March 31, 2026 11:51
_startOrAuthSse's catch block fired onerror then threw. All three callers
(streamableHttp.ts:344, :531, :642) already .catch(error => this.onerror?.(error)),
so every failure double-fired. Removed the internal call; callers handle it.

Fixes #868

Co-authored-by: Anil Kumar <anilkumar567849@gmail.com>
_startOrAuthSse's catch block fired onerror then threw. All three callers
(streamableHttp.ts:344, :531, :642) already .catch(error => this.onerror?.(error)),
so every failure double-fired. Removed the internal call; callers handle it.

Fixes #868

Co-authored-by: Anil Kumar <anilkumar567849@gmail.com>
@felixweinberger felixweinberger requested a review from a team as a code owner March 31, 2026 11:58
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Mar 31, 2026

Open in StackBlitz

@modelcontextprotocol/client

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

@modelcontextprotocol/server

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

@modelcontextprotocol/express

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

@modelcontextprotocol/hono

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

@modelcontextprotocol/node

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

commit: 4041340

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.

When executing client.close(), onerror will be executed twice (Streamable HTTP)

1 participant