Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/normalize-headers-no-dom-global.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@modelcontextprotocol/sdk': patch
---

Stop `normalizeHeaders` from referencing the DOM-only global `HeadersInit`, so Node-only projects without the `DOM` lib compile with `skipLibCheck: false`
2 changes: 1 addition & 1 deletion src/shared/transport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export type FetchLike = (url: string | URL, init?: RequestInit) => Promise<Respo
* Normalizes HeadersInit to a plain Record<string, string> for manipulation.
* Handles Headers objects, arrays of tuples, and plain objects.
*/
export function normalizeHeaders(headers: HeadersInit | undefined): Record<string, string> {
export function normalizeHeaders(headers: RequestInit['headers'] | undefined): Record<string, string> {
if (!headers) return {};

if (headers instanceof Headers) {
Expand Down
22 changes: 22 additions & 0 deletions test/shared/transport.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
fetchLeavingRedirects,
fetchWithinOrigin,
isWithinOrigin,
normalizeHeaders,
unfollowedRedirect,
type FetchLike
} from '../../src/shared/transport.js';
Expand Down Expand Up @@ -245,3 +246,24 @@ describe('fetchLeavingRedirects', () => {
expect(calls).toEqual([{ url: 'https://example.com/mcp', init: { ...init, redirect: 'manual' } }]);
});
});

describe('normalizeHeaders', () => {
it('returns an empty object when headers are undefined', () => {
expect(normalizeHeaders(undefined)).toEqual({});
});

it('reads a Headers object', () => {
expect(normalizeHeaders(new Headers({ 'x-test': 'a' }))).toEqual({ 'x-test': 'a' });
});

it('reads an array of tuples', () => {
expect(normalizeHeaders([['x-test', 'a']])).toEqual({ 'x-test': 'a' });
});

it('copies a plain object', () => {
const headers = { 'x-test': 'a' };
const result = normalizeHeaders(headers);
expect(result).toEqual(headers);
expect(result).not.toBe(headers);
});
});
Loading