diff --git a/cmd/mcptools/commands/resources_test.go b/cmd/mcptools/commands/resources_test.go index 19f23bf..0ffda6f 100644 --- a/cmd/mcptools/commands/resources_test.go +++ b/cmd/mcptools/commands/resources_test.go @@ -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", }, }, @@ -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") } diff --git a/pkg/jsonutils/jsonutils.go b/pkg/jsonutils/jsonutils.go index dc9d80c..57ef3d8 100644 --- a/pkg/jsonutils/jsonutils.go +++ b/pkg/jsonutils/jsonutils.go @@ -622,17 +622,24 @@ 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 { @@ -640,17 +647,22 @@ func formatResourcesList(resources any) (string, error) { } 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) } }