@@ -99,10 +99,93 @@ func TestConvertToCallToolResult(t *testing.T) {
9999 assert .Contains (t , text .Text , "value" )
100100 })
101101
102+ t .Run ("image content type is converted to ImageContent" , func (t * testing.T ) {
103+ // base64("hello") = "aGVsbG8="
104+ input := map [string ]interface {}{
105+ "content" : []interface {}{
106+ map [string ]interface {}{"type" : "image" , "data" : "aGVsbG8=" , "mimeType" : "image/png" },
107+ },
108+ }
109+
110+ result , err := ConvertToCallToolResult (input )
111+
112+ require .NoError (t , err )
113+ require .NotNil (t , result )
114+ assert .Len (t , result .Content , 1 )
115+
116+ img , ok := result .Content [0 ].(* sdk.ImageContent )
117+ require .True (t , ok , "Expected ImageContent" )
118+ assert .Equal (t , "image/png" , img .MIMEType )
119+ assert .Equal (t , []byte ("hello" ), img .Data )
120+ })
121+
122+ t .Run ("audio content type is converted to AudioContent" , func (t * testing.T ) {
123+ // base64("world") = "d29ybGQ="
124+ input := map [string ]interface {}{
125+ "content" : []interface {}{
126+ map [string ]interface {}{"type" : "audio" , "data" : "d29ybGQ=" , "mimeType" : "audio/wav" },
127+ },
128+ }
129+
130+ result , err := ConvertToCallToolResult (input )
131+
132+ require .NoError (t , err )
133+ require .NotNil (t , result )
134+ assert .Len (t , result .Content , 1 )
135+
136+ audio , ok := result .Content [0 ].(* sdk.AudioContent )
137+ require .True (t , ok , "Expected AudioContent" )
138+ assert .Equal (t , "audio/wav" , audio .MIMEType )
139+ assert .Equal (t , []byte ("world" ), audio .Data )
140+ })
141+
142+ t .Run ("resource content type is converted to EmbeddedResource" , func (t * testing.T ) {
143+ input := map [string ]interface {}{
144+ "content" : []interface {}{
145+ map [string ]interface {}{
146+ "type" : "resource" ,
147+ "resource" : map [string ]interface {}{
148+ "uri" : "file:///path/to/resource.txt" ,
149+ "mimeType" : "text/plain" ,
150+ "text" : "resource content" ,
151+ },
152+ },
153+ },
154+ }
155+
156+ result , err := ConvertToCallToolResult (input )
157+
158+ require .NoError (t , err )
159+ require .NotNil (t , result )
160+ assert .Len (t , result .Content , 1 )
161+
162+ res , ok := result .Content [0 ].(* sdk.EmbeddedResource )
163+ require .True (t , ok , "Expected EmbeddedResource" )
164+ require .NotNil (t , res .Resource )
165+ assert .Equal (t , "file:///path/to/resource.txt" , res .Resource .URI )
166+ assert .Equal (t , "text/plain" , res .Resource .MIMEType )
167+ assert .Equal (t , "resource content" , res .Resource .Text )
168+ })
169+
170+ t .Run ("resource content type without resource field is skipped" , func (t * testing.T ) {
171+ input := map [string ]interface {}{
172+ "content" : []interface {}{
173+ map [string ]interface {}{"type" : "resource" },
174+ },
175+ }
176+
177+ result , err := ConvertToCallToolResult (input )
178+
179+ require .NoError (t , err )
180+ require .NotNil (t , result )
181+ // Resource item without "resource" field is skipped
182+ assert .Empty (t , result .Content )
183+ })
184+
102185 t .Run ("unknown content type is treated as text" , func (t * testing.T ) {
103186 input := map [string ]interface {}{
104187 "content" : []interface {}{
105- map [string ]interface {}{"type" : "image " , "text" : "image data" },
188+ map [string ]interface {}{"type" : "custom_type " , "text" : "custom data" },
106189 },
107190 }
108191
@@ -114,7 +197,7 @@ func TestConvertToCallToolResult(t *testing.T) {
114197
115198 text , ok := result .Content [0 ].(* sdk.TextContent )
116199 require .True (t , ok )
117- assert .Equal (t , "image data" , text .Text )
200+ assert .Equal (t , "custom data" , text .Text )
118201 })
119202
120203 t .Run ("simple string value is wrapped as text" , func (t * testing.T ) {
0 commit comments