Title: typing.Dict[str, X] return annotation is wrapped in {"result": ...}, unlike dict[str, X] · Issue #3745 · modelcontextprotocol/python-sdk · GitHub
Open Graph Title: typing.Dict[str, X] return annotation is wrapped in {"result": ...}, unlike dict[str, X] · Issue #3745 · modelcontextprotocol/python-sdk
X Title: typing.Dict[str, X] return annotation is wrapped in {"result": ...}, unlike dict[str, X] · Issue #3745 · 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/3745
X: @github
Domain: github.com
IPv4 address: 140.82.114.3
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"typing.Dict[str, X] return annotation is wrapped in {\"result\": ...}, unlike dict[str, X]","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`-> typing.Dict[str, Any]` and `-> dict[str, Any]` are the same type, but `MCPServer` gives them different output schemas and different `structuredContent`:\n\n- `-> dict[str, Any]`: `outputSchema` is the object itself (`{\"type\": \"object\", \"additionalProperties\": true, ...}`) and the result is `{\"ok\": true}`.\n- `-> typing.Dict[str, Any]`: the result is wrapped, so `outputSchema` is `{\"properties\": {\"result\": {...}}, \"required\": [\"result\"], ...}` and the result is `{\"result\": {\"ok\": true}}`.\n\nSo modernising annotations changes what a tool returns on the wire. Ruff's UP006 (and pyupgrade) rewrite `Dict` to `dict` automatically, and that silently changed one of our tools' output shape. A client that had cached the tool's earlier output schema then rejected its results.\n\n**Expected:** both spellings behave like `dict[str, Any]` does today (and `typing.List[...]`, `typing.Tuple[...]` like their builtin forms).\n\n**Cause:** in `_create_output_model` (`src/mcp/server/mcpserver/utilities/func_metadata.py`), the generic branch is `elif isinstance(type_expr, GenericAlias):`, with `GenericAlias` from `types`. `typing.Dict[str, Any]` is a `typing._GenericAlias`, not a `types.GenericAlias`, so it skips the `origin is dict` case and falls through to the final `else`, which wraps it.\n\n**Possible fix:** test the origin instead of the alias class, e.g. `elif get_origin(type_expr) is not None:`. The other generics that reach the final `else` today (Union, Optional, Literal, ...) all have an origin other than `dict`, so they would still be wrapped as now. I'm happy to send a PR with tests if a maintainer assigns this to me.\n\nRelated, but different: #3725 is about bare `dict`/`list`/`tuple` without parameters.\n\n### Example Code\n\n```Python\nimport asyncio\nimport typing\n\nfrom mcp.server.mcpserver import MCPServer\n\nserver = MCPServer(name=\"repro\")\n\n\n@server.tool()\ndef typing_dict() -> typing.Dict[str, typing.Any]:\n return {\"ok\": True}\n\n\n@server.tool()\ndef builtin_dict() -> dict[str, typing.Any]:\n return {\"ok\": True}\n\n\nasync def main() -> None:\n tools = {tool.name: tool for tool in await server.list_tools()}\n for name in (\"typing_dict\", \"builtin_dict\"):\n result = await server.call_tool(name, {})\n print(name, tools[name].output_schema, result.structured_content)\n\n\nasyncio.run(main())\n```\n\nOutput:\n\n```\ntyping_dict {'properties': {'result': {'additionalProperties': True, 'title': 'Result', 'type': 'object'}}, 'required': ['result'], 'title': 'typing_dictOutput', 'type': 'object'} {'result': {'ok': True}}\nbuiltin_dict {'additionalProperties': True, 'title': 'builtin_dictDictOutput', 'type': 'object'} {'ok': True}\n```\n\n### Python & MCP Python SDK\n\n```Text\nPython 3.12\nmcp 2.3.0 (also on main: func_metadata.py still uses isinstance(type_expr, GenericAlias))\n```\n\nAI-assisted report.\n","author":{"url":"https://github.com/benjamin-di","@type":"Person","name":"benjamin-di"},"datePublished":"2026-10-23T08:06:03Z","url":"https://github.com/modelcontextprotocol/python-sdk/issues/3745"}
| 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:af607ffc-d20d-49cd-da2c-83b2d5eb7aac |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D806:F7F6B:398E1C:51B3B9:6B05B3A4 |
| html-safe-nonce | 32b59917e1b3daf38d9a74643273ab2e31447125b0e81d54eb8e3e17d95813a0 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEODA2OkY3RjZCOjM5OEUxQzo1MUIzQjk6NkIwNUIzQTQiLCJ2aXNpdG9yX2lkIjoiODA0NDA3MjgwMzQxNjUxOTU4OCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 515d71d5f3cd044a1e8fce090aa9b36b986b2a939a17fe42d438193bf4c7e7c6 |
| hovercard-subject-tag | issue:5994238545 |
| 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/3745/issue_layout |
| twitter:image | https://opengraph.githubassets.com/3b33e5e6a2a98608c9653b58ea2f2ac5738cc56c7135f81061f7f030171803cf/modelcontextprotocol/python-sdk/issues/3745 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/3b33e5e6a2a98608c9653b58ea2f2ac5738cc56c7135f81061f7f030171803cf/modelcontextprotocol/python-sdk/issues/3745 |
| 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 | benjamin-di |
| 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