Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions src/ModelContextProtocol/Client/McpClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ namespace ModelContextProtocol.Client;
internal sealed class McpClient : McpJsonRpcEndpoint, IMcpClient
{
private readonly McpClientOptions _options;
private readonly ILogger _logger;
private readonly IClientTransport _clientTransport;

private volatile bool _isInitializing;
Expand All @@ -28,10 +27,9 @@ internal sealed class McpClient : McpJsonRpcEndpoint, IMcpClient
/// <param name="serverConfig">The server configuration.</param>
/// <param name="loggerFactory">The logger factory.</param>
public McpClient(IClientTransport transport, McpClientOptions options, McpServerConfig serverConfig, ILoggerFactory? loggerFactory)
: base(transport, loggerFactory)
: base(transport, loggerFactory?.CreateLogger<McpClient>())
{
_options = options;
_logger = (ILogger?)loggerFactory?.CreateLogger<McpClient>() ?? NullLogger.Instance;
_clientTransport = transport;

EndpointName = $"Client ({serverConfig.Id}: {serverConfig.Name})";
Expand Down
4 changes: 1 addition & 3 deletions src/ModelContextProtocol/Server/McpServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ namespace ModelContextProtocol.Server;
internal sealed class McpServer : McpJsonRpcEndpoint, IMcpServer
{
private readonly IServerTransport? _serverTransport;
private readonly ILogger _logger;
private readonly string _serverDescription;
private volatile bool _isInitializing;

Expand All @@ -28,12 +27,11 @@ internal sealed class McpServer : McpJsonRpcEndpoint, IMcpServer
/// <param name="serviceProvider">Optional service provider to use for dependency injection</param>
/// <exception cref="McpServerException"></exception>
public McpServer(ITransport transport, McpServerOptions options, ILoggerFactory? loggerFactory, IServiceProvider? serviceProvider)
: base(transport, loggerFactory)
: base(transport, loggerFactory?.CreateLogger<McpServer>())
{
Throw.IfNull(options);

_serverTransport = transport as IServerTransport;
_logger = (ILogger?)loggerFactory?.CreateLogger<McpServer>() ?? NullLogger.Instance;
ServerInstructions = options.ServerInstructions;
Services = serviceProvider;
_serverDescription = $"{options.ServerInfo.Name} {options.ServerInfo.Version}";
Expand Down
11 changes: 5 additions & 6 deletions src/ModelContextProtocol/Shared/McpJsonRpcEndpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,26 +28,25 @@ internal abstract class McpJsonRpcEndpoint : IAsyncDisposable
private readonly Dictionary<string, Func<JsonRpcRequest, CancellationToken, Task<object?>>> _requestHandlers = [];
private int _nextRequestId;
private readonly JsonSerializerOptions _jsonOptions;
private readonly ILogger _logger;
private bool _isDisposed;

protected readonly ILogger _logger;

/// <summary>
/// Initializes a new instance of the <see cref="McpJsonRpcEndpoint"/> class.
/// </summary>
/// <param name="transport">An MCP transport implementation.</param>
/// <param name="loggerFactory">The logger factory.</param>
protected McpJsonRpcEndpoint(ITransport transport, ILoggerFactory? loggerFactory = null)
/// <param name="logger">The logger.</param>
protected McpJsonRpcEndpoint(ITransport transport, ILogger? logger = null)
{
Throw.IfNull(transport);

loggerFactory ??= NullLoggerFactory.Instance;

_transport = transport;
_pendingRequests = new();
_notificationHandlers = new();
_nextRequestId = 1;
_jsonOptions = McpJsonUtilities.DefaultOptions;
_logger = (ILogger?)loggerFactory?.CreateLogger<McpClient>() ?? NullLogger.Instance;
_logger = logger ?? NullLogger.Instance;
Comment thread
halter73 marked this conversation as resolved.
Outdated
}

/// <summary>
Expand Down