diff --git a/core/Microsoft.Mcp.Core/src/Services/Azure/Authentication/WindowHandleProvider.cs b/core/Microsoft.Mcp.Core/src/Services/Azure/Authentication/WindowHandleProvider.cs index 4eb3483d27..c0abac68d0 100644 --- a/core/Microsoft.Mcp.Core/src/Services/Azure/Authentication/WindowHandleProvider.cs +++ b/core/Microsoft.Mcp.Core/src/Services/Azure/Authentication/WindowHandleProvider.cs @@ -26,18 +26,19 @@ public static IntPtr GetWindowHandle() try { IntPtr display = XOpenDisplay(":1"); - Console.WriteLine(display == IntPtr.Zero + + // Do not write to standard output because it is interpreted as a JSON RPC response + // from the MCP server. Instead, write to standard error for diagnostics. + Console.Error.WriteLine(display == IntPtr.Zero ? "No X display available. Running in headless mode." : "X display is available."); return display; } - catch (Exception) + catch (Exception exception) { // X11 display detection failed; running in headless mode. // Avoid logging exception details to console to prevent information disclosure. - Console.ForegroundColor = ConsoleColor.Red; - Console.WriteLine($"Failed to detect X display. Running in headless mode. Exception type: {typeof(Exception).FullName}"); - Console.ResetColor(); + Console.Error.WriteLine($"Failed to detect X display. Running in headless mode. Exception type: {exception.GetType().FullName}"); } } diff --git a/servers/Azure.Mcp.Server/changelog-entries/1777662676190.yaml b/servers/Azure.Mcp.Server/changelog-entries/1777662676190.yaml new file mode 100644 index 0000000000..527c544203 --- /dev/null +++ b/servers/Azure.Mcp.Server/changelog-entries/1777662676190.yaml @@ -0,0 +1,3 @@ +changes: + - section: "Bugs Fixed" + description: "Fix issue where writing exception to stdout is interpreted as JSON RPC response."