Skip to content

fix: forward Error.cause in SdkError constructor - #2663

Open
anshusaurav wants to merge 1 commit into
modelcontextprotocol:mainfrom
anshusaurav:fix/sdk-error-cause-chain-2657
Open

fix: forward Error.cause in SdkError constructor#2663
anshusaurav wants to merge 1 commit into
modelcontextprotocol:mainfrom
anshusaurav:fix/sdk-error-cause-chain-2657

Conversation

@anshusaurav

Copy link
Copy Markdown

Summary

Fixes #2657.

SdkError's third constructor parameter is data, not ErrorOptions, so when classifyNetworkError passed { cause: error } it landed in error.data.cause instead of error.cause. This broke standard cause-chain walking used by loggers (pino) and error trackers (Sentry) — the chain terminated at SdkError instead of reaching the root network error.

Changes

  • SdkError constructor: added an optional options?: ErrorOptions parameter (4th arg), forwarded to super(message, options). Fully backward-compatible — existing 2- and 3-arg call sites are unaffected.
  • SdkHttpError constructor: same treatment, forwarding options through to super().
  • classifyNetworkError: moved { cause: error } from the data slot to the new options parameter so the underlying network error is reachable via the standard error.cause property.
  • Test update: probeAuthSeam.test.ts assertion updated from error.data.cause to error.cause.

Test plan

  • New sdkErrorCause.test.ts verifying:
    • SdkError forwards cause to Error.cause when passed via options
    • data and cause remain independent when both are provided
    • cause is undefined when options are omitted (backward compat)
    • SdkHttpError forwards cause through the inheritance chain
  • Existing probeAuthSeam.test.ts updated and passing
  • Full pnpm typecheck:all passes
  • Full pnpm build:all passes
  • Full pnpm lint:all passes (after prettier formatting)

…l#2657)

SdkError's third parameter is `data`, not `ErrorOptions`, so
`classifyNetworkError`'s `{ cause: error }` landed in `data` instead
of `Error.cause`. This broke standard cause-chain walking used by
loggers (pino) and error trackers (Sentry).

Add an `options?: ErrorOptions` parameter to both `SdkError` and
`SdkHttpError` constructors, forwarding it to `super()`. Fix the
call site in `classifyNetworkError` to pass the underlying error
as `options.cause` rather than as `data`.
@anshusaurav
anshusaurav requested a review from a team as a code owner August 14, 2026 10:19
@changeset-bot

changeset-bot Bot commented Aug 14, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 4461157

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

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@pkg-pr-new

pkg-pr-new Bot commented Aug 14, 2026

Copy link
Copy Markdown

Open in StackBlitz

@modelcontextprotocol/client

npm i https://pkg.pr.new/@modelcontextprotocol/client@2663

@modelcontextprotocol/codemod

npm i https://pkg.pr.new/@modelcontextprotocol/codemod@2663

@modelcontextprotocol/core

npm i https://pkg.pr.new/@modelcontextprotocol/core@2663

@modelcontextprotocol/server

npm i https://pkg.pr.new/@modelcontextprotocol/server@2663

@modelcontextprotocol/server-legacy

npm i https://pkg.pr.new/@modelcontextprotocol/server-legacy@2663

@modelcontextprotocol/express

npm i https://pkg.pr.new/@modelcontextprotocol/express@2663

@modelcontextprotocol/fastify

npm i https://pkg.pr.new/@modelcontextprotocol/fastify@2663

@modelcontextprotocol/hono

npm i https://pkg.pr.new/@modelcontextprotocol/hono@2663

@modelcontextprotocol/node

npm i https://pkg.pr.new/@modelcontextprotocol/node@2663

commit: 4461157

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.

[v2] classifyNetworkError passes { cause } into SdkError's data slot, so the underlying network error never reaches Error.cause

1 participant