Skip to content
Draft
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
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 @@ 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.
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