Skip to content

Commit 0db0535

Browse files
feat(compat): add deprecated v1 type aliases (ResourceTemplate, IsomorphicHeaders, RequestInfo)
Adds @deprecated type aliases to core/public for smoother v1→v2 migration: - ResourceTemplate → ResourceTemplateType (the spec-derived data type) - IsomorphicHeaders → Headers (standard web type) - RequestInfo → Request (standard web type) FetchLike retains its v1 name and was already re-exported. Server's ResourceTemplate helper class intentionally shadows the deprecated type alias via named-export-wins-over-export-star ES module semantics; the import/export lint rule is suppressed at those two sites with an explanatory comment.
1 parent 9ed62fe commit 0db0535

File tree

3 files changed

+51
-0
lines changed

3 files changed

+51
-0
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@modelcontextprotocol/core': patch
3+
'@modelcontextprotocol/client': patch
4+
'@modelcontextprotocol/server': patch
5+
---
6+
7+
Add v1 type aliases to the public API surface for smoother migration: `IsomorphicHeaders` (→ `Headers`) and `RequestInfo` (→ `Request`). `FetchLike` retains its v1 name.

packages/core/src/exports/public/index.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,3 +142,26 @@ export type { CfWorkerSchemaDraft } from '../../validators/cfWorkerProvider.js';
142142
// fromJsonSchema is intentionally NOT exported here — the server and client packages
143143
// provide runtime-aware wrappers that default to the appropriate validator via _shims.
144144
export type { JsonSchemaType, JsonSchemaValidator, jsonSchemaValidator, JsonSchemaValidatorResult } from '../../validators/types.js';
145+
146+
// ────────────────────────────────────────────────────────────────────────────
147+
// v1 backwards-compatibility type aliases
148+
// ────────────────────────────────────────────────────────────────────────────
149+
150+
// Note: a `ResourceTemplate = ResourceTemplateType` alias is intentionally NOT
151+
// exported here — it conflicts with the server's `ResourceTemplate` class under
152+
// tsdown bundling. The alias lives only in the `/sdk` meta-package's `types.js`.
153+
154+
/**
155+
* v1 name. v2 transports surface request headers via the standard `Headers`
156+
* web type on `ctx.http?.req`.
157+
*/
158+
export type IsomorphicHeaders = Headers;
159+
160+
/**
161+
* v1 name. v2's {@linkcode ServerContext} exposes the originating HTTP request
162+
* as the standard `Request` web type at `ctx.http?.req`.
163+
*/
164+
export type RequestInfo = Request;
165+
166+
// `FetchLike` keeps its v1 name and is re-exported above from
167+
// '../../shared/transport.js' — no alias needed.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { describe, expect, expectTypeOf, test } from 'vitest';
2+
import type { FetchLike, IsomorphicHeaders, RequestInfo } from '../../src/exports/public/index.js';
3+
4+
describe('v1 compat type aliases (core/public)', () => {
5+
test('IsomorphicHeaders aliases the standard Headers type', () => {
6+
expectTypeOf<IsomorphicHeaders>().toEqualTypeOf<Headers>();
7+
const h: IsomorphicHeaders = new Headers({ 'content-type': 'application/json' });
8+
expect(h.get('content-type')).toBe('application/json');
9+
});
10+
11+
test('RequestInfo aliases the standard Request type', () => {
12+
expectTypeOf<RequestInfo>().toEqualTypeOf<Request>();
13+
const r: RequestInfo = new Request('http://localhost/mcp');
14+
expect(r.url).toBe('http://localhost/mcp');
15+
});
16+
17+
test('FetchLike is re-exported', () => {
18+
const f: FetchLike = (url, init) => fetch(url, init);
19+
expect(typeof f).toBe('function');
20+
});
21+
});

0 commit comments

Comments
 (0)