Skip to content

Commit d4a8eb0

Browse files
cliffhallclaude
andcommitted
fix(everything): summarize the elicitation form's own fields
The accepted-form summary of trigger-elicitation-request read `color` and `petType`, which the form does not define, and never printed `firstLine` or the five enum fields. The summary is now derived from the form's properties, with a label map typed by the form's field names, so a field added to or removed from the form fails to compile until the summary follows. Closes #5209 Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: cliffhall <[email protected]>
1 parent 846cc6c commit d4a8eb0

3 files changed

Lines changed: 185 additions & 130 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@modelcontextprotocol/server-everything": patch
3+
---
4+
5+
`trigger-elicitation-request` now summarizes an accepted form by the fields the form actually asks for: it lists the favorite first line and the five enum fields, and no longer reports `color` or `petType`, which the form never defined.

‎src/everything/__tests__/sampling-elicitation.test.ts‎

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -336,35 +336,61 @@ describe("trigger-elicitation-request", () => {
336336
`);
337337
});
338338

339-
it("summarizes every field of an accepted form", async () => {
340-
// `color` and `petType` are not in the requested schema; the summary
341-
// still reads them if a client sends them (#4854 baseline).
339+
it("summarizes every field of an accepted form, in the form's order (#5209)", async () => {
342340
const content = {
343341
name: "Ada",
344342
check: false,
345-
color: "teal",
343+
firstLine: "Call me Ishmael.",
346344
347345
homepage: "https://example.com",
348346
birthdate: "1815-12-10",
349347
integer: 0,
350348
number: 3.5,
351-
petType: "pet-2",
349+
untitledSingleSelectEnum: "Joey",
350+
untitledMultipleSelectEnum: ["Piano", "Drums"],
351+
titledSingleSelectEnum: "hero-3",
352+
titledMultipleSelectEnum: ["fish-2"],
353+
legacyTitledEnum: "pet-2",
352354
};
353-
const { texts } = await trigger({ action: "accept", content });
355+
const { texts, asked } = await trigger({ action: "accept", content });
354356
expect(texts).toEqual([
355357
"✅ User provided the requested information!",
356358
"User inputs:\n" +
357359
"- Name: Ada\n" +
358360
"- Agreed to terms: false\n" +
359-
"- Favorite Color: teal\n" +
361+
"- Favorite first line: Call me Ishmael.\n" +
360362
"- Email: [email protected]\n" +
361363
"- Homepage: https://example.com\n" +
362364
"- Birthdate: 1815-12-10\n" +
363-
"- Favorite Integer: 0\n" +
364-
"- Favorite Number: 3.5\n" +
365-
"- Pet Type: pet-2",
365+
"- Favorite integer: 0\n" +
366+
"- Favorite number: 3.5\n" +
367+
"- Favorite friend: Joey\n" +
368+
"- Favorite instruments: Piano, Drums\n" +
369+
"- Favorite hero: hero-3\n" +
370+
"- Favorite fish: fish-2\n" +
371+
"- Favorite pet: pet-2",
366372
`\nRaw result: ${JSON.stringify({ action: "accept", content }, null, 2)}`,
367373
]);
374+
// One line per field the form asked for: the summary and the requested
375+
// schema list the same fields.
376+
const params = asked[0];
377+
expect(params && "requestedSchema" in params).toBe(true);
378+
if (params && "requestedSchema" in params) {
379+
expect(Object.keys(content)).toEqual(
380+
Object.keys(params.requestedSchema.properties),
381+
);
382+
}
383+
});
384+
385+
it("leaves out fields the form does not define (#5209)", async () => {
386+
const content = { name: "Ada", color: "teal", petType: "pet-2" };
387+
const { texts } = await trigger({ action: "accept", content });
388+
expect(texts.slice(0, 2)).toEqual([
389+
"✅ User provided the requested information!",
390+
"User inputs:\n- Name: Ada",
391+
]);
392+
// The raw result still shows what the client sent.
393+
expect(texts[2]).toContain('"color": "teal"');
368394
});
369395

370396
it("summarizes an accepted form with no fields filled", async () => {

‎src/everything/tools/trigger-elicitation-request.ts‎

Lines changed: 144 additions & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)