Skip to content

Commit c5c8a68

Browse files
committed
Fix Pydantic field alias consistency in structured output
Resolve inconsistency between schema and actual output when using Pydantic models with field aliases as tool return types: - Add by_alias=True parameter to model_dump() call in func_metadata.py - Add comprehensive test case to verify alias consistency - Ensure schema generation and structured output use same aliased field names Before: Schema shows "first", "second" but output uses "field_first", "field_second" After: Both schema and output consistently use aliased field names
1 parent 906ceea commit c5c8a68

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/mcp/server/fastmcp/utilities/func_metadata.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ def convert_result(self, result: Any) -> Any:
111111

112112
assert self.output_model is not None, "Output model must be set if output schema is defined"
113113
validated = self.output_model.model_validate(result)
114-
structured_content = validated.model_dump(mode="json")
114+
structured_content = validated.model_dump(mode="json", by_alias=True)
115115

116116
return (unstructured_content, structured_content)
117117

0 commit comments

Comments
 (0)