Skip to content
Open
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
4 changes: 2 additions & 2 deletions cmd/mcptools/commands/configs.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
"sort"
"strings"

"github.com/f/mcptools/pkg/jsonutils"
"github.com/spf13/cobra"
"golang.org/x/term"
"golang.org/x/text/cases"
"golang.org/x/text/language"
)
Expand Down Expand Up @@ -516,7 +516,7 @@ func formatColoredGroupedServers(servers []ServerConfig) string {

var buf bytes.Buffer
// Check if we're outputting to a terminal (for colors)
useColors := term.IsTerminal(int(os.Stdout.Fd()))
useColors := jsonutils.IsTerminal()

for _, source := range sourceOrder {
// Print source header with bold blue
Expand Down
17 changes: 10 additions & 7 deletions pkg/jsonutils/jsonutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,11 @@ const (
shortTypeArray = "arr"
)

// isTerminal determines if stdout is a terminal (for colorized output).
func isTerminal() bool {
// IsTerminal reports whether stdout is a terminal and NO_COLOR is not set.
func IsTerminal() bool {
if _, noColor := os.LookupEnv("NO_COLOR"); noColor {
return false
}
return term.IsTerminal(int(os.Stdout.Fd()))
}

Expand Down Expand Up @@ -152,7 +155,7 @@ func formatToolsList(tools any) (string, error) {
termWidth := getTermWidth()
descIndent := " " // 5 spaces for description indentation
descWidth := termWidth - len(descIndent)
useColors := isTerminal()
useColors := IsTerminal()

for i, t := range toolsSlice {
tool, ok1 := t.(map[string]any)
Expand Down Expand Up @@ -620,7 +623,7 @@ func formatResourcesList(resources any) (string, error) {

var buf bytes.Buffer
w := tabwriter.NewWriter(&buf, 0, 0, 2, ' ', 0)
useColors := isTerminal()
useColors := IsTerminal()

// NOTE: Ensure that the column headers are the same length,
// including the color escape sequences!
Expand Down Expand Up @@ -685,7 +688,7 @@ func formatPromptsList(prompts any) (string, error) {
termWidth := getTermWidth()
descIndent := " " // 5 spaces for description indentation
descWidth := termWidth - len(descIndent)
useColors := isTerminal()
useColors := IsTerminal()

for i, p := range promptsSlice {
prompt, ok1 := p.(map[string]any)
Expand Down Expand Up @@ -731,7 +734,7 @@ func formatContent(content any) (string, error) {
}

var buf strings.Builder
useColors := isTerminal()
useColors := IsTerminal()

for _, c := range contentSlice {
contentItem, ok1 := c.(map[string]any)
Expand Down Expand Up @@ -775,7 +778,7 @@ func formatGenericMap(data map[string]any) (string, error) {

var buf bytes.Buffer
w := tabwriter.NewWriter(&buf, 0, 0, 2, ' ', 0)
useColors := isTerminal()
useColors := IsTerminal()

if useColors {
fmt.Fprintf(w, "%sKEY%s\t%sVALUE%s\n",
Expand Down
8 changes: 8 additions & 0 deletions pkg/jsonutils/jsonutils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -504,3 +504,11 @@ func TestNormalizeParameterType(t *testing.T) {
})
}
}

func TestIsTerminal_NoColor(t *testing.T) {
// With NO_COLOR set, isTerminal should return false
t.Setenv("NO_COLOR", "1")
if IsTerminal() {
t.Error("IsTerminal() should return false when NO_COLOR is set")
}
}