11package io.modelcontextprotocol.kotlin.sdk.types
22
33import kotlinx.serialization.EncodeDefault
4- import kotlinx.serialization.ExperimentalSerializationApi
54import kotlinx.serialization.SerialName
65import kotlinx.serialization.Serializable
76import kotlinx.serialization.json.JsonObject
87
98/* *
10- * A request from the server to elicit additional information from the user via the client.
9+ * Represents an `elicitation/create` request from the server to the client.
1110 *
12- * This request type allows servers to prompt users for structured input through forms
13- * or dialogs presented by the client. The server defines a schema for the requested data,
14- * and the client presents an appropriate UI to collect this information.
11+ * Supports two modes: form mode ([ElicitRequestFormParams]) for collecting structured data
12+ * in-band, and URL mode ([ElicitRequestURLParams]) for directing the user to an external URL.
1513 *
16- * @property params The elicitation parameters including the message and requested schema .
14+ * @property params The elicitation parameters — either form or URL mode .
1715 */
1816@Serializable
1917public data class ElicitRequest (override val params : ElicitRequestParams ) : ServerRequest {
20- @OptIn(ExperimentalSerializationApi ::class )
2118 @EncodeDefault
2219 public override val method: Method = Method .Defined .ElicitationCreate
2320
@@ -30,8 +27,13 @@ public data class ElicitRequest(override val params: ElicitRequestParams) : Serv
3027 /* *
3128 * A restricted subset of JSON Schema defining the structure of the requested data.
3229 */
33- public val requestedSchema: ElicitRequestParams .RequestedSchema
34- get() = params.requestedSchema
30+ @Deprecated(
31+ " Use (params as ElicitRequestFormParams).requestedSchema" ,
32+ ReplaceWith (" (params as ElicitRequestFormParams).requestedSchema" ),
33+ DeprecationLevel .WARNING ,
34+ )
35+ public val requestedSchema: ElicitRequestParams .RequestedSchema ?
36+ get() = (params as ? ElicitRequestFormParams )?.requestedSchema
3537
3638 /* *
3739 * Metadata for this request. May include a progressToken for out-of-band progress notifications.
@@ -41,55 +43,124 @@ public data class ElicitRequest(override val params: ElicitRequestParams) : Serv
4143}
4244
4345/* *
44- * Parameters for an elicitation/create request.
46+ * Represents the parameters for an ` elicitation/create` request.
4547 *
46- * @property message The message to present to the user. This should clearly explain
47- * what information is being requested and why.
48- * @property requestedSchema A restricted subset of JSON Schema defining the structure
49- * of the requested data. Only top-level properties are allowed,
50- * without nesting.
51- * @property meta Optional metadata for this request. May include a progressToken for
52- * out-of-band progress notifications.
48+ * Implementations: [ElicitRequestFormParams], [ElicitRequestURLParams].
5349 */
54- @Serializable
55- public data class ElicitRequestParams (
56- val message : String ,
57- val requestedSchema : RequestedSchema ,
58- @SerialName(" _meta" )
59- override val meta : RequestMeta ? = null ,
60- ) : RequestParams {
50+ @Serializable(with = ElicitRequestParamsSerializer ::class )
51+ public sealed interface ElicitRequestParams : RequestParams {
52+ public val message: String
6153
6254 /* *
6355 * A restricted JSON Schema for elicitation requests.
6456 *
6557 * Only supports top-level primitive properties without nesting. Each property
6658 * represents a field in the form or dialog presented to the user.
6759 *
60+ * @property schema Optional URI to a JSON Schema definition.
6861 * @property properties A map of property names to their schema definitions.
6962 * Each property must be a primitive type (string, number, boolean).
7063 * @property required Optional list of property names that must be provided by the user.
7164 * If omitted, all fields are considered optional.
7265 * @property type Always "object" for elicitation schemas.
7366 */
7467 @Serializable
75- public data class RequestedSchema (val properties : JsonObject , val required : List <String >? = null ) {
76- @OptIn(ExperimentalSerializationApi ::class )
68+ public data class RequestedSchema (
69+ @SerialName($$" $schema " )
70+ val schema : String? = null ,
71+ val properties : Map <String , PrimitiveSchemaDefinition >,
72+ val required : List <String >? = null ,
73+ ) {
7774 @EncodeDefault
7875 val type: String = " object"
7976 }
8077}
8178
8279/* *
83- * The client's response to an [ElicitRequest].
80+ * Creates an [ElicitRequestFormParams] for backwards compatibility.
81+ *
82+ * @param message The message to present to the user.
83+ * @param requestedSchema The JSON Schema for the requested data.
84+ * @param meta Optional request metadata.
85+ * @return A configured [ElicitRequestFormParams] instance.
86+ */
87+ @Deprecated(
88+ " Use ElicitRequestFormParams instead" ,
89+ ReplaceWith (" ElicitRequestFormParams(message, requestedSchema = requestedSchema, meta = meta)" ),
90+ DeprecationLevel .WARNING ,
91+ )
92+ @Suppress(" FunctionNaming" , " FunctionName" )
93+ public fun ElicitRequestParams (
94+ message : String ,
95+ requestedSchema : ElicitRequestParams .RequestedSchema ,
96+ meta : RequestMeta ? = null,
97+ ): ElicitRequestFormParams = ElicitRequestFormParams (
98+ message = message,
99+ requestedSchema = requestedSchema,
100+ meta = meta,
101+ )
102+
103+ /* *
104+ * Represents form mode parameters for an `elicitation/create` request.
105+ *
106+ * Collects non-sensitive structured data from the user via a form presented by the client.
84107 *
85- * Represents the user's action and, if accepted, the submitted form data.
108+ * @property message The message to present to the user describing what information is being requested.
109+ * @property task If specified, the caller is requesting task-augmented execution. The request
110+ * will return a [CreateTaskResult] immediately, and the actual result can be retrieved
111+ * later via `tasks/result`.
112+ * @property requestedSchema A restricted subset of JSON Schema. Only top-level properties
113+ * are allowed, without nesting.
114+ * @property meta Optional metadata. May include a progressToken for out-of-band progress notifications.
115+ */
116+ @Serializable
117+ public data class ElicitRequestFormParams (
118+ override val message : String ,
119+ val task : TaskMetadata ? = null ,
120+ val requestedSchema : ElicitRequestParams .RequestedSchema ,
121+ @SerialName(" _meta" )
122+ override val meta : RequestMeta ? = null ,
123+ ) : ElicitRequestParams {
124+ @EncodeDefault
125+ public val mode: String = " form"
126+ }
127+
128+ /* *
129+ * Represents URL mode parameters for an `elicitation/create` request.
130+ *
131+ * Directs the user to an external URL for out-of-band interactions (e.g., OAuth flows,
132+ * payment processing, or entering sensitive credentials) that must not pass through the MCP client.
133+ *
134+ * @property message The message explaining why the interaction is needed.
135+ * @property elicitationId A unique identifier for this elicitation. The client MUST treat
136+ * this ID as an opaque value.
137+ * @property url The URL that the user should navigate to.
138+ * @property task If specified, the caller is requesting task-augmented execution. The request
139+ * will return a [CreateTaskResult] immediately, and the actual result can be retrieved
140+ * later via `tasks/result`.
141+ * @property meta Optional metadata. May include a progressToken for out-of-band progress notifications.
142+ */
143+ @Serializable
144+ public data class ElicitRequestURLParams (
145+ override val message : String ,
146+ val elicitationId : String ,
147+ val url : String ,
148+ val task : TaskMetadata ? = null ,
149+ @SerialName(" _meta" )
150+ override val meta : RequestMeta ? = null ,
151+ ) : ElicitRequestParams {
152+ @EncodeDefault
153+ public val mode: String = " url"
154+ }
155+
156+ /* *
157+ * Represents the client's response to an [ElicitRequest].
86158 *
87- * @property action The user action in response to the elicitation prompt .
88- * @property content The submitted form data, only present when [action] is [Action.Accept].
89- * Contains values matching the requested schema, where keys correspond
90- * to property names and values are primitives (string, number, or boolean) .
159+ * @property action The user action in response to the elicitation.
160+ * @property content The submitted form data, only present when [action] is [Action.Accept]
161+ * and mode was form. Contains values matching the requested schema. Omitted for
162+ * URL mode responses .
91163 * @property meta Optional metadata for this response.
92- * @throws IllegalArgumentException if content is provided with a non-accept action.
93164 */
94165@Serializable
95166public data class ElicitResult (
0 commit comments