Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions cmd/mcptools/commands/resources_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ func TestResourcesCmdRun_Help(t *testing.T) {
}

func TestResourcesCmdRun_Success(t *testing.T) {
t.Skip("Skipping resources command test as resources are not working as expected")
// Create a mock client that returns successful response
mockResponse := map[string]any{
"resources": []any{
map[string]any{
"uri": "test-resource",
"type": "text",
"uri": "test://resource",
"mimeType": "text/plain",
"name": "TestResource",
"description": "Test resource description",
},
},
Expand Down Expand Up @@ -59,6 +59,8 @@ func TestResourcesCmdRun_Success(t *testing.T) {

// Verify output contains expected content
output := buf.String()
assertContains(t, output, "test-resource")
assertContains(t, output, "TestResource")
assertContains(t, output, "test://resource")
assertContains(t, output, "text/plain")
assertContains(t, output, "Test resource description")
}
32 changes: 22 additions & 10 deletions pkg/jsonutils/jsonutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -622,35 +622,47 @@ func formatResourcesList(resources any) (string, error) {
w := tabwriter.NewWriter(&buf, 0, 0, 2, ' ', 0)
useColors := isTerminal()

// NOTE: Ensure that the column headers are the same length,
// including the color escape sequences!
if useColors {
fmt.Fprintf(w, "%s%sNAME%s\t%sTYPE%s\t%sURI%s\n",
ColorBold, ColorCyan, ColorReset,
fmt.Fprintf(w, "%sNAME%s\t%sMIMETYPE%s\t%sURI%s\t%sDESCRIPTION%s\n",
ColorCyan, ColorReset,
ColorCyan, ColorReset,
ColorCyan, ColorReset,
ColorCyan, ColorReset)
fmt.Fprintf(w, "%s----%s\t%s--------%s\t%s---%s\t%s----------%s\n",
ColorCyan, ColorReset,
ColorCyan, ColorReset,
ColorCyan, ColorReset,
ColorCyan, ColorReset)
} else {
fmt.Fprintln(w, "NAME\tTYPE\tURI")
fmt.Fprintln(w, "NAME\tMIMETYPE\tURI\tDESCRIPTION")
fmt.Fprintln(w, "----\t--------\t---\t-----------")
}

fmt.Fprintln(w, "----\t----\t---")

for _, r := range resourcesSlice {
resource, ok1 := r.(map[string]any)
if !ok1 {
continue
}

name, _ := resource["name"].(string)
resType, _ := resource["type"].(string)
mimeType, _ := resource["mimeType"].(string)
uri, _ := resource["uri"].(string)
desc, _ := resource["description"].(string)
if len(desc) > 50 {
desc = desc[:47] + "..."
}

// Use the entire URI instead of truncating
if useColors {
fmt.Fprintf(w, "%s%s%s\t%s%s\t%s%s%s\n",
fmt.Fprintf(w, "%s%s%s\t%s%s%s\t%s%s%s\t%s\n",
ColorGreen, name, ColorReset,
resType, ColorReset,
ColorYellow, uri, ColorReset)
ColorGreen, mimeType, ColorReset,
ColorYellow, uri, ColorReset,
desc)
} else {
fmt.Fprintf(w, "%s\t%s\t%s\n", name, resType, uri)
fmt.Fprintf(w, "%s\t%s\t%s\t%s\n", name, mimeType, uri, desc)
}
}

Expand Down