If the model to return by a tool is defined like:
class Foo(BaseModel):
field_first: str | None = Field(
default=None, alias="first", description="The first field."
)
field_second: str | None = Field(
default=None, alias="second", description="The second field."
)
In outputSchema of tools/list they will be displayed as "first" and "second".
At the same time model_dump in
|
structured_content = validated.model_dump(mode="json") |
will produce the dump with "field_first" and "field_second".
To keep the schema and the tool response consistent, consider adding by_alias=True to the call of model_dump.
If the model to return by a tool is defined like:
In
outputSchemaoftools/listthey will be displayed as "first" and "second".At the same time
model_dumpinpython-sdk/src/mcp/server/fastmcp/utilities/func_metadata.py
Line 114 in 6f43d1f
will produce the dump with "field_first" and "field_second".
To keep the schema and the tool response consistent, consider adding
by_alias=Trueto the call ofmodel_dump.