FastMCP Schema Bug: Sending null for Optional Fields Triggers Validation Error
A developer discovered a schema contradiction in FastMCP, the Python framework used to build MCP servers, where fields with None defaults are advertised as accepting null in the generated JSON schema but are rejected at runtime when null is explicitly passed. FastMCP builds its tool schemas from Pydantic models using bare type annotations, meaning a parameter like title: str = None is treated as requiring a strict string rather than an optional one. The mismatch means that omitting a field entirely works correctly, but passing the null value the schema itself advertises as the default triggers a Pydantic validation error before the function body even executes. This is particularly problematic for AI clients and LLMs that construct tool calls programmatically from the schema, as they have no way to distinguish between omitting a key and supplying its documented default. The author confirmed the bug affects all implicitly optional parameters across their server and noted the resulting error message gives callers no hint of the underlying schema inconsistency.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.

Discussion (0)
Log in to join the discussion and vote.
Log in