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.
0 commit comments