Skip to content

fix: avoid DOM-only HeadersInit in v1 declarations - #2570

Open
kocaemre wants to merge 1 commit into
modelcontextprotocol:v1.xfrom
kocaemre:fix/v1-normalize-headers-node-types
Open

kocaemre wants to merge 1 commit into
modelcontextprotocol:v1.xfrom
kocaemre:fix/v1-normalize-headers-node-types

Conversation

@kocaemre

Copy link
Copy Markdown

Summary

Fixes the v1 declaration output so Node-only TypeScript projects do not need the DOM lib just to consume normalizeHeaders.

The generated shared/transport.d.ts currently exposes the bare global HeadersInit, which is not provided by @types/node even when Node fetch globals are enabled. This changes the public signature to RequestInit['headers'], matching the same runtime inputs without pulling in a DOM-only alias.

Also updates two internal client header annotations for the same reason and adds a patch changeset.

Verification

npm run build:esm
npm run build:cjs
npm run typecheck
npm run lint
npm test -- test/client/sse.test.ts test/client/streamableHttp.test.ts

Node-only declaration smoke test:

# temp project with:
#   lib: ["ES2023"]
#   types: ["node"]
#   skipLibCheck: false
#   @types/node@22.20.1
#   TypeScript 5.9

import { normalizeHeaders } from "@modelcontextprotocol/sdk/shared/transport";

const headers = normalizeHeaders({ "x-test": "value" });
headers["x-test"].toUpperCase();

Result: npx tsc -p tsconfig.json passes.

Fixes #2568

@kocaemre
kocaemre requested a review from a team as a code owner July 28, 2026 12:11
@changeset-bot

changeset-bot Bot commented Jul 28, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: fbf2e98

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

@claude claude Bot added the v1 Issues / PRs related to v1.x label Aug 18, 2026
@kocaemre

Copy link
Copy Markdown
Author

Rebased this branch onto current v1.x (a9f6eb70) to clear the stale branch state.

Re-ran the relevant local checks after the rebase:

npm ci
npm run build:esm
npm run build:cjs
npm run typecheck
npm run lint
npm test -- test/client/sse.test.ts test/client/streamableHttp.test.ts
git diff --check upstream/v1.x..HEAD

Results: ESM/CJS builds passed, typecheck passed, lint/prettier passed, focused client transport tests passed (65 passed), and git diff --check was clean.

Note: before npm ci, the local checkout had drifted to zod@4.3.6 and npm run typecheck failed in existing tests that still use the Zod v3 z.record(valueSchema) call shape. npm ci restored the lockfile version (zod@3.25.76), after which the checks above passed.

@kocaemre
kocaemre force-pushed the fix/v1-normalize-headers-node-types branch from 6b74bc7 to 10b945a Compare August 28, 2026 18:08
@pkg-pr-new

pkg-pr-new Bot commented Aug 28, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

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

commit: fbf2e98

@kocaemre
kocaemre force-pushed the fix/v1-normalize-headers-node-types branch from 10b945a to 781cc62 Compare September 7, 2026 09:01
@kocaemre

kocaemre commented Sep 7, 2026

Copy link
Copy Markdown
Author

Rebased this branch onto current v1.x (12b42567) to clear the stale/behind state.

Re-ran the relevant local checks after the rebase:

npm ci
npm run build:esm
npm run build:cjs
npm run typecheck
npm run lint
npm test -- test/client/sse.test.ts test/client/streamableHttp.test.ts
git diff --check origin/v1.x..HEAD
git status --short

Results: ESM/CJS builds passed, typecheck passed, lint/prettier passed, focused client transport tests passed (65 passed), diff check was clean, and the working tree is clean.

npm ci completed successfully and reported the repository's current audit state (17 vulnerabilities) without modifying the lockfile.

@kocaemre

Copy link
Copy Markdown
Author

Refreshed this branch onto current v1.x (289ac2c3) and force-pushed 16e543ee to clear the stale/behind state.

