Avoid intermediate strings in MCP transport serialization (#1274)
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com> Co-authored-by: Stephen Toub <stoub@microsoft.com> Co-authored-by: halter73 <54385+halter73@users.noreply.github.com>
This commit is contained in:
parent
c3bb9c1955
commit
f3da4729f5
1 changed files with 136 additions and 63 deletions
|
|
@ -74,9 +74,9 @@ public class StreamServerTransport : TransportBase
|
|||
|
||||
try
|
||||
{
|
||||
var json = JsonSerializer.Serialize(message, McpJsonUtilities.JsonContext.Default.JsonRpcMessage);
|
||||
LogTransportSendingMessageSensitive(Name, json);
|
||||
await _outputStream.WriteAsync(Encoding.UTF8.GetBytes(json), cancellationToken).ConfigureAwait(false);
|
||||
var json = JsonSerializer.SerializeToUtf8Bytes(message, McpJsonUtilities.JsonContext.Default.JsonRpcMessage);
|
||||
LogTransportSendingMessageSensitive(message);
|
||||
await _outputStream.WriteAsync(json, cancellationToken).ConfigureAwait(false);
|
||||
await _outputStream.WriteAsync(s_newlineBytes, cancellationToken).ConfigureAwait(false);
|
||||
await _outputStream.FlushAsync(cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue