Skip to content

Tool outputSchema is generated in validation mode, so serialization aliases and computed fields don't match structuredContent #3644

Description

@jayzuccarelli

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    v1Affects the v1.x maintenance linev2Affects the v2 line (2.x on main)

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions