Skip to content

Commit 885cc12

Browse files
halter73Copilot
andcommitted
Remove stateless check from ClientSupportsMrtr
ClientSupportsMrtr now purely reflects whether the client negotiated the MRTR protocol version, independent of server transport mode. The stateless guard is moved to the call site that gates the high-level await path (which requires storing continuations). This makes IsMrtrSupported return true in stateless mode when the protocol matches, which is correct for the low-level IncompleteResultException API. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 80417c0 commit 885cc12

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

src/ModelContextProtocol.Core/Server/McpServerImpl.cs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1143,11 +1143,9 @@ internal static LoggingLevel ToLoggingLevel(LogLevel level) =>
11431143
private partial void ReadResourceCompleted(string resourceUri);
11441144

11451145
/// <summary>
1146-
/// Checks whether the negotiated protocol version enables MRTR and the server
1147-
/// operates in a mode where MRTR continuations can be stored (i.e., not stateless).
1146+
/// Checks whether the negotiated protocol version enables MRTR.
11481147
/// </summary>
11491148
internal bool ClientSupportsMrtr() =>
1150-
_sessionTransport is not StreamableHttpServerTransport { Stateless: true } &&
11511149
_negotiatedProtocolVersion is not null &&
11521150
_negotiatedProtocolVersion == ServerOptions.ExperimentalProtocolVersion;
11531151

@@ -1217,8 +1215,9 @@ private void WrapHandlerWithMrtr(string method)
12171215
// high-level handlers that call ElicitAsync/SampleAsync.
12181216
}
12191217

1220-
// Not a retry, or a retry without a continuation - check if the client supports MRTR.
1221-
if (!ClientSupportsMrtr())
1218+
// Not a retry, or a retry without a continuation - check if the client supports MRTR
1219+
// and the server is stateful (the high-level await path requires storing continuations).
1220+
if (!ClientSupportsMrtr() || _sessionTransport is StreamableHttpServerTransport { Stateless: true })
12221221
{
12231222
return await InvokeWithIncompleteResultHandlingAsync(originalHandler, request, cancellationToken).ConfigureAwait(false);
12241223
}
@@ -1262,10 +1261,10 @@ private void WrapHandlerWithMrtr(string method)
12621261
}
12631262
catch (IncompleteResultException ex)
12641263
{
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())
1264+
// Allow the IncompleteResult if the client supports MRTR or the server is stateless
1265+
// (in stateless mode, the tool handler has explicitly chosen to return an IncompleteResult
1266+
// via the low-level API, so we trust that decision regardless of negotiated version).
1267+
if (!ClientSupportsMrtr() && _sessionTransport is not StreamableHttpServerTransport { Stateless: true })
12691268
{
12701269
throw new McpException(
12711270
"A tool handler returned an incomplete result, but the client does not support Multi Round-Trip Requests (MRTR). " +

0 commit comments

Comments
 (0)