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
- Minimize cancellation doc to focus on MCP protocol behavior, not
CancellationToken patterns
- Simplify ping doc to a single API call example
- Soften capabilities overview to not prescribe initialize handshake steps
- Remove enum row from JSON Schema type mapping table
- Replace file path examples with ID-based lookups to avoid path traversal
- Use BlobResourceContents.FromBytes() factory consistently
- Switch inline markdown links to reference-style
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copy file name to clipboardExpand all lines: docs/concepts/cancellation/cancellation.md
+7-38Lines changed: 7 additions & 38 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,46 +7,18 @@ uid: cancellation
7
7
8
8
## Cancellation
9
9
10
-
MCP supports [cancellation] of in-flight requests. Either side can cancel a previously issued request by using .NET's [task cancellation] with a `CancellationToken` to send a cancellation notification.
10
+
MCP supports [cancellation] of in-flight requests. Either side can cancel a previously issued request, and `CancellationToken` parameters on MCP methods are wired to send and receive `notifications/cancelled` notifications over the protocol.
When a client cancels a pending request, a `notifications/cancelled` notification is sent to the server. The server's `CancellationToken` for that request is then triggered, allowing the server-side handler to stop work gracefully. This same mechanism works in reverse for server-to-client requests.
18
-
19
-
### Client-side cancellation
20
-
21
-
All client methods accept a `CancellationToken` parameter. Cancel a pending request by canceling the token:
When the `CancellationToken` is cancelled, a `notifications/cancelled` notification is automatically sent to the server with the request ID, allowing the server to stop processing.
17
+
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.
46
18
47
19
### Server-side cancellation handling
48
20
49
-
Server tool methods should accept a `CancellationToken`parameter and check it during long-running operations:
21
+
Server tool methods receive a `CancellationToken`that is triggered when the client sends a cancellation notification. Pass this token through to any async operations so they stop promptly:
@@ -56,17 +28,14 @@ public static async Task<string> LongComputation(
56
28
{
57
29
for (inti=0; i<iterations; i++)
58
30
{
59
-
// Check for cancellation on each iteration
60
-
cancellationToken.ThrowIfCancellationRequested();
61
-
62
31
awaitTask.Delay(1000, cancellationToken);
63
32
}
64
33
65
34
return$"Completed {iterations} iterations.";
66
35
}
67
36
```
68
37
69
-
When the client sends a cancellation notification, the `CancellationToken` provided to the tool method is automatically triggered. The `OperationCanceledException` propagates back to the client as a cancellation response.
38
+
When the client sends a cancellation notification, the `OperationCanceledException` propagates back to the client as a cancellation response.
70
39
71
40
### Cancellation notification details
72
41
@@ -75,9 +44,9 @@ The cancellation notification includes:
75
44
-**RequestId**: The ID of the request to cancel, allowing the receiver to correlate the cancellation with the correct in-flight request.
76
45
-**Reason**: An optional human-readable reason for the cancellation.
77
46
47
+
Cancellation notifications can be observed by registering a handler:
48
+
78
49
```csharp
79
-
// This is sent automatically when a CancellationToken is cancelled,
80
-
// but you can also observe cancellation notifications:
Copy file name to clipboardExpand all lines: docs/concepts/capabilities/capabilities.md
+2-10Lines changed: 2 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -13,13 +13,7 @@ MCP uses a [capability negotiation] mechanism during connection initialization.
13
13
14
14
### Overview
15
15
16
-
When a client connects to a server, the initialization handshake includes:
17
-
18
-
1. The **client** sends an `initialize` request with its <xref:ModelContextProtocol.Protocol.ClientCapabilities> and protocol version.
19
-
2. The **server** responds with its <xref:ModelContextProtocol.Protocol.ServerCapabilities> and the negotiated protocol version.
20
-
3. The client sends an `initialized` notification to confirm the session is ready.
21
-
22
-
Both sides should check the other's capabilities before using optional features.
16
+
During connection setup, clients and servers exchange their supported capabilities so each side can adapt its behavior accordingly. After initialization, both sides should check the other's capabilities before using optional features.
23
17
24
18
### Client capabilities
25
19
@@ -119,9 +113,7 @@ if (client.ServerCapabilities.Completions is not null)
119
113
120
114
### Protocol version negotiation
121
115
122
-
The client specifies the MCP protocol version it supports in the `initialize` request. The server responds with the negotiated protocol version, which may differ from the client's requested version if the server supports an earlier version.
123
-
124
-
After initialization, the negotiated version is available on both sides:
116
+
During connection setup, the client and server negotiate a mutually supported MCP protocol version. After initialization, the negotiated version is available on both sides:
The ping operation is a simple request/response exchange. Either the client or the server can initiate a ping, and the other side responds automatically. Ping responses are handled automatically—callers only need to invoke the method to send a ping.
17
-
18
14
### Pinging from the client
19
15
20
16
Use the <xref:ModelContextProtocol.Client.McpClient.PingAsync*> method to verify the server is responsive:
Copy file name to clipboardExpand all lines: docs/concepts/prompts/prompts.md
+4-4Lines changed: 4 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -94,11 +94,11 @@ public static IEnumerable<ChatMessage> AnalyzeImage(
94
94
For protocol-specific content types like <xref:ModelContextProtocol.Protocol.EmbeddedResourceBlock>, use <xref:ModelContextProtocol.Protocol.PromptMessage> instead of `ChatMessage`. `PromptMessage` has a `Role` property and a single `Content` property of type <xref:ModelContextProtocol.Protocol.ContentBlock>:
95
95
96
96
```csharp
97
-
[McpServerPrompt, Description("A prompt that includes a file resource")]
97
+
[McpServerPrompt, Description("A prompt that includes a document resource")]
Copy file name to clipboardExpand all lines: docs/concepts/tools/tools.md
+8-9Lines changed: 8 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -84,16 +84,16 @@ Return an <xref:ModelContextProtocol.Protocol.EmbeddedResourceBlock> to embed a
84
84
The resource can contain either text or binary data through <xref:ModelContextProtocol.Protocol.TextResourceContents> or <xref:ModelContextProtocol.Protocol.BlobResourceContents>:
85
85
86
86
```csharp
87
-
[McpServerTool, Description("Returns a file as an embedded resource")]
@@ -291,7 +291,6 @@ Tool parameters are described using [JSON Schema 2020-12]. JSON schemas are auto
291
291
|`int`, `long`|`integer`|
292
292
|`float`, `double`|`number`|
293
293
|`bool`|`boolean`|
294
-
|`enum`|`string` with `enum` values |
295
294
| Complex types |`object` with `properties`|
296
295
297
296
Use `[Description]` attributes on parameters to populate the `description` field in the generated schema. This helps LLMs understand what each parameter expects.
0 commit comments