Local verification on the refreshed head:

  • npm ci
  • npm run typecheck
  • npm run lint
  • npm test (52 files / 1647 tests passed)
  • npm run build
  • git diff --check upstream/v1.x..HEAD

Push note: the local push hook runner was unavailable (Can't find lefthook in PATH), so I used LEFTHOOK=0 for the push after the repo checks above passed.

GitHub checks are now green as well (build, test, test-e2e, conformance, and pkg publish all passed; publish skipped as expected for PRs).

@kocaemre

Copy link
Copy Markdown
Author

Refreshed this v1.x PR again onto current v1.x (4b0051f4) after it became BEHIND.

Verification on the rebased head 7a4a7ebb:

  • npm ci
  • npm run build:esm
  • npm run build:cjs
  • npm run typecheck
  • npm run lint
  • npm test -- test/client/sse.test.ts test/client/streamableHttp.test.ts — 65 passed
  • git diff --check upstream/v1.x..HEAD

I also attempted full npm test; it reached 1688 passing tests and then failed in upstream/unrelated server/process tests outside this PR's diff (test/server/streamableHttp.test.ts chunk/replay assertions and test/integration-tests/processCleanup.test.ts timeout). The focused client transport tests covering the changed files are passing.

Duplicate/overlap sweep note: the later open PR #2807 touches only src/shared/transport.ts; this older PR still covers the v1 client transport type surfaces as well (src/client/sse.ts, src/client/streamableHttp.ts, src/shared/transport.ts).

@kocaemre
kocaemre force-pushed the fix/v1-normalize-headers-node-types branch 2 times, most recently from 7a4a7eb to 99d14cd Compare October 1, 2026 20:45
@kocaemre

kocaemre commented Oct 1, 2026

Copy link
Copy Markdown
Author

Rebased this onto current v1.x (0ff63772) after the branch went BEHIND.

Fresh local verification on signed-off head 99d14cd1:

  • npm ci — completed (npm audit still reports existing dependency advisories)
  • npm run build:esm — passed
  • npm run build:cjs — passed
  • npm run typecheck — passed
  • npm run lint — passed
  • npm test -- test/client/sse.test.ts test/client/streamableHttp.test.ts — 65 passed
  • declaration smoke — passed: no HeadersInit remains in emitted ESM/CJS transport declarations
  • git diff --check upstream/v1.x..HEAD — clean

I also attempted full npm test; it reached 1804 passing tests and then failed in unrelated server/process tests outside this PR's touched client transport declaration files (test/server/streamableHttp.test.ts and test/integration-tests/processCleanup.test.ts).

Signed-off-by: Emre K <110906681+kocaemre@users.noreply.github.com>
@kocaemre
kocaemre force-pushed the fix/v1-normalize-headers-node-types branch from 99d14cd to fbf2e98 Compare October 2, 2026 22:49
@kocaemre

kocaemre commented Oct 2, 2026

Copy link
Copy Markdown
Author

Rebased this v1.x PR onto current upstream/v1.x (a8cf5036) and force-pushed signed-off head fbf2e986bf4dedf557867fad652a2a9affe6ce3c.

Verification on the refreshed branch:

  • npm ci ✅
  • npm run build:esm ✅
  • npm run build:cjs ✅
  • npm run typecheck ✅
  • npm run lint ✅
  • npm test -- test/client/sse.test.ts test/client/streamableHttp.test.ts ✅ 65 passed
  • declaration smoke over emitted ESM/CJS client/shared transport .d.ts files ✅ no HeadersInit
  • git diff --check upstream/v1.x..HEAD ✅

I also attempted the full local npm test; it reached 1847 passed / 56 files, then failed in unrelated server/process tests outside this PR's client transport declaration diff:

  • test/server/streamableHttp.test.ts: 4 existing stream/replay assertions
  • test/integration-tests/processCleanup.test.ts: 1 local timeout

Push note: the repo hook runner was not available locally (lefthook not in PATH), so I used LEFTHOOK=0 for the force-push after the checks above passed.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

v1 Issues / PRs related to v1.x

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant