ajv-provider.d.ts 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /**
  2. * AJV-based JSON Schema validator provider
  3. */
  4. import Ajv from 'ajv';
  5. import type { JsonSchemaType, JsonSchemaValidator, jsonSchemaValidator } from './types.js';
  6. /**
  7. * @example
  8. * ```typescript
  9. * // Use with default AJV instance (recommended)
  10. * import { AjvJsonSchemaValidator } from '@modelcontextprotocol/sdk/validation/ajv';
  11. * const validator = new AjvJsonSchemaValidator();
  12. *
  13. * // Use with custom AJV instance
  14. * import { Ajv } from 'ajv';
  15. * const ajv = new Ajv({ strict: true, allErrors: true });
  16. * const validator = new AjvJsonSchemaValidator(ajv);
  17. * ```
  18. */
  19. export declare class AjvJsonSchemaValidator implements jsonSchemaValidator {
  20. private _ajv;
  21. /**
  22. * Create an AJV validator
  23. *
  24. * @param ajv - Optional pre-configured AJV instance. If not provided, a default instance will be created.
  25. *
  26. * @example
  27. * ```typescript
  28. * // Use default configuration (recommended for most cases)
  29. * import { AjvJsonSchemaValidator } from '@modelcontextprotocol/sdk/validation/ajv';
  30. * const validator = new AjvJsonSchemaValidator();
  31. *
  32. * // Or provide custom AJV instance for advanced configuration
  33. * import { Ajv } from 'ajv';
  34. * import addFormats from 'ajv-formats';
  35. *
  36. * const ajv = new Ajv({ validateFormats: true });
  37. * addFormats(ajv);
  38. * const validator = new AjvJsonSchemaValidator(ajv);
  39. * ```
  40. */
  41. constructor(ajv?: Ajv);
  42. /**
  43. * Create a validator for the given JSON Schema
  44. *
  45. * The validator is compiled once and can be reused multiple times.
  46. * If the schema has an $id, it will be cached by AJV automatically.
  47. *
  48. * @param schema - Standard JSON Schema object
  49. * @returns A validator function that validates input data
  50. */
  51. getValidator<T>(schema: JsonSchemaType): JsonSchemaValidator<T>;
  52. }
  53. //# sourceMappingURL=ajv-provider.d.ts.map