(result *mcp.CallToolResult)
| 86 | } |
| 87 | |
| 88 | func convertJSONTextResultToCSV(result *mcp.CallToolResult) *mcp.CallToolResult { |
| 89 | if len(result.Content) != 1 { |
| 90 | return utils.NewToolResultError("failed to convert response to CSV: expected a single text content response") |
| 91 | } |
| 92 | |
| 93 | text, ok := result.Content[0].(*mcp.TextContent) |
| 94 | if !ok { |
| 95 | return utils.NewToolResultError("failed to convert response to CSV: expected a text content response") |
| 96 | } |
| 97 | |
| 98 | csvText, err := jsonTextToCSV(text.Text) |
| 99 | if err != nil { |
| 100 | return utils.NewToolResultErrorFromErr("failed to convert response to CSV", err) |
| 101 | } |
| 102 | |
| 103 | result.Content = []mcp.Content{&mcp.TextContent{Text: csvText}} |
| 104 | result.StructuredContent = nil |
| 105 | return result |
| 106 | } |
| 107 | |
| 108 | func jsonTextToCSV(text string) (string, error) { |
| 109 | decoder := json.NewDecoder(strings.NewReader(text)) |
no test coverage detected