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
Copy file name to clipboardExpand all lines: docs/concepts/cancellation/cancellation.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
@@ -44,7 +44,7 @@ The cancellation notification includes:
44
44
-**RequestId**: The ID of the request to cancel, allowing the receiver to correlate the cancellation with the correct in-flight request.
45
45
-**Reason**: An optional human-readable reason for the cancellation.
46
46
47
-
Cancellation notifications can be observed by registering a handler:
47
+
Cancellation notifications can be observed by registering a handler. For broader interception of notifications and other messages, <xref:ModelContextProtocol.Server.McpMessageFilter> delegates can be added to the <xref:ModelContextProtocol.Server.McpMessageFilters.IncomingFilters> collection in <xref:ModelContextProtocol.Server.McpServerOptions.Filters>.
Copy file name to clipboardExpand all lines: docs/concepts/capabilities/capabilities.md
+1-5Lines changed: 1 addition & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,14 +7,10 @@ uid: capabilities
7
7
8
8
## Capabilities
9
9
10
-
MCP uses a [capability negotiation] mechanism during connection initialization. Clients and servers exchange their supported capabilities, allowing each side to understand what features the other supports and adapt behavior accordingly.
10
+
MCP uses a [capability negotiation] mechanism during connection setup. Clients and servers exchange their supported capabilities so each side can adapt its behavior accordingly. Both sides should check the other's capabilities before using optional features.
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.
17
-
18
14
### Client capabilities
19
15
20
16
<xref:ModelContextProtocol.Protocol.ClientCapabilities> declares what features the client supports:
Copy file name to clipboardExpand all lines: docs/concepts/elicitation/elicitation.md
+3-5Lines changed: 3 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -73,8 +73,6 @@ var result = await server.ElicitAsync(new ElicitRequestParams
73
73
}, cancellationToken);
74
74
```
75
75
76
-
If the client returns accepted content with missing fields, the server automatically fills those fields with their schema defaults. This ensures tools always receive complete data regardless of client behavior.
77
-
78
76
#### Enum schema formats
79
77
80
78
Enum schemas allow the server to present a set of choices to the user.
@@ -91,9 +89,9 @@ Enum schemas allow the server to present a set of choices to the user.
Copy file name to clipboardExpand all lines: docs/concepts/prompts/prompts.md
+12-4Lines changed: 12 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -15,11 +15,19 @@ This document covers implementing prompts on the server, consuming them from the
15
15
16
16
### Defining prompts on the server
17
17
18
-
Prompts are defined as methods marked with the <xref:ModelContextProtocol.Server.McpServerPromptAttribute> attribute within a class marked with <xref:ModelContextProtocol.Server.McpServerPromptTypeAttribute>. Prompts can return `ChatMessage` instances for simple text/image content, or <xref:ModelContextProtocol.Protocol.PromptMessage> instances when protocol-specific content types like <xref:ModelContextProtocol.Protocol.EmbeddedResourceBlock> are needed.
18
+
Prompts can be defined in several ways:
19
+
20
+
- Using the <xref:ModelContextProtocol.Server.McpServerPromptAttribute> attribute on methods within a class marked with <xref:ModelContextProtocol.Server.McpServerPromptTypeAttribute>
21
+
- Using <xref:ModelContextProtocol.Server.McpServerPrompt.Create*> factory methods from a delegate, `MethodInfo`, or `AIFunction`
22
+
- Deriving from <xref:ModelContextProtocol.Server.McpServerPrompt> or <xref:ModelContextProtocol.Server.DelegatingMcpServerPrompt>
23
+
- Implementing a custom <xref:ModelContextProtocol.Server.McpRequestHandler`2> via <xref:ModelContextProtocol.Server.McpServerHandlers>
24
+
- Implementing a low-level <xref:ModelContextProtocol.Server.McpRequestFilter`2>
25
+
26
+
The attribute-based approach is the most common and is shown throughout this document. Prompts can return `ChatMessage` instances for simple text/image content, or <xref:ModelContextProtocol.Protocol.PromptMessage> instances when protocol-specific content types like <xref:ModelContextProtocol.Protocol.EmbeddedResourceBlock> are needed.
19
27
20
28
#### Simple prompts
21
29
22
-
A prompt without arguments returns a fixed message:
30
+
A prompt without arguments:
23
31
24
32
```csharp
25
33
[McpServerPromptType]
@@ -33,7 +41,7 @@ public class MyPrompts
33
41
34
42
#### Prompts with arguments
35
43
36
-
Prompts can accept parameters to customize the generated messages. Use `[Description]` attributes to document each parameter:
44
+
Prompts can accept parameters to customize the generated messages. Use `[Description]` attributes to document each parameter. In addition to prompt arguments, methods can accept special parameter types that are resolved automatically: <xref:ModelContextProtocol.Server.McpServer>, `IProgress<ProgressNotificationValue>`, `ClaimsPrincipal`, and any service registered through dependency injection.
37
45
38
46
```csharp
39
47
[McpServerPromptType]
@@ -66,7 +74,7 @@ builder.Services.AddMcpServer()
66
74
67
75
### Rich content in prompts
68
76
69
-
Prompt messages can contain more than just text. For text and image content, use `ChatMessage` from Microsoft.Extensions.AI. For protocol-specific content types like embedded resources, use <xref:ModelContextProtocol.Protocol.PromptMessage>instead.
77
+
Prompt messages can contain more than just text. For text and image content, use `ChatMessage` from Microsoft.Extensions.AI. `DataContent` is automatically mapped to the appropriate MCP content block: image MIME types become <xref:ModelContextProtocol.Protocol.ImageContentBlock>, audio MIME types become <xref:ModelContextProtocol.Protocol.AudioContentBlock>, and all other MIME types become <xref:ModelContextProtocol.Protocol.EmbeddedResourceBlock> with binary resource contents. For text embedded resources specifically, use <xref:ModelContextProtocol.Protocol.PromptMessage>directly.
Copy file name to clipboardExpand all lines: docs/concepts/resources/resources.md
+9-1Lines changed: 9 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -15,7 +15,15 @@ This document covers implementing resources on the server, consuming them from t
15
15
16
16
### Defining resources on the server
17
17
18
-
Resources are defined as methods marked with the <xref:ModelContextProtocol.Server.McpServerResourceAttribute> attribute within a class marked with <xref:ModelContextProtocol.Server.McpServerResourceTypeAttribute>. The attribute specifies the URI template that identifies the resource.
18
+
Resources can be defined in several ways:
19
+
20
+
- Using the <xref:ModelContextProtocol.Server.McpServerResourceAttribute> attribute on methods within a class marked with <xref:ModelContextProtocol.Server.McpServerResourceTypeAttribute>
21
+
- Using <xref:ModelContextProtocol.Server.McpServerResource.Create*> factory methods from a delegate, `MethodInfo`, or `AIFunction`
22
+
- Deriving from <xref:ModelContextProtocol.Server.McpServerResource> or <xref:ModelContextProtocol.Server.DelegatingMcpServerResource>
23
+
- Implementing a custom <xref:ModelContextProtocol.Server.McpRequestHandler`2> via <xref:ModelContextProtocol.Server.McpServerHandlers>
24
+
- Implementing a low-level <xref:ModelContextProtocol.Server.McpRequestFilter`2>
25
+
26
+
The attribute-based approach is the most common and is shown throughout this document.
Copy file name to clipboardExpand all lines: docs/concepts/roots/roots.md
+1-8Lines changed: 1 addition & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -23,18 +23,11 @@ Each root is represented by a <xref:ModelContextProtocol.Protocol.Root> with a U
23
23
24
24
### Declaring roots capability on the client
25
25
26
-
Clients advertise their support for roots in the capabilities sent during initialization. To enable roots, configure the <xref:ModelContextProtocol.Protocol.ClientCapabilities.Roots> property and provide a handler that returns the root list:
26
+
Clients advertise their support for roots in the capabilities sent during initialization. The roots capability is created automatically when a roots handler is provided. Configure the handler through <xref:ModelContextProtocol.McpClientHandlers.RootsHandler>:
27
27
28
28
```csharp
29
29
varoptions=newMcpClientOptions
30
30
{
31
-
Capabilities=newClientCapabilities
32
-
{
33
-
Roots=newRootsCapability
34
-
{
35
-
ListChanged=true// Notify server when roots change
Copy file name to clipboardExpand all lines: docs/concepts/tools/tools.md
+19-8Lines changed: 19 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -15,7 +15,15 @@ This document covers tool content types, change notifications, and schema genera
15
15
16
16
### Defining tools on the server
17
17
18
-
Tools are defined as methods marked with the <xref:ModelContextProtocol.Server.McpServerToolAttribute> attribute within a class marked with <xref:ModelContextProtocol.Server.McpServerToolTypeAttribute>. Parameters are automatically deserialized from JSON and documented using `[Description]` attributes.
18
+
Tools can be defined in several ways:
19
+
20
+
- Using the <xref:ModelContextProtocol.Server.McpServerToolAttribute> attribute on methods within a class marked with <xref:ModelContextProtocol.Server.McpServerToolTypeAttribute>
21
+
- Using <xref:ModelContextProtocol.Server.McpServerTool.Create*> factory methods from a delegate, `MethodInfo`, or `AIFunction`
22
+
- Deriving from <xref:ModelContextProtocol.Server.McpServerTool> or <xref:ModelContextProtocol.Server.DelegatingMcpServerTool>
23
+
- Implementing a custom <xref:ModelContextProtocol.Server.McpRequestHandler`2> via <xref:ModelContextProtocol.Server.McpServerHandlers>
24
+
- Implementing a low-level <xref:ModelContextProtocol.Server.McpRequestFilter`2>
25
+
26
+
The attribute-based approach is the most common and is shown throughout this document. Parameters are automatically deserialized from JSON and documented using `[Description]` attributes. In addition to tool arguments, methods can accept special parameter types that are resolved automatically: <xref:ModelContextProtocol.Server.McpServer>, `IProgress<ProgressNotificationValue>`, `ClaimsPrincipal`, and any service registered through dependency injection.
19
27
20
28
```csharp
21
29
[McpServerToolType]
@@ -37,7 +45,7 @@ builder.Services.AddMcpServer()
37
45
38
46
### Content types
39
47
40
-
Tools can return various content types. The simplest is a `string`, which is automatically wrapped in a <xref:ModelContextProtocol.Protocol.TextContentBlock>. For richer content, tools can return one or more <xref:ModelContextProtocol.Protocol.ContentBlock> instances.
48
+
Tools can return various content types. The simplest is a `string`, which is automatically wrapped in a <xref:ModelContextProtocol.Protocol.TextContentBlock>. For richer content, tools can return one or more <xref:ModelContextProtocol.Protocol.ContentBlock> instances. Tools can also return `DataContent` from Microsoft.Extensions.AI, which is automatically mapped to the appropriate MCP content block: image MIME types become <xref:ModelContextProtocol.Protocol.ImageContentBlock>, audio MIME types become <xref:ModelContextProtocol.Protocol.AudioContentBlock>, and all other MIME types become <xref:ModelContextProtocol.Protocol.EmbeddedResourceBlock> with binary resource contents.
@@ -195,7 +201,12 @@ Tool errors in MCP are distinct from protocol errors. When a tool encounters an
195
201
196
202
#### Automatic exception handling
197
203
198
-
When a tool method throws an exception, the server automatically catches it and returns a `CallToolResult` with `IsError = true`. <xref:ModelContextProtocol.McpProtocolException> is re-thrown as a JSON-RPC error, and `OperationCanceledException` is re-thrown when the cancellation token was triggered. All other exceptions are returned as tool error results. For <xref:ModelContextProtocol.McpException> subclasses, the exception message is included in the error text; for other exceptions, a generic message is returned to avoid leaking internal details.
204
+
When a tool method throws an exception, the server catches it and returns a `CallToolResult` with `IsError = true`, with the following exceptions:
205
+
206
+
-<xref:ModelContextProtocol.McpProtocolException> is re-thrown as a JSON-RPC error response (not a tool error result).
207
+
-`OperationCanceledException` is re-thrown when the cancellation token was triggered.
208
+
209
+
For all other exceptions, the error is returned as a tool result. If the exception derives from <xref:ModelContextProtocol.McpException> (excluding `McpProtocolException`, which is re-thrown above), its message is included in the error text; otherwise, a generic message is returned to avoid leaking internal details.
199
210
200
211
```csharp
201
212
[McpServerTool, Description("Divides two numbers")]
0 commit comments