msgspec
msgspec copied to clipboard
Simplify JSON schema of Optionals
I am using msgspec to generate JSON schemas for MCP tools, and MCP clients don't recognize the descriptions of optional fields when they are embedded in an anyOf. By special-casing the Optional[...] case of Union when generating a JSON schema to not use anyOf, MCP clients are able to recognize the "description" as well as the optionality of the field.