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
Servers request structured data from users with the <xref:ModelContextProtocol.Server.McpServer.ElicitAsync*> extension method on <xref:ModelContextProtocol.Server.McpServer>.
15
+
The C# SDK registers an instance of <xref:ModelContextProtocol.Server.McpServer> with the dependency injection container,
16
+
so tools can simply add a parameter of type <xref:ModelContextProtocol.Server.McpServer> to their method signature to access it.
20
17
21
18
The MCP Server must specify the schema of each input value it is requesting from the user.
22
19
Only primitive types (string, number, boolean) are supported for elicitation requests.
@@ -31,21 +28,16 @@ The following example demonstrates how a server could request a boolean response
31
28
32
29
### Client Support for Elicitation
33
30
34
-
Elicitation is an optional feature so clients declare their support for it in their capabilities as part of the `initialize` request. In the MCP C# SDK, this is done by configuring an [ElicitationHandler] in the [McpClientOptions]:
Elicitation is an optional feature so clients declare their support for it in their capabilities as part of the `initialize` request. In the MCP C# SDK, this is done by configuring an <xref:ModelContextProtocol.Client.McpClientHandlers.ElicitationHandler> in the <xref:ModelContextProtocol.Client.McpClientOptions>:
The ElicitationHandler is an asynchronous method that will be called when the server requests additional information.
42
36
The ElicitationHandler must request input from the user and return the data in a format that matches the requested schema.
43
37
This will be highly dependent on the client application and how it interacts with the user.
44
38
45
-
If the user provides the requested information, the ElicitationHandler should return an [ElicitResult] with the action set to "accept" and the content containing the user's input.
46
-
If the user does not provide the requested information, the ElicitationHandler should return an [ElicitResult] with the action set to "reject" and no content.
If the user provides the requested information, the ElicitationHandler should return an <xref:ModelContextProtocol.Protocol.ElicitResult> with the action set to "accept" and the content containing the user's input.
40
+
If the user does not provide the requested information, the ElicitationHandler should return an [<xref:ModelContextProtocol.Protocol.ElicitResult> with the action set to "reject" and no content.
49
41
50
42
Below is an example of how a console application might handle elicitation requests.
Copy file name to clipboardExpand all lines: docs/concepts/logging/logging.md
+7-24Lines changed: 7 additions & 24 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -49,53 +49,36 @@ Servers built with the C# SDK always declare the logging capability. Doing so do
49
49
to send log messages -- only allows it. Note that stateless MCP servers may not be capable of sending log
50
50
messages as there may not be an open connection to the client on which the log messages could be sent.
51
51
52
-
The C# SDK provides an extension method [WithSetLoggingLevelHandler] on [IMcpServerBuilder] to allow the
52
+
The C# SDK provides an extension method <xref:Microsoft.Extensions.DependencyInjection.McpServerBuilderExtensions.WithSetLoggingLevelHandler*> on <xref:Microsoft.Extensions.DependencyInjection.IMcpServerBuilder> to allow the
53
53
server to perform any special logic it wants to perform when a client sets the logging level. However, the
54
-
SDK already takes care of setting the [LoggingLevel] in the [IMcpServer], so most servers will not need to
54
+
SDK already takes care of setting the <xref:ModelContextProtocol.Server.McpServer.LoggingLevel> in the <xref:ModelContextProtocol.Server.McpServer>, so most servers will not need to
MCP Servers using the MCP C# SDK can obtain an [ILoggerProvider] from the IMcpServer [AsClientLoggerProvider] extension method,
63
-
and from that can create an [ILogger] instance for logging messages that should be sent to the MCP client.
57
+
MCP Servers using the MCP C# SDK can obtain an [ILoggerProvider](https://learn.microsoft.com/dotnet/api/microsoft.extensions.logging.iloggerprovider) from the IMcpServer <xref:ModelContextProtocol.Server.McpServer.AsClientLoggerProvider> extension method,
58
+
and from that can create an [ILogger](https://learn.microsoft.com/dotnet/api/microsoft.extensions.logging.ilogger) instance for logging messages that should be sent to the MCP client.
Clients should check if the server supports logging by checking the <xref:ModelContextProtocol.Protocol.ServerCapabilities.Logging> property of the <xref:ModelContextProtocol.Client.McpClient.ServerCapabilities> field of <xref:ModelContextProtocol.Client.McpClient>.
If the server supports logging, the client should set the level of log messages it wishes to receive with
85
-
the [SetLoggingLevel] method on [IMcpClient]. If the client does not set a logging level, the server might choose
72
+
the <xref:ModelContextProtocol.Client.McpClient.SetLoggingLevel*> method on <xref:ModelContextProtocol.Client.McpClient>. If the client does not set a logging level, the server might choose
86
73
to send all log messages or none -- this is not specified in the protocol -- so it is important that the client
87
74
sets a logging level to ensure it receives the desired log messages and only those messages.
88
75
89
76
The `loggingLevel` set by the client is an MCP logging level.
90
77
See the [Logging Levels](#logging-levels) section above for the mapping between MCP and .NET logging levels.
Lastly, the client must configure a notification handler for [NotificationMethods.LoggingMessageNotification] notifications.
81
+
Lastly, the client must configure a notification handler for <xref:ModelContextProtocol.Protocol.NotificationMethods.LoggingMessageNotification> notifications.
97
82
The following example simply writes the log messages to the console.
Copy file name to clipboardExpand all lines: docs/concepts/progress/progress.md
+9-19Lines changed: 9 additions & 19 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -17,17 +17,13 @@ This project illustrates the common case of a server tool that performs a long-r
17
17
18
18
### Server Implementation
19
19
20
-
When processing a request, the server can use the [sendNotificationAsync] extension method of [IMcpServer] to send progress updates,
20
+
When processing a request, the server can use the <xref:ModelContextProtocol.McpSession.SendNotificationAsync*> extension method of <xref:ModelContextProtocol.Server.McpServer> to send progress updates,
21
21
specifying `"notifications/progress"` as the notification method name.
22
-
The C# SDK registers an instance of [IMcpServer] with the dependency injection container,
23
-
so tools can simply add a parameter of type [IMcpServer] to their method signature to access it.
24
-
The parameters passed to [sendNotificationAsync] should be an instance of [ProgressNotificationParams], which includes the current progress, total steps, and an optional message.
22
+
The C# SDK registers an instance of <xref:ModelContextProtocol.Server.McpServer> with the dependency injection container,
23
+
so tools can simply add a parameter of type <xref:ModelContextProtocol.Server.McpServer> to their method signature to access it.
24
+
The parameters passed to <xref:ModelContextProtocol.McpSession.SendNotificationAsync*> should be an instance of <xref:ModelContextProtocol.Protocol.ProgressNotificationParams>, which includes the current progress, total steps, and an optional message.
The server must verify that the caller provided a `progressToken` in the request and include it in the call to [sendNotificationAsync]. The following example demonstrates how a server can send a progress notification:
26
+
The server must verify that the caller provided a `progressToken` in the request and include it in the call to <xref:ModelContextProtocol.McpSession.SendNotificationAsync*>. The following example demonstrates how a server can send a progress notification:
@@ -38,10 +34,7 @@ Note that servers are not required to support progress tracking, so clients shou
38
34
39
35
In the MCP C# SDK, clients can specify a `progressToken` in the request parameters when calling a tool method.
40
36
The client should also provide a notification handler to process "notifications/progress" notifications.
41
-
There are two way to do this. The first is to register a notification handler using the [RegisterNotificationHandler] method on the [IMcpClient] instance. A handler registered this way will receive all progress notifications sent by the server.
There are two way to do this. The first is to register a notification handler using the <xref:ModelContextProtocol.McpSession.RegisterNotificationHandler*> method on the <xref:ModelContextProtocol.Client.McpClient> instance. A handler registered this way will receive all progress notifications sent by the server.
The second way is to pass a [Progress`<T>`] instance to the tool method. [Progress`<T>`] is a standard .NET type that provides a way to receive progress updates.
61
-
For the purposes of MCP progress notifications, `T` should be [ProgressNotificationValue].
62
-
The MCP C# SDK will automatically handle progress notifications and report them through the [Progress`<T>`] instance.
53
+
The second way is to pass a [`Progress<T>`](https://learn.microsoft.com/dotnet/api/system.progress-1) instance to the tool method. `Progress<T>` is a standard .NET type that provides a way to receive progress updates.
54
+
For the purposes of MCP progress notifications, `T` should be <xref:ModelContextProtocol.ProgressNotificationValue>.
55
+
The MCP C# SDK will automatically handle progress notifications and report them through the `Progress<T>` instance.
63
56
This notification handler will only receive progress updates for the specific request that was made,
64
57
rather than all progress notifications from the server.
0 commit comments