Skip to content

Commit 37c6dbe

Browse files
author
Abhimanyu Siwach
committed
Add a restricted json schema
1 parent c608e32 commit 37c6dbe

File tree

3 files changed

+315
-63
lines changed

3 files changed

+315
-63
lines changed

docs/specification/draft/client/elicitation.mdx

Lines changed: 114 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,15 @@ their needs—the protocol itself does not mandate any specific user interac
2020
model.
2121

2222
<Warning>
23-
For trust & safety and security, there **SHOULD** always
24-
be a human in the loop with the ability to deny elicitation requests.
23+
For trust & safety and security:
24+
25+
- Servers **MUST NOT** use elicitation to request sensitive information.
2526

2627
Applications **SHOULD**:
2728

2829
- Provide UI that makes it clear which server is requesting information
2930
- Allow users to review and modify their responses before sending
30-
- Respect user privacy and provide clear cancel options
31+
- Respect user privacy and provide clear decline and cancel options
3132
</Warning>
3233

3334
## Capabilities
@@ -82,6 +83,7 @@ To request information from a user, servers send an `elicitation/create` request
8283
"jsonrpc": "2.0",
8384
"id": 1,
8485
"result": {
86+
"action": "accept",
8587
"content": {
8688
"name": "octocat"
8789
}
@@ -131,6 +133,7 @@ To request information from a user, servers send an `elicitation/create` request
131133
"jsonrpc": "2.0",
132134
"id": 2,
133135
"result": {
136+
"action": "accept",
134137
"content": {
135138
"name": "Monalisa Octocat",
136139
"email": "[email protected]",
@@ -140,6 +143,30 @@ To request information from a user, servers send an `elicitation/create` request
140143
}
141144
```
142145

146+
**Decline Response Example:**
147+
148+
```json
149+
{
150+
"jsonrpc": "2.0",
151+
"id": 2,
152+
"result": {
153+
"action": "decline"
154+
}
155+
}
156+
```
157+
158+
**Cancel Response Example:**
159+
160+
```json
161+
{
162+
"jsonrpc": "2.0",
163+
"id": 2,
164+
"result": {
165+
"action": "cancel"
166+
}
167+
}
168+
```
169+
143170
## Message Flow
144171

145172
```mermaid
@@ -163,14 +190,15 @@ sequenceDiagram
163190

164191
## Request Schema
165192

166-
The `requestedSchema` 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:
193+
The `requestedSchema` field allows servers to define the structure of the expected response using a restricted subset of JSON Schema. To simplify implementation for clients, elicitation schemas are limited to flat objects with primitive properties only:
167194

168195
```json
169196
"requestedSchema": {
170197
"type": "object",
171198
"properties": {
172199
"propertyName": {
173200
"type": "string",
201+
"title": "Display Name",
174202
"description": "Description of the property"
175203
},
176204
"anotherProperty": {
@@ -183,70 +211,106 @@ The `requestedSchema` field allows servers to define the structure of the expect
183211
}
184212
```
185213

186-
The schema can include:
187-
- Property definitions with types
188-
- Required field specifications
189-
- Validation constraints (min/max values, patterns, formats)
190-
- Descriptions for UI presentation
214+
### Supported Schema Types
215+
216+
The schema is restricted to these primitive types:
217+
218+
1. **String Schema**
219+
```json
220+
{
221+
"type": "string",
222+
"title": "Display Name",
223+
"description": "Description text",
224+
"minLength": 3,
225+
"maxLength": 50,
226+
"pattern": "^[A-Za-z]+$",
227+
"format": "email"
228+
}
229+
```
230+
Supported formats: `email`, `uri`, `date`, `date-time`
231+
232+
2. **Number Schema**
233+
```json
234+
{
235+
"type": "number", // or "integer"
236+
"title": "Display Name",
237+
"description": "Description text",
238+
"minimum": 0,
239+
"maximum": 100
240+
}
241+
```
242+
243+
3. **Boolean Schema**
244+
```json
245+
{
246+
"type": "boolean",
247+
"title": "Display Name",
248+
"description": "Description text",
249+
"default": false
250+
}
251+
```
252+
253+
4. **Enum Schema**
254+
```json
255+
{
256+
"type": "string",
257+
"title": "Display Name",
258+
"description": "Description text",
259+
"enum": ["option1", "option2", "option3"],
260+
"enumNames": ["Option 1", "Option 2", "Option 3"]
261+
}
262+
```
191263

192264
Clients can use this schema to:
193265
1. Generate appropriate input forms
194266
2. Validate user input before sending
195267
3. Provide better guidance to users
196268

197-
## Response Content
269+
Note that complex nested structures, arrays of objects, and other advanced JSON Schema features are intentionally not supported to simplify client implementation.
198270

199-
Responses to elicitation requests contain a content object with key-value pairs:
271+
## Response Actions
200272

201-
```json
202-
"content": {
203-
"propertyName": "value",
204-
"anotherProperty": 42
205-
}
206-
```
207-
208-
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.
209-
210-
## Error Handling
211-
212-
Clients **SHOULD** return standard JSON-RPC errors for common failure cases:
213-
214-
Example when the user cancels:
273+
Elicitation responses use a three-action model to clearly distinguish between different user actions:
215274

216275
```json
217276
{
218277
"jsonrpc": "2.0",
219278
"id": 1,
220-
"error": {
221-
"code": -1,
222-
"message": "User rejected the elicitation request"
279+
"result": {
280+
"action": "accept", // or "decline" or "cancel"
281+
"content": {
282+
"propertyName": "value",
283+
"anotherProperty": 42
284+
}
223285
}
224286
}
225287
```
226288

227-
Example when validation fails:
289+
The three response actions are:
228290

229-
```json
230-
{
231-
"jsonrpc": "2.0",
232-
"id": 1,
233-
"error": {
234-
"code": -32602,
235-
"message": "Invalid parameters",
236-
"data": {
237-
"validationErrors": {
238-
"email": "Invalid email format"
239-
}
240-
}
241-
}
242-
}
243-
```
291+
1. **Accept** (`action: "accept"`): User explicitly approved and submitted the form with data
292+
- The `content` field contains the submitted data matching the requested schema
293+
- Example: User clicked "Submit", "OK", "Confirm", etc.
294+
295+
2. **Decline** (`action: "decline"`): User explicitly rejected the request
296+
- The `content` field is typically omitted
297+
- Example: User clicked "Decline", "Reject", "No", etc.
298+
299+
3. **Cancel** (`action: "cancel"`): User dismissed without making an explicit choice
300+
- The `content` field is typically omitted
301+
- Example: User closed the dialog, clicked outside, pressed Escape, etc.
302+
303+
Servers should handle each state appropriately:
304+
- **Accept**: Process the submitted data
305+
- **Decline**: Handle explicit rejection (e.g., offer alternatives)
306+
- **Cancel**: Handle dismissal (e.g., prompt again later)
244307

245308
## Security Considerations
246309

247-
1. Clients **SHOULD** implement user approval controls
248-
2. Both parties **SHOULD** validate elicitation content against the provided schema
249-
3. Clients **SHOULD** provide clear indication of which server is requesting information
250-
4. Clients **SHOULD** allow users to reject elicitation requests at any time
251-
5. Clients **SHOULD** implement rate limiting
252-
6. Both parties **MUST** handle sensitive data appropriately
310+
1. Servers **MUST NOT** request sensitive information through elicitation
311+
2. Clients **SHOULD** implement user approval controls
312+
3. Both parties **SHOULD** validate elicitation content against the provided schema
313+
4. Clients **SHOULD** provide clear indication of which server is requesting information
314+
5. Clients **SHOULD** allow users to reject elicitation requests at any time
315+
6. Clients **SHOULD** implement rate limiting
316+
7. Clients **SHOULD** present elicitation requests in a way that makes it clear what information is being requested and why

0 commit comments

Comments
 (0)