Skip to content

Commit cc7e97c

Browse files
Copilotstephentoub
andcommitted
Remove Debug-level logging, keep only Trace-level logging for sent messages
Addresses review feedback to only have Trace-level logging for JSON-RPC payloads. Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
1 parent 7cd6a01 commit cc7e97c

5 files changed

Lines changed: 6 additions & 44 deletions

File tree

src/ModelContextProtocol.Core/Client/SseClientSessionTransport.cs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,7 @@ public override async Task SendMessageAsync(
8080
messageId = messageWithId.Id.ToString();
8181
}
8282

83-
if (_logger.IsEnabled(LogLevel.Trace))
84-
{
85-
LogTransportSendingMessageSensitive(Name, JsonSerializer.Serialize(message, McpJsonUtilities.JsonContext.Default.JsonRpcMessage));
86-
}
87-
else
88-
{
89-
LogTransportSendingMessage(Name, messageId);
90-
}
83+
LogTransportSendingMessageSensitive(Name, JsonSerializer.Serialize(message, McpJsonUtilities.JsonContext.Default.JsonRpcMessage));
9184

9285
using var httpRequestMessage = new HttpRequestMessage(HttpMethod.Post, _messageEndpoint);
9386
StreamableHttpClientSessionTransport.CopyAdditionalHeaders(httpRequestMessage.Headers, _options.AdditionalHeaders, sessionId: null, protocolVersion: null);

src/ModelContextProtocol.Core/Client/StreamClientSessionTransport.cs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -105,14 +105,7 @@ public override async Task SendMessageAsync(JsonRpcMessage message, Cancellation
105105

106106
var json = JsonSerializer.Serialize(message, McpJsonUtilities.JsonContext.Default.JsonRpcMessage);
107107

108-
if (Logger.IsEnabled(LogLevel.Trace))
109-
{
110-
LogTransportSendingMessageSensitive(Name, json);
111-
}
112-
else
113-
{
114-
LogTransportSendingMessage(Name, id);
115-
}
108+
LogTransportSendingMessageSensitive(Name, json);
116109

117110
using var _ = await _sendLock.LockAsync(cancellationToken).ConfigureAwait(false);
118111
try

src/ModelContextProtocol.Core/Client/StreamableHttpClientSessionTransport.cs

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -75,20 +75,7 @@ internal async Task<HttpResponseMessage> SendHttpRequestAsync(JsonRpcMessage mes
7575
$"Call {nameof(McpClient)}.{nameof(McpClient.ResumeSessionAsync)} to resume existing sessions.");
7676
}
7777

78-
string messageId = "(no id)";
79-
if (message is JsonRpcMessageWithId messageWithId)
80-
{
81-
messageId = messageWithId.Id.ToString();
82-
}
83-
84-
if (_logger.IsEnabled(LogLevel.Trace))
85-
{
86-
LogTransportSendingMessageSensitive(Name, JsonSerializer.Serialize(message, McpJsonUtilities.JsonContext.Default.JsonRpcMessage));
87-
}
88-
else
89-
{
90-
LogTransportSendingMessage(Name, messageId);
91-
}
78+
LogTransportSendingMessageSensitive(Name, JsonSerializer.Serialize(message, McpJsonUtilities.JsonContext.Default.JsonRpcMessage));
9279

9380
using var sendCts = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken, _connectionCts.Token);
9481
cancellationToken = sendCts.Token;

src/ModelContextProtocol.Core/Protocol/TransportBase.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,6 @@ protected void SetDisconnected(Exception? error = null)
166166
[LoggerMessage(Level = LogLevel.Error, Message = "{EndpointName} transport send failed for message ID '{MessageId}'.")]
167167
private protected partial void LogTransportSendFailed(string endpointName, string messageId, Exception exception);
168168

169-
[LoggerMessage(Level = LogLevel.Debug, Message = "{EndpointName} transport sending message with ID '{MessageId}'.")]
170-
private protected partial void LogTransportSendingMessage(string endpointName, string messageId);
171-
172169
[LoggerMessage(Level = LogLevel.Trace, Message = "{EndpointName} transport sending message. Message: '{Message}'.")]
173170
private protected partial void LogTransportSendingMessageSensitive(string endpointName, string message);
174171

src/ModelContextProtocol.Core/Server/StreamServerTransport.cs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -74,17 +74,9 @@ public override async Task SendMessageAsync(JsonRpcMessage message, Cancellation
7474

7575
try
7676
{
77-
if (Logger.IsEnabled(LogLevel.Trace))
78-
{
79-
var json = JsonSerializer.Serialize(message, McpJsonUtilities.JsonContext.Default.JsonRpcMessage);
80-
LogTransportSendingMessageSensitive(Name, json);
81-
await _outputStream.WriteAsync(Encoding.UTF8.GetBytes(json), cancellationToken).ConfigureAwait(false);
82-
}
83-
else
84-
{
85-
LogTransportSendingMessage(Name, id);
86-
await JsonSerializer.SerializeAsync(_outputStream, message, McpJsonUtilities.DefaultOptions.GetTypeInfo(typeof(JsonRpcMessage)), cancellationToken).ConfigureAwait(false);
87-
}
77+
var json = JsonSerializer.Serialize(message, McpJsonUtilities.JsonContext.Default.JsonRpcMessage);
78+
LogTransportSendingMessageSensitive(Name, json);
79+
await _outputStream.WriteAsync(Encoding.UTF8.GetBytes(json), cancellationToken).ConfigureAwait(false);
8880
await _outputStream.WriteAsync(s_newlineBytes, cancellationToken).ConfigureAwait(false);
8981
await _outputStream.FlushAsync(cancellationToken).ConfigureAwait(false);
9082
}

0 commit comments

Comments
 (0)