Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 824d01d

Browse files
committedApr 4, 2025·
Address more feedback and further cleanup
1 parent 3725859 commit 824d01d

25 files changed

+41
-128
lines changed
 

‎samples/QuickstartWeatherServer/Tools/WeatherTools.cs

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using ModelContextProtocol;
22
using ModelContextProtocol.Server;
33
using System.ComponentModel;
4-
using System.Net.Http.Json;
54
using System.Text.Json;
65

76
namespace QuickstartWeatherServer.Tools;

‎src/ModelContextProtocol/Client/McpClient.cs

+8-16
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,18 @@
55
using ModelContextProtocol.Protocol.Types;
66
using ModelContextProtocol.Shared;
77
using ModelContextProtocol.Utils.Json;
8-
using System.Diagnostics;
9-
using System.Reflection;
108
using System.Text.Json;
119

1210
namespace ModelContextProtocol.Client;
1311

1412
/// <inheritdoc/>
1513
internal 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,

‎src/ModelContextProtocol/Client/McpClientFactory.cs

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
using ModelContextProtocol.Utils;
66
using Microsoft.Extensions.Logging;
77
using Microsoft.Extensions.Logging.Abstractions;
8-
using System.Reflection;
98

109
namespace ModelContextProtocol.Client;
1110

‎src/ModelContextProtocol/Client/McpClientOptions.cs

-10
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,4 @@ public class McpClientOptions
2828
/// Timeout for initialization sequence.
2929
/// </summary>
3030
public TimeSpan InitializationTimeout { get; set; } = TimeSpan.FromSeconds(60);
31-
32-
/// <summary>Creates a shallow clone of the options.</summary>
33-
internal McpClientOptions Clone() =>
34-
new()
35-
{
36-
ClientInfo = ClientInfo,
37-
Capabilities = Capabilities,
38-
ProtocolVersion = ProtocolVersion,
39-
InitializationTimeout = InitializationTimeout
40-
};
4131
}

‎src/ModelContextProtocol/Client/McpClientTool.cs

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using ModelContextProtocol.Protocol.Types;
22
using ModelContextProtocol.Utils.Json;
3-
using ModelContextProtocol.Utils;
43
using Microsoft.Extensions.AI;
54
using System.Text.Json;
65

‎src/ModelContextProtocol/Configuration/McpServerOptionsSetup.cs

+1-14
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using System.Reflection;
2-
using ModelContextProtocol.Server;
1+
using ModelContextProtocol.Server;
32
using Microsoft.Extensions.Options;
43
using ModelContextProtocol.Utils;
54

