Skip to content

Commit 9846b73

Browse files
authored
Merge pull request #26 from johnstcn/cj/unskip/TestResources
fix(pkg/jsonutils): add description to resource list, unskip test
2 parents 5d86d52 + 5511907 commit 9846b73

File tree

2 files changed

+28
-14
lines changed

2 files changed

+28
-14
lines changed

cmd/mcptools/commands/resources_test.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ func TestResourcesCmdRun_Help(t *testing.T) {
2525
}
2626

2727
func TestResourcesCmdRun_Success(t *testing.T) {
28-
t.Skip("Skipping resources command test as resources are not working as expected")
2928
// Create a mock client that returns successful response
3029
mockResponse := map[string]any{
3130
"resources": []any{
3231
map[string]any{
33-
"uri": "test-resource",
34-
"type": "text",
32+
"uri": "test://resource",
33+
"mimeType": "text/plain",
34+
"name": "TestResource",
3535
"description": "Test resource description",
3636
},
3737
},
@@ -59,6 +59,8 @@ func TestResourcesCmdRun_Success(t *testing.T) {
5959

6060
// Verify output contains expected content
6161
output := buf.String()
62-
assertContains(t, output, "test-resource")
62+
assertContains(t, output, "TestResource")
63+
assertContains(t, output, "test://resource")
64+
assertContains(t, output, "text/plain")
6365
assertContains(t, output, "Test resource description")
6466
}

pkg/jsonutils/jsonutils.go

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -622,35 +622,47 @@ func formatResourcesList(resources any) (string, error) {
622622
w := tabwriter.NewWriter(&buf, 0, 0, 2, ' ', 0)
623623
useColors := isTerminal()
624624

625+
// NOTE: Ensure that the column headers are the same length,
626+
// including the color escape sequences!
625627
if useColors {
626-
fmt.Fprintf(w, "%s%sNAME%s\t%sTYPE%s\t%sURI%s\n",
627-
ColorBold, ColorCyan, ColorReset,
628+
fmt.Fprintf(w, "%sNAME%s\t%sMIMETYPE%s\t%sURI%s\t%sDESCRIPTION%s\n",
629+
ColorCyan, ColorReset,
630+
ColorCyan, ColorReset,
631+
ColorCyan, ColorReset,
632+
ColorCyan, ColorReset)
633+
fmt.Fprintf(w, "%s----%s\t%s--------%s\t%s---%s\t%s----------%s\n",
634+
ColorCyan, ColorReset,
635+
ColorCyan, ColorReset,
628636
ColorCyan, ColorReset,
629637
ColorCyan, ColorReset)
630638
} else {
631-
fmt.Fprintln(w, "NAME\tTYPE\tURI")
639+
fmt.Fprintln(w, "NAME\tMIMETYPE\tURI\tDESCRIPTION")
640+
fmt.Fprintln(w, "----\t--------\t---\t-----------")
632641
}
633642

634-
fmt.Fprintln(w, "----\t----\t---")
635-
636643
for _, r := range resourcesSlice {
637644
resource, ok1 := r.(map[string]any)
638645
if !ok1 {
639646
continue
640647
}
641648

642649
name, _ := resource["name"].(string)
643-
resType, _ := resource["type"].(string)
650+
mimeType, _ := resource["mimeType"].(string)
644651
uri, _ := resource["uri"].(string)
652+
desc, _ := resource["description"].(string)
653+
if len(desc) > 50 {
654+
desc = desc[:47] + "..."
655+
}
645656

646657
// Use the entire URI instead of truncating
647658
if useColors {
648-
fmt.Fprintf(w, "%s%s%s\t%s%s\t%s%s%s\n",
659+
fmt.Fprintf(w, "%s%s%s\t%s%s%s\t%s%s%s\t%s\n",
649660
ColorGreen, name, ColorReset,
650-
resType, ColorReset,
651-
ColorYellow, uri, ColorReset)
661+
ColorGreen, mimeType, ColorReset,
662+
ColorYellow, uri, ColorReset,
663+
desc)
652664
} else {
653-
fmt.Fprintf(w, "%s\t%s\t%s\n", name, resType, uri)
665+
fmt.Fprintf(w, "%s\t%s\t%s\t%s\n", name, mimeType, uri, desc)
654666
}
655667
}
656668

0 commit comments

Comments
 (0)