@@ -77,6 +77,11 @@ func AsImageContent(content interface{}) (*ImageContent, bool) {
7777 return asType [ImageContent ](content )
7878}
7979
80+ // AsImageContent attempts to cast the given interface to AudioContent
81+ func AsAudioContent (content interface {}) (* AudioContent , bool ) {
82+ return asType [AudioContent ](content )
83+ }
84+
8085// AsEmbeddedResource attempts to cast the given interface to EmbeddedResource
8186func AsEmbeddedResource (content interface {}) (* EmbeddedResource , bool ) {
8287 return asType [EmbeddedResource ](content )
@@ -202,6 +207,15 @@ func NewImageContent(data, mimeType string) ImageContent {
202207 }
203208}
204209
210+ // Helper function to create a new AudioContent
211+ func NewAudioContent (data , mimeType string ) AudioContent {
212+ return AudioContent {
213+ Type : "audio" ,
214+ Data : data ,
215+ MIMEType : mimeType ,
216+ }
217+ }
218+
205219// Helper function to create a new EmbeddedResource
206220func NewEmbeddedResource (resource ResourceContents ) EmbeddedResource {
207221 return EmbeddedResource {
@@ -239,6 +253,23 @@ func NewToolResultImage(text, imageData, mimeType string) *CallToolResult {
239253 }
240254}
241255
256+ // NewToolResultAudio creates a new CallToolResult with both text and audio content
257+ func NewToolResultAudio (text , imageData , mimeType string ) * CallToolResult {
258+ return & CallToolResult {
259+ Content : []Content {
260+ TextContent {
261+ Type : "text" ,
262+ Text : text ,
263+ },
264+ AudioContent {
265+ Type : "audio" ,
266+ Data : imageData ,
267+ MIMEType : mimeType ,
268+ },
269+ },
270+ }
271+ }
272+
242273// NewToolResultResource creates a new CallToolResult with an embedded resource
243274func NewToolResultResource (
244275 text string ,
@@ -415,6 +446,14 @@ func ParseContent(contentMap map[string]any) (Content, error) {
415446 }
416447 return NewImageContent (data , mimeType ), nil
417448
449+ case "audio" :
450+ data := ExtractString (contentMap , "data" )
451+ mimeType := ExtractString (contentMap , "mimeType" )
452+ if data == "" || mimeType == "" {
453+ return nil , fmt .Errorf ("audio data or mimeType is missing" )
454+ }
455+ return NewAudioContent (data , mimeType ), nil
456+
418457 case "resource" :
419458 resourceMap := ExtractMap (contentMap , "resource" )
420459 if resourceMap == nil {
0 commit comments