Skip to content

fix(errors): forward SdkError causes onto Error.cause - #2666

Open
eddinos2 wants to merge 1 commit into
modelcontextprotocol:mainfrom
eddinos2:fix/sdkerror-forward-cause
Open

fix(errors): forward SdkError causes onto Error.cause#2666
eddinos2 wants to merge 1 commit into
modelcontextprotocol:mainfrom
eddinos2:fix/sdkerror-forward-cause

Conversation

@eddinos2

@eddinos2 eddinos2 commented Aug 15, 2026

Copy link
Copy Markdown

Summary

SdkError third argument is data, but classifyNetworkError passed { cause }. That left the underlying fetch/DNS error on .data.cause instead of .cause, so pino/Sentry cause-chain walkers lost ENOTFOUND vs ECONNREFUSED detail.

  • Peel { cause } out of the data bag into ErrorOptions
  • Accept an explicit options?: ErrorOptions on SdkError / SdkHttpError
  • Construct the era-negotiation failure with a real { cause }
  • Add regression tests

Closes #2657

Test plan

  • pnpm --filter @modelcontextprotocol/core-internal test (1438 passed, including new cause tests)

classifyNetworkError (and any site that passes `{ cause }` as the data
argument) left the underlying fetch/DNS error in `.data.cause`, so pino
and Sentry cause-chain walkers stopped at the SdkError and lost
ENOTFOUND vs ECONNREFUSED detail.

Peel a `cause` key out of the data bag into ErrorOptions, accept an
explicit options argument, and construct the negotiation failure with
`{ cause }` on ErrorOptions. Adds focused regression tests.
@eddinos2
eddinos2 requested a review from a team as a code owner August 15, 2026 23:06
@changeset-bot

changeset-bot Bot commented Aug 15, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 93b5f60

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@2666

@modelcontextprotocol/codemod

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

@modelcontextprotocol/core

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

@modelcontextprotocol/server

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

@modelcontextprotocol/server-legacy

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

@modelcontextprotocol/express

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

@modelcontextprotocol/fastify

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

@modelcontextprotocol/hono

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

@modelcontextprotocol/node

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

commit: 93b5f60

@eddinos2

Copy link
Copy Markdown
Author

Happy to adjust the peel heuristics if you'd rather keep cause inside data for back-compat and only document .cause — current approach peels so pino/Sentry work with zero consumer changes.

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