Repository navigation
mcp-client: pretty-print JSON output when stdout is a terminal - #835
Merged
Merged
Conversation
Default -pretty to true when stdout is an interactive TTY so commands like 'mcp-client -tool get_mesh_info' or 'discover_remote_services' emit readable 2-space indented JSON out of the box, while keeping compact single-line output when piped to jq, files, or E2E test harnesses.
Contributor
There was a problem hiding this comment.
Code Review
This pull request introduces a -pretty flag to the MCP client, enabling pretty-printed JSON output by default when stdout is an interactive terminal. It implements terminal detection using go-isatty and formats JSON outputs while preserving plain text. Unit and integration tests are added to verify the formatting logic and terminal detection. The review feedback suggests optimizing the integration test by skipping it when running in short mode (testing.Short()) to improve test execution speed.
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Make
mcp-clienthuman-friendly in interactive terminals while keeping full backwards compatibility with scripts,jqpipelines, and E2E Bats tests (tail -n 1):-prettyflag defaulting totruewhenos.Stdoutis an interactive terminal (github.com/mattn/go-isatty, already ingo.mod) andfalsewhen piped/redirected.{...}/[...]) with 2 spaces viajson.Indentfor both MCP toolTextContentresponses and-streamdata:SSE payloads, leaving plain-text responses and usage hints untouched.cmd/mcp-client/main_test.go.Verification
CGO_ENABLED=1 go test -race -count=1 ./cmd/mcp-client/...golangci-lint run ./cmd/mcp-client/...deadcode -test ./...