Skip to content

Commit 898684d

Browse files
halter73Copilot
andcommitted
Reorganize MRTR tests by what they actually test
Move server-behavior tests from Client/ to Server/ and drop the misleading McpClient prefix. Most MRTR tests verify server-side behavior (handler lifecycle, backcompat resolution, low-level API) but were in Client/ because they use ClientServerTestBase. Split McpClientMrtrTests (17 tests) into: - Client/MrtrIntegrationTests: E2E round-trips and client retry (10) - Server/MrtrHandlerLifecycleTests: cancellation, disposal, logging (7) Rename and move to Server/: - McpClientMrtrCompatTests → MrtrBackcompatTests - McpClientMrtrLowLevelTests → MrtrLowLevelApiTests - McpClientMrtrMessageFilterTests → MrtrMessageFilterTests - McpClientMrtrSessionLimitTests → MrtrSessionLimitTests - McpClientMrtrWithTasksTests → MrtrTaskIntegrationTests Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent d1bd8ad commit 898684d

File tree

10 files changed

+474
-391
lines changed

10 files changed

+474
-391
lines changed

src/ModelContextProtocol.Core/Server/McpServerImpl.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1249,9 +1249,9 @@ private void WrapHandlerWithMrtr(string method)
12491249
inputResponses = JsonSerializer.Deserialize(responsesNode, McpJsonUtilities.JsonContext.Default.IDictionaryStringInputResponse);
12501250
}
12511251

1252-
var nextExchangeTask = existingContinuation.MrtrContext.ResetForNextExchange(existingContinuation.PendingExchange!);
1253-
12541252
var exchange = existingContinuation.PendingExchange!;
1253+
var nextExchangeTask = existingContinuation.MrtrContext.ResetForNextExchange(exchange);
1254+
12551255
if (inputResponses is not null &&
12561256
inputResponses.TryGetValue(exchange.Key, out var response))
12571257
{

tests/ModelContextProtocol.AspNetCore.Tests/MrtrProtocolTests.cs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -858,8 +858,19 @@ public async Task SessionDelete_CancelsPendingMrtrContinuation()
858858
using var deleteResponse = await HttpClient.DeleteAsync("", TestContext.Current.CancellationToken);
859859
Assert.Equal(HttpStatusCode.OK, deleteResponse.StatusCode);
860860

861-
// Allow a moment for the async cancellation to propagate through the handler task.
862-
await Task.Delay(100, TestContext.Current.CancellationToken);
861+
// Poll for the async cancellation to propagate through the handler task.
862+
// Under thread pool starvation, this can take significantly longer than 100ms.
863+
var deadline = DateTime.UtcNow.AddSeconds(30);
864+
while (true)
865+
{
866+
if (MockLoggerProvider.LogMessages.Any(m => m.Message.Contains("pending MRTR continuation"))
867+
|| DateTime.UtcNow >= deadline)
868+
{
869+
break;
870+
}
871+
872+
await Task.Delay(100, TestContext.Current.CancellationToken);
873+
}
863874

864875
// 3. Verify that the MRTR cancellation was logged at Debug level.
865876
var mrtrCancelledLog = MockLoggerProvider.LogMessages

tests/ModelContextProtocol.Tests/Client/McpClientDeferredTaskCreationTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ public async Task DeferredTaskCreation_ElicitThenCreateTask_ReturnsTaskResult()
205205
Assert.NotEmpty(result.Task.TaskId);
206206

207207
// Wait for the tool to finish in the background.
208-
await _toolAfterTaskCreation.Task.WaitAsync(TimeSpan.FromSeconds(10), TestContext.Current.CancellationToken);
208+
await _toolAfterTaskCreation.Task.WaitAsync(TimeSpan.FromSeconds(30), TestContext.Current.CancellationToken);
209209
var taskStatus = await WaitForTaskCompletionAsync(result.Task.TaskId);
210210
Assert.Equal(McpTaskStatus.Completed, taskStatus.Status);
211211
}

tests/ModelContextProtocol.Tests/Client/McpClientMrtrTests.cs renamed to tests/ModelContextProtocol.Tests/Client/MrtrIntegrationTests.cs

Lines changed: 5 additions & 358 deletions
Large diffs are not rendered by default.

tests/ModelContextProtocol.Tests/Client/McpClientMrtrCompatTests.cs renamed to tests/ModelContextProtocol.Tests/Server/MrtrBackcompatTests.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,17 @@
66
using ModelContextProtocol.Tests.Utils;
77
using System.Text.Json;
88

9-
namespace ModelContextProtocol.Tests.Client;
9+
namespace ModelContextProtocol.Tests.Server;
1010

