fix: alias-normalize CallToolResult structuredContent after validate by coder058 · Pull Request #3468 · modelcontextprotocol/python-sdk · GitHub
Skip to content

fix: alias-normalize CallToolResult structuredContent after validate - #3468

Closed
coder058 wants to merge 1 commit into
modelcontextprotocol:mainfrom
coder058:fix/calltoolresult-structured-content-alias-normalize
Closed

coder058 wants to merge 1 commit into
modelcontextprotocol:mainfrom
coder058:fix/calltoolresult-structured-content-alias-normalize

Conversation

@coder058

@coder058 coder058 commented Sep 7, 2026

Copy link
Copy Markdown

Fixes #3467

Summary

FuncMetadata.convert_result validates CallToolResult.structured_content but returns the result unchanged. Plain model returns validate then model_dump/dump_python with by_alias=True, so wire keys match outputSchema. The CallToolResult path skipped that dump, so Python field names that pass validation (populate_by_name / by_name) could be emitted while outputSchema advertises aliases.

Motivation and Context

Clients validating structuredContent against the published outputSchema reject otherwise-valid tool results when aliases are used. This aligns the CallToolResult short-circuit with the plain-return path (#1073 / #1099). Distinct from #3100 / #3118 (schema generation mode).

How Has This Been Tested?

Breaking Changes

None intended. Wire output for CallToolResult tools that previously leaked Python field names will now use aliases (matching schema / plain returns).

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I am assigned to the linked issue (or it is labeled help wanted, or I'm a maintainer)
  • I have disclosed any AI assistance and can explain the change in my own words
  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

Additional context

Smallest fix: after validate_python(..., by_alias=True, by_name=True) on CallToolResult.structured_content, dump with by_alias=True and model_copy the normalized dict — same serialization as the plain-return path.

AI disclosure

This PR was prepared with AI assistance (Cursor / Grok): issue draft, repro, patch, and PR text. Changes were verified locally on current main (08a3bc8) with the new regression test and the full test_func_metadata.py file.

@chatgpt-codex-connector

Copy link
Copy Markdown

@github-actions github-actions Bot added the missing-issue-link Auto-closed: PR needs a linked issue assigned to its author (see CONTRIBUTING.md) label Sep 7, 2026
@github-actions

github-actions Bot commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

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.

CallToolResult structuredContent is not alias-normalized to match outputSchema

1 participant