Skip to content

Commit 1162a06

Browse files
authored
Merge branch 'main' into fix/utf8-stdio-encoding
2 parents 12eca75 + a97a74f commit 1162a06

File tree

3 files changed

+43
-4
lines changed

3 files changed

+43
-4
lines changed

src/ModelContextProtocol/Server/McpToolAttribute.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public sealed class McpToolAttribute : Attribute
1212
/// <summary>
1313
/// Attribute to mark a method as an MCP tool.
1414
/// </summary>
15-
/// <param name="name">The name of the tool. If not provided, the class name will be used.</param>
15+
/// <param name="name">The name of the tool. If not provided, the method name will be used.</param>
1616
public McpToolAttribute(string? name = null)
1717
{
1818
Name = name;

tests/ModelContextProtocol.Tests/Server/McpServerTests.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,12 @@ public async Task StartAsync_Should_Throw_InvalidOperationException_If_Already_I
8989
{
9090
// Arrange
9191
await using var server = McpServerFactory.Create(_serverTransport.Object, _options, _loggerFactory.Object, _serviceProvider);
92-
server.GetType().GetField("_isInitializing", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance)?.SetValue(server, true);
92+
var task = server.StartAsync(TestContext.Current.CancellationToken);
9393

9494
// Act & Assert
9595
await Assert.ThrowsAsync<InvalidOperationException>(() => server.StartAsync(TestContext.Current.CancellationToken));
96+
97+
await task;
9698
}
9799

98100
[Fact]

tests/ModelContextProtocol.Tests/Transport/SseClientTransportTests.cs

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,49 @@ public async Task ConnectAsync_Should_Connect_Successfully()
107107
[Fact]
108108
public async Task ConnectAsync_Throws_If_Already_Connected()
109109
{
110-
await using var transport = new SseClientTransport(_transportOptions, _serverConfig, NullLoggerFactory.Instance);
111-
transport.GetType().BaseType!.GetField("_isConnected", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance)?.SetValue(transport, true);
110+
using var mockHttpHandler = new MockHttpHandler();
111+
using var httpClient = new HttpClient(mockHttpHandler);
112+
await using var transport = new SseClientTransport(_transportOptions, _serverConfig, httpClient, NullLoggerFactory.Instance);
113+
var tcsConnected = new TaskCompletionSource();
114+
var tcsDone = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously);
115+
var callIndex = 0;
116+
117+
mockHttpHandler.RequestHandler = async (request) =>
118+
{
119+
switch (callIndex++)
120+
{
121+
case 0:
122+
return new HttpResponseMessage
123+
{
124+
StatusCode = HttpStatusCode.OK,
125+
Content = new StringContent("event: endpoint\r\ndata: http://localhost\r\n\r\n")
126+
};
127+
case 1:
128+
tcsConnected.SetResult();
129+
await tcsDone.Task;
130+
return new HttpResponseMessage
131+
{
132+
StatusCode = HttpStatusCode.OK,
133+
Content = new StringContent("")
134+
};
135+
default:
136+
return new HttpResponseMessage
137+
{
138+
StatusCode = HttpStatusCode.OK,
139+
Content = new StringContent("")
140+
};
141+
}
142+
};
112143

144+
var task = transport.ConnectAsync(TestContext.Current.CancellationToken);
145+
await tcsConnected.Task;
146+
Assert.True(transport.IsConnected);
113147
var action = async () => await transport.ConnectAsync();
114148
var exception = await Assert.ThrowsAsync<McpTransportException>(action);
115149
Assert.Equal("Transport is already connected", exception.Message);
150+
tcsDone.SetResult();
151+
await transport.CloseAsync();
152+
await task;
116153
}
117154

118155
[Fact]

0 commit comments

Comments
 (0)