Skip to content

Commit 329f848

Browse files
authored
Enhance HTTP and MCP session logging (#608)
1 parent e1a2564 commit 329f848

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/ModelContextProtocol.Core/McpSession.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ public McpSession(
9595
_requestHandlers = requestHandlers;
9696
_notificationHandlers = notificationHandlers;
9797
_logger = logger ?? NullLogger.Instance;
98+
LogSessionCreated(EndpointName, _sessionId, _transportKind);
9899
}
99100

100101
/// <summary>
@@ -701,6 +702,7 @@ public void Dispose()
701702
}
702703

703704
_pendingRequests.Clear();
705+
LogSessionDisposed(EndpointName, _sessionId, _transportKind);
704706
}
705707

706708
#if !NET
@@ -783,4 +785,10 @@ private static TimeSpan GetElapsed(long startingTimestamp) =>
783785

784786
[LoggerMessage(Level = LogLevel.Trace, Message = "{EndpointName} sending message. Message: '{Message}'.")]
785787
private partial void LogSendingMessageSensitive(string endpointName, string message);
788+
789+
[LoggerMessage(Level = LogLevel.Trace, Message = "{EndpointName} session {SessionId} created with transport {TransportKind}")]
790+
private partial void LogSessionCreated(string endpointName, string sessionId, string transportKind);
791+
792+
[LoggerMessage(Level = LogLevel.Trace, Message = "{EndpointName} session {SessionId} disposed with transport {TransportKind}")]
793+
private partial void LogSessionDisposed(string endpointName, string sessionId, string transportKind);
786794
}

0 commit comments

Comments
 (0)