Title: CallToolResult structuredContent is not alias-normalized to match outputSchema · Issue #3467 · modelcontextprotocol/python-sdk · GitHub
Open Graph Title: CallToolResult structuredContent is not alias-normalized to match outputSchema · Issue #3467 · modelcontextprotocol/python-sdk
X Title: CallToolResult structuredContent is not alias-normalized to match outputSchema · Issue #3467 · modelcontextprotocol/python-sdk
Description: Initial Checks I confirm that I'm using the newest release of my line (the latest 2.x, or the latest 1.x if I'm still on v1) I confirm that I searched for my issue in https://github.com/modelcontextprotocol/python-sdk/issues before openi...
Open Graph Description: Initial Checks I confirm that I'm using the newest release of my line (the latest 2.x, or the latest 1.x if I'm still on v1) I confirm that I searched for my issue in https://github.com/modelcontex...
X Description: Initial Checks I confirm that I'm using the newest release of my line (the latest 2.x, or the latest 1.x if I'm still on v1) I confirm that I searched for my issue in https://github.com/mod...
Opengraph URL: https://github.com/modelcontextprotocol/python-sdk/issues/3467
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"CallToolResult structuredContent is not alias-normalized to match outputSchema","articleBody":"### Initial Checks\n\n- [x] I confirm that I'm using the newest release of my line (the latest 2.x, or the latest 1.x if I'm still on v1)\n- [x] I confirm that I searched for my issue in https://github.com/modelcontextprotocol/python-sdk/issues before opening this issue\n\n### Release line\n\n2.x (current stable)\n\n### Description\n\n`FuncMetadata.convert_result` treats a plain model return and a `CallToolResult` return differently for Pydantic field aliases.\n\n- Plain returns: `validate_python(..., by_alias=True, by_name=True)` then `model_dump(..., by_alias=True)` / `dump_python(..., by_alias=True)`, so `structuredContent` keys match `outputSchema`.\n- `CallToolResult` path: `validate_python(result.structured_content)` only, then returns the result **unchanged**.\n\nBecause validation accepts Python field names when `populate_by_name` / `by_name` is in play, a tool can pass validation while emitting wire keys that do **not** match the published `outputSchema` (which uses aliases). Clients that validate `structuredContent` against `outputSchema` then reject a server-produced payload.\n\nRelated but not the same as #1073 / #1099 (plain-return alias dump) or #3100 / #3118 (schema validation vs serialization mode). This is specifically the `CallToolResult` short-circuit skipping alias normalization.\n\nVerified on current `main` tip `08a3bc8eaf5bb69a6cb05ac708a86f5325977c20`.\n\nExpected: after validating `CallToolResult.structured_content`, normalize it the same way as the plain-return path (`by_alias` dump) before returning.\n\n### Example Code\n\n```python\nfrom __future__ import annotations\nimport json\nfrom typing import Annotated\n\nfrom pydantic import BaseModel, ConfigDict, Field\nfrom mcp_types import CallToolResult, TextContent\nfrom mcp.server.mcpserver.utilities.func_metadata import func_metadata\n\n\nclass AliasOut(BaseModel):\n model_config = ConfigDict(populate_by_name=True)\n field_first: str = Field(alias=\"first\")\n field_second: str = Field(alias=\"second\")\n\n\ndef plain() -> AliasOut:\n return AliasOut(field_first=\"a\", field_second=\"b\")\n\n\ndef via_call_tool_result() -> Annotated[CallToolResult, AliasOut]:\n # Python field names — accepted by validate when populate_by_name is on\n return CallToolResult(\n content=[TextContent(text=\"ok\")],\n structured_content={\"field_first\": \"a\", \"field_second\": \"b\"},\n )\n\n\nplain_meta = func_metadata(plain)\nctr_meta = func_metadata(via_call_tool_result)\n\nprint(\"outputSchema keys:\", sorted(plain_meta.output_schema[\"properties\"]))\nprint(\"plain:\", json.dumps(plain_meta.convert_result(plain()).structured_content, sort_keys=True))\nprint(\n \"CallToolResult:\",\n json.dumps(ctr_meta.convert_result(via_call_tool_result()).structured_content, sort_keys=True),\n)\n```\n\nObserved on `main` @ `08a3bc8`:\n\n```text\noutputSchema keys: ['first', 'second']\nplain: {\"first\": \"a\", \"second\": \"b\"}\nCallToolResult: {\"field_first\": \"a\", \"field_second\": \"b\"}\n```\n\n### Python & MCP Python SDK\n\n- Python: 3.12.10\n- MCP Python SDK: current `main` @ `08a3bc8eaf5bb69a6cb05ac708a86f5325977c20` (`2.1.2.dev16+08a3bc8`)\n- Pydantic: 2.12.5 (venv) / also reproduced with system 2.13.5 for imports\n\n### AI disclosure\n\nThis issue was drafted with AI assistance (Cursor / Grok). I verified the reproduction on current `main` and reviewed the `convert_result` paths in `func_metadata.py` before filing. I would like to open a fix PR for this issue.\r\n","author":{"url":"https://github.com/coder058","@type":"Person","name":"coder058"},"datePublished":"2026-09-07T12:26:33Z","url":"https://github.com/modelcontextprotocol/python-sdk/issues/3467"}
| 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:e9c3cc50-2a3c-001c-a8dd-f14126c2d9b6 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8410:229B2E:A12B9D:D6AD99:6B00E6E6 |
| html-safe-nonce | 3ea9ceaf1d4a3e8786a4cf98eec1b57a16f7fe1ec570b72fa0874f348d98bff4 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4NDEwOjIyOUIyRTpBMTJCOUQ6RDZBRDk5OjZCMDBFNkU2IiwidmlzaXRvcl9pZCI6IjQzODQwODM4NDQ4MDI4NjQ4NzAiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | b1d472e706fc72eb13511ebc650693c7a415fff0d4c7922c88689b0bef5fe004 |
| hovercard-subject-tag | issue:5374653582 |
| 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/3467/issue_layout |
| twitter:image | https://opengraph.githubassets.com/851ffd4955acaaab2542331f803656ee09c62ed565489acaf6344d690f05820e/modelcontextprotocol/python-sdk/issues/3467 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/851ffd4955acaaab2542331f803656ee09c62ed565489acaf6344d690f05820e/modelcontextprotocol/python-sdk/issues/3467 |
| og:image:alt | Initial Checks I confirm that I'm using the newest release of my line (the latest 2.x, or the latest 1.x if I'm still on v1) I confirm that I searched for my issue in https://github.com/modelcontex... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | coder058 |
| hostname | github.com |
| expected-hostname | github.com |
| None | 27088b6977484d0d3321d9a11c907c6d6637b315cfa359ef7952dbf6292f9b14 |
| 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 | 624179fb8b88d26ba5bba08894eb60a1c5a1d93d |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width