@@ -2,6 +2,7 @@ package main
2
2
3
3
import (
4
4
"bytes"
5
+ "crypto/rand"
5
6
"encoding/json"
6
7
"fmt"
7
8
"io"
@@ -11,8 +12,6 @@ import (
11
12
"slices"
12
13
"strings"
13
14
14
- "crypto/rand"
15
-
16
15
"github.com/spf13/cobra"
17
16
"github.com/spf13/viper"
18
17
)
@@ -161,7 +160,7 @@ func main() {
161
160
_ = rootCmd .MarkPersistentFlagRequired ("stdio-server-cmd" )
162
161
163
162
// Add global flag for pretty printing
164
- rootCmd .PersistentFlags ().Bool ("pretty" ,true ,"Pretty print MCP response (only for JSON responses)" )
163
+ rootCmd .PersistentFlags ().Bool ("pretty" ,true ,"Pretty print MCP response (only for JSONor JSONL responses)" )
165
164
166
165
// Add the tools command to the root command
167
166
rootCmd .AddCommand (toolsCmd )
@@ -426,15 +425,26 @@ func printResponse(response string, prettyPrint bool) error {
426
425
// Extract text from content items of type "text"
427
426
for _ ,content := range resp .Result .Content {
428
427
if content .Type == "text" {
429
- // Unmarshal the text content
430
- var textContent map [string ]interface {}
431
- if err := json .Unmarshal ([]byte (content .Text ),& textContent );err != nil {
432
- return fmt .Errorf ("failed to parse text content: %w" ,err )
428
+ var textContentObj map [string ]interface {}
429
+ err := json .Unmarshal ([]byte (content .Text ),& textContentObj )
430
+
431
+ if err == nil {
432
+ prettyText ,err := json .MarshalIndent (textContentObj ,"" ," " )
433
+ if err != nil {
434
+ return fmt .Errorf ("failed to pretty print text content: %w" ,err )
435
+ }
436
+ fmt .Println (string (prettyText ))
437
+ continue
438
+ }
439
+
440
+ // Fallback parsing as JSONL
441
+ var textContentList []map [string ]interface {}
442
+ if err := json .Unmarshal ([]byte (content .Text ),& textContentList );err != nil {
443
+ return fmt .Errorf ("failed to parse text content as a list: %w" ,err )
433
444
}
434
- // Pretty print the text content
435
- prettyText ,err := json .MarshalIndent (textContent ,"" ," " )
445
+ prettyText ,err := json .MarshalIndent (textContentList ,"" ," " )
436
446
if err != nil {
437
- return fmt .Errorf ("failed to pretty printtext content: %w" ,err )
447
+ return fmt .Errorf ("failed to pretty printarray content: %w" ,err )
438
448
}
439
449
fmt .Println (string (prettyText ))
440
450
}