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: 4 additions & 0 deletions cmd/mcptools/commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ const (
FlagTransport = "--transport"
FlagAuthUser = "--auth-user"
FlagAuthHeader = "--auth-header"
FlagQuiet = "--quiet"
FlagQuietShort = "-q"
)

// entity types.
Expand Down Expand Up @@ -51,6 +53,8 @@ var (
AuthUser string
// AuthHeader is a custom Authorization header.
AuthHeader string
// QuietMode suppresses startup messages.
QuietMode bool
)

// RootCmd creates the root command.
Expand Down
11 changes: 8 additions & 3 deletions cmd/mcptools/commands/shell.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ func ShellCmd() *cobra.Command { //nolint:gocyclo
case cmdArgs[i] == FlagAuthHeader && i+1 < len(cmdArgs):
AuthHeader = cmdArgs[i+1]
i += 2
case cmdArgs[i] == FlagQuiet || cmdArgs[i] == FlagQuietShort:
QuietMode = true
i++
default:
parsedArgs = append(parsedArgs, cmdArgs[i])
i++
Expand All @@ -64,9 +67,11 @@ func ShellCmd() *cobra.Command { //nolint:gocyclo
os.Exit(1)
}

fmt.Fprintf(thisCmd.OutOrStdout(), "mcp > MCP Tools Shell (%s)\n", Version)
fmt.Fprintf(thisCmd.OutOrStdout(), "mcp > Connected to Server: %s\n", strings.Join(parsedArgs, " "))
fmt.Fprintf(thisCmd.OutOrStdout(), "\nmcp > Type '/h' for help or '/q' to quit\n")
if !QuietMode {
fmt.Fprintf(thisCmd.OutOrStdout(), "mcp > MCP Tools Shell (%s)\n", Version)
fmt.Fprintf(thisCmd.OutOrStdout(), "mcp > Connected to Server: %s\n", strings.Join(parsedArgs, " "))
fmt.Fprintf(thisCmd.OutOrStdout(), "\nmcp > Type '/h' for help or '/q' to quit\n")
}

line := liner.NewLiner()
line.SetCtrlCAborts(true)
Expand Down
61 changes: 61 additions & 0 deletions cmd/mcptools/commands/shell_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -365,3 +365,64 @@ func TestShellExit(t *testing.T) {
})
}
}

func TestShellQuietFlag(t *testing.T) {
tests := []struct { //nolint:govet
name string
args []string
unexpectedOutput []string
expectStartup bool
}{
{
name: "without quiet flag shows startup messages",
args: []string{"echo", "test"},
expectStartup: true,
},
{
name: "with --quiet flag suppresses startup messages",
args: []string{"--quiet", "echo", "test"},
expectStartup: false,
unexpectedOutput: []string{"MCP Tools Shell", "Connected to Server", "Type '/h' for help"},
},
{
name: "with -q flag suppresses startup messages",
args: []string{"-q", "echo", "test"},
expectStartup: false,
unexpectedOutput: []string{"MCP Tools Shell", "Connected to Server", "Type '/h' for help"},
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
// Reset QuietMode before each test
QuietMode = false

cmd, buf, cleanupSetup := setupTestCommand(t, "/q\n")
defer cleanupSetup()

cleanupClient := setupMockClient(func(_ string, _ any) (map[string]any, error) {
return map[string]any{}, nil
})
defer cleanupClient()

cmd.SetArgs(tt.args)
err := cmd.Execute()
if err != nil {
t.Errorf("cmd.Execute() error = %v", err)
}

output := buf.String()
if tt.expectStartup {
if !strings.Contains(output, "MCP Tools Shell") {
t.Errorf("Expected startup messages, got: %s", output)
}
} else {
for _, unexpected := range tt.unexpectedOutput {
if strings.Contains(output, unexpected) {
t.Errorf("Expected output to NOT contain %q, got: %s", unexpected, output)
}
}
}
})
}
}