Skip to content

[v1.x] fix(shared): stop referencing the DOM-only global HeadersInit in normalizeHeaders - #2807

Open
nikolas-sapa wants to merge 4 commits into
modelcontextprotocol:v1.xfrom
nikolas-sapa:fix/headersinit-node-consumers
Open

[v1.x] fix(shared): stop referencing the DOM-only global HeadersInit in normalizeHeaders#2807
nikolas-sapa wants to merge 4 commits into
modelcontextprotocol:v1.xfrom
nikolas-sapa:fix/headersinit-node-consumers

Conversation

@nikolas-sapa

Copy link
Copy Markdown

Summary

Fixes #2568 (marked ready for work).

shared/transport.d.ts exports normalizeHeaders(headers: HeadersInit | undefined). HeadersInit is a web-IDL type alias that @types/node structurally cannot bind globally — it binds Headers/Request/RequestInit/Response from undici-types, but a typedef cannot be declaration-merged the way the interface-shaped ones can (see the DefinitelyTyped PR #74414 review noted in the issue). So Node-only consumers compiling with "lib": ["ES2023"], "types": ["node"], "skipLibCheck": false fail on the published declaration:

node_modules/@modelcontextprotocol/sdk/dist/esm/shared/transport.d.ts(7,51): error TS2304: Cannot find name 'HeadersInit'.

This changes the signature to RequestInit['headers'] | undefined — same-behaviour, dependent only on a global @types/node does bind, and exactly what the v2 rewrite already does (#1279). Runtime code is unchanged. This is the 1.x backport the issue asks for (v2 is outside the peer range @anthropic-ai/claude-agent-sdk pins).

Verification

Consumer repro (lib: ["ES2023"], types: ["node"], moduleResolution: "bundler", skipLibCheck: false, importing client/index.js and shared/transport.js):

  • against @modelcontextprotocol/sdk@1.30.0 from npm: dist/esm/shared/transport.d.ts(7,51): error TS2304: Cannot find name 'HeadersInit'. — exactly the issue's error
  • against this branch's emitted dist/esm: tsc --noEmit exits 0, including passing a Headers instance and tuple arrays through normalizeHeaders

Repo typecheck error set is byte-identical with and without this change (verified by diffing tsgo --noEmit output on the clean tree vs the fix — the 8 pre-existing errors are unrelated test-file drift in this environment).

Type of change

  • Bug fix (non-breaking change that fixes an issue)

Checklist

  • Bug fix with the consumer reproduction documented above; changeset included (@modelcontextprotocol/sdk: patch)
  • No runtime behaviour change; single signature + doc comment touched, per the issue's stated blast radius

…alizeHeaders

shared/transport.d.ts exports normalizeHeaders(headers: HeadersInit | undefined),
and HeadersInit is a web-IDL type alias that @types/node structurally cannot
bind globally (it binds Headers/Request/RequestInit/Response, but not the
HeadersInit typedef — see DefinitelyTyped PR #74414 review). Node-only
consumers compiling with skipLibCheck: false and no "DOM" lib fail with
TS2304: Cannot find name 'HeadersInit' (reported against 1.23.0-beta.0
through 1.30.0).

Use RequestInit['headers'] instead — same-behaviour, and exactly what the
v2 rewrite already does (modelcontextprotocol#1279). Runtime code is unchanged.

Verified: a Node-only consumer (lib ES2023, types node, skipLibCheck false)
fails with the reported TS2304 against @modelcontextprotocol/sdk@1.30.0 and
typechecks clean against this branch's emitted declarations. Full repo
typecheck error set is byte-identical with and without this change.

Fixes modelcontextprotocol#2568
@nikolas-sapa
nikolas-sapa requested a review from a team as a code owner September 13, 2026 12:34
@changeset-bot

changeset-bot Bot commented Sep 13, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: cb54794

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

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

pkg-pr-new Bot commented Sep 13, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@modelcontextprotocol/sdk@2807

commit: cb54794

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.

1 participant