MCP TypeScript SDK (V2) / @modelcontextprotocol/server / shimsNode
shimsNode
Classes
DefaultJsonSchemaValidator
Defined in: packages/core-internal/src/validators/ajvProvider.ts:81
AJV-backed JSON Schema validator. See @modelcontextprotocol/{client,server}/validators/ajv for the customisation entry point (re-exports Ajv and addFormats from the bundled copy).
Default validates as JSON Schema 2020-12 (SEP-1613). Schemas declaring a different $schema are rejected with a plain Error; pass a pre-configured Ajv instance to validate other dialects. The SDK bundles ajv internally but does not re-export Ajv2020 (its type graph tips downstream declaration bundling — see #2339). To construct a custom 2020-12 instance, add ajv to your own dependencies (matching the SDK's pinned version) and import { Ajv2020 } from 'ajv/dist/2020.js' — new Ajv(...) is the draft-07 class and would silently downgrade dialect.
Examples
Use with default configuration
const validator = new AjvJsonSchemaValidator();Use with a custom AJV instance
// import { Ajv2020 } from 'ajv/dist/2020.js';
const ajv = new Ajv2020({ strict: false, validateSchema: false, allErrors: true });
const validator = new AjvJsonSchemaValidator(ajv);Register ajv-formats
// import { Ajv2020 } from 'ajv/dist/2020.js';
const ajv = new Ajv2020({ strict: false, validateSchema: false, allErrors: true });
addFormats(ajv);
const validator = new AjvJsonSchemaValidator(ajv);Implements
Constructors
Constructor
new DefaultJsonSchemaValidator(
ajv?):DefaultJsonSchemaValidator
Defined in: packages/core-internal/src/validators/ajvProvider.ts:96
Parameters
ajv?
AjvLike
Optional pre-configured AJV-compatible instance. When supplied, this instance is used for every schema regardless of its declared $schema (the caller owns dialect choice). When omitted, the provider constructs a single Ajv2020 instance with strict: false, validateFormats: true, validateSchema: false, allErrors: true, and ajv-formats registered — lazily, on the first getValidator call, so constructing the provider (e.g. as the default validator of a Client/Server that never validates a JSON Schema) does not pay the ajv + ajv-formats instantiation cost. The parameter is typed structurally so consumers who don't pass an instance need not have ajv installed.
Returns
Methods
getValidator()
getValidator<
T>(schema):JsonSchemaValidator<T>
Defined in: packages/core-internal/src/validators/ajvProvider.ts:106
Create a validator for the given JSON Schema
Type Parameters
T
T
Parameters
schema
Standard JSON Schema object
Returns
A validator function that can be called multiple times
Implementation of
jsonSchemaValidator.getValidator
Variables
process
process:
NodeJS.Process
Defined in: node_modules/.pnpm/@types+node@24.12.0/node_modules/@types/node/globals.d.ts:3