feat: Add output schema generation for tools and update documentation #757
+1,321
−14
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.
Output Schema Support with Semantic Metadata Enhancement
This PR adds automatic JSON Schema generation for tool return types with intelligent semantic metadata enhancement, enabling LLMs and client applications to understand both the structure and semantic meaning of data they'll receive from tools.
Motivation and Context
Implementation Details
Core Schema Enhancement System
python-sdk/src/mcp/server/fastmcp/utilities/schema.py
detect_semantic_format()
: Analyzes field names and types to detect semantic meaningenhance_output_schema()
: Embeds semantic metadata within JSON Schema propertiesSupported Semantic Types
email
,url
(including uri, link, href variations)datetime
with subtypes (date_only
,time_only
,datetime
)audio
,video
,image
with format detection (audio_file
,video_file
,image_file
)file_path
,identifier
(id, uuid, guid),status
,color
currency
,percentage
(validated for numeric types only)Automatic Integration
tools/base.py
viaTool.from_function()
How Has This Been Tested?
Comprehensive Test Suite (29 Total Tests)
test_schema_utilities.py
): 21 tests covering all semantic detection scenariostest_tool_manager.py
): 8 tests inTestOutputSchema
classSchema Enhancement Examples
Before and After Transformations
Client Application Benefits
Breaking Changes
Types of changes
Checklist
Additional Context and Implementation Notes
Core Architecture
Design Decisions
Performance Considerations
Future Extensibility
Fixes #754