diff --git a/.changeset/compat-v1-type-aliases.md b/.changeset/compat-v1-type-aliases.md new file mode 100644 index 000000000..9ff92dbed --- /dev/null +++ b/.changeset/compat-v1-type-aliases.md @@ -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. diff --git a/packages/core/src/exports/public/index.ts b/packages/core/src/exports/public/index.ts index 2dc1e13a8..f242070bd 100644 --- a/packages/core/src/exports/public/index.ts +++ b/packages/core/src/exports/public/index.ts @@ -142,3 +142,26 @@ export type { CfWorkerSchemaDraft } from '../../validators/cfWorkerProvider.js'; // 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`. + +/** + * v1 name. v2 transports surface request headers via the standard `Headers` + * web type on `ctx.http?.req`. + */ +export type IsomorphicHeaders = Headers; + +/** + * v1 name. v2's {@linkcode ServerContext} exposes the originating HTTP request + * as the standard `Request` web type at `ctx.http?.req`. + */ +export type RequestInfo = Request; + +// `FetchLike` keeps its v1 name and is re-exported above from +// '../../shared/transport.js' — no alias needed. diff --git a/packages/core/test/exports/public.compat.test.ts b/packages/core/test/exports/public.compat.test.ts new file mode 100644 index 000000000..c28e9ffb9 --- /dev/null +++ b/packages/core/test/exports/public.compat.test.ts @@ -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().toEqualTypeOf(); + 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().toEqualTypeOf(); + 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'); + }); +});