mcp-use
Version:
Opinionated MCP Framework for TypeScript (@modelcontextprotocol/sdk compatible) - Build MCP Agents, Clients and Servers with support for ChatGPT Apps, Code Mode, OAuth, Notifications, Sampling, Observability and more.
270 lines • 10.2 kB
TypeScript
import type { ZodSchema } from "zod";
import type { JSONSchema } from "./Type.js";
export declare class JSONSchemaToZod {
/**
* Converts a JSON schema to a Zod schema.
*
* @param {JSONSchema} schema - The JSON schema.
* @returns {ZodSchema} - The Zod schema.
*/
static convert(schema: JSONSchema): ZodSchema;
/**
* Checks if data matches a condition schema.
*
* @param {JSONValue} data - The data to check.
* @param {JSONSchema} condition - The condition schema.
* @returns {boolean} - Whether the data matches the condition.
*/
private static matchesCondition;
/**
* Validates data against a conditional schema and adds issues to context if validation fails.
*
* @param {JSONValue} data - The data to validate.
* @param {JSONSchema} schema - The conditional schema.
* @param {z.RefinementCtx} ctx - The Zod refinement context.
*/
private static validateConditionalSchema;
/**
* Validates that all required properties are present in the data.
*
* @param {JSONValue} data - The data to validate.
* @param {JSONSchema} schema - The schema containing required properties.
* @param {z.RefinementCtx} ctx - The Zod refinement context.
*/
private static validateRequiredProperties;
/**
* Validates property patterns for string properties.
*
* @param {JSONValue} data - The data to validate.
* @param {JSONSchema} schema - The schema containing property patterns.
* @param {z.RefinementCtx} ctx - The Zod refinement context.
*/
private static validatePropertyPatterns;
/**
* Validates nested if-then-else conditions.
*
* @param {JSONValue} data - The data to validate.
* @param {JSONSchema} schema - The schema containing if-then-else conditions.
* @param {z.RefinementCtx} ctx - The Zod refinement context.
*/
private static validateNestedConditions;
/**
* Parses a JSON schema and returns the corresponding Zod schema.
* This is the main entry point for schema conversion.
*
* @param {JSONSchema} schema - The JSON schema.
* @returns {ZodTypeAny} - The ZodTypeAny schema.
*/
private static parseSchema;
/**
* Handles schemas with an array of types.
*
* @param {JSONSchema} schema - The JSON schema with type array.
* @returns {ZodTypeAny} - The ZodTypeAny schema.
*/
private static handleTypeArray;
/**
* Handles nullable types by creating a nullable schema.
*
* @param {JSONSchema} schema - The JSON schema with nullable type.
* @returns {ZodTypeAny} - The nullable Zod schema.
*/
private static handleNullableType;
/**
* Creates a union type from an array of types.
*
* @param {string[]} types - Array of type strings.
* @param {JSONSchema} baseSchema - The base schema to apply to each type.
* @returns {ZodTypeAny} - The union Zod schema.
*/
private static createUnionFromTypes;
/**
* Handles schemas with a single type.
*
* @param {JSONSchema} schema - The JSON schema with single type.
* @returns {ZodTypeAny} - The ZodTypeAny schema.
*/
private static handleSingleType;
/**
* Parses a number schema.
*
* @param {JSONSchema} schema - The JSON schema for a number.
* @returns {ZodTypeAny} - The ZodTypeAny schema.
*/
private static parseNumberSchema;
/**
* Applies bounds validation to a number schema.
*
* @param {z.ZodNumber} numberSchema - The base number schema.
* @param {JSONSchema} schema - The JSON schema with bounds.
* @returns {z.ZodNumber} - The updated schema with bounds validation.
*/
private static applyNumberBounds;
/**
* Applies multipleOf validation to a number schema.
*
* @param {z.ZodNumber} numberSchema - The base number schema.
* @param {JSONSchema} schema - The JSON schema with multipleOf.
* @returns {z.ZodNumber} - The updated schema with multipleOf validation.
*/
private static applyNumberMultipleOf;
/**
* Applies enum validation to a number schema.
*
* @param {z.ZodNumber} numberSchema - The base number schema.
* @param {JSONSchema} schema - The JSON schema with enum.
* @returns {z.ZodNumber} - The updated schema with enum validation.
*/
private static applyNumberEnum;
/**
* Applies integer constraint to a number schema if needed.
*
* @param {z.ZodNumber} numberSchema - The base number schema.
* @param {JSONSchema} schema - The JSON schema.
* @returns {z.ZodNumber} - The updated schema with integer validation if needed.
*/
private static applyIntegerConstraint;
/**
* Parses a string schema.
*
* @param {JSONSchema} schema - The JSON schema for a string.
* @returns {ZodTypeAny} - The ZodTypeAny schema.
*/
private static parseString;
/**
* Applies format validation to a string schema.
*
* @param {z.ZodString} stringSchema - The base string schema.
* @param {JSONSchema} schema - The JSON schema with format.
* @returns {ZodTypeAny} - The updated schema with format validation.
*/
private static applyStringFormat;
/**
* Applies pattern validation to a string schema.
*
* @param {z.ZodString} stringSchema - The base string schema.
* @param {JSONSchema} schema - The JSON schema with pattern.
* @returns {z.ZodString} - The updated schema with pattern validation.
*/
private static applyStringPattern;
/**
* Applies length constraints to a string schema.
*
* @param {z.ZodString} stringSchema - The base string schema.
* @param {JSONSchema} schema - The JSON schema with length constraints.
* @returns {z.ZodString} - The updated schema with length validation.
*/
private static applyStringLength;
/**
* Applies enum validation to a string schema.
*
* @param {z.ZodString} stringSchema - The base string schema.
* @param {JSONSchema} schema - The JSON schema with enum.
* @returns {ZodTypeAny} - The updated schema with enum validation.
*/
private static applyStringEnum;
/**
* Parses a JSON schema of type array and returns the corresponding Zod schema.
*
* @param {JSONSchema} schema - The JSON schema.
* @returns {ZodTypeAny} - The ZodTypeAny schema.
*/
private static parseArray;
/**
* Applies constraints to an array schema.
*
* @param {z.ZodArray<any>} arraySchema - The base array schema.
* @param {JSONSchema} schema - The JSON schema with array constraints.
* @returns {z.ZodTypeAny} - The updated array schema with constraints.
*/
private static applyArrayConstraints;
/**
* Parses an object schema.
*
* @param {JSONSchema} schema - The JSON schema for an object.
* @returns {ZodTypeAny} - The ZodTypeAny schema.
*/
private static parseObject;
/**
* Processes object properties and builds the shape object.
*
* @param {JSONSchema} schema - The JSON schema for an object.
* @param {Record<string, ZodTypeAny>} shape - The shape object to populate.
*/
private static processObjectProperties;
/**
* Processes additionalProperties configuration.
*
* @param {JSONSchema} schema - The JSON schema for an object.
* @param {z.ZodObject<any, any>} objectSchema - The Zod object schema.
* @returns {z.ZodObject<any, any>} - The updated Zod object schema.
*/
private static processAdditionalProperties;
/**
* Parses a conditional schema with if-then-else.
*
* @param {JSONSchema} schema - The JSON schema with conditional validation.
* @returns {ZodTypeAny} - The conditional Zod schema.
*/
private static parseConditional;
/**
* Creates a base object schema from the given JSON schema.
*
* @param {JSONSchema} schema - The JSON schema.
* @returns {z.ZodObject<any, any>} - The base Zod object schema.
*/
private static createBaseObjectSchema;
/**
* Applies default values from schema properties to data object.
*
* @param {JSONValue} data - The original data object.
* @param {JSONSchema} schema - The schema with default values.
* @returns {JSONValue} - The data object with defaults applied.
*/
private static applyDefaultValues;
/**
* Parses a schema with combinators (oneOf, anyOf, allOf).
* Delegates to the appropriate combinator parser based on which combinator is present.
*
* @param {JSONSchema} schema - The JSON schema with combinators.
* @returns {ZodTypeAny} - The ZodTypeAny schema.
*/
private static parseCombinator;
/**
* Parses a oneOf combinator schema.
*
* @param {JSONSchema[]} schemas - Array of JSON schemas in the oneOf.
* @returns {ZodTypeAny} - The ZodTypeAny schema.
*/
private static parseOneOf;
/**
* Parses an anyOf combinator schema.
*
* @param {JSONSchema[]} schemas - Array of JSON schemas in the anyOf.
* @returns {ZodTypeAny} - The ZodTypeAny schema.
*/
private static parseAnyOf;
/**
* Creates a union from an array of schemas, handling special cases.
*
* @param {JSONSchema[]} schemas - Array of JSON schemas to create a union from.
* @returns {ZodTypeAny} - The union Zod schema.
*/
private static createUnionFromSchemas;
/**
* Parses an allOf combinator schema by merging all schemas.
*
* @param {JSONSchema[]} schemas - Array of JSON schemas in the allOf.
* @returns {ZodTypeAny} - The ZodTypeAny schema.
*/
private static parseAllOf;
/**
* Merges two JSON schemas together.
*
* @param {JSONSchema} baseSchema - The base JSON schema.
* @param {JSONSchema} addSchema - The JSON schema to add.
* @returns {JSONSchema} - The merged JSON schema
*/
private static mergeSchemas;
}
//# sourceMappingURL=JSONSchemaToZod.d.ts.map