Create an AJV validator
Optionalajv: AjvOptional pre-configured AJV instance. If not provided, a default instance will be created.
// Use default configuration (recommended for most cases)
import { AjvJsonSchemaValidator } from '@modelcontextprotocol/sdk/validation/ajv';
const validator = new AjvJsonSchemaValidator();
// Or provide custom AJV instance for advanced configuration
import { Ajv } from 'ajv';
import addFormats from 'ajv-formats';
const ajv = new Ajv({ validateFormats: true });
addFormats(ajv);
const validator = new AjvJsonSchemaValidator(ajv);
Create a validator for the given JSON Schema
The validator is compiled once and can be reused multiple times. If the schema has an $id, it will be cached by AJV automatically.
Standard JSON Schema object
A validator function that validates input data
Example