10000 feat: Add structured output support for tool functions #993
+2,287
−53
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Adds support for structured output in FastMCP tools, allowing tool functions to return well-typed, validated data that clients can easily process.
Key Changes
structured_output
parameter to@mcp.tool
decorator.structured_output=True
triggers structured output support:outputSchema
is generated from modelstructuredContent
results are validated on the server before sendingdict[str, ...]
are used asstructuredContent
and automatically replicated incontent
block for BC (note: FastMCP delegates to lowlevel server, so includes this support)structuredContent
results against tooloutputSchema
examples/fastmcp/weather_structured.py
showing various return type optionsSupported return types
@mcp.tool(structured_output=True)
supports the following function return types:outputSchema
{\"result\": value}
Motivation and Context
Support structured output as defined in spec rev 2025-06-18
How Has This Been Tested?
New tests added
Breaking Changes
Types of changes
Checklist
Additional context
Many thanks to @davemssavage, who prototyped an initial version of this functionality.