@@ -25,18 +24,6 @@ public void Configure(McpServerOptions options)
2524
{
2625
Throw.IfNull(options);
2726

28-
// Configure the option's server information based on the current process,
29-
// if it otherwise lacks server information.
30-
if (options.ServerInfo is not { } serverInfo)
31-
{
32-
var assemblyName = Assembly.GetEntryAssembly()?.GetName();
33-
options.ServerInfo = new()
34-
{
35-
Name = assemblyName?.Name ?? "McpServer",
36-
Version = assemblyName?.Version?.ToString() ?? "1.0.0",
37-
};
38-
}
39-
4027
// Collect all of the provided tools into a tools collection. If the options already has
4128
// a collection, add to it, otherwise create a new one. We want to maintain the identity
4229
// of an existing collection in case someone has provided their own derived type, wants

‎src/ModelContextProtocol/Protocol/Transport/StdioClientTransport.cs

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
using Microsoft.Extensions.Logging.Abstractions;
33
using ModelContextProtocol.Logging;
44
using ModelContextProtocol.Utils;
5-
using System.ComponentModel;
65
using System.Diagnostics;
76
using System.Text;
87

‎src/ModelContextProtocol/Protocol/Transport/StdioServerTransport.cs

+1-3
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,7 @@ public StdioServerTransport(string serverName, ILoggerFactory? loggerFactory = n
7070
private static string GetServerName(McpServerOptions serverOptions)
7171
{
7272
Throw.IfNull(serverOptions);
73-
Throw.IfNull(serverOptions.ServerInfo);
74-
Throw.IfNull(serverOptions.ServerInfo.Name);
7573

76-
return serverOptions.ServerInfo.Name;
74+
return serverOptions.ServerInfo?.Name ?? McpServer.DefaultImplementation.Name;
7775
}
7876
}

‎src/ModelContextProtocol/Protocol/Types/ListRootsRequestParams.cs

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
using ModelContextProtocol.Protocol.Messages;
2-
3-
namespace ModelContextProtocol.Protocol.Types;
1+
namespace ModelContextProtocol.Protocol.Types;
42

53
/// <summary>
64
/// A request from the server to get a list of root URIs from the client.

‎src/ModelContextProtocol/Server/McpServer.cs

+10-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ namespace ModelContextProtocol.Server;
1111
/// <inheritdoc />
1212
internal sealed class McpServer : McpEndpoint, IMcpServer
1313
{
14+
internal static Implementation DefaultImplementation { get; } = new()
15+
{
16+
Name = DefaultAssemblyName.Name ?? nameof(McpServer),
17+
Version = DefaultAssemblyName.Version?.ToString() ?? "1.0.0",
18+
};
19+
1420
private readonly EventHandler? _toolsChangedDelegate;
1521
private readonly EventHandler? _promptsChangedDelegate;
1622

@@ -32,9 +38,11 @@ public McpServer(ITransport transport, McpServerOptions options, ILoggerFactory?
3238
Throw.IfNull(transport);
3339
Throw.IfNull(options);
3440

41+
options ??= new();
42+
3543
ServerOptions = options;
3644
Services = serviceProvider;
37-
_endpointName = $"Server ({options.ServerInfo.Name} {options.ServerInfo.Version})";
45+
_endpointName = $"Server ({options.ServerInfo?.Name ?? DefaultImplementation.Name} {options.ServerInfo?.Version ?? DefaultImplementation.Version})";
3846

3947
_toolsChangedDelegate = delegate
4048
{
@@ -158,7 +166,7 @@ private void SetInitializeHandler(McpServerOptions options)
158166
{
159167
ProtocolVersion = options.ProtocolVersion,
160168
Instructions = options.ServerInstructions,
161-
ServerInfo = options.ServerInfo,
169+
ServerInfo = options.ServerInfo ?? DefaultImplementation,
162170
Capabilities = ServerCapabilities ?? new(),
163171
});
164172
},

‎src/ModelContextProtocol/Server/McpServerExtensions.cs

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using Microsoft.Extensions.AI;
2-
using ModelContextProtocol.Client;
32
using ModelContextProtocol.Protocol.Messages;
43
using ModelContextProtocol.Protocol.Types;
54
using ModelContextProtocol.Utils;

‎src/ModelContextProtocol/Server/McpServerOptions.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public class McpServerOptions
1414
/// <summary>
1515
/// Information about this server implementation.
1616
/// </summary>
17-
public required Implementation ServerInfo { get; set; }
17+
public Implementation? ServerInfo { get; set; }
1818

1919
/// <summary>
2020
/// Server capabilities to advertise to the server.

‎src/ModelContextProtocol/Shared/McpEndpoint.cs

+4-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
using ModelContextProtocol.Server;
77
using ModelContextProtocol.Utils;
88
using System.Diagnostics.CodeAnalysis;
9-
using System.Text.Json.Serialization.Metadata;
9+
using System.Reflection;
1010

1111
namespace ModelContextProtocol.Shared;
1212

@@ -19,6 +19,9 @@ namespace ModelContextProtocol.Shared;
1919
/// </summary>
2020
internal abstract class McpEndpoint : IAsyncDisposable
2121
{
22+
/// <summary>Cached naming information used for name/version when none is specified.</summary>
23+
internal static AssemblyName DefaultAssemblyName { get; } = (Assembly.GetEntryAssembly() ?? Assembly.GetExecutingAssembly()).GetName();
24+
2225
private McpSession? _session;
2326
private CancellationTokenSource? _sessionCts;
2427

‎src/ModelContextProtocol/Shared/McpSession.cs

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
using ModelContextProtocol.Logging;
44
using ModelContextProtocol.Protocol.Messages;
55
using ModelContextProtocol.Protocol.Transport;
6-
using ModelContextProtocol.Server;
76
using ModelContextProtocol.Utils;
87
using ModelContextProtocol.Utils.Json;
98
using System.Collections.Concurrent;

‎tests/ModelContextProtocol.TestServer/Program.cs

-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ private static async Task Main(string[] args)
3838

3939
McpServerOptions options = new()
4040
{
41-
ServerInfo = new Implementation() { Name = "TestServer", Version = "1.0.0" },
4241
Capabilities = new ServerCapabilities()
4342
{
4443
Tools = ConfigureTools(),

‎tests/ModelContextProtocol.TestSseServer/Program.cs

-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ private static void ConfigureSerilog(ILoggingBuilder loggingBuilder)
2525

2626
private static void ConfigureOptions(McpServerOptions options)
2727
{
28-
options.ServerInfo = new Implementation() { Name = "TestServer", Version = "1.0.0" };
2928
options.Capabilities = new ServerCapabilities()
3029
{
3130
Tools = new(),

‎tests/ModelContextProtocol.Tests/Client/McpClientFactoryTests.cs

+8-22
Original file line numberDiff line numberDiff line change
@@ -11,29 +11,24 @@ namespace ModelContextProtocol.Tests.Client;
1111

1212
public class McpClientFactoryTests
1313
{
14-
private readonly McpClientOptions _defaultOptions = new()
15-
{
16-
ClientInfo = new() { Name = "TestClient", Version = "1.0.0" }
17-
};
18-
1914
[Fact]
2015
public async Task CreateAsync_WithInvalidArgs_Throws()
2116
{
22-
await Assert.ThrowsAsync<ArgumentNullException>("serverConfig", () => McpClientFactory.CreateAsync((McpServerConfig)null!, _defaultOptions, cancellationToken: TestContext.Current.CancellationToken));
17+
await Assert.ThrowsAsync<ArgumentNullException>("serverConfig", () => McpClientFactory.CreateAsync((McpServerConfig)null!, cancellationToken: TestContext.Current.CancellationToken));
2318

2419
await Assert.ThrowsAsync<ArgumentException>("serverConfig", () => McpClientFactory.CreateAsync(new McpServerConfig()
2520
{
2621
Name = "name",
2722
Id = "id",
2823
TransportType = "somethingunsupported",
29-
}, _defaultOptions, cancellationToken: TestContext.Current.CancellationToken));
24+
}, cancellationToken: TestContext.Current.CancellationToken));
3025

3126
await Assert.ThrowsAsync<InvalidOperationException>(() => McpClientFactory.CreateAsync(new McpServerConfig()
3227
{
3328
Name = "name",
3429
Id = "id",
3530
TransportType = TransportTypes.StdIo,
36-
}, _defaultOptions, (_, __) => null!, cancellationToken: TestContext.Current.CancellationToken));
31+
}, createTransportFunc: (_, __) => null!, cancellationToken: TestContext.Current.CancellationToken));
3732
}
3833

3934
[Fact]
@@ -78,8 +73,7 @@ public async Task CreateAsync_WithValidStdioConfig_CreatesNewClient()
7873
// Act
7974
await using var client = await McpClientFactory.CreateAsync(
8075
serverConfig,
81-
_defaultOptions,
82-
(_, __) => new NopTransport(),
76+
createTransportFunc: (_, __) => new NopTransport(),
8377
cancellationToken: TestContext.Current.CancellationToken);
8478

8579
// Assert
@@ -102,8 +96,7 @@ public async Task CreateAsync_WithNoTransportOptions_CreatesNewClient()
10296
// Act
10397
await using var client = await McpClientFactory.CreateAsync(
10498
serverConfig,
105-
_defaultOptions,
106-
(_, __) => new NopTransport(),
99+
createTransportFunc: (_, __) => new NopTransport(),
107100
cancellationToken: TestContext.Current.CancellationToken);
108101

109102
// Assert
@@ -126,8 +119,7 @@ public async Task CreateAsync_WithValidSseConfig_CreatesNewClient()
126119
// Act
127120
await using var client = await McpClientFactory.CreateAsync(
128121
serverConfig,
129-
_defaultOptions,
130-
(_, __) => new NopTransport(),
122+
createTransportFunc: (_, __) => new NopTransport(),
131123
cancellationToken: TestContext.Current.CancellationToken);
132124

133125
// Assert
@@ -157,8 +149,7 @@ public async Task CreateAsync_WithSse_CreatesCorrectTransportOptions()
157149
// Act
158150
await using var client = await McpClientFactory.CreateAsync(
159151
serverConfig,
160-
_defaultOptions,
161-
(_, __) => new NopTransport(),
152+
createTransportFunc: (_, __) => new NopTransport(),
162153
cancellationToken: TestContext.Current.CancellationToken);
163154

164155
// Assert
@@ -186,7 +177,7 @@ public async Task McpFactory_WithInvalidTransportOptions_ThrowsFormatException(s
186177
};
187178

188179
// act & assert
189-
await Assert.ThrowsAsync<ArgumentException>(() => McpClientFactory.CreateAsync(config, _defaultOptions, cancellationToken: TestContext.Current.CancellationToken));
180+
await Assert.ThrowsAsync<ArgumentException>(() => McpClientFactory.CreateAsync(config, cancellationToken: TestContext.Current.CancellationToken));
190181
}
191182

192183
[Theory]
@@ -205,11 +196,6 @@ public async Task CreateAsync_WithCapabilitiesOptions(Type transportType)
205196

206197
var clientOptions = new McpClientOptions
207198
{
208-
ClientInfo = new Implementation
209-
{
210-
Name = "TestClient",
211-
Version = "1.0.0.0"
212-
},
213199
Capabilities = new ClientCapabilities
214200
{
215201
Sampling = new SamplingCapability

‎tests/ModelContextProtocol.Tests/ClientIntegrationTests.cs

-5
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@
55
using ModelContextProtocol.Protocol.Types;
66
using ModelContextProtocol.Tests.Utils;
77
using OpenAI;
8-
using System.Text.Encodings.Web;
98
using System.Text.Json;
10-
using System.Text.Json.Serialization;
11-
using System.Text.Json.Serialization.Metadata;
129

1310
namespace ModelContextProtocol.Tests;
1411

@@ -367,7 +364,6 @@ public async Task Sampling_Stdio(string clientId)
367364
int samplingHandlerCalls = 0;
368365
await using var client = await _fixture.CreateClientAsync(clientId, new()
369366
{
370-
ClientInfo = new() { Name = "Sampling_Stdio", Version = "1.0.0" },
371367
Capabilities = new()
372368
{
373369
Sampling = new()
@@ -532,7 +528,6 @@ public async Task SamplingViaChatClient_RequestResponseProperlyPropagated()
532528
.CreateSamplingHandler();
533529
await using var client = await McpClientFactory.CreateAsync(_fixture.EverythingServerConfig, new()
534530
{
535-
ClientInfo = new() { Name = nameof(SamplingViaChatClient_RequestResponseProperlyPropagated), Version = "1.0.0" },
536531
Capabilities = new()
537532
{
538533
Sampling = new()

‎tests/ModelContextProtocol.Tests/DiagnosticTests.cs

-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using ModelContextProtocol.Client;
22
using ModelContextProtocol.Protocol.Transport;
3-
using ModelContextProtocol.Protocol.Types;
43
using ModelContextProtocol.Server;
54
using OpenTelemetry.Trace;
65
using System.Diagnostics;
@@ -49,7 +48,6 @@ private static async Task RunConnected(Func<IMcpClient, IMcpServer, Task> action
4948

5049
await using (IMcpServer server = McpServerFactory.Create(serverTransport, new()
5150
{
52-
ServerInfo = new Implementation { Name = "TestServer", Version = "1.0.0" },
5351
Capabilities = new()
5452
{
5553
Tools = new()

‎tests/ModelContextProtocol.Tests/Server/McpServerFactoryTests.cs

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using ModelContextProtocol.Protocol.Types;
2-
using ModelContextProtocol.Server;
1+
using ModelContextProtocol.Server;
32
using ModelContextProtocol.Tests.Utils;
43

54
namespace ModelContextProtocol.Tests.Server;
@@ -13,7 +12,6 @@ public McpServerFactoryTests(ITestOutputHelper testOutputHelper)
1312
{
1413
_options = new McpServerOptions
1514
{
16-
ServerInfo = new Implementation { Name = "TestServer", Version = "1.0" },
1715
ProtocolVersion = "1.0",
1816
InitializationTimeout = TimeSpan.FromSeconds(30)
1917
};

‎tests/ModelContextProtocol.Tests/Server/McpServerTests.cs

+2-3
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ private static McpServerOptions CreateOptions(ServerCapabilities? capabilities =
2424
{
2525
return new McpServerOptions
2626
{
27-
ServerInfo = new Implementation { Name = "TestServer", Version = "1.0" },
2827
ProtocolVersion = "2024",
2928
InitializationTimeout = TimeSpan.FromSeconds(30),
3029
Capabilities = capabilities,
@@ -189,8 +188,8 @@ await Can_Handle_Requests(
189188
{
190189
var result = JsonSerializer.Deserialize<InitializeResult>(response);
191190
Assert.NotNull(result);
192-
Assert.Equal("TestServer", result.ServerInfo.Name);
193-
Assert.Equal("1.0", result.ServerInfo.Version);
191+
Assert.Equal("ModelContextProtocol.Tests", result.ServerInfo.Name);
192+
Assert.Equal("1.0.0.0", result.ServerInfo.Version);
194193
Assert.Equal("2024", result.ProtocolVersion);
195194
});
196195
}

‎tests/ModelContextProtocol.Tests/SseIntegrationTests.cs

-17
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,6 @@ public async Task ConnectAndReceiveMessage_InMemoryServer()
2929
await using InMemoryTestSseServer server = new(CreatePortNumber(), LoggerFactory.CreateLogger<InMemoryTestSseServer>());
3030
await server.StartAsync();
3131

32-
var defaultOptions = new McpClientOptions
33-
{
34-
ClientInfo = new() { Name = "IntegrationTestClient", Version = "1.0.0" }
35-
};
36-
3732
var defaultConfig = new McpServerConfig
3833
{
3934
Id = "test_server",
@@ -46,7 +41,6 @@ public async Task ConnectAndReceiveMessage_InMemoryServer()
4641
// Act
4742
await using var client = await McpClientFactory.CreateAsync(
4843
defaultConfig,
49-
defaultOptions,
5044
loggerFactory: LoggerFactory,
5145
cancellationToken: TestContext.Current.CancellationToken);
5246

@@ -120,11 +114,6 @@ public async Task Sampling_Sse_EverythingServer()
120114
int samplingHandlerCalls = 0;
121115
var defaultOptions = new McpClientOptions
122116
{
123-
ClientInfo = new()
124-
{
125-
Name = "IntegrationTestClient",
126-
Version = "1.0.0"
127-
},
128117
Capabilities = new()
129118
{
130119
Sampling = new()
@@ -175,11 +164,6 @@ public async Task ConnectAndReceiveMessage_InMemoryServer_WithFullEndpointEventU
175164
server.UseFullUrlForEndpointEvent = true;
176165
await server.StartAsync();
177166

178-
var defaultOptions = new McpClientOptions
179-
{
180-
ClientInfo = new() { Name = "IntegrationTestClient", Version = "1.0.0" }
181-
};
182-
183167
var defaultConfig = new McpServerConfig
184168
{
185169
Id = "test_server",
@@ -192,7 +176,6 @@ public async Task ConnectAndReceiveMessage_InMemoryServer_WithFullEndpointEventU
192176
// Act
193177
await using var client = await McpClientFactory.CreateAsync(
194178
defaultConfig,
195-
defaultOptions,
196179
loggerFactory: LoggerFactory,
197180
cancellationToken: TestContext.Current.CancellationToken);
198181

‎tests/ModelContextProtocol.Tests/SseServerIntegrationTestFixture.cs

+1-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using ModelContextProtocol.Client;
2-
using ModelContextProtocol.Protocol.Transport;
1+
using ModelContextProtocol.Protocol.Transport;
32
using ModelContextProtocol.Test.Utils;
43
using ModelContextProtocol.Tests.Utils;
54
using ModelContextProtocol.TestSseServer;
@@ -32,11 +31,6 @@ public SseServerIntegrationTestFixture()
3231
_serverTask = Program.MainAsync([port.ToString()], new XunitLoggerProvider(_delegatingTestOutputHelper), _stopCts.Token);
3332
}
3433

35-
public static McpClientOptions CreateDefaultClientOptions() => new()
36-
{
37-
ClientInfo = new() { Name = "IntegrationTestClient", Version = "1.0.0" },
38-
};
39-
4034
public void Initialize(ITestOutputHelper output)
4135
{
4236
_delegatingTestOutputHelper.CurrentTestOutputHelper = output;

‎tests/ModelContextProtocol.Tests/SseServerIntegrationTests.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ private Task<IMcpClient> GetClientAsync(McpClientOptions? options = null)
2727
{
2828
return McpClientFactory.CreateAsync(
2929
_fixture.DefaultConfig,
30-
options ?? SseServerIntegrationTestFixture.CreateDefaultClientOptions(),
30+
options,
3131
loggerFactory: LoggerFactory,
3232
cancellationToken: TestContext.Current.CancellationToken);
3333
}
@@ -220,8 +220,8 @@ public async Task Sampling_Sse_TestServer()
220220
// Set up the sampling handler
221221
int samplingHandlerCalls = 0;
222222
#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously
223-
var options = SseServerIntegrationTestFixture.CreateDefaultClientOptions();
224-
options.Capabilities ??= new();
223+
McpClientOptions options = new();
224+
options.Capabilities = new();
225225
options.Capabilities.Sampling ??= new();
226226
options.Capabilities.Sampling.SamplingHandler = async (_, _, _) =>
227227
{

‎tests/ModelContextProtocol.Tests/Transport/StdioServerTransportTests.cs

-8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using Microsoft.Extensions.Options;
22
using ModelContextProtocol.Protocol.Messages;
33
using ModelContextProtocol.Protocol.Transport;
4-
using ModelContextProtocol.Protocol.Types;
54
using ModelContextProtocol.Server;
65
using ModelContextProtocol.Tests.Utils;
76
using ModelContextProtocol.Utils.Json;
@@ -21,11 +20,6 @@ public StdioServerTransportTests(ITestOutputHelper testOutputHelper)
2120
{
2221
_serverOptions = new McpServerOptions
2322
{
24-
ServerInfo = new Implementation
25-
{
26-
Name = "Test Server",
27-
Version = "1.0"
28-
},
2923
ProtocolVersion = "2.0",
3024
InitializationTimeout = TimeSpan.FromSeconds(10),
3125
ServerInstructions = "Test Instructions"
@@ -49,8 +43,6 @@ public void Constructor_Throws_For_Null_Options()
4943

5044
Assert.Throws<ArgumentNullException>("serverOptions", () => new StdioServerTransport((IOptions<McpServerOptions>)null!));
5145
Assert.Throws<ArgumentNullException>("serverOptions", () => new StdioServerTransport((McpServerOptions)null!));
52-
Assert.Throws<ArgumentNullException>("serverOptions.ServerInfo", () => new StdioServerTransport(new McpServerOptions() { ServerInfo = null! }));
53-
Assert.Throws<ArgumentNullException>("serverOptions.ServerInfo.Name", () => new StdioServerTransport(new McpServerOptions() { ServerInfo = new() { Name = null!, Version = "" } }));
5446
}
5547

5648
[Fact]

0 commit comments

Comments
 (0)
Please sign in to comment.