@@ -10,6 +10,7 @@ const createDocumentSchema = z.object({
1010 documentTypeId : z . string ( ) . uuid ( "Must be a valid document type type UUID" ) ,
1111 parentId : z . string ( ) . uuid ( "Must be a valid document UUID" ) . optional ( ) ,
1212 name : z . string ( ) ,
13+ cultures : z . array ( z . string ( ) ) . optional ( ) . describe ( "Array of culture codes. If not provided, will fetch available cultures from Umbraco. If empty array provided, will create without culture (null culture)." ) ,
1314 values : z
1415 . array (
1516 z . object ( {
@@ -25,7 +26,11 @@ const createDocumentSchema = z.object({
2526
2627const CreateDocumentTool = CreateUmbracoTool (
2728 "create-document" ,
28- `Creates a document,
29+ `Creates a document with support for multiple cultures.
30+
31+ If cultures parameter is provided, a variant will be created for each culture code.
32+ If cultures parameter is not provided, the tool will automatically fetch available cultures from Umbraco and create variants for all of them.
33+ If an empty cultures array is provided, a single variant with null culture will be created (original behavior).
2934
3035 Always follow these requirements when creating documents exactly, do not deviate in any way.
3136
@@ -633,6 +638,37 @@ const CreateDocumentTool = CreateUmbracoTool(
633638
634639 const documentId = uuidv4 ( ) ;
635640
641+ // Determine cultures to use
642+ let culturesToUse : ( string | null ) [ ] = [ ] ;
643+
644+ if ( model . cultures === undefined ) {
645+ // If cultures not provided, fetch available cultures from Umbraco
646+ try {
647+ const cultureResponse = await client . getCulture ( { take : 100 } ) ;
648+ culturesToUse = cultureResponse . items . map ( culture => culture . name ) ;
649+ // If no cultures available, fallback to null culture
650+ if ( culturesToUse . length === 0 ) {
651+ culturesToUse = [ null ] ;
652+ }
653+ } catch ( error ) {
654+ // If fetching cultures fails, fallback to null culture
655+ culturesToUse = [ null ] ;
656+ }
657+ } else if ( model . cultures . length === 0 ) {
658+ // If empty array provided, use null culture (original behavior)
659+ culturesToUse = [ null ] ;
660+ } else {
661+ // Use provided cultures
662+ culturesToUse = model . cultures ;
663+ }
664+
665+ // Create variants for each culture
666+ const variants = culturesToUse . map ( culture => ( {
667+ culture,
668+ name : model . name ,
669+ segment : null ,
670+ } ) ) ;
671+
636672 const payload : CreateDocumentRequestModel = {
637673 id : documentId ,
638674 documentType : {
@@ -645,13 +681,7 @@ const CreateDocumentTool = CreateUmbracoTool(
645681 : undefined ,
646682 template : null ,
647683 values : model . values ,
648- variants : [
649- {
650- culture : null ,
651- name : model . name ,
652- segment : null ,
653- } ,
654- ] ,
684+ variants,
655685 } ;
656686
657687 const response = await client . postDocument ( payload ) ;
0 commit comments