MCP-Web Decompose Zod Schema API
PlanBuilder
Class — packages/decompose-zod-schema/src/plan-builder.ts
Fluent builder for constructing schema decomposition plans.
Provides a more ergonomic API for building complex split plans compared to manually constructing arrays.
Methods:
addSplit(path: string): thisAdds a simple path split.
addEnumSplit(path: string, chunkSize: number): thisAdds an enum split that chunks the enum into equal-sized groups.
addEnumSlice(path: string, start: number, end: number): thisAdds an enum slice from start to end index.
addEnumSliceFromIndex(path: string, start: number): thisAdds an enum slice from start index to end.
addEnumSliceToIndex(path: string, end: number): thisAdds an enum slice from start to end index.
addEntireEnumSlice(path: string): thisAdds a slice for the entire enum (equivalent to just the path).
addArraySplit(path: string): thisAdds an array split for item-by-item operations.
addRecordSplit(path: string): thisAdds a record split for key-value operations.
addConditionalEnumSplit(path: string, maxSize: number, schema: ZodObject<Record<string, ZodType>>): thisAdds a conditional enum split based on size. Only splits if enum exceeds maxSize, otherwise adds simple path.
build(): SplitPlanBuilds and returns the split plan.
SizeBasedSuggestionStrategy
Class — packages/decompose-zod-schema/src/split-suggestions.ts
Size-based suggestion strategy that splits schemas based on token count and enum size limits
Properties:
name: anyMethods:
suggest(schema: ZodObject<Record<string, ZodType>>, options: SizeBasedOptions): SplitPlanSuggestionStrategyRegistry
Class — packages/decompose-zod-schema/src/split-suggestions.ts
Registry of available suggestion strategies for future extensibility
Methods:
register(strategy: SuggestionStrategy): voidget(name: string): SuggestionStrategy | undefinedlist(): string[]suggest(strategyName: string, schema: ZodObject<Record<string, ZodType>>, options: unknown): SplitPlanSemanticSuggestionStrategy
Class — packages/decompose-zod-schema/src/split-suggestions.ts
Future strategy example: Semantic-based suggestion This could analyze schema property names, types, and relationships to create more intelligent groupings
Properties:
name: anyMethods:
suggest(schema: ZodObject<Record<string, ZodType>>, _options?: unknown): SplitPlanDecomposedSchema
Interface — packages/decompose-zod-schema/src/types.ts
A decomposed schema segment with metadata about its source.
Properties:
name: stringGenerated name for this schema segment.
schema: ZodObjectThe Zod schema for this segment.
targetPaths: string[]Original paths from the source schema included in this segment.
ArraySplit
Interface — packages/decompose-zod-schema/src/types.ts
Parsed array split information.
Properties:
path: stringBase path to the array property.
isArrayElement: booleanWhether this represents array element operations.
excludedSubArrays: string[]Paths to exclude from the split.
DecompositionOptions
Interface — packages/decompose-zod-schema/src/types.ts
Options for automatic schema decomposition.
Properties:
maxTokensPerSchema?: numberMaximum estimated tokens per decomposed schema.
maxOptionsPerEnum?: numberMaximum options per enum before splitting.
SuggestionStrategy
Interface — packages/decompose-zod-schema/src/types.ts
Strategy interface for suggesting decomposition plans.
Properties:
name: stringName identifier for the strategy.
Methods:
suggest(schema: ZodObject<Record<string, ZodType>>, options?: unknown): SplitPlanGenerates a split plan for the given schema.
SizeBasedOptions
Interface — packages/decompose-zod-schema/src/types.ts
Options for size-based decomposition strategy.
Properties:
maxTokensPerSchema: numberMaximum estimated tokens per decomposed schema.
maxOptionsPerEnum: numberMaximum options per enum before splitting.
SplitGroup
Interface — packages/decompose-zod-schema/src/types.ts
Internal grouping of related splits.
Properties:
name: stringGroup name.
paths: string[]Paths included in this group.
schemas: Record<string, ZodType>Schemas for each path.
Split
Type — packages/decompose-zod-schema/src/types.ts
Split specification for decomposing schemas.
Supports various notations:
- Simple path:
'user'- Extract the 'user' property - Nested path:
'profile.bio'- Extract nested property - Enum chunking:
'category[50]'- Split enum into chunks of 50 - Enum slice:
'category[0:50]'- Extract enum options 0-49 - Array split:
'items[]'- Split array for item operations - Record split:
'records{}'- Split record for key-value operations
SplitPlan
Type — packages/decompose-zod-schema/src/types.ts
Array of split specifications defining how to decompose a schema.
decomposeSchema
Function — packages/decompose-zod-schema/src/decompose.ts
Decomposes a Zod schema into smaller schemas based on a split plan or options.
This function supports two modes:
- Manual decomposition: Pass a SplitPlan array to control exactly how the schema is split
- Automatic decomposition: Pass options to automatically suggest splits based on size
decomposeSchema(schema: ZodObject<Record<string, ZodType>>, planOrOptions: SplitPlan | DecompositionOptions): DecomposedSchema[]decomposeSchemaWithPlan
Function — packages/decompose-zod-schema/src/decompose.ts
Manually decompose a schema using a predefined split plan. This function takes a schema and a split plan that defines exactly how to split it.
decomposeSchemaWithPlan(schema: ZodObject<Record<string, ZodType>>, plan: SplitPlan): DecomposedSchema[]suggestDecompositionPlan
Function — packages/decompose-zod-schema/src/split-suggestions.ts
Default size-based suggestion function
suggestDecompositionPlan(schema: ZodObject<Record<string, ZodType>>, options: SizeBasedOptions): SplitPlansuggestWithStrategy
Function — packages/decompose-zod-schema/src/split-suggestions.ts
Convenience function that uses the default registry
suggestWithStrategy(strategyName: string, schema: ZodObject<Record<string, ZodType>>, options: unknown): SplitPlanconditionalEnumSplit
Function — packages/decompose-zod-schema/src/utils.ts
Helper function to create conditional enum splits based on enum size
conditionalEnumSplit(path: string, maxSize: number, schema: ZodObject<Record<string, ZodType>>): string[]applyPartialUpdate
Variable — packages/decompose-zod-schema/src/apply.ts
unknownsplitSchema
Variable — packages/decompose-zod-schema/src/schemas.ts
A split can be of the following types:
- string // Simple path like 'user' or 'profile.bio'
${string}[${number}]// Enum split into equal max. sized subarrays 'category[50]'${string}[${number}:${number}]// Enum slice like 'category[0:50]'${string}[${number}:]// Enum slice from index to end like 'category[50:]'${string}[:${number}]// Enum slice from start to index like 'category[:50]'${string}[:]// Entire enum (equivalent to just the path)${string}[]// Array split - transforms z.array(T) to z.object({ index: number, value: T })${string}{}; // Record split - transforms z.record(K, V) to z.object({ key: K, value: V })
defaultStrategyRegistry
Variable — packages/decompose-zod-schema/src/split-suggestions.ts
Default registry instance
setNestedValue
Variable — packages/decompose-zod-schema/src/utils.ts
unknownevenChunk
Variable — packages/decompose-zod-schema/src/utils.ts
unknownparseEnumSplit
Variable — packages/decompose-zod-schema/src/utils.ts
unknowngetSchemaAtPath
Variable — packages/decompose-zod-schema/src/utils.ts
unknownextractSchemaForPaths
Variable — packages/decompose-zod-schema/src/utils.ts
unknownestimateTokensByJsonSchema
Variable — packages/decompose-zod-schema/src/utils.ts
unknownvalidatePlan
Variable — packages/decompose-zod-schema/src/validate.ts
unknownvalidateSliceCompleteness
Variable — packages/decompose-zod-schema/src/validate.ts
unknown