Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
7 changes: 7 additions & 0 deletions .changeset/compat-v1-type-aliases.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@modelcontextprotocol/core': patch
'@modelcontextprotocol/client': patch
'@modelcontextprotocol/server': patch
---

Add v1 type aliases to the public API surface for smoother migration: `IsomorphicHeaders` (→ `Headers`) and `RequestInfo` (→ `Request`). `FetchLike` retains its v1 name.
23 changes: 23 additions & 0 deletions packages/core/src/exports/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,3 +142,26 @@
// fromJsonSchema is intentionally NOT exported here — the server and client packages
// provide runtime-aware wrappers that default to the appropriate validator via _shims.
export type { JsonSchemaType, JsonSchemaValidator, jsonSchemaValidator, JsonSchemaValidatorResult } from '../../validators/types.js';

// ────────────────────────────────────────────────────────────────────────────
// v1 backwards-compatibility type aliases
// ────────────────────────────────────────────────────────────────────────────

// Note: a `ResourceTemplate = ResourceTemplateType` alias is intentionally NOT
// exported here — it conflicts with the server's `ResourceTemplate` class under
// tsdown bundling. The alias lives only in the `/sdk` meta-package's `types.js`.

/**
* @deprecated Use the standard `Headers` web type. v2 transports surface
* request headers via `Headers` on `ctx.http?.req`.
*/
export type IsomorphicHeaders = Headers;
Comment thread
felixweinberger marked this conversation as resolved.

/**
* @deprecated Use the standard `Request` web type. v2's {@linkcode ServerContext}
* exposes the originating HTTP request at `ctx.http?.req`.
*/
export type RequestInfo = Request;

Check warning on line 164 in packages/core/src/exports/public/index.ts

View check run for this annotation

Claude / Claude Code Review

Use globalThis.Request to disambiguate from MCP Request type

nit: `export type RequestInfo = Request;` relies on the bare `Request` identifier resolving to the global Web Fetch `Request`, but this same module also re-exports the MCP protocol `Request` type via `export * from '../../types/types.js'` (line 81). The codebase convention for this exact ambiguity is to write `globalThis.Request` (see `shared/protocol.ts:261`, `types/types.ts:523`) — consider `export type RequestInfo = globalThis.Request;` so a future `import type { Request }` here can't silentl
Comment thread
felixweinberger marked this conversation as resolved.
Outdated

// `FetchLike` keeps its v1 name and is re-exported above from
// '../../shared/transport.js' — no alias needed.
21 changes: 21 additions & 0 deletions packages/core/test/exports/public.compat.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { describe, expect, expectTypeOf, test } from 'vitest';
import type { FetchLike, IsomorphicHeaders, RequestInfo } from '../../src/exports/public/index.js';

describe('v1 compat type aliases (core/public)', () => {
test('IsomorphicHeaders aliases the standard Headers type', () => {
expectTypeOf<IsomorphicHeaders>().toEqualTypeOf<Headers>();
const h: IsomorphicHeaders = new Headers({ 'content-type': 'application/json' });
expect(h.get('content-type')).toBe('application/json');
});

test('RequestInfo aliases the standard Request type', () => {
expectTypeOf<RequestInfo>().toEqualTypeOf<Request>();
const r: RequestInfo = new Request('http://localhost/mcp');
expect(r.url).toBe('http://localhost/mcp');
});

test('FetchLike is re-exported', () => {
const f: FetchLike = (url, init) => fetch(url, init);
expect(typeof f).toBe('function');
});
});
Loading