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/elicitation/elicitation.md
+54-10Lines changed: 54 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,13 +9,19 @@ uid: elicitation
9
9
10
10
The **elicitation** feature allows servers to request additional information from users during interactions. This enables more dynamic and interactive AI experiences, making it easier to gather necessary context before executing tasks.
11
11
12
+
The protocol supports two modes of elicitation:
13
+
-**Form (In-Band)**: The server requests structured data (strings, numbers, booleans, enums) which the client collects via a form interface and returns to the server.
14
+
-**URL Mode**: The server provides a URL for the user to visit (e.g., for OAuth, payments, or sensitive data entry). The interaction happens outside the MCP client.
15
+
12
16
### Server Support for Elicitation
13
17
14
-
Servers request structured data from users with the <xref:ModelContextProtocol.Server.McpServer.ElicitAsync*> extension method on <xref:ModelContextProtocol.Server.McpServer>.
18
+
Servers request information from users with the <xref:ModelContextProtocol.Server.McpServer.ElicitAsync*> extension method on <xref:ModelContextProtocol.Server.McpServer>.
15
19
The C# SDK registers an instance of <xref:ModelContextProtocol.Server.McpServer> with the dependency injection container,
16
20
so tools can simply add a parameter of type <xref:ModelContextProtocol.Server.McpServer> to their method signature to access it.
17
21
18
-
The MCP Server must specify the schema of each input value it is requesting from the user.
22
+
#### Form Mode Elicitation (In-Band)
23
+
24
+
For form-based elicitation, the MCP Server must specify the schema of each input value it is requesting from the user.
19
25
Primitive types (string, number, boolean) and enum types are supported for elicitation requests.
20
26
The schema may include a description to help the user understand what is being requested.
21
27
@@ -33,18 +39,56 @@ The following example demonstrates how a server could request a boolean response
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>:
44
+
For URL mode elicitation, the server provides a URL that the user must visit to complete an action. This is useful for scenarios like OAuth flows, payment processing, or collecting sensitive credentials that should not be exposed to the MCP client.
Message="Please authorize access to your account by logging in through your browser."
57
+
},
58
+
cancellationToken);
59
+
```
60
+
61
+
### Client Support for Elicitation
45
62
46
-
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.
47
-
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.
63
+
Elicitation is an optional feature so clients declare their support for it in their capabilities as part of the `initialize` request. Clients can support `Form` (in-band), `Url` (out-of-band), or both.
64
+
65
+
In the MCP C# SDK, this is done by configuring the capabilities and an <xref:ModelContextProtocol.Client.McpClientHandlers.ElicitationHandler> in the <xref:ModelContextProtocol.Client.McpClientOptions>:
66
+
67
+
```csharp
68
+
varoptions=newMcpClientOptions
69
+
{
70
+
Capabilities=newClientCapabilities
71
+
{
72
+
Elicitation=newElicitationCapability
73
+
{
74
+
Form=newFormElicitationCapability(),
75
+
Url=newUrlElicitationCapability()
76
+
}
77
+
},
78
+
Handlers=newMcpClientHandlers
79
+
{
80
+
ElicitationHandler=HandleElicitationAsync
81
+
}
82
+
};
83
+
```
84
+
85
+
The `ElicitationHandler` is an asynchronous method that will be called when the server requests additional information. The handler should check the `Mode` of the request:
86
+
87
+
-**Form Mode**: Present the form defined by `RequestedSchema` to the user. Return the user's input in the `Content` of the result.
88
+
-**URL Mode**: Present the `Message` and `Url` to the user. Ask for consent to open the URL. If the user consents, open the URL and return `Action="accept"`. If the user declines, return `Action="decline"`.
89
+
90
+
If the user provides the requested information (or consents to URL mode), the ElicitationHandler should return an <xref:ModelContextProtocol.Protocol.ElicitResult> with the action set to "accept".
91
+
If the user does not provide the requested information, the ElicitationHandler should return an <xref:ModelContextProtocol.Protocol.ElicitResult> with the action set to "reject" (or "decline" / "cancel").
48
92
49
93
Below is an example of how a console application might handle elicitation requests.
/// Gets or sets the elicitation mode: "form" for in-band data collection or "url" for out-of-band URL navigation.
16
+
/// </summary>
17
+
/// <remarks>
18
+
/// <list type="bullet">
19
+
/// <item><description><b>form</b>: Client collects structured data via a form interface. Data is exposed to the client.</description></item>
20
+
/// <item><description><b>url</b>: Client navigates user to a URL for out-of-band interaction. Sensitive data is not exposed to the client.</description></item>
21
+
/// </list>
22
+
/// </remarks>
23
+
[JsonPropertyName("mode")]
24
+
[field:MaybeNull]
25
+
publicstringMode
26
+
{
27
+
get=>field??="form";
28
+
set
29
+
{
30
+
if(valueis not ("form" or "url"))
31
+
{
32
+
thrownewArgumentException("Mode must be 'form' or 'url'.",nameof(value));
33
+
}
34
+
field=value;
35
+
}
36
+
}
37
+
38
+
/// <summary>
39
+
/// Gets or sets a unique identifier for this elicitation request.
40
+
/// </summary>
41
+
/// <remarks>
42
+
/// <para>
43
+
/// Used to track and correlate the elicitation across multiple messages, especially for out-of-band flows
44
+
/// that may complete asynchronously.
45
+
/// </para>
46
+
/// <para>
47
+
/// Required for url mode elicitation to enable progress tracking and completion detection.
48
+
/// </para>
49
+
/// </remarks>
50
+
[JsonPropertyName("elicitationId")]
51
+
publicstring?ElicitationId{get;set;}
52
+
53
+
/// <summary>
54
+
/// Gets or sets the URL to navigate to for out-of-band elicitation.
55
+
/// </summary>
56
+
/// <remarks>
57
+
/// <para>
58
+
/// Required when <see cref="Mode"/> is "url". The client should prompt the user for consent
59
+
/// and then navigate to this URL in a user-agent (browser) where the user completes
60
+
/// the required interaction.
61
+
/// </para>
62
+
/// <para>
63
+
/// URLs must not appear in any other field of the elicitation request for security reasons.
64
+
/// </para>
65
+
/// </remarks>
66
+
[JsonPropertyName("url")]
67
+
publicstring?Url{get;set;}
68
+
14
69
/// <summary>
15
70
/// Gets or sets the message to present to the user.
16
71
/// </summary>
72
+
/// <remarks>
73
+
/// For form mode, this describes what information is being requested.
74
+
/// For url mode, this explains why the user needs to navigate to the URL.
75
+
/// </remarks>
17
76
[JsonPropertyName("message")]
18
77
publicrequiredstringMessage{get;set;}
19
78
20
79
/// <summary>
21
-
/// Gets or sets the requested schema.
80
+
/// Gets or sets the requested schema for form mode elicitation.
22
81
/// </summary>
23
82
/// <remarks>
83
+
/// Only applicable when <see cref="Mode"/> is "form".
24
84
/// May be one of <see cref="StringSchema"/>, <see cref="NumberSchema"/>, <see cref="BooleanSchema"/>,
0 commit comments