Skip to content

Commit e17d32a

Browse files
authored
Merge pull request #185 from docker/catalog-show_improve-output-readability
improve catalog show output readability
2 parents a6fbcc8 + 2585b6d commit e17d32a

File tree

1 file changed

+65
-2
lines changed

1 file changed

+65
-2
lines changed

cmd/docker-mcp/catalog/show.go

Lines changed: 65 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"time"
1111

1212
"github.com/mikefarah/yq/v4/pkg/yqlib"
13+
"github.com/moby/term"
1314
"gopkg.in/yaml.v3"
1415

1516
"github.com/docker/mcp-gateway/pkg/yq"
@@ -115,13 +116,44 @@ func Show(ctx context.Context, name string, format Format, mcpOAuthDcrEnabled bo
115116
return fmt.Errorf("failed to unmarshal catalog data: %w", err)
116117
}
117118
keys := getSortedKeys(registry.Registry)
118-
for _, k := range keys {
119+
120+
termWidth := getTerminalWidth()
121+
wrapWidth := termWidth - 10
122+
if wrapWidth < 40 {
123+
wrapWidth = 40
124+
}
125+
126+
serverCount := len(keys)
127+
headerLineWidth := termWidth - 4
128+
if headerLineWidth > 78 {
129+
headerLineWidth = 78
130+
}
131+
132+
fmt.Println()
133+
fmt.Printf(" \033[1mMCP Server Directory\033[0m\n")
134+
fmt.Printf(" %d servers available\n", serverCount)
135+
fmt.Printf(" %s\n", strings.Repeat("─", headerLineWidth))
136+
fmt.Println()
137+
138+
for i, k := range keys {
119139
val, ok := registry.Registry[k]
120140
if !ok {
121141
continue
122142
}
123-
fmt.Printf("%s: %s\n", k, strings.TrimSpace(val.Description))
143+
fmt.Printf(" \033[1m%s\033[0m\n", k)
144+
wrappedDesc := wrapText(strings.TrimSpace(val.Description), wrapWidth, " ")
145+
fmt.Println(wrappedDesc)
146+
147+
if i < len(keys)-1 {
148+
fmt.Println()
149+
}
124150
}
151+
152+
fmt.Println()
153+
fmt.Printf(" %s\n", strings.Repeat("─", headerLineWidth))
154+
fmt.Printf(" %d servers total\n", serverCount)
155+
fmt.Println()
156+
125157
return nil
126158
}
127159

@@ -137,3 +169,34 @@ func getSortedKeys(m map[string]Tile) []string {
137169
func isURL(fileOrURL string) bool {
138170
return strings.HasPrefix(fileOrURL, "http://") || strings.HasPrefix(fileOrURL, "https://")
139171
}
172+
173+
func getTerminalWidth() int {
174+
fd, _ := term.GetFdInfo(os.Stdout)
175+
ws, err := term.GetWinsize(fd)
176+
if err != nil {
177+
return 80
178+
}
179+
return int(ws.Width)
180+
}
181+
182+
func wrapText(text string, width int, indent string) string {
183+
words := strings.Fields(text)
184+
if len(words) == 0 {
185+
return ""
186+
}
187+
188+
var lines []string
189+
currentLine := words[0]
190+
191+
for _, word := range words[1:] {
192+
if len(currentLine)+1+len(word) > width {
193+
lines = append(lines, indent+currentLine)
194+
currentLine = word
195+
} else {
196+
currentLine += " " + word
197+
}
198+
}
199+
lines = append(lines, indent+currentLine)
200+
201+
return strings.Join(lines, "\n")
202+
}

0 commit comments

Comments
 (0)