Skip to content

Commit 9ba1f47

Browse files
Enable netfx UI MCP clients (modelcontextprotocol#1639)
1 parent 8ddb3cc commit 9ba1f47

1 file changed

Lines changed: 17 additions & 2 deletions

File tree

src/ModelContextProtocol.Core/Client/StdioClientTransport.cs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,14 +187,29 @@ public async Task<ITransport> ConnectAsync(CancellationToken cancellationToken =
187187
lock (s_consoleEncodingLock)
188188
{
189189
Encoding originalInputEncoding = Console.InputEncoding;
190+
bool encodingChanged = false;
190191
try
191192
{
192-
Console.InputEncoding = StreamClientSessionTransport.NoBomUtf8Encoding;
193+
try
194+
{
195+
Console.InputEncoding = StreamClientSessionTransport.NoBomUtf8Encoding;
196+
encodingChanged = true;
197+
}
198+
catch
199+
{
200+
// Host has no usable console (e.g. WPF/WinForms on .NET Framework with no
201+
// AllocConsole). The child inherits the current Console.InputEncoding;
202+
// non-ASCII stdin may be misencoded, but the connect itself proceeds.
203+
}
204+
193205
processStarted = process.Start();
194206
}
195207
finally
196208
{
197-
Console.InputEncoding = originalInputEncoding;
209+
if (encodingChanged)
210+
{
211+
Console.InputEncoding = originalInputEncoding;
212+
}
198213
}
199214
}
200215
#endif

0 commit comments

Comments
 (0)