Skip to content
7 changes: 4 additions & 3 deletions src/ModelContextProtocol.Core/McpSessionHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -355,8 +355,9 @@ private void HandleMessageWithId(JsonRpcMessage message, JsonRpcMessageWithId me
}

LogRequestHandlerCalled(EndpointName, request.Method);
long startingTimestamp = Stopwatch.GetTimestamp();
JsonNode? result = await handler(request, cancellationToken).ConfigureAwait(false);
LogRequestHandlerCompleted(EndpointName, request.Method);
LogRequestHandlerCompleted(EndpointName, request.Method, GetElapsed(startingTimestamp).TotalMilliseconds);

await SendMessageAsync(new JsonRpcResponse
{
Expand Down Expand Up @@ -882,8 +883,8 @@ private static McpProtocolException CreateRemoteProtocolException(JsonRpcError e
[LoggerMessage(Level = LogLevel.Information, Message = "{EndpointName} method '{Method}' request handler called.")]
private partial void LogRequestHandlerCalled(string endpointName, string method);

[LoggerMessage(Level = LogLevel.Information, Message = "{EndpointName} method '{Method}' request handler completed.")]
private partial void LogRequestHandlerCompleted(string endpointName, string method);
[LoggerMessage(Level = LogLevel.Information, Message = "{EndpointName} method '{Method}' request handler completed in {ElapsedMilliseconds}ms.")]
private partial void LogRequestHandlerCompleted(string endpointName, string method, double elapsedMilliseconds);

[LoggerMessage(Level = LogLevel.Warning, Message = "{EndpointName} method '{Method}' request handler failed.")]
private partial void LogRequestHandlerException(string endpointName, string method, Exception exception);
Expand Down