Title: Bare `dict` / `list` / `tuple` return annotations silently produce no structured output · Issue #3725 · modelcontextprotocol/python-sdk · GitHub
Open Graph Title: Bare `dict` / `list` / `tuple` return annotations silently produce no structured output · Issue #3725 · modelcontextprotocol/python-sdk
X Title: Bare `dict` / `list` / `tuple` return annotations silently produce no structured output · Issue #3725 · 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/3725
X: @github
Domain: github.com
IPv4 address: 140.82.112.3
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Bare `dict` / `list` / `tuple` return annotations silently produce no structured output","articleBody":"### Initial Checks\r\n\r\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)\r\n- [x] I confirm that I searched for my issue in https://github.com/modelcontextprotocol/python-sdk/issues before opening this issue\r\n\r\n### Release line\r\n\r\n2.x (current stable)\r\n\r\n### Description\r\n\r\nA tool annotated with a bare `dict` (or `list` / `tuple`) gets no `outputSchema` and no `structuredContent`. The result only arrives as JSON text. `-> dict[str, Any]` works, and `-> str` gets `{\"result\": ...}`. With `structured_output=True` the bare annotation raises `InvalidSignature: Function f: return type \u003cclass 'dict'> is not serializable for structured output`, which reads as if a dict weren't serializable.\r\n\r\n**Expected:** `-> dict` behaves like `dict[str, Any]`, and `-> list` / `-> tuple` like `list[Any]` (wrapped in `{\"result\": ...}`). Failing that, the structured-output docs could say that bare containers opt out.\r\n\r\n**Cause:** `_create_output_model` sends bare `dict` / `list` / `tuple` to the \"other class types\" case. `get_type_hints(dict)` is empty, so the model stays `None`: the silent opt-out documented for classes without type hints, which isn't obvious for builtins. We hit it while building an MCP server: our tools were `-> dict`, and our client code expected `structured_content` that was always `None`.\r\n\r\n**Proposed fix:** a case before the class fallback that sends bare `dict` down the `dict[str, ...]` path and wraps bare `list` / `tuple` like their generic forms, plus a test and one sentence in `docs/servers/structured-output.md`. It's about 10 lines of code, and the full suite passes (6206 passed). One behaviour change to weigh: existing bare `-> dict` / `-> list` tools would start publishing an `outputSchema` and validating their results.\r\n\r\nI'd like to send this as a PR if you're open to it. It's on a branch: https://github.com/g-s-jithesh/python-sdk/commit/6ecfa04ece6032816c7d3a087fd8c841cb0c43e1\r\n\r\nI used an AI coding assistant (Claude Code) to help investigate this and draft the fix. I reproduced the bug myself and reviewed the change.\r\n\r\n### Example Code\r\n\r\n```Python\r\nimport asyncio\r\nfrom typing import Any\r\n\r\nfrom mcp import Client\r\nfrom mcp.server.mcpserver import MCPServer\r\n\r\nmcp = MCPServer(\"repro\")\r\n\r\n\r\n@mcp.tool()\r\ndef bare() -> dict:\r\n return {\"id\": 1}\r\n\r\n\r\n@mcp.tool()\r\ndef typed() -> dict[str, Any]:\r\n return {\"id\": 1}\r\n\r\n\r\nasync def main() -> None:\r\n async with Client(mcp) as client:\r\n for name in (\"bare\", \"typed\"):\r\n print(name, (await client.call_tool(name, {})).structured_content)\r\n\r\n\r\nasyncio.run(main())\r\n# bare None\r\n# typed {'id': 1}\r\n```\r\n\r\n### Python & MCP Python SDK\r\n\r\n```Text\r\nPython 3.14, Windows 11; mcp 2.3.0, and main at 9f66f37 (src/mcp/server/mcpserver/utilities/func_metadata.py, _create_output_model)\r\n```\r\n","author":{"url":"https://github.com/g-s-jithesh","@type":"Person","name":"g-s-jithesh"},"datePublished":"2026-10-17T12:21:26Z","url":"https://github.com/modelcontextprotocol/python-sdk/issues/3725"}
| 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:300e5f34-aa8d-c8ab-3b2b-88074ebb487a |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E316:2CC991:37B594:4E8CE5:6B05B3A6 |
| html-safe-nonce | c19617ddad464ce37d073ad287e13b06fb71e51950e83c5f1a0a925a6494fc71 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFMzE2OjJDQzk5MTozN0I1OTQ6NEU4Q0U1OjZCMDVCM0E2IiwidmlzaXRvcl9pZCI6IjMyMTQzNDkxNzEwMjUwOTc2MzgiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | f46cf061792e9f4d6dc1c2b54dd679ed01be5a2386597b886105b733aa953869 |
| hovercard-subject-tag | issue:5898266933 |
| 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/3725/issue_layout |
| twitter:image | https://opengraph.githubassets.com/87c70bfb6d2401655f4abaea25d7e4d377e1164ca7d908fd42c168aced9a293e/modelcontextprotocol/python-sdk/issues/3725 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/87c70bfb6d2401655f4abaea25d7e4d377e1164ca7d908fd42c168aced9a293e/modelcontextprotocol/python-sdk/issues/3725 |
| 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 | g-s-jithesh |
| hostname | github.com |
| expected-hostname | github.com |
| None | 106bb568ff143beb0075344f71b9097568f02130f2e85ac7ca2a4b82efb00b47 |
| 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 | b207ef4132553ef1428fae8ca470a518d651ce07 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width