Redirect writing errors to stdio to stderr#2559
Conversation
There was a problem hiding this comment.
Pull request overview
This PR prevents diagnostic output from being written to standard output (stdout), which is reserved for JSON-RPC responses in the MCP server, by redirecting X11 display detection messages to standard error (stderr).
Changes:
- Updated Linux X11 display detection logging in
WindowHandleProviderto write toConsole.Errorinstead ofConsole.WriteLine. - Simplified the failure-path console output when X11 detection throws.
- Added an Azure.Mcp.Server changelog entry documenting the bug fix.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| core/Microsoft.Mcp.Core/src/Services/Azure/Authentication/WindowHandleProvider.cs | Redirects X11 detection output from stdout to stderr to avoid JSON-RPC parsing issues. |
| servers/Azure.Mcp.Server/changelog-entries/1777662676190.yaml | Documents the bug fix in the server changelog entry system. |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
jongio
left a comment
There was a problem hiding this comment.
Clean fix - redirecting X11 display detection diagnostics from stdout to stderr prevents JSON-RPC parsing failures on the stdio transport.
Verified no other Console.WriteLine calls in the server's runtime path need this treatment - the remaining ones in CommandFactory.cs are intentional JSON-RPC output, and CustomHelpAction.cs only runs for --help.
Removing Console.ForegroundColor/Console.ResetColor is also a good call - these set global console state that could leak color codes into stdout on concurrent writes.
What does this PR do?
This redirects writing exceptions to stdio and writes to err instead. Anything written to stdio is considered a response from the MCP server and is interpreted as JSON RPC. Consequently, is failed to be interpreted by Docker gateway.
In Visual Studio Code, it outputs a warning but keeps reading from stdio which succeeds later on.
In Docker Gateway, it stops reading input from stdio:
GitHub issue number?
[Link to the GitHub issue this PR addresses]Pre-merge Checklist
servers/Azure.Mcp.Server/README.mdand/orservers/Fabric.Mcp.Server/README.mddocumentationREADME.mdchanges running the script./eng/scripts/Process-PackageReadMe.ps1. See Package READMEToolDescriptionEvaluatorand obtained a score of0.4or more and a top 3 ranking for all related test promptsconsolidated-tools.jsonbreaking-changelabelservers/Azure.Mcp.Server/docs/azmcp-commands.md./eng/scripts/Update-AzCommandsMetadata.ps1to update tool metadata inazmcp-commands.md(required for CI)servers/Azure.Mcp.Server/docs/e2eTestPrompts.mdcrypto mining, spam, data exfiltration, etc.)/azp run mcp - pullrequest - liveto run Live Test Pipeline