Skip to content

pretty print json #114

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 5, 2025
Merged

pretty print json #114

merged 3 commits into from
Apr 5, 2025

Conversation

mntlty
Copy link
Collaborator

@mntlty mntlty commented Apr 5, 2025

  • create a config struct for running the server
  • pretty print json

Closes: #113

Introduces a new flag pretty-print-json which will format json output from the server for easier visualization.
As the list of configuration options was growing, I opted to add a config struct instead of adding one more to the pile.

(partial output in the screenshot below)
Screenshot 2025-04-04 at 5 30 41 PM

With all of this code in main, there isn't a good way to add tests here and it felt a bit out of place to add to pkg/github/server.go
A refactor would be very helpful to make this easier.

I did not add a new option to the launch.json for it, as I feel like it is still best to be disabled by default.

A future enhancement might be to incorporate https://github.com/cli/go-gh/blob/61bf393cf4aeea6d00a6251390f5f67f5b67e727/pkg/jsonpretty/format.go

@Copilot Copilot AI review requested due to automatic review settings April 5, 2025 00:36
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds a new configuration option to pretty print JSON output from the server and refactors the server setup to use a dedicated configuration struct.

  • Introduces a runConfig struct to encapsulate server configuration options.
  • Adds a pretty-print-json flag and implements JSONPrettyPrintWriter for pretty printing JSON output.
Comments suppressed due to low confidence (2)

cmd/github-mcp-server/main.go:123

  • Add tests for JSONPrettyPrintWriter to validate the pretty printing behavior with various JSON inputs, including invalid JSON scenarios.
func (j JSONPrettyPrintWriter) Write(p []byte) (n int, err error) {

cmd/github-mcp-server/main.go:131

  • Consider adding tests for runStdioServer to verify that all configuration options (including the new pretty-print-json flag) are correctly handled.
func runStdioServer(cfg runConfig) error {

Tip: If you use Visual Studio Code, you can request a review from Copilot before you push from the "Source Control" tab. Learn more

@@ -95,15 +107,36 @@ func initLogger(outPath string) (*log.Logger, error) {
return logger, nil
}

func runStdioServer(readOnly bool, logger *log.Logger, logCommands bool, exportTranslations bool) error {
type runConfig struct {
Copy link
Member

Choose a reason for hiding this comment

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

I'd probably just call this config but other than that lgtm!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

going to leave it so you don't have to do another review

@mntlty mntlty merged commit 270bbf7 into main Apr 5, 2025
14 checks passed
@mntlty mntlty deleted the pretty_print_json branch April 5, 2025 00:59
manian0430 pushed a commit to ChrisLally/github-mcp-server that referenced this pull request Apr 12, 2025
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.

Add support for pretty printing json output
2 participants