Skip to content

mcp-client: pretty-print JSON output when stdout is a terminal - #835

Merged
aojea merged 2 commits into
google:mainfrom
fedebongio:feat/mcp-client-pretty-json
Oct 30, 2026
Merged

aojea merged 2 commits into
google:mainfrom
fedebongio:feat/mcp-client-pretty-json

Conversation

@fedebongio

Copy link
Copy Markdown
Collaborator

Summary

Make mcp-client human-friendly in interactive terminals while keeping full backwards compatibility with scripts, jq pipelines, and E2E Bats tests (tail -n 1):

  • Add -pretty flag defaulting to true when os.Stdout is an interactive terminal (github.com/mattn/go-isatty, already in go.mod) and false when piped/redirected.
  • Indent JSON object/array payloads ({...} / [...]) with 2 spaces via json.Indent for both MCP tool TextContent responses and -stream data: SSE payloads, leaving plain-text responses and usage hints untouched.
  • Add unit and CLI integration tests in 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 ./...

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.
@fedebongio
fedebongio requested a review from aojea as a code owner October 30, 2026 05:52

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread cmd/mcp-client/main_test.go Resolved
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@aojea
aojea merged commit 6a4e8c0 into google:main Oct 30, 2026
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants