Skip to content

Commit fb4efc9

Browse files
author
Abhimanyu Siwach
committed
add request schema and content object
1 parent bf41e65 commit fb4efc9

File tree

3 files changed

+128
-79
lines changed

3 files changed

+128
-79
lines changed

docs/specification/draft/client/elicitation.mdx

Lines changed: 87 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ The Model Context Protocol (MCP) provides a standardized way for servers to requ
88
information from users through the client during interactions. This flow allows clients to
99
maintain control over user interactions and data sharing while enabling servers to gather
1010
necessary information dynamically—creating more interactive and context-aware experiences.
11-
Servers can request text, image, or audio responses from users with optional structured schemas.
11+
Servers can request structured data from users with optional JSON schemas to validate responses.
1212

1313
## User Interaction Model
1414

@@ -51,6 +51,8 @@ The client declares support for elicitation during initialization.
5151

5252
To request information from a user, servers send an `elicitation/create` request:
5353

54+
#### Simple Text Request
55+
5456
**Request:**
5557

5658
```json
@@ -71,25 +73,44 @@ To request information from a user, servers send an `elicitation/create` request
7173
"jsonrpc": "2.0",
7274
"id": 1,
7375
"result": {
74-
"content": [
75-
{
76-
"type": "text",
77-
"text": "octocat"
78-
}
79-
]
76+
"content": {
77+
"username": "octocat"
78+
}
8079
}
8180
}
8281
```
8382

84-
**Request with multiple responses:**
83+
#### Structured Data Request with Schema
84+
85+
**Request:**
8586

8687
```json
8788
{
8889
"jsonrpc": "2.0",
8990
"id": 2,
9091
"method": "elicitation/create",
9192
"params": {
92-
"message": "What is your favorite color?"
93+
"message": "Please provide your contact information",
94+
"requestSchema": {
95+
"type": "object",
96+
"properties": {
97+
"name": {
98+
"type": "string",
99+
"description": "Your full name"
100+
},
101+
"email": {
102+
"type": "string",
103+
"format": "email",
104+
"description": "Your email address"
105+
},
106+
"age": {
107+
"type": "number",
108+
"minimum": 18,
109+
"description": "Your age"
110+
}
111+
},
112+
"required": ["name", "email"]
113+
}
93114
}
94115
}
95116
```
@@ -101,17 +122,11 @@ To request information from a user, servers send an `elicitation/create` request
101122
"jsonrpc": "2.0",
102123
"id": 2,
103124
"result": {
104-
"content": [
105-
{
106-
"type": "text",
107-
"text": "Blue"
108-
},
109-
{
110-
"type": "image",
111-
"data": "base64-encoded-image-data",
112-
"mimeType": "image/jpeg"
113-
}
114-
]
125+
"content": {
126+
"name": "Monalisa Octocat",
127+
"email": "[email protected]",
128+
"age": 30
129+
}
115130
}
116131
}
117132
```
@@ -137,61 +152,51 @@ sequenceDiagram
137152
Note over Server: Continue processing with new information
138153
```
139154

140-
## Data Types
141-
142-
### Elicitation Content
155+
## Request Schema
143156

144-
Responses to elicitation requests can contain an array of content items:
157+
The `requestSchema` field allows servers to define the structure of the expected response using JSON Schema. This follows the same pattern as the `inputSchema` field in the Tool interface:
145158

146159
```json
147-
"content": [
148-
{
149-
"type": "text",
150-
"text": "User's response text"
160+
"requestSchema": {
161+
"type": "object",
162+
"properties": {
163+
"propertyName": {
164+
"type": "string",
165+
"description": "Description of the property"
166+
},
167+
"anotherProperty": {
168+
"type": "number",
169+
"minimum": 0,
170+
"maximum": 100
171+
}
151172
},
152-
{
153-
"type": "image",
154-
"data": "base64-encoded-image-data",
155-
"mimeType": "image/jpeg"
156-
},
157-
{
158-
"type": "audio",
159-
"data": "base64-encoded-audio-data",
160-
"mimeType": "audio/wav"
161-
}
162-
]
173+
"required": ["propertyName"]
174+
}
163175
```
164176

165-
Each content item can be one of:
177+
The schema can include:
178+
- Property definitions with types
179+
- Required field specifications
180+
- Validation constraints (min/max values, patterns, formats)
181+
- Descriptions for UI presentation
166182

167-
#### Text Content
183+
Clients can use this schema to:
184+
1. Generate appropriate input forms
185+
2. Validate user input before sending
186+
3. Provide better guidance to users
168187

