You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When both the client and server opt in to the experimental [MRTR](xref:mrtr) protocol, elicitation requests are handled via incomplete result / retry instead of a direct JSON-RPC request. This is transparent — the existing `ElicitAsync` API works identically regardless of whether MRTR is active.
176
+
177
+
#### High-level API
178
+
179
+
No code changes are needed. `ElicitAsync` automatically uses MRTR when both sides have opted in, and falls back to legacy JSON-RPC requests otherwise:
180
+
181
+
```csharp
182
+
// This code works the same with or without MRTR — the SDK handles it transparently.
For stateless servers or scenarios requiring manual control, throw <xref:ModelContextProtocol.Protocol.IncompleteResultException> with an elicitation input request. On retry, read the client's response from <xref:ModelContextProtocol.Protocol.RequestParams.InputResponses>:
202
+
203
+
```csharp
204
+
[McpServerTool, Description("Tool that elicits via low-level MRTR")]
205
+
publicstaticstringElicitWithMrtr(
206
+
McpServerserver,
207
+
RequestContext<CallToolRequestParams>context)
208
+
{
209
+
// On retry, process the client's elicitation response
210
+
if (context.Params!.InputResponses?.TryGetValue("user_input", outvarresponse) istrue)
> See [Multi Round-Trip Requests (MRTR)](xref:mrtr) for the full protocol details, including multiple round trips, concurrent input requests, and the compatibility matrix.
248
+
173
249
### URL Elicitation Required Error
174
250
175
251
When a tool cannot proceed without first completing a URL-mode elicitation (for example, when third-party OAuth authorization is needed), and calling `ElicitAsync` is not practical (for example in <xref: ModelContextProtocol.AspNetCore.HttpServerTransportOptions.Stateless> is enabled disabling server-to-client requests), the server may throw a <xref:ModelContextProtocol.UrlElicitationRequiredException>. This is a specialized error (JSON-RPC error code `-32042`) that signals to the client that one or more URL-mode elicitations must be completed before the original request can be retried.
Copy file name to clipboardExpand all lines: docs/concepts/index.md
+2Lines changed: 2 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -18,6 +18,8 @@ Install the SDK and build your first MCP client and server.
18
18
|[Progress tracking](progress/progress.md)| Learn how to track progress for long-running operations through notification messages. |
19
19
|[Cancellation](cancellation/cancellation.md)| Learn how to cancel in-flight MCP requests using cancellation tokens and notifications. |
20
20
|[Pagination](pagination/pagination.md)| Learn how to use cursor-based pagination when listing tools, prompts, and resources. |
21
+
|[Tasks](tasks/tasks.md)| Learn how to create and manage long-running tool call tasks. |
22
+
|[Multi Round-Trip Requests (MRTR)](mrtr/mrtr.md)| Learn how servers request client input during tool execution using incomplete results and retries. |
When both the client and server opt in to the experimental [MRTR](xref:mrtr) protocol, root list requests are handled via incomplete result / retry instead of a direct JSON-RPC request. This is transparent — the existing `RequestRootsAsync` API works identically regardless of whether MRTR is active.
110
+
111
+
#### High-level API
112
+
113
+
No code changes are needed. `RequestRootsAsync` automatically uses MRTR when both sides have opted in:
114
+
115
+
```csharp
116
+
// This code works the same with or without MRTR — the SDK handles it transparently.
For stateless servers or scenarios requiring manual control, throw <xref:ModelContextProtocol.Protocol.IncompleteResultException> with a roots input request. On retry, read the client's response from <xref:ModelContextProtocol.Protocol.RequestParams.InputResponses>:
127
+
128
+
```csharp
129
+
[McpServerTool, Description("Tool that requests roots via low-level MRTR")]
130
+
publicstaticstringListRootsWithMrtr(
131
+
McpServerserver,
132
+
RequestContext<CallToolRequestParams>context)
133
+
{
134
+
// On retry, process the client's roots response
135
+
if (context.Params!.InputResponses?.TryGetValue("get_roots", outvarresponse) istrue)
> See [Multi Round-Trip Requests (MRTR)](xref:mrtr) for the full protocol details, including load shedding, multiple round trips, and the compatibility matrix.
Sampling requires the client to advertise the `sampling` capability. This is handled automatically — when a <xref:ModelContextProtocol.Client.McpClientHandlers.SamplingHandler> is set, the client includes the sampling capability during initialization. The server can check whether the client supports sampling before calling <xref:ModelContextProtocol.Server.McpServer.SampleAsync*>; if sampling is not supported, the method throws <xref:System.InvalidOperationException>.
120
+
121
+
### Multi Round-Trip Requests (MRTR)
122
+
123
+
When both the client and server opt in to the experimental [MRTR](xref:mrtr) protocol, sampling requests are handled via incomplete result / retry instead of a direct JSON-RPC request. This is transparent — the existing `SampleAsync` and `AsSamplingChatClient` APIs work identically regardless of whether MRTR is active.
124
+
125
+
#### High-level API
126
+
127
+
No code changes are needed. `SampleAsync` and `AsSamplingChatClient` automatically use MRTR when both sides have opted in, and fall back to legacy JSON-RPC requests otherwise:
128
+
129
+
```csharp
130
+
// This code works the same with or without MRTR — the SDK handles it transparently.
131
+
varresult=awaitserver.SampleAsync(
132
+
newCreateMessageRequestParams
133
+
{
134
+
Messages=
135
+
[
136
+
newSamplingMessage
137
+
{
138
+
Role=Role.User,
139
+
Content= [newTextContentBlock { Text="Summarize the data" }]
140
+
}
141
+
],
142
+
MaxTokens=256,
143
+
},
144
+
cancellationToken);
145
+
```
146
+
147
+
#### Low-level API
148
+
149
+
For stateless servers or scenarios requiring manual control, throw <xref:ModelContextProtocol.Protocol.IncompleteResultException> with a sampling input request. On retry, read the client's response from <xref:ModelContextProtocol.Protocol.RequestParams.InputResponses>:
150
+
151
+
```csharp
152
+
[McpServerTool, Description("Tool that samples via low-level MRTR")]
153
+
publicstaticstringSampleWithMrtr(
154
+
McpServerserver,
155
+
RequestContext<CallToolRequestParams>context)
156
+
{
157
+
// On retry, process the client's sampling response
158
+
if (context.Params!.InputResponses?.TryGetValue("llm_call", outvarresponse) istrue)
Content= [newTextContentBlock { Text="Summarize the data" }]
182
+
}
183
+
],
184
+
MaxTokens=256
185
+
})
186
+
},
187
+
requestState: "awaiting-sample");
188
+
}
189
+
```
190
+
191
+
> [!TIP]
192
+
> See [Multi Round-Trip Requests (MRTR)](xref:mrtr) for the full protocol details, including load shedding, multiple round trips, and the compatibility matrix.
0 commit comments