On v2 (2118f14), a tool returning a model with a serialization_alias or a @computed_field advertises an outputSchema that its own structuredContent violates:
from pydantic import BaseModel, Field, computed_field
from mcp.server.mcpserver.utilities.func_metadata import func_metadata
class Out(BaseModel):
user_id: int = Field(serialization_alias="userId")
@computed_field
@property
def doubled(self) -> int:
return self.user_id * 2
def tool() -> Out:
return Out(user_id=3)
m = func_metadata(tool)
print(sorted(m.output_schema["properties"])) # ['user_id']
print(sorted(m.convert_result(Out(user_id=3)).structured_content)) # ['doubled', 'userId']
Clients that validate structuredContent against outputSchema (as the spec says they should) reject these results. camelCase serialization aliases are common for JS-facing tools, so this hits anyone using them.
I had a fix for this in #3118 (closed in the v2 cleanup) and can port it to v2 with a regression test if you'd like to assign this to me.
On v2 (
2118f14), a tool returning a model with aserialization_aliasor a@computed_fieldadvertises anoutputSchemathat its ownstructuredContentviolates:Clients that validate
structuredContentagainstoutputSchema(as the spec says they should) reject these results. camelCase serialization aliases are common for JS-facing tools, so this hits anyone using them.I had a fix for this in #3118 (closed in the v2 cleanup) and can port it to v2 with a regression test if you'd like to assign this to me.