fix: normalize null to undefined in ElicitResultSchema content field (#1204)

This commit is contained in:
Matt 2025-12-01 17:02:13 +00:00 • committed by GitHub
commit a6ee2cb3c2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1831,8 +1831,13 @@ export const ElicitResultSchema = ResultSchema.extend({
/**
* The submitted form data, only present when action is "accept".
* Contains values matching the requested schema.
* Per MCP spec, content is "typically omitted" for decline/cancel actions.
* We normalize null to undefined for leniency while maintaining type compatibility.
*/
content: z.record(z.string(), z.union([z.string(), z.number(), z.boolean(), z.array(z.string())])).optional()
content: z.preprocess(
val => (val === null ? undefined : val),
z.record(z.string(), z.union([z.string(), z.number(), z.boolean(), z.array(z.string())])).optional()
)
});
/* Autocomplete */