-
Notifications
You must be signed in to change notification settings - Fork 355
Prevent MCP stdio startup diagnostics from polluting JSON-RPC stdout #26921
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
+91
−31
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
7ab1c17
Initial plan
Copilot 18d15f3
test: add integration coverage for mcp-server stdio stream cleanliness
Copilot c6c3c3f
test: harden mcp stdio integration test execution
Copilot cdd16dc
test: keep stderr validation while avoiding stdio hang risk
Copilot 169717f
fix: silence stdio diagnostics for mcp-server startup
Copilot e636d8b
docs: clarify diagnostic output behavior in mcp helpers
Copilot 3d30f1b
test: finalize stdio stream-safety adjustments
Copilot fd5f56e
docs: clarify stdio diagnostic suppression semantics
Copilot 1923df0
docs: document diagnostic stream behavior for mcp modes
Copilot a8345cc
refactor: use logger for mcp startup diagnostics
Copilot be474a2
docs: clarify logger-only diagnostics in mcp helpers
Copilot 90ab934
Merge branch 'main' into copilot/fix-mcp-server-stdout-diagnostics
pelikhan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| //go:build integration | ||
|
|
||
| package cli | ||
|
|
||
| import ( | ||
| "bytes" | ||
| "context" | ||
| "errors" | ||
| "os" | ||
| "os/exec" | ||
| "path/filepath" | ||
| "strings" | ||
| "testing" | ||
| "time" | ||
|
|
||
| "github.com/github/gh-aw/pkg/testutil" | ||
| ) | ||
|
|
||
| func TestMCPServer_StdioDiagnosticsGoToStderr(t *testing.T) { | ||
| binaryPath := "../../gh-aw" | ||
| if _, err := os.Stat(binaryPath); os.IsNotExist(err) { | ||
| t.Skip("Skipping test: gh-aw binary not found. Run 'make build' first.") | ||
| } | ||
|
|
||
| tmpDir := testutil.TempDir(t, "mcp-stdio-*") | ||
| workflowsDir := filepath.Join(tmpDir, ".github", "workflows") | ||
| if err := os.MkdirAll(workflowsDir, 0755); err != nil { | ||
| t.Fatalf("Failed to create workflows directory: %v", err) | ||
| } | ||
|
|
||
| workflowPath := filepath.Join(workflowsDir, "test.md") | ||
| workflowContent := `--- | ||
| on: push | ||
| engine: copilot | ||
| --- | ||
| # Test Workflow | ||
| ` | ||
| if err := os.WriteFile(workflowPath, []byte(workflowContent), 0644); err != nil { | ||
| t.Fatalf("Failed to write workflow file: %v", err) | ||
| } | ||
|
|
||
| if err := initTestGitRepo(tmpDir); err != nil { | ||
| t.Fatalf("Failed to initialize git repository: %v", err) | ||
| } | ||
|
|
||
| originalDir, err := os.Getwd() | ||
| if err != nil { | ||
| t.Fatalf("Failed to get current working directory: %v", err) | ||
| } | ||
|
|
||
| absBinaryPath := filepath.Join(originalDir, binaryPath) | ||
| ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) | ||
| defer cancel() | ||
|
|
||
| cmd := exec.CommandContext(ctx, absBinaryPath, "mcp-server", "--cmd", absBinaryPath) | ||
| cmd.Dir = tmpDir | ||
| cmd.Stdin = strings.NewReader("") | ||
|
|
||
| env := make([]string, 0, len(os.Environ())) | ||
| for _, entry := range os.Environ() { | ||
| if strings.HasPrefix(entry, "GITHUB_ACTOR=") { | ||
| continue | ||
| } | ||
| env = append(env, entry) | ||
| } | ||
| cmd.Env = env | ||
|
|
||
| var stdout bytes.Buffer | ||
| var stderr bytes.Buffer | ||
| cmd.Stdout = &stdout | ||
| cmd.Stderr = &stderr | ||
|
|
||
| err = cmd.Run() | ||
| if err != nil && !errors.Is(ctx.Err(), context.DeadlineExceeded) { | ||
| var exitErr *exec.ExitError | ||
| if !errors.As(err, &exitErr) { | ||
| t.Fatalf("Failed to run MCP server process: %v", err) | ||
| } | ||
| } | ||
|
|
||
| stdoutText := strings.TrimSpace(stdout.String()) | ||
| if stdoutText != "" { | ||
| t.Fatalf("Expected stdout to remain clean for JSON-RPC, got: %q", stdoutText) | ||
| } | ||
|
|
||
| } |
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot use logger instead of diagnostic output
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in
a8345cc(with follow-up docs inbe474a2): I removed the diagnostic output writer plumbing and switched startup/validation diagnostics to logger-only (mcpLog/mcpValidationLog). Screenshot: N/A (no UI changes).