Skip to content

Commit e316e7d

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 e316e7d

File tree

4 files changed

+63
-0
lines changed

4 files changed

+63
-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 deprecated v1 type aliases to the public API surface for smoother migration: `ResourceTemplate` (→ `ResourceTemplateType`), `IsomorphicHeaders` (→ `Headers`), and `RequestInfo` (→ `Request`). `FetchLike` retains its v1 name. All aliases are `@deprecated` and will be removed in v3.

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

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,3 +142,32 @@ 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 (deprecated, removed in v3)
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+
* @deprecated Use the standard {@linkcode Headers} web type. Removed in v3.
156+
*
157+
* v1's `IsomorphicHeaders` (`Record<string, string | string[] | undefined>`) is
158+
* no longer used; v2 transports surface request headers via the standard
159+
* `Headers` API on `ctx.http?.req`.
160+
*/
161+
export type IsomorphicHeaders = Headers;
162+
163+
/**
164+
* @deprecated Use the standard {@linkcode Request} web type. Removed in v3.
165+
*
166+
* v1's `RequestInfo` (`{ headers; url? }`) is no longer used; v2's
167+
* {@linkcode ServerContext} exposes the originating HTTP request as a standard
168+
* `Request` at `ctx.http?.req`.
169+
*/
170+
export type RequestInfo = Request;
171+
172+
// `FetchLike` keeps its v1 name and is re-exported above from
173+
// '../../shared/transport.js' — no alias needed.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/* eslint-disable @typescript-eslint/no-deprecated */
2+
import { describe, expect, expectTypeOf, test } from 'vitest';
3+
import type { FetchLike, IsomorphicHeaders, RequestInfo } from '../../src/exports/public/index.js';
4+
5+
describe('v1 compat type aliases (core/public)', () => {
6+
test('IsomorphicHeaders aliases the standard Headers type', () => {
7+
expectTypeOf<IsomorphicHeaders>().toEqualTypeOf<Headers>();
8+
const h: IsomorphicHeaders = new Headers({ 'content-type': 'application/json' });
9+
expect(h.get('content-type')).toBe('application/json');
10+
});
11+
12+
test('RequestInfo aliases the standard Request type', () => {
13+
expectTypeOf<RequestInfo>().toEqualTypeOf<Request>();
14+
const r: RequestInfo = new Request('http://localhost/mcp');
15+
expect(r.url).toBe('http://localhost/mcp');
16+
});
17+
18+
test('FetchLike is re-exported', () => {
19+
const f: FetchLike = (url, init) => fetch(url, init);
20+
expect(typeof f).toBe('function');
21+
});
22+
});

packages/server/src/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ export type {
2323
ResourceMetadata,
2424
ToolCallback
2525
} from './server/mcp.js';
26+
// The `ResourceTemplate` helper class intentionally shadows the deprecated
27+
// `ResourceTemplate` type alias re-exported from core/public below. ES module
28+
// semantics resolve this correctly (named export wins over `export *`).
29+
// eslint-disable-next-line import/export
2630
export { McpServer, ResourceTemplate } from './server/mcp.js';
2731
export type { HostHeaderValidationResult } from './server/middleware/hostHeaderValidation.js';
2832
export { hostHeaderValidationResponse, localhostAllowedHostnames, validateHostHeader } from './server/middleware/hostHeaderValidation.js';
@@ -47,4 +51,5 @@ export { ExperimentalServerTasks } from './experimental/tasks/server.js';
4751
export { fromJsonSchema } from './fromJsonSchema.js';
4852

4953
// re-export curated public API from core
54+
// eslint-disable-next-line import/export -- see ResourceTemplate note above
5055
export * from '@modelcontextprotocol/core/public';

0 commit comments

Comments
 (0)