Skip to content

Commit 1436a5a

Browse files
committed
docs(core): align validator examples with bundled-shim surface
After PR #2088, end users can no longer import or construct AjvJsonSchemaValidator / CfWorkerJsonSchemaValidator — client/server bundle them via the runtime shim and expose only the jsonSchemaValidator interface as the public extension point. - Strip impossible `new AjvJsonSchemaValidator()` / `new CfWorkerJsonSchemaValidator()` snippets from JSDoc on the validation module, ajvProvider, cfWorkerProvider, and fromJsonSchema; mark the provider classes @internal. - fromJsonSchema example now declares `validator: jsonSchemaValidator` and notes that consumers importing from server/client omit the second arg. - Drop the type-only re-exports of AjvJsonSchemaValidator, CfWorkerJsonSchemaValidator, and CfWorkerSchemaDraft from core/public — with the runtime classes unreachable, a type-only handle is dead surface. - Reword the migration docs to describe backends by name (AJV / @cfworker/json-schema) instead of the now-internal class names.
1 parent ba61c07 commit 1436a5a

11 files changed

Lines changed: 34 additions & 173 deletions

.changeset/workerd-shim-vendors-cfworker.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,5 @@ Make validator backends symmetrical in core and bundle automatic defaults in cli
99
Core no longer re-exports concrete validator providers as runtime values from the root/public barrels. AJV/AJV formats and `@cfworker/json-schema` are optional peer backends behind explicit core validator provider subpaths, used internally by client/server shims.
1010

1111
Client/server continue to select defaults automatically: Node shims use AJV, while browser/workerd shims use `@cfworker/json-schema`. Those backends are bundled into the shim chunks that select them, so users do not need to install validator packages or import explicit validators for default behavior. Advanced users can still pass their own `jsonSchemaValidator` implementation.
12+
13+
`AjvJsonSchemaValidator` and `CfWorkerJsonSchemaValidator` are now `@internal` and no longer surface from `@modelcontextprotocol/core/public` (not even as types). The `jsonSchemaValidator` interface remains the public extension point for custom validators. Example JSDoc snippets no longer demonstrate direct validator instantiation.

docs/migration-SKILL.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -509,8 +509,8 @@ Type changes in handler context:
509509

510510
The SDK now auto-selects the appropriate JSON Schema validator based on runtime:
511511

512-
- Node.js → `AjvJsonSchemaValidator` (no change from v1)
513-
- Cloudflare Workers (workerd) → `CfWorkerJsonSchemaValidator` (previously required manual config)
512+
- Node.js → AJV (no change from v1)
513+
- Cloudflare Workers (workerd) → `@cfworker/json-schema` (previously required manual config)
514514

515515
**No action required** for most users. Cloudflare Workers users can remove explicit `jsonSchemaValidator` configuration:
516516

