From 7e8ad105dec164f749b3e9cca2e875174e6bd223 Mon Sep 17 00:00:00 2001 From: Felix Weinberger Date: Wed, 24 Jun 2026 15:50:25 +0000 Subject: [PATCH] fix(packaging): inline json-schema-typed in dist .d.mts; move validator provider types to subpath-only MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The bundled server/client dist .d.mts files leaked two type references that break downstream consumers with skipLibCheck:false (the TS default): - types-*.d.mts imported 'json-schema-typed', which is not a dependency of server/client (only of core, which is bundled). Fixed by adding 'json-schema-typed' to dts.resolve so the JSONSchema type is inlined. - ajvProvider-*.d.mts referenced URIComponent without a declaration. ajv@8.18.0's .d.ts does `import { URIComponent } from "fast-uri"`, but fast-uri ships its types as `export = namespace`, which the dts bundler cannot destructure — it drops the import and leaves the bare reference. Fixed by removing the type-only re-exports of AjvJsonSchemaValidator / CfWorkerJsonSchemaValidator / CfWorkerSchemaDraft from the public root barrel: those classes/types are still exported from the dedicated /validators/ajv and /validators/cf-worker subpaths (and the runtime _shims conditional), so the inlined ajv type chunk is no longer reachable from index.d.mts. The codemod already routes v1 imports to the subpaths. Also: - @modelcontextprotocol/node package.json: remove typesVersions.sse entry pointing at nonexistent dist/sse.d.mts. - server/client READMEs: note that TS >=6.0 needs "types": ["node"] in tsconfig (TS 6 dropped implicit @types inclusion; the published .d.mts references Buffer). Verified: pnpm build:all + typecheck:all + docs:check green; fresh npm install of packed tarballs + `npx tsc --noEmit` (NodeNext + bundler, strict, skipLibCheck:false) is clean. --- .changeset/validators-subpath-only.md | 6 +++++ packages/client/README.md | 2 ++ packages/client/tsdown.config.ts | 3 ++- packages/core/src/exports/public/index.ts | 8 +++---- packages/core/src/validators/fastUriShim.d.ts | 24 +++++++++++++++++++ packages/middleware/node/package.json | 7 ------ packages/server/README.md | 2 ++ packages/server/tsdown.config.ts | 3 ++- 8 files changed, 42 insertions(+), 13 deletions(-) create mode 100644 .changeset/validators-subpath-only.md create mode 100644 packages/core/src/validators/fastUriShim.d.ts diff --git a/.changeset/validators-subpath-only.md b/.changeset/validators-subpath-only.md new file mode 100644 index 0000000000..d175a9e87e --- /dev/null +++ b/.changeset/validators-subpath-only.md @@ -0,0 +1,6 @@ +--- +'@modelcontextprotocol/server': patch +'@modelcontextprotocol/client': patch +--- + +`AjvJsonSchemaValidator`, `CfWorkerJsonSchemaValidator` and `CfWorkerSchemaDraft` types are now only exported from the `/validators/ajv` and `/validators/cf-worker` subpaths, not the package root. The codemod already routes v1 imports there. diff --git a/packages/client/README.md b/packages/client/README.md index e9ce66f511..3248ec9859 100644 --- a/packages/client/README.md +++ b/packages/client/README.md @@ -16,6 +16,8 @@ The MCP (Model Context Protocol) TypeScript client SDK. Build MCP clients that c npm install @modelcontextprotocol/client@alpha ``` +TypeScript ≥6.0 no longer auto-includes `@types/*` — add `"types": ["node"]` to your `tsconfig.json` `compilerOptions` (the published `.d.mts` references `Buffer`). + ## Documentation - **[Repository README](https://github.com/modelcontextprotocol/typescript-sdk#readme)** — overview, package layout, examples diff --git a/packages/client/tsdown.config.ts b/packages/client/tsdown.config.ts index 773e07c920..70d5d7af4b 100644 --- a/packages/client/tsdown.config.ts +++ b/packages/client/tsdown.config.ts @@ -20,10 +20,11 @@ export default defineConfig({ shims: true, dts: { resolver: 'tsc', - resolve: ['ajv', 'ajv-formats'], + resolve: ['ajv', 'ajv-formats', 'json-schema-typed'], compilerOptions: { baseUrl: '.', paths: { + 'fast-uri': ['../core/src/validators/fastUriShim.d.ts'], '@modelcontextprotocol/core': ['../core/src/index.ts'], '@modelcontextprotocol/core/public': ['../core/src/exports/public/index.ts'], '@modelcontextprotocol/core/validators/ajv': ['../core/src/validators/ajvProvider.ts'], diff --git a/packages/core/src/exports/public/index.ts b/packages/core/src/exports/public/index.ts index c7cc53e0cb..b6feba9f13 100644 --- a/packages/core/src/exports/public/index.ts +++ b/packages/core/src/exports/public/index.ts @@ -129,10 +129,10 @@ export { export type { SpecTypeName, SpecTypes } from '../../types/specTypeSchema.js'; export { isSpecType, specTypeSchemas } from '../../types/specTypeSchema.js'; export type { StandardSchemaV1, StandardSchemaV1Sync, StandardSchemaWithJSON } from '../../util/standardSchema.js'; -// Validator providers are type-only here — import the runtime classes from the explicit -// `@modelcontextprotocol/{client,server}/validators/{ajv,cf-worker}` subpaths to customise. -export type { AjvJsonSchemaValidator } from '../../validators/ajvProvider.js'; -export type { CfWorkerJsonSchemaValidator, CfWorkerSchemaDraft } from '../../validators/cfWorkerProvider.js'; +// Validator provider classes (`AjvJsonSchemaValidator`, `CfWorkerJsonSchemaValidator`) are +// intentionally NOT re-exported here — import them from the explicit +// `@modelcontextprotocol/{client,server}/validators/{ajv,cf-worker}` subpaths so the +// root entrypoint's bundled `.d.mts` doesn't pull the inlined ajv/cfworker type chunks. // 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'; diff --git a/packages/core/src/validators/fastUriShim.d.ts b/packages/core/src/validators/fastUriShim.d.ts new file mode 100644 index 0000000000..e2f5e21506 --- /dev/null +++ b/packages/core/src/validators/fastUriShim.d.ts @@ -0,0 +1,24 @@ +/** + * dts-bundling shim for `fast-uri`. + * + * ajv@8.18.0's published .d.ts does `import { URIComponent } from "fast-uri"`, + * but fast-uri ships its types as `export = namespace`, which rolldown's dts + * bundler can't destructure into a named import — it drops the import and + * leaves a dangling `URIComponent` reference in the bundled .d.mts (TS2304 for + * downstream consumers with `skipLibCheck: false`). + * + * The server/client tsdown configs map `fast-uri` to this file via + * `dts.compilerOptions.paths` so the type is inlined as a plain named export. + * Runtime code is unaffected (this is a `.d.ts`; the path mapping is dts-only). + */ +export interface URIComponent { + scheme?: string; + userinfo?: string; + host?: string; + port?: number | string; + path?: string; + query?: string; + fragment?: string; + reference?: string; + error?: string; +} diff --git a/packages/middleware/node/package.json b/packages/middleware/node/package.json index 30fa7ed663..9b12fa1fc0 100644 --- a/packages/middleware/node/package.json +++ b/packages/middleware/node/package.json @@ -27,13 +27,6 @@ } }, "types": "./dist/index.d.mts", - "typesVersions": { - "*": { - "sse": [ - "dist/sse.d.mts" - ] - } - }, "files": [ "dist" ], diff --git a/packages/server/README.md b/packages/server/README.md index 0dfe938209..7f46a411df 100644 --- a/packages/server/README.md +++ b/packages/server/README.md @@ -16,6 +16,8 @@ The MCP (Model Context Protocol) TypeScript server SDK. Build MCP servers that e npm install @modelcontextprotocol/server@alpha ``` +TypeScript ≥6.0 no longer auto-includes `@types/*` — add `"types": ["node"]` to your `tsconfig.json` `compilerOptions` (the published `.d.mts` references `Buffer`). + Optional framework adapters: [`@modelcontextprotocol/express`](https://www.npmjs.com/package/@modelcontextprotocol/express), [`@modelcontextprotocol/hono`](https://www.npmjs.com/package/@modelcontextprotocol/hono), [`@modelcontextprotocol/node`](https://www.npmjs.com/package/@modelcontextprotocol/node). diff --git a/packages/server/tsdown.config.ts b/packages/server/tsdown.config.ts index 891ce49641..ae48c7945b 100644 --- a/packages/server/tsdown.config.ts +++ b/packages/server/tsdown.config.ts @@ -19,10 +19,11 @@ export default defineConfig({ shims: true, dts: { resolver: 'tsc', - resolve: ['ajv', 'ajv-formats'], + resolve: ['ajv', 'ajv-formats', 'json-schema-typed'], compilerOptions: { baseUrl: '.', paths: { + 'fast-uri': ['../core/src/validators/fastUriShim.d.ts'], '@modelcontextprotocol/core': ['../core/src/index.ts'], '@modelcontextprotocol/core/public': ['../core/src/exports/public/index.ts'], '@modelcontextprotocol/core/validators/ajv': ['../core/src/validators/ajvProvider.ts'],