-
Notifications
You must be signed in to change notification settings - Fork 108
Expand file tree
/
Copy pathelicitation-defaults.ts
More file actions
324 lines (300 loc) · 10.4 KB
/
Copy pathelicitation-defaults.ts
File metadata and controls
324 lines (300 loc) · 10.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
/**
* SEP-1034: Elicitation default values test scenarios for MCP servers
*/
import {
ClientScenario,
ConformanceCheck,
DRAFT_PROTOCOL_VERSION
} from '../../types';
import type { RunContext } from '../../connection';
import { connectToServer } from '../../connection/sdk-client';
import { ElicitRequestSchema } from '@modelcontextprotocol/sdk/types.js';
export class ElicitationDefaultsScenario implements ClientScenario {
name = 'elicitation-sep1034-defaults';
readonly source = {
introducedIn: '2025-11-25',
removedIn: DRAFT_PROTOCOL_VERSION
} as const;
description = `Test elicitation with default values for all primitive types (SEP-1034).
**Server Implementation Requirements:**
Implement a tool named \`test_elicitation_sep1034_defaults\` (no arguments) that requests \`elicitation/create\` from the client with a schema containing default values for all primitive types:
- \`name\` (string): default "John Doe"
- \`age\` (integer): default 30
- \`score\` (number): default 95.5
- \`status\` (string enum: ["active", "inactive", "pending"]): default "active"
- \`verified\` (boolean): default true
**Returns**: Text content with the elicitation result
\`\`\`json
{
"content": [
{
"type": "text",
"text": "Elicitation completed: action=<accept/decline/cancel>, content={...}"
}
]
}
\`\`\``;
async run(ctx: RunContext): Promise<ConformanceCheck[]> {
const { serverUrl } = ctx;
const checks: ConformanceCheck[] = [];
try {
const connection = await connectToServer(serverUrl, {}, ctx.specVersion);
let capturedRequest: any = null;
connection.client.setRequestHandler(
ElicitRequestSchema,
async (request) => {
capturedRequest = request;
return {
action: 'accept',
content: {
name: 'Jane Smith',
age: 25,
score: 88.0,
status: 'inactive',
verified: false
}
};
}
);
await connection.client.callTool({
name: 'test_elicitation_sep1034_defaults',
arguments: {}
});
// Validate that elicitation was requested
if (!capturedRequest) {
checks.push({
id: 'elicitation-sep1034-general',
name: 'ElicitationSEP1034General',
description: 'Server requests elicitation with default values',
status: 'FAILURE',
timestamp: new Date().toISOString(),
errorMessage: 'Server did not request elicitation from client',
specReferences: [
{
id: 'SEP-1034',
url: 'https://github.com/modelcontextprotocol/modelcontextprotocol/issues/1034'
}
]
});
await connection.close();
return checks;
}
const schema = capturedRequest.params?.requestedSchema;
const properties = schema?.properties;
// Validate string default
const stringErrors: string[] = [];
if (!properties?.name) {
stringErrors.push('Missing string field "name"');
} else {
if (properties.name.type !== 'string') {
stringErrors.push(
`Expected type "string", got "${properties.name.type}"`
);
}
if (!('default' in properties.name)) {
stringErrors.push('Missing default field');
} else if (properties.name.default !== 'John Doe') {
stringErrors.push(
`Expected default "John Doe", got "${properties.name.default}"`
);
}
}
checks.push({
id: 'elicitation-sep1034-string-default',
name: 'ElicitationSEP1034StringDefault',
description: 'String schema includes default value',
status: stringErrors.length === 0 ? 'SUCCESS' : 'FAILURE',
timestamp: new Date().toISOString(),
errorMessage:
stringErrors.length > 0 ? stringErrors.join('; ') : undefined,
specReferences: [
{
id: 'SEP-1034',
url: 'https://github.com/modelcontextprotocol/modelcontextprotocol/issues/1034'
}
],
details: {
field: 'name',
schema: properties?.name
}
});
// Validate integer default
const integerErrors: string[] = [];
if (!properties?.age) {
integerErrors.push('Missing integer field "age"');
} else {
if (properties.age.type !== 'integer') {
integerErrors.push(
`Expected type "integer", got "${properties.age.type}"`
);
}
if (!('default' in properties.age)) {
integerErrors.push('Missing default field');
} else if (properties.age.default !== 30) {
integerErrors.push(
`Expected default 30, got ${properties.age.default}`
);
}
}
checks.push({
id: 'elicitation-sep1034-integer-default',
name: 'ElicitationSEP1034IntegerDefault',
description: 'Integer schema includes default value',
status: integerErrors.length === 0 ? 'SUCCESS' : 'FAILURE',
timestamp: new Date().toISOString(),
errorMessage:
integerErrors.length > 0 ? integerErrors.join('; ') : undefined,
specReferences: [
{
id: 'SEP-1034',
url: 'https://github.com/modelcontextprotocol/modelcontextprotocol/issues/1034'
}
],
details: {
field: 'age',
schema: properties?.age
}
});
// Validate number default
const numberErrors: string[] = [];
if (!properties?.score) {
numberErrors.push('Missing number field "score"');
} else {
if (properties.score.type !== 'number') {
numberErrors.push(
`Expected type "number", got "${properties.score.type}"`
);
}
if (!('default' in properties.score)) {
numberErrors.push('Missing default field');
} else if (properties.score.default !== 95.5) {
numberErrors.push(
`Expected default 95.5, got ${properties.score.default}`
);
}
}
checks.push({
id: 'elicitation-sep1034-number-default',
name: 'ElicitationSEP1034NumberDefault',
description: 'Number schema includes default value',
status: numberErrors.length === 0 ? 'SUCCESS' : 'FAILURE',
timestamp: new Date().toISOString(),
errorMessage:
numberErrors.length > 0 ? numberErrors.join('; ') : undefined,
specReferences: [
{
id: 'SEP-1034',
url: 'https://github.com/modelcontextprotocol/modelcontextprotocol/issues/1034'
}
],
details: {
field: 'score',
schema: properties?.score
}
});
// Validate enum default
const enumErrors: string[] = [];
if (!properties?.status) {
enumErrors.push('Missing enum field "status"');
} else {
if (properties.status.type !== 'string') {
enumErrors.push(
`Expected type "string", got "${properties.status.type}"`
);
}
if (!properties.status.enum || !Array.isArray(properties.status.enum)) {
enumErrors.push('Missing or invalid enum array');
}
if (!('default' in properties.status)) {
enumErrors.push('Missing default field');
} else {
if (properties.status.default !== 'active') {
enumErrors.push(
`Expected default "active", got "${properties.status.default}"`
);
}
if (
properties.status.enum &&
!properties.status.enum.includes(properties.status.default)
) {
enumErrors.push(
`Default value "${properties.status.default}" is not a valid enum member`
);
}
}
}
checks.push({
id: 'elicitation-sep1034-enum-default',
name: 'ElicitationSEP1034EnumDefault',
description: 'Enum schema includes valid default value',
status: enumErrors.length === 0 ? 'SUCCESS' : 'FAILURE',
timestamp: new Date().toISOString(),
errorMessage: enumErrors.length > 0 ? enumErrors.join('; ') : undefined,
specReferences: [
{
id: 'SEP-1034',
url: 'https://github.com/modelcontextprotocol/modelcontextprotocol/issues/1034'
}
],
details: {
field: 'status',
schema: properties?.status
}
});
// Validate boolean default (regression test - already supported)
const booleanErrors: string[] = [];
if (!properties?.verified) {
booleanErrors.push('Missing boolean field "verified"');
} else {
if (properties.verified.type !== 'boolean') {
booleanErrors.push(
`Expected type "boolean", got "${properties.verified.type}"`
);
}
if (!('default' in properties.verified)) {
booleanErrors.push('Missing default field');
} else if (properties.verified.default !== true) {
booleanErrors.push(
`Expected default true, got ${properties.verified.default}`
);
}
}
checks.push({
id: 'elicitation-sep1034-boolean-default',
name: 'ElicitationSEP1034BooleanDefault',
description: 'Boolean schema includes default value',
status: booleanErrors.length === 0 ? 'SUCCESS' : 'FAILURE',
timestamp: new Date().toISOString(),
errorMessage:
booleanErrors.length > 0 ? booleanErrors.join('; ') : undefined,
specReferences: [
{
id: 'SEP-1034',
url: 'https://github.com/modelcontextprotocol/modelcontextprotocol/issues/1034'
}
],
details: {
field: 'verified',
schema: properties?.verified
}
});
await connection.close();
} catch (error) {
checks.push({
id: 'elicitation-sep1034-general',
name: 'ElicitationSEP1034General',
description: 'Server requests elicitation with default values',
status: 'FAILURE',
timestamp: new Date().toISOString(),
errorMessage: `Failed: ${error instanceof Error ? error.message : String(error)}`,
specReferences: [
{
id: 'SEP-1034',
url: 'https://github.com/modelcontextprotocol/modelcontextprotocol/issues/1034'
}
]
});
}
return checks;
}
}