Skip to content

Commit e1474b4

Browse files
halter73Copilot
andcommitted
Add integration tests and fix test forward-compatibility
Add McpClient + Stateful Streamable HTTP integration tests for MRTR, and a test verifying experimental protocol version negotiation. Fix the sampling log assertion in MapMcpTests to handle MRTR mode where sampling is embedded in the IncompleteResult exchange. Demote MrtrHandlerError from Error to Debug to avoid double-logging since the observer just confirms the exception was observed. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 898684d commit e1474b4

File tree

4 files changed

+409
-3
lines changed

4 files changed

+409
-3
lines changed

src/ModelContextProtocol.Core/Server/McpServerImpl.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1732,7 +1732,7 @@ private async Task TrackDeferredHandlerTaskAsync(
17321732
[LoggerMessage(Level = LogLevel.Debug, Message = "Cancelled {Count} pending MRTR continuation(s) during session disposal.")]
17331733
private partial void MrtrContinuationsCancelled(int count);
17341734

1735-
[LoggerMessage(Level = LogLevel.Error, Message = "An MRTR handler threw an unhandled exception.")]
1735+
[LoggerMessage(Level = LogLevel.Debug, Message = "An MRTR handler threw an unhandled exception.")]
17361736
private partial void MrtrHandlerError(Exception exception);
17371737

17381738
/// <summary>

tests/ModelContextProtocol.AspNetCore.Tests/MapMcpTests.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,9 +197,17 @@ public async Task Sampling_DoesNotCloseStreamPrematurely()
197197
m.Category == "ModelContextProtocol.Client.McpClient" &&
198198
m.Message.Contains("request '2' for method 'tools/call'"));
199199

200-
Assert.Single(MockLoggerProvider.LogMessages, m =>
200+
// In MRTR mode, sampling is embedded in the IncompleteResult exchange within tools/call,
201+
// so there's no separate sampling/createMessage JSON-RPC request logged by the server.
202+
bool hasSeparateSamplingRequest = MockLoggerProvider.LogMessages.Any(m =>
201203
m.Category == "ModelContextProtocol.Server.McpServer" &&
202-
m.Message.Contains("request '2' for method 'sampling/createMessage'"));
204+
m.Message.Contains("for method 'sampling/createMessage'"));
205+
if (hasSeparateSamplingRequest)
206+
{
207+
Assert.Single(MockLoggerProvider.LogMessages, m =>
208+
m.Category == "ModelContextProtocol.Server.McpServer" &&
209+
m.Message.Contains("request '2' for method 'sampling/createMessage'"));
210+
}
203211
}
204212

205213
[Fact]

0 commit comments

Comments
 (0)