Skip to content

fix(core-internal): preserve error cause and support ErrorOptions in SdkError - #2665

Open
teddiesloco wants to merge 2 commits into
modelcontextprotocol:mainfrom
teddiesloco:fix/sdk-error-cause-chaining
Open

fix(core-internal): preserve error cause and support ErrorOptions in SdkError#2665
teddiesloco wants to merge 2 commits into
modelcontextprotocol:mainfrom
teddiesloco:fix/sdk-error-cause-chaining

Conversation

@teddiesloco

Copy link
Copy Markdown

Summary

Fixes #2657

When network or protocol errors occur, telemetry collectors and error tracers (e.g. Sentry, Pino, OpenTelemetry) rely on the standard ECMAScript 2022 Error.cause property on Error instances.

Previously, SdkError accepted data?: ErrorData but did not pass options?: ErrorOptions to super(message, options). As a result, when classifyNetworkError or custom error handlers constructed an SdkError, the underlying root cause (e.g. ENOTFOUND, ECONNREFUSED, or TypeError) was not accessible via standard error.cause.

Changes

  1. Updated SdkError constructor to support options?: ErrorOptions while maintaining full backward compatibility with data?: ErrorData.
  2. Automatically extracted cause from data.cause or direct options.cause and passed to super(message, errorOptions).
  3. Added unit tests in packages/core-internal/test/types/errorSurfacePins.test.ts verifying that error.cause is preserved across construction styles.

Verification

pnpm --filter @modelcontextprotocol/core-internal test test/types/errorSurfacePins.test.ts
# 13 passed

@teddiesloco
teddiesloco requested a review from a team as a code owner August 15, 2026 06:32
@changeset-bot

changeset-bot Bot commented Aug 15, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 68b1e17

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 15, 2026

Copy link
Copy Markdown

Open in StackBlitz

@modelcontextprotocol/client

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

@modelcontextprotocol/codemod

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

@modelcontextprotocol/core

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

@modelcontextprotocol/server

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

@modelcontextprotocol/server-legacy

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

@modelcontextprotocol/express

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

@modelcontextprotocol/fastify

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

@modelcontextprotocol/hono

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

@modelcontextprotocol/node

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

commit: 68b1e17

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