1111
/// <summary>
12-
/// Tests for MRTR compatibility across different experimental/non-experimental combinations.
13-
/// This test class configures the server WITHOUT ExperimentalProtocolVersion to test scenarios
14-
/// where the server is not opted-in to the experimental protocol.
12+
/// Tests for the server's backward-compatible resolution of MRTR-native tools.
13+
/// Verifies that when a tool throws IncompleteResultException and the client doesn't support MRTR,
14+
/// the server resolves input requests via standard JSON-RPC calls (elicitation, sampling, roots)
15+
/// and retries the handler.
1516
/// </summary>
16-
public class McpClientMrtrCompatTests : ClientServerTestBase
17+
public class MrtrBackcompatTests : ClientServerTestBase
1718
{
18-
public McpClientMrtrCompatTests(ITestOutputHelper testOutputHelper)
19+
public MrtrBackcompatTests(ITestOutputHelper testOutputHelper)
1920
: base(testOutputHelper, startServer: false)
2021
{
2122
}

tests/ModelContextProtocol.Tests/Server/MrtrHandlerLifecycleTests.cs

Lines changed: 424 additions & 0 deletions
Large diffs are not rendered by default.

tests/ModelContextProtocol.Tests/Client/McpClientMrtrLowLevelTests.cs renamed to tests/ModelContextProtocol.Tests/Server/MrtrLowLevelApiTests.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55
using ModelContextProtocol.Server;
66
using System.Text.Json;
77

8-
namespace ModelContextProtocol.Tests.Client;
8+
namespace ModelContextProtocol.Tests.Server;
99

1010
/// <summary>
11-
/// Integration tests for the low-level MRTR API where tool handlers directly throw
12-
/// <see cref="IncompleteResultException"/> and manage request state themselves.
11+
/// Tests for the low-level MRTR server API — IsMrtrSupported, IncompleteResultException,
12+
/// and client auto-retry of incomplete results.
1313
/// </summary>
14-
public class McpClientMrtrLowLevelTests : ClientServerTestBase
14+
public class MrtrLowLevelApiTests : ClientServerTestBase
1515
{
16-
public McpClientMrtrLowLevelTests(ITestOutputHelper testOutputHelper)
16+
public MrtrLowLevelApiTests(ITestOutputHelper testOutputHelper)
1717
: base(testOutputHelper, startServer: false)
1818
{
1919
}

tests/ModelContextProtocol.Tests/Client/McpClientMrtrMessageFilterTests.cs renamed to tests/ModelContextProtocol.Tests/Server/MrtrMessageFilterTests.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,18 @@
77
using System.Collections.Concurrent;
88
using System.Text.Json;
99

10-
namespace ModelContextProtocol.Tests.Client;
10+
namespace ModelContextProtocol.Tests.Server;
1111

1212
/// <summary>
13-
/// Tests that verify transport middleware sees raw MRTR JSON-RPC messages and
14-
/// that old-style sampling/elicitation JSON-RPC requests are NOT sent when MRTR is active.
13+
/// Tests that message filters correctly observe MRTR protocol behavior — verifying that
14+
/// IncompleteResult responses are visible to outgoing filters, and that no legacy
15+
/// elicitation/sampling requests are sent when MRTR is active.
1516
/// </summary>
16-
public class McpClientMrtrMessageFilterTests : ClientServerTestBase
17+
public class MrtrMessageFilterTests : ClientServerTestBase
1718
{
1819
private readonly ConcurrentBag<string> _outgoingRequestMethods = [];
1920

20-
public McpClientMrtrMessageFilterTests(ITestOutputHelper testOutputHelper)
21+
public MrtrMessageFilterTests(ITestOutputHelper testOutputHelper)
2122
: base(testOutputHelper, startServer: false)
2223
{
2324
}

tests/ModelContextProtocol.Tests/Client/McpClientMrtrSessionLimitTests.cs renamed to tests/ModelContextProtocol.Tests/Server/MrtrSessionLimitTests.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,13 @@
77
using System.Collections.Concurrent;
88
using System.Text.Json.Nodes;
99

10-
namespace ModelContextProtocol.Tests.Client;
10+
namespace ModelContextProtocol.Tests.Server;
1111

1212
/// <summary>
13-
/// Tests proving that outgoing message filters can track and limit per-session MRTR flows.
14-
/// This demonstrates that protocol-level sessions enable session-scoped resource governance
15-
/// that would not be possible without the Mcp-Session-Id routing mechanism.
13+
/// Tests for session-scoped MRTR resource governance — verifying that outgoing message
14+
/// filters can track and limit MRTR round trips per session.
1615
/// </summary>
17-
public class McpClientMrtrSessionLimitTests : ClientServerTestBase
16+
public class MrtrSessionLimitTests : ClientServerTestBase
1817
{
1918
/// <summary>
2019
/// Tracks the number of pending MRTR flows per session. Incremented when an IncompleteResult
@@ -39,7 +38,7 @@ public class McpClientMrtrSessionLimitTests : ClientServerTestBase
3938
/// </summary>
4039
private int _blockedFlowCount;
4140

42-
public McpClientMrtrSessionLimitTests(ITestOutputHelper testOutputHelper)
41+
public MrtrSessionLimitTests(ITestOutputHelper testOutputHelper)
4342
: base(testOutputHelper, startServer: false)
4443
{
4544
}

tests/ModelContextProtocol.Tests/Client/McpClientMrtrWithTasksTests.cs renamed to tests/ModelContextProtocol.Tests/Server/MrtrTaskIntegrationTests.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@
55
using ModelContextProtocol.Server;
66
using ModelContextProtocol.Tests.Utils;
77

8-
namespace ModelContextProtocol.Tests.Client;
8+
namespace ModelContextProtocol.Tests.Server;
99

1010
/// <summary>
11-
/// Tests for MRTR (Multi Round-Trip Requests) interacting with the Task system.
12-
/// Verifies that task status tracking works correctly during MRTR-resolved sampling/elicitation,
13-
/// and that task-based methods (SampleAsTaskAsync/ElicitAsTaskAsync) bypass MRTR interception.
11+
/// Tests for the interaction between MRTR and the Tasks feature — verifying that MRTR-driven
12+
/// tool calls correctly track task status (InputRequired), and that task-based sampling
13+
/// bypasses MRTR interception.
1414
/// </summary>
15-
public class McpClientMrtrWithTasksTests : ClientServerTestBase
15+
public class MrtrTaskIntegrationTests : ClientServerTestBase
1616
{
17-
public McpClientMrtrWithTasksTests(ITestOutputHelper testOutputHelper)
17+
public MrtrTaskIntegrationTests(ITestOutputHelper testOutputHelper)
1818
: base(testOutputHelper, startServer: false)
1919
{
2020
}

0 commit comments

Comments
 (0)