⚠️ IOException / HttpRequestException Model Context Protocol C# SDK .NET 10
✓ Verified Oct 2026
Fix: MCP Server Connection Refused & Pipe Closed Errors in C#
Fix MCP server pipe is being closed and connection refused errors in C#. Redirect stdout logging to stderr and configure 0.0.0.0 container binding.
Raw Error Payload / Console String
{
"transportError": "Stdio stream corrupted. Client received: [14:20:00 INF] Application started. Expected: JSON-RPC 2.0 message payload."
} Trigger Scenario
Connecting Claude Desktop or Cursor to a C# MCP server running on stdio while standard console logging writes to stdout.
Root Cause
In stdio mode, stdout is reserved for JSON-RPC. Logging to stdout invalidates JSON protocol streams. In HTTP mode, binding to 127.0.0.1 in Docker rejects external connections.
Step-by-Step Resolution
1
Redirect console logging to stderr Set options.LogToStandardErrorThreshold = LogLevel.Trace in AddConsole logger setup.
2
Bind to 0.0.0.0 in Docker Declare ENV ASPNETCORE_URLS=http://+:5050 in your Dockerfile.
3
Disable reverse proxy buffering Ensure proxy_buffering off; is configured for streaming SSE endpoints.
Verified C# (.NET 10) Solution Code
// Fix stdio logging corruption in Program.cs:
services.AddLogging(builder =>
{
builder.AddConsole(options =>
{
options.LogToStandardErrorThreshold = LogLevel.Trace;
});
});
Comprehensive Engineering Guide
Read Full Deep Dive Fix MCP Server Connection Issues in C#: Stdio vs HTTP Transport Troubleshooting