@@ -32,119 +32,157 @@ const config = {
3232 } ,
3333} ;
3434
35- /** The form: one field of each type form-mode elicitation supports. */
36- const requestedSchema : ElicitRequestFormParams [ "requestedSchema" ] = {
37- type : "object" ,
38- properties : {
39- name : {
40- title : "String" ,
41- type : "string" ,
42- description : "Your full, legal name" ,
43- } ,
44- check : {
45- title : "Boolean" ,
46- type : "boolean" ,
47- description : "Agree to the terms and conditions" ,
48- } ,
49- firstLine : {
50- title : "String with default" ,
51- type : "string" ,
52- description : "Favorite first line of a story" ,
53- default : "It was a dark and stormy night." ,
54- } ,
55- email : {
56- title : "String with email format" ,
57- type : "string" ,
58- format : "email" ,
59- description :
60- "Your email address (will be verified, and never shared with anyone else)" ,
61- } ,
62- homepage : {
63- type : "string" ,
64- format : "uri" ,
65- title : "String with uri format" ,
66- description : "Portfolio / personal website" ,
67- } ,
68- birthdate : {
69- title : "String with date format" ,
70- type : "string" ,
71- format : "date" ,
72- description : "Your date of birth" ,
73- } ,
74- integer : {
75- title : "Integer" ,
76- type : "integer" ,
77- description :
78- "Your favorite integer (do not give us your phone number, pin, or other sensitive info)" ,
79- minimum : 1 ,
80- maximum : 100 ,
81- default : 42 ,
82- } ,
83- number : {
84- title : "Number in range 1-1000" ,
85- type : "number" ,
86- description : "Favorite number (there are no wrong answers)" ,
87- minimum : 0 ,
88- maximum : 1000 ,
89- default : 3.14 ,
90- } ,
91- untitledSingleSelectEnum : {
35+ /** The form's fields: one of each type form-mode elicitation supports. */
36+ const properties = {
37+ name : {
38+ title : "String" ,
39+ type : "string" ,
40+ description : "Your full, legal name" ,
41+ } ,
42+ check : {
43+ title : "Boolean" ,
44+ type : "boolean" ,
45+ description : "Agree to the terms and conditions" ,
46+ } ,
47+ firstLine : {
48+ title : "String with default" ,
49+ type : "string" ,
50+ description : "Favorite first line of a story" ,
51+ default : "It was a dark and stormy night." ,
52+ } ,
53+ email : {
54+ title : "String with email format" ,
55+ type : "string" ,
56+ format : "email" ,
57+ description :
58+ "Your email address (will be verified, and never shared with anyone else)" ,
59+ } ,
60+ homepage : {
61+ type : "string" ,
62+ format : "uri" ,
63+ title : "String with uri format" ,
64+ description : "Portfolio / personal website" ,
65+ } ,
66+ birthdate : {
67+ title : "String with date format" ,
68+ type : "string" ,
69+ format : "date" ,
70+ description : "Your date of birth" ,
71+ } ,
72+ integer : {
73+ title : "Integer" ,
74+ type : "integer" ,
75+ description :
76+ "Your favorite integer (do not give us your phone number, pin, or other sensitive info)" ,
77+ minimum : 1 ,
78+ maximum : 100 ,
79+ default : 42 ,
80+ } ,
81+ number : {
82+ title : "Number in range 1-1000" ,
83+ type : "number" ,
84+ description : "Favorite number (there are no wrong answers)" ,
85+ minimum : 0 ,
86+ maximum : 1000 ,
87+ default : 3.14 ,
88+ } ,
89+ untitledSingleSelectEnum : {
90+ type : "string" ,
91+ title : "Untitled Single Select Enum" ,
92+ description : "Choose your favorite friend" ,
93+ enum : [ "Monica" , "Rachel" , "Joey" , "Chandler" , "Ross" , "Phoebe" ] ,
94+ default : "Monica" ,
95+ } ,
96+ untitledMultipleSelectEnum : {
97+ type : "array" ,
98+ title : "Untitled Multiple Select Enum" ,
99+ description : "Choose your favorite instruments" ,
100+ minItems : 1 ,
101+ maxItems : 3 ,
102+ items : {
92103 type : "string" ,
93- title : "Untitled Single Select Enum" ,
94- description : "Choose your favorite friend" ,
95- enum : [ "Monica" , "Rachel" , "Joey" , "Chandler" , "Ross" , "Phoebe" ] ,
96- default : "Monica" ,
104+ enum : [ "Guitar" , "Piano" , "Violin" , "Drums" , "Bass" ] ,
97105 } ,
98- untitledMultipleSelectEnum : {
99- type : "array" ,
100- title : "Untitled Multiple Select Enum" ,
101- description : "Choose your favorite instruments" ,
102- minItems : 1 ,
103- maxItems : 3 ,
104- items : {
105- type : "string" ,
106- enum : [ "Guitar" , "Piano" , "Violin" , "Drums" , "Bass" ] ,
107- } ,
108- default : [ "Guitar" ] ,
109- } ,
110- titledSingleSelectEnum : {
111- type : "string" ,
112- title : "Titled Single Select Enum" ,
113- description : "Choose your favorite hero" ,
114- oneOf : [
115- { const : "hero-1" , title : "Superman" } ,
116- { const : "hero-2" , title : "Green Lantern" } ,
117- { const : "hero-3" , title : "Wonder Woman" } ,
106+ default : [ "Guitar" ] ,
107+ } ,
108+ titledSingleSelectEnum : {
109+ type : "string" ,
110+ title : "Titled Single Select Enum" ,
111+ description : "Choose your favorite hero" ,
112+ oneOf : [
113+ { const : "hero-1" , title : "Superman" } ,
114+ { const : "hero-2" , title : "Green Lantern" } ,
115+ { const : "hero-3" , title : "Wonder Woman" } ,
116+ ] ,
117+ default : "hero-1" ,
118+ } ,
119+ titledMultipleSelectEnum : {
120+ type : "array" ,
121+ title : "Titled Multiple Select Enum" ,
122+ description : "Choose your favorite types of fish" ,
123+ minItems : 1 ,
124+ maxItems : 3 ,
125+ items : {
126+ anyOf : [
127+ { const : "fish-1" , title : "Tuna" } ,
128+ { const : "fish-2" , title : "Salmon" } ,
129+ { const : "fish-3" , title : "Trout" } ,
118130 ] ,
119- default : "hero-1" ,
120- } ,
121- titledMultipleSelectEnum : {
122- type : "array" ,
123- title : "Titled Multiple Select Enum" ,
124- description : "Choose your favorite types of fish" ,
125- minItems : 1 ,
126- maxItems : 3 ,
127- items : {
128- anyOf : [
129- { const : "fish-1" , title : "Tuna" } ,
130- { const : "fish-2" , title : "Salmon" } ,
131- { const : "fish-3" , title : "Trout" } ,
132- ] ,
133- } ,
134- default : [ "fish-1" ] ,
135- } ,
136- legacyTitledEnum : {
137- type : "string" ,
138- title : "Legacy Titled Single Select Enum" ,
139- description : "Choose your favorite type of pet" ,
140- enum : [ "pet-1" , "pet-2" , "pet-3" , "pet-4" , "pet-5" ] ,
141- enumNames : [ "Cats" , "Dogs" , "Birds" , "Fish" , "Reptiles" ] ,
142- default : "pet-1" ,
143131 } ,
132+ default : [ "fish-1" ] ,
133+ } ,
134+ legacyTitledEnum : {
135+ type : "string" ,
136+ title : "Legacy Titled Single Select Enum" ,
137+ description : "Choose your favorite type of pet" ,
138+ enum : [ "pet-1" , "pet-2" , "pet-3" , "pet-4" , "pet-5" ] ,
139+ enumNames : [ "Cats" , "Dogs" , "Birds" , "Fish" , "Reptiles" ] ,
140+ default : "pet-1" ,
144141 } ,
142+ } satisfies ElicitRequestFormParams [ "requestedSchema" ] [ "properties" ] ;
143+
144+ /** The form, as the elicitation request carries it. */
145+ const requestedSchema : ElicitRequestFormParams [ "requestedSchema" ] = {
146+ type : "object" ,
147+ properties,
145148 required : [ "name" ] ,
146149} ;
147150
151+ /**
152+ * The label each field gets in the summary of an accepted form. Keyed by the
153+ * form's own field names, so a field added to or removed from the form fails
154+ * to compile until its label follows, and the summary cannot drift from the
155+ * form again (#5209).
156+ */
157+ const summaryLabels : Record < keyof typeof properties , string > = {
158+ name : "Name" ,
159+ check : "Agreed to terms" ,
160+ firstLine : "Favorite first line" ,
161+ email : "Email" ,
162+ homepage : "Homepage" ,
163+ birthdate : "Birthdate" ,
164+ integer : "Favorite integer" ,
165+ number : "Favorite number" ,
166+ untitledSingleSelectEnum : "Favorite friend" ,
167+ untitledMultipleSelectEnum : "Favorite instruments" ,
168+ titledSingleSelectEnum : "Favorite hero" ,
169+ titledMultipleSelectEnum : "Favorite fish" ,
170+ legacyTitledEnum : "Favorite pet" ,
171+ } ;
172+
173+ /**
174+ * One summary line per form field the user answered, in the form's order.
175+ * A field the form does not define is left out, whatever the client sent.
176+ */
177+ const summarize = ( userData : Record < string , unknown > ) : string [ ] =>
178+ ( Object . keys ( properties ) as ( keyof typeof properties ) [ ] )
179+ . filter ( ( field ) => userData [ field ] !== undefined )
180+ . map ( ( field ) => {
181+ const value = userData [ field ] ;
182+ const shown = Array . isArray ( value ) ? value . join ( ", " ) : String ( value ) ;
183+ return `- ${ summaryLabels [ field ] } : ${ shown } ` ;
184+ } ) ;
185+
148186/**
149187 * Registers the 'trigger-elicitation-request' tool.
150188 *
@@ -197,21 +235,7 @@ export const registerTriggerElicitationRequestTool = (server: McpServer) => {
197235 } ) ;
198236
199237 // Only access answer.content when action is accept
200- const userData = answer . content ;
201- const lines = [ ] ;
202- if ( userData . name ) lines . push ( `- Name: ${ userData . name } ` ) ;
203- if ( userData . check !== undefined )
204- lines . push ( `- Agreed to terms: ${ userData . check } ` ) ;
205- if ( userData . color ) lines . push ( `- Favorite Color: ${ userData . color } ` ) ;
206- if ( userData . email ) lines . push ( `- Email: ${ userData . email } ` ) ;
207- if ( userData . homepage ) lines . push ( `- Homepage: ${ userData . homepage } ` ) ;
208- if ( userData . birthdate )
209- lines . push ( `- Birthdate: ${ userData . birthdate } ` ) ;
210- if ( userData . integer !== undefined )
211- lines . push ( `- Favorite Integer: ${ userData . integer } ` ) ;
212- if ( userData . number !== undefined )
213- lines . push ( `- Favorite Number: ${ userData . number } ` ) ;
214- if ( userData . petType ) lines . push ( `- Pet Type: ${ userData . petType } ` ) ;
238+ const lines = summarize ( answer . content ) ;
215239
216240 content . push ( {
217241 type : "text" ,
0 commit comments