55using ModelContextProtocol . Protocol . Types ;
66using ModelContextProtocol . Shared ;
77using ModelContextProtocol . Utils . Json ;
8- using System . Diagnostics ;
9- using System . Reflection ;
108using System . Text . Json ;
119
1210namespace ModelContextProtocol . Client ;
1311
1412/// <inheritdoc/>
1513internal sealed class McpClient : McpEndpoint , IMcpClient
1614{
17- /// <summary>Cached naming information used for client name/version when none is specified.</summary>
18- private static readonly AssemblyName s_asmName = ( Assembly . GetEntryAssembly ( ) ?? Assembly . GetExecutingAssembly ( ) ) . GetName ( ) ;
15+ private static Implementation DefaultImplementation { get ; } = new ( )
16+ {
17+ Name = DefaultAssemblyName . Name ?? nameof ( McpClient ) ,
18+ Version = DefaultAssemblyName . Version ? . ToString ( ) ?? "1.0.0" ,
19+ } ;
1920
2021 private readonly IClientTransport _clientTransport ;
2122 private readonly McpClientOptions _options ;
@@ -37,17 +38,9 @@ internal sealed class McpClient : McpEndpoint, IMcpClient
3738 public McpClient ( IClientTransport clientTransport , McpClientOptions ? options , McpServerConfig serverConfig , ILoggerFactory ? loggerFactory )
3839 : base ( loggerFactory )
3940 {
40- _clientTransport = clientTransport ;
41+ options ??= new ( ) ;
4142
42- if ( options ? . ClientInfo is null )
43- {
44- options = options ? . Clone ( ) ?? new ( ) ;
45- options . ClientInfo = new ( )
46- {
47- Name = s_asmName . Name ?? nameof ( McpClient ) ,
48- Version = s_asmName . Version ? . ToString ( ) ?? "1.0.0" ,
49- } ;
50- }
43+ _clientTransport = clientTransport ;
5144 _options = options ;
5245
5346 EndpointName = $ "Client ({ serverConfig . Id } : { serverConfig . Name } )";
@@ -122,14 +115,13 @@ public async Task ConnectAsync(CancellationToken cancellationToken = default)
122115 try
123116 {
124117 // Send initialize request
125- Debug . Assert ( _options . ClientInfo is not null , "ClientInfo should be set by the constructor" ) ;
126118 var initializeResponse = await this . SendRequestAsync (
127119 RequestMethods . Initialize ,
128120 new InitializeRequestParams
129121 {
130122 ProtocolVersion = _options . ProtocolVersion ,
131123 Capabilities = _options . Capabilities ?? new ClientCapabilities ( ) ,
132- ClientInfo = _options . ClientInfo !
124+ ClientInfo = _options . ClientInfo ?? DefaultImplementation ,
133125 } ,
134126 McpJsonUtilities . JsonContext . Default . InitializeRequestParams ,
135127 McpJsonUtilities . JsonContext . Default . InitializeResult ,
0 commit comments