convertResult translates an MCP CallToolResult into a workspacesdk.CallMCPToolResponse. It iterates over content items and maps each recognized type.
(result *mcp.CallToolResult)
| 1043 | // workspacesdk.CallMCPToolResponse. It iterates over content |
| 1044 | // items and maps each recognized type. |
| 1045 | func convertResult(result *mcp.CallToolResult) workspacesdk.CallMCPToolResponse { |
| 1046 | if result == nil { |
| 1047 | return workspacesdk.CallMCPToolResponse{} |
| 1048 | } |
| 1049 | |
| 1050 | var content []workspacesdk.MCPToolContent |
| 1051 | for _, item := range result.Content { |
| 1052 | switch c := item.(type) { |
| 1053 | case mcp.TextContent: |
| 1054 | content = append(content, workspacesdk.MCPToolContent{ |
| 1055 | Type: "text", |
| 1056 | Text: c.Text, |
| 1057 | }) |
| 1058 | case mcp.ImageContent: |
| 1059 | content = append(content, workspacesdk.MCPToolContent{ |
| 1060 | Type: "image", |
| 1061 | Data: c.Data, |
| 1062 | MediaType: c.MIMEType, |
| 1063 | }) |
| 1064 | case mcp.AudioContent: |
| 1065 | content = append(content, workspacesdk.MCPToolContent{ |
| 1066 | Type: "audio", |
| 1067 | Data: c.Data, |
| 1068 | MediaType: c.MIMEType, |
| 1069 | }) |
| 1070 | case mcp.EmbeddedResource: |
| 1071 | content = append(content, workspacesdk.MCPToolContent{ |
| 1072 | Type: "resource", |
| 1073 | Text: fmt.Sprintf("[embedded resource: %T]", c.Resource), |
| 1074 | }) |
| 1075 | case mcp.ResourceLink: |
| 1076 | content = append(content, workspacesdk.MCPToolContent{ |
| 1077 | Type: "resource", |
| 1078 | Text: fmt.Sprintf("[resource link: %s]", c.URI), |
| 1079 | }) |
| 1080 | default: |
| 1081 | content = append(content, workspacesdk.MCPToolContent{ |
| 1082 | Type: "text", |
| 1083 | Text: fmt.Sprintf("[unsupported content type: %T]", item), |
| 1084 | }) |
| 1085 | } |
| 1086 | } |
| 1087 | |
| 1088 | return workspacesdk.CallMCPToolResponse{ |
| 1089 | Content: content, |
| 1090 | IsError: result.IsError, |
| 1091 | } |
| 1092 | } |
no outgoing calls