Skip to content

fix(server): generate tool output schema in serialization mode - #3118

Closed
jayzuccarelli wants to merge 1 commit into
modelcontextprotocol:mainfrom
jayzuccarelli:fix/output-schema-serialization-mode
Closed

jayzuccarelli wants to merge 1 commit into
modelcontextprotocol:mainfrom
jayzuccarelli:fix/output-schema-serialization-mode

Conversation

@jayzuccarelli

@jayzuccarelli jayzuccarelli commented Jul 17, 2026 •

Copy link
Copy Markdown

Fixes #3100.

The tool output schema is generated with model_json_schema(), which defaults to validation mode, but structured content is serialized with model_dump(mode="json", by_alias=True) in FuncMetadata.convert_result. The two disagree for:

  • @computed_fields — present in the serialized payload, absent from the schema.
  • serialization_alias — the dumped key uses the serialization alias, but the schema advertises the validation name.

So a client validating structured content against the published outputSchema sees unexpected or misnamed properties.

Generate the output schema in serialization mode so it matches what the server actually sends. Added regression tests for the computed-field and serialization-alias cases (the existing test_structured_output_aliases only covers plain alias=, which agrees in both modes).

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 2 files

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread src/mcp/server/mcpserver/utilities/func_metadata.py Outdated
@jayzuccarelli

Copy link
Copy Markdown
Author

Checking in on this one — all green on my side. Let me know if anything's blocking.

@jayzuccarelli

Copy link
Copy Markdown
Author

Checking back on this one. Still mergeable, 30 checks green, and cubic's review points are all addressed.

It's independent of #3119: different failure mode, no overlap in the diff, so it can land on its own if that's simpler. Say the word and I'll rebase onto current main.

Computed fields and serialization aliases are part of the dumped
structured content, so the published output schema must be generated
in serialization mode or clients see keys the schema never advertised.
A directly-returned CallToolResult is normalized the same way.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013imUsuHJy6xYdvZdxgmqtF
@maxisbey

maxisbey commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

Thanks for the PR, and sorry it sat here without a proper review.

We're closing most of the open PR backlog. v2 is out and changed a lot of the SDK, so many older PRs no longer apply as written, and we're a small team that realistically doesn't have the capacity to work through the rest.

If this still matters to you on v2, the most useful thing you can do is open an issue (or comment on the existing one) with your use case and a repro. Hearing why it matters to you is what we use to decide what to prioritise.

AI Disclaimer

@maxisbey maxisbey closed this Oct 5, 2026
@maxisbey maxisbey added the missing-issue-link Auto-closed: PR needs a linked issue assigned to its author (see CONTRIBUTING.md) label Oct 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

missing-issue-link Auto-closed: PR needs a linked issue assigned to its author (see CONTRIBUTING.md)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Generated output schema uses Pydantic's validation shape while structured output uses its serialization shape

2 participants