@@ -141,4 +141,102 @@ func TestUnmarshalToolWithoutRawSchema(t *testing.T) {
141141 })
142142 assert .Empty (t , toolUnmarshalled .InputSchema .Required )
143143 assert .Empty (t , toolUnmarshalled .RawInputSchema )
144- }
144+ }
145+
146+ func TestToolWithObjectAndArray (t * testing.T ) {
147+ // Create a tool with both object and array properties
148+ tool := NewTool ("reading-list" ,
149+ WithDescription ("A tool for managing reading lists" ),
150+ WithObject ("preferences" ,
151+ Description ("User preferences for the reading list" ),
152+ Properties (map [string ]interface {}{
153+ "theme" : map [string ]interface {}{
154+ "type" : "string" ,
155+ "description" : "UI theme preference" ,
156+ "enum" : []string {"light" , "dark" },
157+ },
158+ "maxItems" : map [string ]interface {}{
159+ "type" : "number" ,
160+ "description" : "Maximum number of items in the list" ,
161+ "minimum" : 1 ,
162+ "maximum" : 100 ,
163+ },
164+ })),
165+ WithArray ("books" ,
166+ Description ("List of books to read" ),
167+ Required (),
168+ Items (map [string ]interface {}{
169+ "type" : "object" ,
170+ "properties" : map [string ]interface {}{
171+ "title" : map [string ]interface {}{
172+ "type" : "string" ,
173+ "description" : "Book title" ,
174+ "required" : true ,
175+ },
176+ "author" : map [string ]interface {}{
177+ "type" : "string" ,
178+ "description" : "Book author" ,
179+ },
180+ "year" : map [string ]interface {}{
181+ "type" : "number" ,
182+ "description" : "Publication year" ,
183+ "minimum" : 1000 ,
184+ },
185+ },
186+ })))
187+
188+ // Marshal to JSON
189+ data , err := json .Marshal (tool )
190+ assert .NoError (t , err )
191+
192+ // Unmarshal to verify the structure
193+ var result map [string ]interface {}
194+ err = json .Unmarshal (data , & result )
195+ assert .NoError (t , err )
196+
197+ // Verify tool properties
198+ assert .Equal (t , "reading-list" , result ["name" ])
199+ assert .Equal (t , "A tool for managing reading lists" , result ["description" ])
200+
201+ // Verify schema was properly included
202+ schema , ok := result ["inputSchema" ].(map [string ]interface {})
203+ assert .True (t , ok )
204+ assert .Equal (t , "object" , schema ["type" ])
205+
206+ // Verify properties
207+ properties , ok := schema ["properties" ].(map [string ]interface {})
208+ assert .True (t , ok )
209+
210+ // Verify preferences object
211+ preferences , ok := properties ["preferences" ].(map [string ]interface {})
212+ assert .True (t , ok )
213+ assert .Equal (t , "object" , preferences ["type" ])
214+ assert .Equal (t , "User preferences for the reading list" , preferences ["description" ])
215+
216+ prefProps , ok := preferences ["properties" ].(map [string ]interface {})
217+ assert .True (t , ok )
218+ assert .Contains (t , prefProps , "theme" )
219+ assert .Contains (t , prefProps , "maxItems" )
220+
221+ // Verify books array
222+ books , ok := properties ["books" ].(map [string ]interface {})
223+ assert .True (t , ok )
224+ assert .Equal (t , "array" , books ["type" ])
225+ assert .Equal (t , "List of books to read" , books ["description" ])
226+
227+ // Verify array items schema
228+ items , ok := books ["items" ].(map [string ]interface {})
229+ assert .True (t , ok )
230+ assert .Equal (t , "object" , items ["type" ])
231+
232+ itemProps , ok := items ["properties" ].(map [string ]interface {})
233+ assert .True (t , ok )
234+ assert .Contains (t , itemProps , "title" )
235+ assert .Contains (t , itemProps , "author" )
236+ assert .Contains (t , itemProps , "year" )
237+
238+ // Verify required fields
239+ required , ok := schema ["required" ].([]interface {})
240+ assert .True (t , ok )
241+ assert .Contains (t , required , "books" )
242+ }
0 commit comments