Use different logger categories for client and server in McpJsonRpcEndpoint (#110)
* Use different logger categories for client and server in McpJsonRpcEndpoint * Address PR feedback
This commit is contained in:
parent
d1217c57af
commit
8be681543d
3 changed files with 3 additions and 8 deletions
|
|
@ -15,7 +15,6 @@ namespace ModelContextProtocol.Client;
|
||||||
internal sealed class McpClient : McpJsonRpcEndpoint, IMcpClient
|
internal sealed class McpClient : McpJsonRpcEndpoint, IMcpClient
|
||||||
{
|
{
|
||||||
private readonly McpClientOptions _options;
|
private readonly McpClientOptions _options;
|
||||||
private readonly ILogger _logger;
|
|
||||||
private readonly IClientTransport _clientTransport;
|
private readonly IClientTransport _clientTransport;
|
||||||
|
|
||||||
private volatile bool _isInitializing;
|
private volatile bool _isInitializing;
|
||||||
|
|
@ -31,7 +30,6 @@ internal sealed class McpClient : McpJsonRpcEndpoint, IMcpClient
|
||||||
: base(transport, loggerFactory)
|
: base(transport, loggerFactory)
|
||||||
{
|
{
|
||||||
_options = options;
|
_options = options;
|
||||||
_logger = (ILogger?)loggerFactory?.CreateLogger<McpClient>() ?? NullLogger.Instance;
|
|
||||||
_clientTransport = transport;
|
_clientTransport = transport;
|
||||||
|
|
||||||
EndpointName = $"Client ({serverConfig.Id}: {serverConfig.Name})";
|
EndpointName = $"Client ({serverConfig.Id}: {serverConfig.Name})";
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,6 @@ namespace ModelContextProtocol.Server;
|
||||||
internal sealed class McpServer : McpJsonRpcEndpoint, IMcpServer
|
internal sealed class McpServer : McpJsonRpcEndpoint, IMcpServer
|
||||||
{
|
{
|
||||||
private readonly IServerTransport? _serverTransport;
|
private readonly IServerTransport? _serverTransport;
|
||||||
private readonly ILogger _logger;
|
|
||||||
private readonly string _serverDescription;
|
private readonly string _serverDescription;
|
||||||
private volatile bool _isInitializing;
|
private volatile bool _isInitializing;
|
||||||
|
|
||||||
|
|
@ -33,7 +32,6 @@ internal sealed class McpServer : McpJsonRpcEndpoint, IMcpServer
|
||||||
Throw.IfNull(options);
|
Throw.IfNull(options);
|
||||||
|
|
||||||
_serverTransport = transport as IServerTransport;
|
_serverTransport = transport as IServerTransport;
|
||||||
_logger = (ILogger?)loggerFactory?.CreateLogger<McpServer>() ?? NullLogger.Instance;
|
|
||||||
ServerInstructions = options.ServerInstructions;
|
ServerInstructions = options.ServerInstructions;
|
||||||
Services = serviceProvider;
|
Services = serviceProvider;
|
||||||
_serverDescription = $"{options.ServerInfo.Name} {options.ServerInfo.Version}";
|
_serverDescription = $"{options.ServerInfo.Name} {options.ServerInfo.Version}";
|
||||||
|
|
|
||||||
|
|
@ -28,9 +28,10 @@ internal abstract class McpJsonRpcEndpoint : IAsyncDisposable
|
||||||
private readonly Dictionary<string, Func<JsonRpcRequest, CancellationToken, Task<object?>>> _requestHandlers = [];
|
private readonly Dictionary<string, Func<JsonRpcRequest, CancellationToken, Task<object?>>> _requestHandlers = [];
|
||||||
private int _nextRequestId;
|
private int _nextRequestId;
|
||||||
private readonly JsonSerializerOptions _jsonOptions;
|
private readonly JsonSerializerOptions _jsonOptions;
|
||||||
private readonly ILogger _logger;
|
|
||||||
private bool _isDisposed;
|
private bool _isDisposed;
|
||||||
|
|
||||||
|
protected readonly ILogger _logger;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="McpJsonRpcEndpoint"/> class.
|
/// Initializes a new instance of the <see cref="McpJsonRpcEndpoint"/> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
@ -40,14 +41,12 @@ internal abstract class McpJsonRpcEndpoint : IAsyncDisposable
|
||||||
{
|
{
|
||||||
Throw.IfNull(transport);
|
Throw.IfNull(transport);
|
||||||
|
|
||||||
loggerFactory ??= NullLoggerFactory.Instance;
|
|
||||||
|
|
||||||
_transport = transport;
|
_transport = transport;
|
||||||
_pendingRequests = new();
|
_pendingRequests = new();
|
||||||
_notificationHandlers = new();
|
_notificationHandlers = new();
|
||||||
_nextRequestId = 1;
|
_nextRequestId = 1;
|
||||||
_jsonOptions = McpJsonUtilities.DefaultOptions;
|
_jsonOptions = McpJsonUtilities.DefaultOptions;
|
||||||
_logger = (ILogger?)loggerFactory?.CreateLogger<McpClient>() ?? NullLogger.Instance;
|
_logger = loggerFactory?.CreateLogger(GetType()) ?? NullLogger.Instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue