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
> The source and lifetime of the `CancellationToken` provided to server handlers depends on the transport and session mode. In [stateless mode](xref:stateless#stateless-mode-recommended), the token is tied to the HTTP request — if the client disconnects, the handler is cancelled. In [stateful mode](xref:stateless#stateful-mode-sessions), the token is tied to the session lifetime. See [Cancellation and disposal](xref:stateless#cancellation-and-disposal) for details.
17
+
15
18
### How cancellation maps to MCP notifications
16
19
17
20
When a `CancellationToken` passed to a client method (such as <xref:ModelContextProtocol.Client.McpClient.CallToolAsync*>) is cancelled, a `notifications/cancelled` notification is sent to the server with the request ID. On the server side, the `CancellationToken` provided to the tool method is then triggered, allowing the handler to stop work gracefully. This same mechanism works in reverse for server-to-client requests.
Copy file name to clipboardExpand all lines: docs/concepts/elicitation/elicitation.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -172,7 +172,7 @@ Here's an example implementation of how a console application might handle elici
172
172
173
173
### URL Elicitation Required Error
174
174
175
-
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.
175
+
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 [stateless](xref:stateless) mode where server-to-client requests are disabled), 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.
176
176
177
177
#### Throwing UrlElicitationRequiredException on the Server
When using the legacy SSE transport, be aware that the `HttpContext` returned by `IHttpContextAccessor` references the long-lived SSE connection request — not the individual `POST` request that triggered the tool call. This means:
36
+
37
+
- The `HttpContext.User` may contain stale claims if the client's token was refreshed after the SSE connection was established.
38
+
- Request headers, query strings, and other per-request metadata will reflect the initial SSE connection, not the current operation.
39
+
40
+
The Streamable HTTP transport does not have this issue because each tool call is its own HTTP request, so `IHttpContextAccessor.HttpContext` always reflects the current request. In [stateless](xref:stateless) mode, this is guaranteed since every request creates a fresh server context.
41
+
42
+
<!-- mlc-disable-next-line -->
43
+
> [!NOTE]
44
+
> The server validates that the user identity has not changed between the session-initiating request and subsequent requests (using the `sub`, `NameIdentifier`, or `UPN` claim). If the user identity changes, the request is rejected with `403 Forbidden`. However, other claims (roles, permissions, custom claims) are not re-validated and may become stale over the lifetime of a session.
Copy file name to clipboardExpand all lines: docs/concepts/index.md
+1Lines changed: 1 addition & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -36,5 +36,6 @@ Install the SDK and build your first MCP client and server.
36
36
|[Prompts](prompts/prompts.md)| Learn how to implement and consume reusable prompt templates with rich content types. |
37
37
|[Completions](completions/completions.md)| Learn how to implement argument auto-completion for prompts and resource templates. |
38
38
|[Logging](logging/logging.md)| Learn how to implement logging in MCP servers and how clients can consume log messages. |
39
+
|[Stateless and Stateful](stateless/stateless.md)| Learn when to use stateless vs. stateful mode for HTTP servers and how to configure sessions. |
39
40
|[HTTP Context](httpcontext/httpcontext.md)| Learn how to access the underlying `HttpContext` for a request. |
40
41
|[MCP Server Handler Filters](filters.md)| Learn how to add filters to the handler pipeline. Filters let you wrap the original handler with additional functionality. |
Servers built with the C# SDK always declare the logging capability. Doing so does not obligate the server
49
-
to send log messages—only allows it. Note that stateless MCP servers might not be capable of sending log
49
+
to send log messages—only allows it. Note that [stateless](xref:stateless) MCP servers might not be capable of sending log
50
50
messages as there might not be an open connection to the client on which the log messages could be sent.
51
51
52
52
The C# SDK provides an extension method <xref:Microsoft.Extensions.DependencyInjection.McpServerBuilderExtensions.WithSetLoggingLevelHandler*> on <xref:Microsoft.Extensions.DependencyInjection.IMcpServerBuilder> to allow the
0 commit comments