Similar issue to #1259 which was fixed in #1274.
Read / deserialization is still encoding to a string. We should try to keep as utf8 bytes and deserialize from those:
|
var line = await _inputReader.ReadLineAsync(shutdownToken).ConfigureAwait(false); |
|
if (string.IsNullOrWhiteSpace(line)) |
|
{ |
|
if (line is null) |
|
{ |
|
LogTransportEndOfStream(Name); |
|
break; |
|
} |
|
|
|
continue; |
|
} |
|
|
|
LogTransportReceivedMessageSensitive(Name, line); |
|
|
|
try |
|
{ |
|
if (JsonSerializer.Deserialize(line, McpJsonUtilities.DefaultOptions.GetTypeInfo(typeof(JsonRpcMessage))) is JsonRpcMessage message) |
|
if (await _serverOutput.ReadLineAsync(cancellationToken).ConfigureAwait(false) is not string line) |
|
{ |
|
LogTransportEndOfStream(Name); |
|
break; |
|
} |
|
|
|
if (string.IsNullOrWhiteSpace(line)) |
|
{ |
|
continue; |
|
} |
|
|
|
LogTransportReceivedMessageSensitive(Name, line); |
|
|
|
await ProcessMessageAsync(line, cancellationToken).ConfigureAwait(false); |
|
private async Task ProcessMessageAsync(string line, CancellationToken cancellationToken) |
|
{ |
|
try |
|
{ |
|
var message = (JsonRpcMessage?)JsonSerializer.Deserialize(line.AsSpan().Trim(), McpJsonUtilities.DefaultOptions.GetTypeInfo(typeof(JsonRpcMessage))); |
|
if (message != null) |
Similar issue to #1259 which was fixed in #1274.
Read / deserialization is still encoding to a string. We should try to keep as utf8 bytes and deserialize from those:
csharp-sdk/src/ModelContextProtocol.Core/Server/StreamServerTransport.cs
Lines 100 to 116 in 411cef6
csharp-sdk/src/ModelContextProtocol.Core/Client/StreamClientSessionTransport.cs
Lines 108 to 121 in 411cef6
csharp-sdk/src/ModelContextProtocol.Core/Client/StreamClientSessionTransport.cs
Lines 140 to 145 in 411cef6