169-
```json
170-
{
171-
"type": "text",
172-
"text": "User's response text"
173-
}
174-
```
188+
## Response Content
175189

176-
#### Image Content
190+
Responses to elicitation requests contain a content object with key-value pairs:
177191

178192
```json
179-
{
180-
"type": "image",
181-
"data": "base64-encoded-image-data",
182-
"mimeType": "image/jpeg"
193+
"content": {
194+
"propertyName": "value",
195+
"anotherProperty": 42
183196
}
184197
```
185198

186-
#### Audio Content
187-
188-
```json
189-
{
190-
"type": "audio",
191-
"data": "base64-encoded-audio-data",
192-
"mimeType": "audio/wav"
193-
}
194-
```
199+
The structure of this object should match the schema provided in the request, if one was specified. If no schema was provided, the client can structure the response as appropriate for the use case.
195200

196201
## Error Handling
197202

@@ -210,10 +215,29 @@ Example when the user cancels:
210215
}
211216
```
212217

218+
Example when validation fails:
219+
220+
```json
221+
{
222+
"jsonrpc": "2.0",
223+
"id": 1,
224+
"error": {
225+
"code": -32602,
226+
"message": "Invalid parameters",
227+
"data": {
228+
"validationErrors": {
229+
"email": "Invalid email format"
230+
}
231+
}
232+
}
233+
}
234+
```
235+
213236
## Security Considerations
214237

215238
1. Clients **SHOULD** implement user approval controls
216-
2. Both parties **SHOULD** validate elicitation content
239+
2. Both parties **SHOULD** validate elicitation content against the provided schema
217240
3. Clients **SHOULD** provide clear indication of which server is requesting information
218241
4. Clients **SHOULD** allow users to cancel elicitation requests at any time
219-
5. Structured output should be validated against the provided schema when possible
242+
5. Servers **SHOULD NOT** request sensitive information (passwords, tokens) through elicitation
243+
6. Clients **SHOULD** sanitize inputs to prevent injection attacks

schema/draft/schema.json

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,33 @@
488488
"message": {
489489
"description": "The message to present to the user.",
490490
"type": "string"
491+
},
492+
"requestSchema": {
493+
"description": "A JSON Schema object defining the expected structure of the response.\nThis follows the same pattern as the inputSchema in Tool interface.",
494+
"properties": {
495+
"properties": {
496+
"additionalProperties": {
497+
"additionalProperties": true,
498+
"properties": {},
499+
"type": "object"
500+
},
501+
"type": "object"
502+
},
503+
"required": {
504+
"items": {
505+
"type": "string"
506+
},
507+
"type": "array"
508+
},
509+
"type": {
510+
"const": "object",
511+
"type": "string"
512+
}
513+
},
514+
"required": [
515+
"type"
516+
],
517+
"type": "object"
491518
}
492519
},
493520
"required": [
@@ -511,21 +538,9 @@
511538
"type": "object"
512539
},
513540
"content": {
514-
"description": "The user's response to the elicitation request.",
515-
"items": {
516-
"anyOf": [
517-
{
518-
"$ref": "#/definitions/TextContent"
519-
},
520-
{
521-
"$ref": "#/definitions/ImageContent"
522-
},
523-
{
524-
"$ref": "#/definitions/AudioContent"
525-
}
526-
]
527-
},
528-
"type": "array"
541+
"additionalProperties": {},
542+
"description": "The user's response to the elicitation request.\nThis follows the same pattern as arguments in tool calls.",
543+
"type": "object"
529544
}
530545
},
531546
"required": [

schema/draft/schema.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1223,6 +1223,15 @@ export interface ElicitRequest extends Request {
12231223
* The message to present to the user.
12241224
*/
12251225
message: string;
1226+
/**
1227+
* A JSON Schema object defining the expected structure of the response.
1228+
* This follows the same pattern as the inputSchema in Tool interface.
1229+
*/
1230+
requestSchema?: {
1231+
type: "object";
1232+
properties?: { [key: string]: object };
1233+
required?: string[];
1234+
};
12261235
};
12271236
}
12281237

@@ -1232,8 +1241,9 @@ export interface ElicitRequest extends Request {
12321241
export interface ElicitResult extends Result {
12331242
/**
12341243
* The user's response to the elicitation request.
1244+
* This follows the same pattern as arguments in tool calls.
12351245
*/
1236-
content: (TextContent | ImageContent | AudioContent)[];
1246+
content: { [key: string]: unknown };
12371247
}
12381248

12391249
/* Client messages */

0 commit comments

Comments
 (0)