Skip to content

Commit 7ad4702

Browse files
halter73Copilot
andcommitted
Fix stateless IncompleteResultException and add stateless MRTR tests
Allow IncompleteResultException to serialize as IncompleteResult in stateless mode where ClientSupportsMrtr() returns false. The low-level API is designed for stateless servers that cannot determine client MRTR support. Add 5 end-to-end tests using Streamable HTTP in stateless mode: - Elicitation, sampling, and roots individually - All three concurrent (with TCS concurrency proof barriers) - Multi-round-trip with requestState across 2 retries Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 9d20c02 commit 7ad4702

File tree

2 files changed

+444
-3
lines changed

2 files changed

+444
-3
lines changed

src/ModelContextProtocol.Core/Server/McpServerImpl.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1247,8 +1247,9 @@ private void WrapHandlerWithMrtr(string method)
12471247

12481248
/// <summary>
12491249
/// Invokes a handler and catches <see cref="IncompleteResultException"/> to convert it to an
1250-
/// <see cref="IncompleteResult"/> JSON response. If MRTR is not supported and the handler throws
1251-
/// <see cref="IncompleteResultException"/>, the exception is wrapped with a descriptive message.
1250+
/// <see cref="IncompleteResult"/> JSON response. In stateless mode, the exception is always
1251+
/// serialized because the server cannot determine client MRTR support. In stateful mode,
1252+
/// if MRTR is not supported, the exception is wrapped with a descriptive message.
12521253
/// </summary>
12531254
private async Task<JsonNode?> InvokeWithIncompleteResultHandlingAsync(
12541255
Func<JsonRpcRequest, CancellationToken, Task<JsonNode?>> handler,
@@ -1261,7 +1262,10 @@ private void WrapHandlerWithMrtr(string method)
12611262
}
12621263
catch (IncompleteResultException ex)
12631264
{
1264-
if (!ClientSupportsMrtr())
1265+
// In stateless mode, the server has no persistent session or negotiated protocol
1266+
// version, so it cannot determine client MRTR support. The tool handler has
1267+
// explicitly chosen to return an IncompleteResult, so we trust that decision.
1268+
if (_sessionTransport is not StreamableHttpServerTransport { Stateless: true } && !ClientSupportsMrtr())
12651269
{
12661270
throw new McpException(
12671271
"A tool handler returned an incomplete result, but the client does not support Multi Round-Trip Requests (MRTR). " +

0 commit comments

Comments
 (0)