@@ -492,3 +492,54 @@ func ParseGetPromptResult(rawMessage *json.RawMessage) (*GetPromptResult, error)
492492
493493 return & result , nil
494494}
495+
496+ func ParseCallToolResult (rawMessage * json.RawMessage ) (* CallToolResult , error ) {
497+ var jsonContent map [string ]any
498+ if err := json .Unmarshal (* rawMessage , & jsonContent ); err != nil {
499+ return nil , fmt .Errorf ("failed to unmarshal response: %w" , err )
500+ }
501+
502+ var result CallToolResult
503+
504+ meta , ok := jsonContent ["_meta" ]
505+ if ok {
506+ if metaMap , ok := meta .(map [string ]any ); ok {
507+ result .Meta = metaMap
508+ }
509+ }
510+
511+ isError , ok := jsonContent ["isError" ]
512+ if ok {
513+ if isErrorBool , ok := isError .(bool ); ok {
514+ result .IsError = isErrorBool
515+ }
516+ }
517+
518+ contents , ok := jsonContent ["content" ]
519+ if ! ok {
520+ return nil , fmt .Errorf ("content is missing" )
521+ }
522+
523+ contentArr , ok := contents .([]any )
524+ if ! ok {
525+ return nil , fmt .Errorf ("content is not an array" )
526+ }
527+
528+ for _ , content := range contentArr {
529+ // Extract content
530+ contentMap , ok := content .(map [string ]any )
531+ if ! ok {
532+ return nil , fmt .Errorf ("content is not an object" )
533+ }
534+
535+ // Process content
536+ content , err := ParseContent (contentMap )
537+ if err != nil {
538+ return nil , err
539+ }
540+
541+ result .Content = append (result .Content , content )
542+ }
543+
544+ return & result , nil
545+ }
0 commit comments