docs/migration.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -901,8 +901,8 @@ server.setRequestHandler('tools/call', async (request, ctx) => {
901901

902902
The SDK now automatically selects the appropriate JSON Schema validator based on your runtime environment:
903903

904-
- **Node.js**: Uses `AjvJsonSchemaValidator` (same as v1 default)
905-
- **Cloudflare Workers**: Uses `CfWorkerJsonSchemaValidator` (previously required manual configuration)
904+
- **Node.js**: Uses AJV (same as v1 default)
905+
- **Cloudflare Workers**: Uses `@cfworker/json-schema` (previously required manual configuration)
906906

907907
This means Cloudflare Workers users no longer need to explicitly pass the validator:
908908

packages/core/src/index.examples.ts

Lines changed: 0 additions & 31 deletions
This file was deleted.

packages/core/src/index.ts

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -29,28 +29,14 @@ export * from './validators/fromJsonSchema.js';
2929
/**
3030
* JSON Schema validation
3131
*
32-
* This module provides configurable JSON Schema validation for the MCP SDK.
33-
* Choose a validator based on your runtime environment:
32+
* Client and server packages automatically select a JSON Schema validator backend based on the
33+
* runtime: AJV-backed on Node.js, `@cfworker/json-schema`-backed on browser/workerd. Both backends
34+
* are bundled into the corresponding shim, so consumers do not need to install or import validator
35+
* packages for the default behaviour.
3436
*
35-
* - `AjvJsonSchemaValidator`: Best for Node.js (default, fastest)
36-
* Used automatically by client/server Node shims.
37-
*
38-
* - `CfWorkerJsonSchemaValidator`: Best for edge runtimes
39-
* Used automatically by client/server browser/workerd shims.
40-
*
41-
* Client and server packages bundle their runtime default validator backends, so most users should
42-
* rely on automatic runtime selection. Advanced users can pass their own validator implementation
43-
* through client/server options.
44-
*
45-
* @example For Node.js with AJV
46-
* ```ts source="./index.examples.ts#validation_ajv"
47-
* const validator = new AjvJsonSchemaValidator();
48-
* ```
49-
*
50-
* @example For Cloudflare Workers
51-
* ```ts source="./index.examples.ts#validation_cfWorker"
52-
* const validator = new CfWorkerJsonSchemaValidator();
53-
* ```
37+
* To override validation, pass an object implementing the {@link jsonSchemaValidator} interface as
38+
* `jsonSchemaValidator` on the client/server options. See `validators/types.ts` for the contract
39+
* and a sample implementation.
5440
*
5541
* @module validation
5642
*/

packages/core/src/validators/ajvProvider.examples.ts

Lines changed: 0 additions & 48 deletions
This file was deleted.

packages/core/src/validators/ajvProvider.ts

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,13 @@ function createDefaultAjvInstance(): Ajv {
2222
}
2323

2424
/**
25-
* @example Use with default AJV instance (recommended)
26-
* ```ts source="./ajvProvider.examples.ts#AjvJsonSchemaValidator_default"
27-
* const validator = new AjvJsonSchemaValidator();
28-
* ```
25+
* AJV-backed validator used as the default in Node shims.
2926
*
30-
* @example Use with custom AJV instance
31-
* ```ts source="./ajvProvider.examples.ts#AjvJsonSchemaValidator_customInstance"
32-
* const ajv = new Ajv({ strict: true, allErrors: true });
33-
* const validator = new AjvJsonSchemaValidator(ajv);
34-
* ```
27+
* Not part of the public surface: end users get this automatically via the runtime shim and
28+
* cannot import it from `@modelcontextprotocol/client` or `@modelcontextprotocol/server`.
29+
* To override validation, implement the {@link jsonSchemaValidator} interface.
3530
*
36-
* @see `CfWorkerJsonSchemaValidator` for the edge-runtime-compatible validator selected automatically by client/server browser/workerd shims.
31+
* @internal
3732
*/
3833
export class AjvJsonSchemaValidator implements jsonSchemaValidator {
3934
private _ajv: Ajv;
@@ -42,18 +37,6 @@ export class AjvJsonSchemaValidator implements jsonSchemaValidator {
4237
* Create an AJV validator
4338
*
4439
* @param ajv - Optional pre-configured AJV instance. If not provided, a default instance will be created.
45-
*
46-
* @example Use default configuration (recommended for most cases)
47-
* ```ts source="./ajvProvider.examples.ts#AjvJsonSchemaValidator_default"
48-
* const validator = new AjvJsonSchemaValidator();
49-
* ```
50-
*
51-
* @example Provide custom AJV instance for advanced configuration
52-
* ```ts source="./ajvProvider.examples.ts#AjvJsonSchemaValidator_constructor_withFormats"
53-
* const ajv = new Ajv({ validateFormats: true });
54-
* addFormats(ajv);
55-
* const validator = new AjvJsonSchemaValidator(ajv);
56-
* ```
5740
*/
5841
constructor(ajv?: Ajv) {
5942
this._ajv = ajv ?? createDefaultAjvInstance();

packages/core/src/validators/cfWorkerProvider.examples.ts

Lines changed: 0 additions & 33 deletions
This file was deleted.

packages/core/src/validators/cfWorkerProvider.ts

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,19 @@ import type { JsonSchemaType, JsonSchemaValidator, jsonSchemaValidator, JsonSche
1414

1515
/**
1616
* JSON Schema draft version supported by @cfworker/json-schema
17+
*
18+
* @internal
1719
*/
1820
export type CfWorkerSchemaDraft = '4' | '7' | '2019-09' | '2020-12';
1921

2022
/**
23+
* `@cfworker/json-schema`-backed validator used as the default in browser/workerd shims.
2124
*
22-
* @example Use with default configuration (2020-12, shortcircuit)
23-
* ```ts source="./cfWorkerProvider.examples.ts#CfWorkerJsonSchemaValidator_default"
24-
* const validator = new CfWorkerJsonSchemaValidator();
25-
* ```
25+
* Not part of the public surface: end users get this automatically via the runtime shim and
26+
* cannot import it from `@modelcontextprotocol/client` or `@modelcontextprotocol/server`.
27+
* To override validation, implement the {@link jsonSchemaValidator} interface.
2628
*
27-
* @example Use with custom configuration
28-
* ```ts source="./cfWorkerProvider.examples.ts#CfWorkerJsonSchemaValidator_customConfig"
29-
* const validator = new CfWorkerJsonSchemaValidator({
30-
* draft: '2020-12',
31-
* shortcircuit: false // Report all errors
32-
* });
33-
* ```
29+
* @internal
3430
*/
3531
export class CfWorkerJsonSchemaValidator implements jsonSchemaValidator {
3632
private shortcircuit: boolean;

packages/core/src/validators/fromJsonSchema.examples.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,23 @@
66
* @module
77
*/
88

9-
import { AjvJsonSchemaValidator } from './ajvProvider.js';
109
import { fromJsonSchema } from './fromJsonSchema.js';
10+
import type { jsonSchemaValidator } from './types.js';
11+
12+
declare const validator: jsonSchemaValidator;
1113

1214
/**
1315
* Example: wrap a raw JSON Schema object for use with registerTool.
16+
*
17+
* Consumers importing `fromJsonSchema` from `@modelcontextprotocol/server` or
18+
* `@modelcontextprotocol/client` omit the second argument — the runtime shim
19+
* supplies the appropriate default validator.
1420
*/
1521
function fromJsonSchema_basicUsage() {
1622
//#region fromJsonSchema_basicUsage
1723
const inputSchema = fromJsonSchema<{ name: string }>(
1824
{ type: 'object', properties: { name: { type: 'string' } }, required: ['name'] },
19-
new AjvJsonSchemaValidator()
25+
validator
2026
);
2127
// Use with server.registerTool('greet', { inputSchema }, handler)
2228
//#endregion fromJsonSchema_basicUsage

0 commit comments

Comments
 (0)