|
1 | 1 | /** |
2 | 2 | * SEP-1034: Elicitation defaults test |
3 | | - * Validates that servers properly apply default values for omitted fields |
4 | | - * in elicitation responses using the elicitInput() helper |
| 3 | + * Validates that clients properly apply default values for omitted fields |
| 4 | + * in elicitation responses before sending them to the server |
5 | 5 | */ |
6 | 6 |
|
7 | 7 | import { Server } from '@modelcontextprotocol/sdk/server/index.js'; |
8 | 8 | import { StreamableHTTPServerTransport } from '@modelcontextprotocol/sdk/server/streamableHttp.js'; |
9 | 9 | import { |
10 | 10 | CallToolRequestSchema, |
11 | | - ListToolsRequestSchema |
| 11 | + ListToolsRequestSchema, |
| 12 | + ElicitResultSchema |
12 | 13 | } from '@modelcontextprotocol/sdk/types.js'; |
13 | 14 | import type { Scenario, ConformanceCheck } from '../../types.js'; |
14 | 15 | import express, { Request, Response } from 'express'; |
@@ -70,43 +71,49 @@ function createServer(checks: ConformanceCheck[]): { |
70 | 71 | if (request.params.name === 'test_client_elicitation_defaults') { |
71 | 72 | try { |
72 | 73 | // Request elicitation with all optional fields having defaults |
73 | | - // Using elicitInput() which validates and applies defaults on server side |
74 | | - const elicitResult = await server.elicitInput({ |
75 | | - message: |
76 | | - 'Test client default value handling - please accept with defaults', |
77 | | - requestedSchema: { |
78 | | - type: 'object', |
79 | | - properties: { |
80 | | - name: { |
81 | | - type: 'string', |
82 | | - description: 'User name', |
83 | | - default: 'John Doe' |
84 | | - }, |
85 | | - age: { |
86 | | - type: 'integer', |
87 | | - description: 'User age', |
88 | | - default: 30 |
89 | | - }, |
90 | | - score: { |
91 | | - type: 'number', |
92 | | - description: 'User score', |
93 | | - default: 95.5 |
94 | | - }, |
95 | | - status: { |
96 | | - type: 'string', |
97 | | - description: 'User status', |
98 | | - enum: ['active', 'inactive', 'pending'], |
99 | | - default: 'active' |
100 | | - }, |
101 | | - verified: { |
102 | | - type: 'boolean', |
103 | | - description: 'Verification status', |
104 | | - default: true |
| 74 | + // Using raw server.request() to verify client applies defaults before sending response |
| 75 | + const elicitResult = await server.request( |
| 76 | + { |
| 77 | + method: 'elicitation/create', |
| 78 | + params: { |
| 79 | + message: |
| 80 | + 'Test client default value handling - please accept with defaults', |
| 81 | + requestedSchema: { |
| 82 | + type: 'object', |
| 83 | + properties: { |
| 84 | + name: { |
| 85 | + type: 'string', |
| 86 | + description: 'User name', |
| 87 | + default: 'John Doe' |
| 88 | + }, |
| 89 | + age: { |
| 90 | + type: 'integer', |
| 91 | + description: 'User age', |
| 92 | + default: 30 |
| 93 | + }, |
| 94 | + score: { |
| 95 | + type: 'number', |
| 96 | + description: 'User score', |
| 97 | + default: 95.5 |
| 98 | + }, |
| 99 | + status: { |
| 100 | + type: 'string', |
| 101 | + description: 'User status', |
| 102 | + enum: ['active', 'inactive', 'pending'], |
| 103 | + default: 'active' |
| 104 | + }, |
| 105 | + verified: { |
| 106 | + type: 'boolean', |
| 107 | + description: 'Verification status', |
| 108 | + default: true |
| 109 | + } |
| 110 | + }, |
| 111 | + required: [] // All fields optional, so defaults should apply |
105 | 112 | } |
106 | | - }, |
107 | | - required: [] // All fields optional, so defaults should apply |
108 | | - } |
109 | | - }); |
| 113 | + } |
| 114 | + }, |
| 115 | + ElicitResultSchema |
| 116 | + ); |
110 | 117 |
|
111 | 118 | // Check if elicitation was accepted |
112 | 119 | if (elicitResult.action !== 'accept') { |
@@ -146,7 +153,7 @@ function createServer(checks: ConformanceCheck[]): { |
146 | 153 | checks.push({ |
147 | 154 | id: 'client-elicitation-sep1034-string-default', |
148 | 155 | name: 'ClientElicitationSEP1034StringDefault', |
149 | | - description: 'Server applies string default value for elicitation', |
| 156 | + description: 'Client applies string default value for elicitation', |
150 | 157 | status: stringErrors.length === 0 ? 'SUCCESS' : 'FAILURE', |
151 | 158 | timestamp: new Date().toISOString(), |
152 | 159 | errorMessage: |
@@ -177,7 +184,7 @@ function createServer(checks: ConformanceCheck[]): { |
177 | 184 | checks.push({ |
178 | 185 | id: 'client-elicitation-sep1034-integer-default', |
179 | 186 | name: 'ClientElicitationSEP1034IntegerDefault', |
180 | | - description: 'Server applies integer default value for elicitation', |
| 187 | + description: 'Client applies integer default value for elicitation', |
181 | 188 | status: integerErrors.length === 0 ? 'SUCCESS' : 'FAILURE', |
182 | 189 | timestamp: new Date().toISOString(), |
183 | 190 | errorMessage: |
@@ -210,7 +217,7 @@ function createServer(checks: ConformanceCheck[]): { |
210 | 217 | checks.push({ |
211 | 218 | id: 'client-elicitation-sep1034-number-default', |
212 | 219 | name: 'ClientElicitationSEP1034NumberDefault', |
213 | | - description: 'Server applies number default value for elicitation', |
| 220 | + description: 'Client applies number default value for elicitation', |
214 | 221 | status: numberErrors.length === 0 ? 'SUCCESS' : 'FAILURE', |
215 | 222 | timestamp: new Date().toISOString(), |
216 | 223 | errorMessage: |
@@ -249,7 +256,7 @@ function createServer(checks: ConformanceCheck[]): { |
249 | 256 | checks.push({ |
250 | 257 | id: 'client-elicitation-sep1034-enum-default', |
251 | 258 | name: 'ClientElicitationSEP1034EnumDefault', |
252 | | - description: 'Server applies enum default value for elicitation', |
| 259 | + description: 'Client applies enum default value for elicitation', |
253 | 260 | status: enumErrors.length === 0 ? 'SUCCESS' : 'FAILURE', |
254 | 261 | timestamp: new Date().toISOString(), |
255 | 262 | errorMessage: |
@@ -282,7 +289,7 @@ function createServer(checks: ConformanceCheck[]): { |
282 | 289 | checks.push({ |
283 | 290 | id: 'client-elicitation-sep1034-boolean-default', |
284 | 291 | name: 'ClientElicitationSEP1034BooleanDefault', |
285 | | - description: 'Server applies boolean default value for elicitation', |
| 292 | + description: 'Client applies boolean default value for elicitation', |
286 | 293 | status: booleanErrors.length === 0 ? 'SUCCESS' : 'FAILURE', |
287 | 294 | timestamp: new Date().toISOString(), |
288 | 295 | errorMessage: |
@@ -468,7 +475,7 @@ function createServer(checks: ConformanceCheck[]): { |
468 | 475 | export class ElicitationClientDefaultsScenario implements Scenario { |
469 | 476 | name = 'elicitation-sep1034-client-defaults'; |
470 | 477 | description = |
471 | | - 'Tests server applies default values for omitted elicitation fields (SEP-1034)'; |
| 478 | + 'Tests client applies default values for omitted elicitation fields (SEP-1034)'; |
472 | 479 | private app: express.Application | null = null; |
473 | 480 | private httpServer: any = null; |
474 | 481 | private checks: ConformanceCheck[] = []; |
|
0 commit comments