Title: Generated output schema uses Pydantic's validation shape while structured output uses its serialization shape · Issue #3100 · modelcontextprotocol/python-sdk · GitHub
Open Graph Title: Generated output schema uses Pydantic's validation shape while structured output uses its serialization shape · Issue #3100 · modelcontextprotocol/python-sdk
X Title: Generated output schema uses Pydantic's validation shape while structured output uses its serialization shape · Issue #3100 · modelcontextprotocol/python-sdk
Description: Initial Checks I confirm that I'm using the latest version of MCP Python SDK. I confirm that I searched existing issues and pull requests before opening this issue. Description For a Pydantic return model whose validation and serializati...
Open Graph Description: Initial Checks I confirm that I'm using the latest version of MCP Python SDK. I confirm that I searched existing issues and pull requests before opening this issue. Description For a Pydantic retur...
X Description: Initial Checks I confirm that I'm using the latest version of MCP Python SDK. I confirm that I searched existing issues and pull requests before opening this issue. Description For a Pydantic r...
Opengraph URL: https://github.com/modelcontextprotocol/python-sdk/issues/3100
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Generated output schema uses Pydantic's validation shape while structured output uses its serialization shape","articleBody":"### Initial Checks\n\n- [x] I confirm that I'm using the latest version of MCP Python SDK.\n- [x] I confirm that I searched existing issues and pull requests before opening this issue.\n\n### Description\n\nFor a Pydantic return model whose validation and serialization shapes differ, the generated `outputSchema` describes the validation shape while `structuredContent` uses the serialization shape. The SDK therefore publishes an output schema that rejects its own generated structured result.\n\nThis is related to, but not a duplicate of, #1073 / #1099. That change aligned ordinary field aliases by serializing structured output with aliases. Split `validation_alias` / `serialization_alias` values still expose different validation and serialization shapes, and serialization-only fields such as `computed_field` reveal the same underlying mismatch.\n\n### Example Code\n\n```python\nfrom __future__ import annotations\n\nimport asyncio\nimport json\n\nfrom jsonschema import Draft202012Validator\nfrom pydantic import BaseModel, ConfigDict, Field, computed_field\n\ntry:\n from mcp.server.mcpserver.tools.base import Tool\nexcept ImportError: # MCP Python SDK 1.x\n from mcp.server.fastmcp.tools.base import Tool\n\n\nclass AliasOutput(BaseModel):\n model_config = ConfigDict(extra=\"forbid\", populate_by_name=True)\n value: int = Field(validation_alias=\"wireIn\", serialization_alias=\"wireOut\")\n\n\ndef alias_output() -> AliasOutput:\n return AliasOutput(value=1)\n\n\nclass ComputedOutput(BaseModel):\n model_config = ConfigDict(extra=\"forbid\")\n value: int\n\n @computed_field\n @property\n def doubled(self) -> int:\n return self.value * 2\n\n\ndef computed_output() -> ComputedOutput:\n return ComputedOutput(value=1)\n\n\nasync def check(function: object) -> None:\n tool = Tool.from_function(function)\n converted = await tool.run({}, None, convert_result=True)\n structured = converted[1] if isinstance(converted, tuple) else converted.structured_content\n errors = [\n error.message\n for error in Draft202012Validator(tool.output_schema).iter_errors(structured)\n ]\n print(function.__name__)\n print(\"schema:\", json.dumps(tool.output_schema, sort_keys=True))\n print(\"structured:\", json.dumps(structured, sort_keys=True))\n print(\"schema_errors:\", errors)\n\n\nasync def main() -> None:\n await check(alias_output)\n await check(computed_output)\n\n\nasyncio.run(main())\n```\n\nObserved validator messages:\n\n```text\nalias_output\nschema: ... \"wireIn\" ...\nstructured: {\"wireOut\": 1}\nschema_errors: [\"Additional properties are not allowed ('wireOut' was unexpected)\", \"'wireIn' is a required property\"]\n\ncomputed_output\nschema: ... \"value\" ...\nstructured: {\"doubled\": 2, \"value\": 1}\nschema_errors: [\"Additional properties are not allowed ('doubled' was unexpected)\"]\n```\n\n### Expected behavior\n\nThe generated `outputSchema` should describe the serialized structured output. Generating the output model schema in Pydantic serialization mode makes both witnesses conform: the alias schema uses `wireOut`, and the computed-field schema includes `doubled`.\n\n### Python & MCP Python SDK\n\n- Python: 3.13.13\n- MCP Python SDK: 1.28.1 (latest stable)\n- Also reproduced on current `main`: `2713b53b127afc094dc97d6067df9f69b647661c` (`2.0.0b2`)\n- Pydantic: 2.13.4\n","author":{"url":"https://github.com/destire-mio","@type":"Person","name":"destire-mio"},"datePublished":"2026-07-16T05:06:47Z","url":"https://github.com/modelcontextprotocol/python-sdk/issues/3100"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:f49f234c-c2de-c555-d9f3-16daea5e0f8a |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B2B4:2E7EBB:725DC1:922C6E:6B00E228 |
| html-safe-nonce | dc94f7337ec36401f17f23c399a0d59b666b035ba7d59606dcbd98b89e93bca8 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCMkI0OjJFN0VCQjo3MjVEQzE6OTIyQzZFOjZCMDBFMjI4IiwidmlzaXRvcl9pZCI6IjExODU4Mzg1MTgwMTA3MDAzMjgiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 6d356cc3f494743bf66dc7331cbcdbbef2540b70bd85856e1358d26f417bce6c |
| hovercard-subject-tag | issue:4898887230 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/modelcontextprotocol/python-sdk/3100/issue_layout |
| twitter:image | https://opengraph.githubassets.com/f00c669ef75c14457347f99eabf6a1dd7c05d6e42ae291bd5ebe2dc09bbfa8a9/modelcontextprotocol/python-sdk/issues/3100 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/f00c669ef75c14457347f99eabf6a1dd7c05d6e42ae291bd5ebe2dc09bbfa8a9/modelcontextprotocol/python-sdk/issues/3100 |
| og:image:alt | Initial Checks I confirm that I'm using the latest version of MCP Python SDK. I confirm that I searched existing issues and pull requests before opening this issue. Description For a Pydantic retur... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | destire-mio |
| hostname | github.com |
| expected-hostname | github.com |
| None | 043c3f30fbcbe2c6c8e729e10cbbbc90c406546f9fbbb67c648d38f6b7d16daf |
| turbo-cache-control | no-preview |
| go-import | github.com/modelcontextprotocol/python-sdk git https://github.com/modelcontextprotocol/python-sdk.git |
| octolytics-dimension-user_id | 182288589 |
| octolytics-dimension-user_login | modelcontextprotocol |
| octolytics-dimension-repository_id | 862584018 |
| octolytics-dimension-repository_nwo | modelcontextprotocol/python-sdk |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 862584018 |
| octolytics-dimension-repository_network_root_nwo | modelcontextprotocol/python-sdk |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 5425dc24e8bd8d6fca9641a12afc984825a43875 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width